10.  Input and Output Primitives

      unroff provides one new input primitive and one new output primitive that work with the current input stream and current output stream (and a third primitive which is just an optimization of the latter, as well as a few auxiliary functions).

(emit . args)

      emit is the only stream-based output primitive. It receives any number of strings, symbols, and characters, concatenates its arguments, and sends the resulting string to the current output stream (to standard output if the the current output stream has been assigned #f). emit is primarily used in situations where text has to be output without rescanning it and without applying any character translations. It is also used from within the event procedures that are called for their side-effects, for example, by the prolog and epilog event procedures to generate a header and trailer for each output file. The primitive returns the empty symbol so that it can be called as the last form in an event procedure whose result is used.

      Example: the new troff request for transparent output, as explained in the manual page unroff(1), can be implement like this:

(defrequest '>>
  (lambda (>> code)
    (emit code #\newline)))

(read-line)

      This primitive reads the next input line from the current input stream and returns it as a string. An error is signaled if the current input stream has been bound to #f, which is the case, for example, when unroff has been called with the option -t to start an interactive top level. If an incomplete last line (i.e. a line without a terminating newline) is returned by the target pointed to by the current input stream, a newline is appended. Thus, read-line always returns at least a string containing a newline character.

(read-line-expand)

      This primitive is nothing more than an optimization for

(parse-expand (read-line))
which has been provided to speed up frequently used functions like macro expansion.

(unread-line string)

      This primitive pushes back an input line to the current input stream, which will then be returned by the next call to read-line or read-line-expand, or it will be read by the parser in the normal way when processing the current input file. string need not have a terminating newline. Strings pushed back by multiple calls to unread-line are coalesced and returned as a whole by the next input operation.

(error-port)

      Returns a Scheme output port that is bound to the program's standard error output. This primitive is used by the default Scheme error handler provided by unroff and by the warn utility function[note 4] . Note that error-port returns an ordinary Scheme port, not a stream.


Markup created by unroff 1.0,    March 21, 1996,    net@informatik.uni-bremen.de