Oppolzer - Informatik / Stanford Pascal Compiler


Home       Lebenslauf       Schwerpunkte       Kenntnisse       Seminare       Kunden       Projekte       Produkte       Blog       Stanford Pascal       Kontakt

The Stanford Pascal Compiler / Evolution Steps

Back to Compiler main page

Terminal flag in the Pascal FCB - effects on I/O functions

Compiler version: 05.2017

I had some problems with terminal I/O (especially input) on CMS and Windows. The "normal" behaviour of the READ and READLN procedures doesn't go well with the needs of terminal I/O.

The Pascal FCB (File Control Block) now contains a Terminal flag, which is set on the mainframe (CMS) by use of the TERMIN and TERMOUT function (TSO support still has to be done). TERMIN and TERMOUT also do FILEDEF xxxx TERM on the Pascal TEXT file, which is specified as the argument.

On the other platforms (Non-mainframe), the Terminal flag is set by TERMIN and TERMOUT, too, or by assigning *stdin* or *stdout* to Pascal TEXT files; it is also set implicitly for INPUT and OUTPUT, if there are no external filenames assigned to them using environment variables.

The terminal flag affects some I/O functions:

- RESET on input files does not read the first input buffer (if it would, a line of input would be requested from the user already at RESET time)

- READLN does not read a new input buffer, instead it flushes (ignores) the rest of the existing buffer and schedules a new buffer input for the next READ operation (very important)

- READ of characters does not implicitly read a new input buffer at EOLN; instead the program is required to explicitly READLN at EOLN, so that the next READ of char will read a new input buffer (this way the user gets more control about when an input buffer will be requested from the terminal user)

- READ of integers, reals and boolean still reads until the next nonblank character, and, if needed, these functions even schedule buffer input; this was done for compatibility reasons, because many existing programs expect sequences of WRITELN / READ / WRITELN / READ (involving integers or reals) to work

- maybe there will be (for example) additional READ integer functions in the future, which have a maximum field width, e.g. READ (I : 8); in this case, a maximum of 8 chars would be read and no buffer input would ever occur, even if EOLN would be reached - this would not depend on the Terminal flag at all

Caution: these changes only affect Terminal files, normal File I/O is not affected.

For example: program TESTCEIN.PAS


program TESTCEIN ( OUTPUT ) ; var C : CHAR ; procedure WAIT ; (**********************************) (* WARTET DARAUF, DASS EINE *) (* EINGABE ERFOLGT. *) (**********************************) var I : INTEGER ; C : CHAR ; begin (* WAIT *) WRITELN ( 'Start Funktion Wait' ) ; READLN ; WRITELN ( 'Ende Funktion Wait' ) ; end (* WAIT *) ; procedure READY ; (************************************) (* READY-MELDUNG, DIE QUITTIERT *) (* WERDEN MUSS. *) (************************************) begin (* READY *) WRITELN ; WRITELN ( 'FUNKTION AUSGEFUEHRT (ENTER DRUECKEN)' ) ; WAIT end (* READY *) ; begin (* HAUPTPROGRAMM *) if TRUE then begin TERMIN ( INPUT ) ; TERMOUT ( OUTPUT ) end (* then *) ; CLRSCRN ; WRITELN ( 'lesen bis zum dollarzeichen ...' ) ; WRITELN ( 'erst mal initialisierung ...' ) ; WRITELN ( 'start einleseschleife ...' ) ; RESET ( INPUT ) ; repeat READ ( C ) ; WRITELN ( 'gelesen: <' , C , '> ord = ' , ORD ( C ) : 3 ) ; if EOLN then begin WRITELN ( '*eoln*' ) ; READLN ; WRITELN ( 'readln ausgefuehrt' ) ; if EOF then WRITELN ( '*eof*' ) ; end (* then *) until ( C = '$' ) or EOF ; end (* HAUPTPROGRAMM *) .

Back to Compiler main page