(* Illustrate the use of a FILE OF CHAR to obtain character at a time
input from the console (instead of line-editing).
Note that TEXT files are line-edited, so that INPUT, the "standard"
input file, since it is a TEXT file, will use line-editing for input. *)

(* Using Pascal I/O to interact with a console device is a little
tricky... Pascal-86 has taken the approach of Lazy I/O, as outlined
in chapter 8 of the manual (see discussion of RESET) *)

PROGRAM ECHO(INCHAR, OUTPUT);

       (* FILE OF CHAR is NOT line-edited: the run-time system
          uses the DQ$SPECIAL routine to indicate that transparent
          input is desired. (TEXT files use line-edited input). *)
   VAR INCHAR: FILE OF CHAR;
       CH: CHAR;

BEGIN

   (*  RESET and GET are defined to read in a character to the buffer
      (before the prompt is written). But, Lazy I/O delays the actual
      read until the buffer variable (INCHAR^) is referenced in the
      middle of the loop.   *)
   RESET(INCHAR, ':CI:');
   REPEAT
     WRITE('TYPE A CHAR: ');
     (* Be sure to copy the character from the input buffer
        ("Filled" by RESET and GET) before doing another GET. *)
     CH := INCHAR^;
     GET(INCHAR); (* WON'T actually do a READ until INCHAR^ is referenced
                     the next time around the loop. *)
     WRITELN('YOU TYPED A: ', CH);
     UNTIL CH = ' ';
END.
