1 08/04/86 Multics Pascal Terminal I/O
  2 
  3 Terminal I/O is usually performed over three predefined file
  4 variables, although other file variables can be attached to the
  5 terminal by means of the io_call command or the nonstandard "fconnect"
  6 statement (see the Multics Pascal User's Guide).
  7 
  8 The three predefined file variables are named "input", "output", and
  9 "error".  A program that uses any of these must include its name in
 10 the parameter list of the program header.  These file variables are
 11 not, however, to be declared in the "var" section of the main program.
 12 Default attachments are:
 13 
 14           Pascal file name    I/O switch name     Attachment
 15           ----------------    ---------------     ----------
 16           input               pascal_input_       syn_ user_input
 17           output              pascal_output_      syn_ user_output
 18           error               pascal_error_       syn_ error_output
 19 
 20 All three files are, by default, open at the beginning of program
 21 execution: reset(input), rewrite(output), rewrite(error).
 22 
 23 The "error" file is an extension to standard Pascal. Its use requires
 24 compilation with the default -full_extensions (-full) control argument.
 25 
 26 
 27 Performing I/O: Input and output on the terminal are done using the
 28 standard Pascal I/O statements.  Examples of their use with the
 29 predefined file variables "input", "output", and "error" are given
 30 here:
 31 
 32 
 33 get (input);
 34    read a character into the file variable input^.
 35 read (var_name1 {, ..., var_nameN})
 36    read variable values from "input".
 37 readln (var_name1 {, ..., var_nameN})
 38    read variable values from "input" and position to a new line.
 39 write (expression1 {, ..., expressionN})
 40    write expression values into a buffer to be printed on "output"
 41    with the next writeln to "output"
 42 write (error, expression1 {, ..., expressionN})
 43    write expression values into a buffer to be printed on "error"
 44    with the next writeln to "error".
 45 
 46 
 47 writeln (expression1 {, ..., expressionN})
 48    print on "output" any output buffered for "output" followed by
 49    the expression values followed by a newline character.
 50 writeln (error, expression1 {, ..., expressionN})
 51    print on "error" any output buffered for "error" followed by
 52    the expression values followed by a newline character.
 53 
 54 
 55 The following added statement is a Multics SOL extension:
 56 flush (file_name);   (Pascal 8.02 extension. see NOTE (*) below)
 57    prints the contents of the output buffer for file_name (for example,
 58    for "output" or "error"), which contains the results of any
 59    previous "write" operations, without printing a newline. This
 60    statement is useful for interactive applications, as in:
 61 
 62           write ('Enter a number: ');
 63           flush (output);
 64           readln (number);  {reads on the same line as the question}
 65 
 66 
 67     (*) NOTE : This extension was useful with Pascal 8.02.  Since 8.03
 68     version, "flush" is implicit when file is attached through an IO
 69     module other than "vfile_".  So, it is no more mandatory for
 70     interactive applications.
 71    (see "pascal.changes.gi.info")
 72 
 73 
 74 Prompting:
 75 Characters read by "get" and variable values read by "read" and
 76 "readln" are each prompted for by either the standard Pascal prompt
 77 character "?" or whatever character has been set by the
 78 pascal_set_prompt command. This command can turn prompting off
 79 entirely with the -no_prompt control argument.
 80 
 81 See "Interactive mode" below for a further discussion of prompting.
 82 
 83 
 84 Interactive mode: Pascal compiler provides "-interactive" and
 85 "-no_interactive" arguments.  "-interactive" is the default.
 86 Following describes what is interactive and non interactive mode.
 87 
 88 
 89 Non-interactive mode:
 90 Since the "input" file variable is implicitly reset (opened) at the
 91 start of the program in which it appears as a parameter, the user is
 92 prompted for the first input character when the program begins
 93 executing. This is done so that "input^", "eof", and "eoln" will have
 94 values. Prompting is also done by "readln" to get the first character
 95 of a new line of input. These automatic prompts are undesirable,
 96 however, in the case of a program that prompts explicitly:
 97 
 98      program square_root (input, output);
 99 
100        var number integer;
101 
102        begin        {implicit reset(input), rewrite(output)}
103          write ('Give me an integer: ');
104          readln (number);
105          writeln ('The square root is ', sqrt (number));
106      END.
107 
108 When compiled with "-nint" control argument, this program produces the
109 following scenario:
110 
111           square_root
112           ?         (first character requested by "reset")
113           Give me an integer: ?2
114           ?         (first character of new line requested by "readln")
115           The square root is: 1.4142356237309505E+00
116 
117 
118 Interactive mode provides a way of suppressing the extra prompts.
119 When a program is compiled with the "-interactive" control argument
120 (default), prompts on a file are deferred until the first actual
121 reference to the file (get, read, readln, or reference to file_name^,
122 eoln, or eof).  Therefore when compiled in the default manner, the
123 same program operates as follows:
124 
125           square_root
126           Give me an integer: ?2
127           The square root is 1.4142356237309505E+00
128 
129   These compilation arguments have been provided because generated
130 code for interactive mode is less efficient.  So, if your application
131 does not interact with user terminal IO, use the -no_interactive
132 argument.