Default Streams

Each of the I/O functions listed here has as its first argument the name of a stream that is read or written to. Each of these functions also has a default stream that is used if you omit the name of a specific stream. The default input stream (for LINEIN and CHARIN functions) is the terminal input buffer or user input if the terminal buffer is empty. The default output stream is your terminal.

This means that you can use the LINEIN function to pause processing and read a line entered at the keyboard, as you can with the PARSE PULL instruction. But note these differences:
  • Unlike PARSE PULL, the LINEIN function reads only keyboard entries, regardless of whether there are outstanding items on the default data queue.
  • LINEIN would cause a VM READ if no string is available in the default input stream.
To understand how this works, use the first file-reading program, SHOLIN2 EXEC (see Figure 1) and add an instruction as shown in Figure 1.
Figure 1. SHOLIN3 EXEC
/* SHOLIN3 EXEC                                 */
/* Displays a file one line at a time           */
/* as you press Enter; program                  */
/* ends when the end-of-file is reached         */
/* OR if user types any character.              */
say "Type a file name and file type"
pull fileid
lineno= 1
do until LINES(fileid) = 0
   say lineno LINEIN(fileid)
   if LINEIN() \= "" then leave    /* waits for user to press Enter  */
                                   /* if anything else is typed      */
                                   /* (if LINEIN() does not return   */
                                   /* an empty string), then the     */
                                   /* loop (and the program) ends    */
   lineno = lineno + 1
   end
exit
Or, you could modify the cycling version of this program, SHOLIN1 EXEC (see Figure 1) to let you choose the number of lines to display. To do this, put the display routine inside a DO FOREVER loop, as shown in Figure 2.
Figure 2. SHOLIN4 EXEC
/* SHOLIN4 EXEC                         */
/* Displays a file one line at a time   */
/* as you press Enter, or               */
/* displays a given number of lines.    */
/* Cycles back to the beginning of the  */
/* file when the end-of-file is reached */
/* Program ends only when user types    */
/* any non-numeric character.           */
say "Type a file name and file type"
pull fileid
say "Type a number of lines to display"
say "or press Enter to advance one line"
say "Type any other character to end."
lineno = 1
do forever
   howmany = LINEIN()                 /* pause for user entry and store */
                                      /* it in the variable HOWMANY     */

   if howmany = "" then howmany = 1   /* pressing Enter                 */
                                      /* is the same as entering '1'    */

   if \datatype(howmany,n) then leave /* entering any non-numeric       */
                                      /* character ends the program     */

   do howmany
      say lineno LINEIN(fileid)
      lineno = lineno + 1

      if LINES(fileid) = 0 then
        do
           call LINEIN fileid,1,0
           say ">>> End of File <<<"
           lineno = 1
           end
      end

   end
exit