117 lines
3.9 KiB
HTML
117 lines
3.9 KiB
HTML
|
<html>
|
||
|
<head>
|
||
|
<!-- This file has been generated by unroff 1.0, 03/21/96 19:29:45. -->
|
||
|
<!-- Do not edit! -->
|
||
|
<link rev="made" href="mailto:net@informatik.uni-bremen.de">
|
||
|
<title>unroff Programmer's Manual, section 10.</title>
|
||
|
</head><body>
|
||
|
<h2><a name="section10">10.</a> <tt> </tt>Input and Output Primitives
|
||
|
</h2>
|
||
|
<p>
|
||
|
 <tt> </tt> <tt> </tt> <tt> </tt><i>unroff
|
||
|
</i>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).<tt> </tt>
|
||
|
<h2>
|
||
|
(emit <i>.</i> <i>args</i>)
|
||
|
</h2>
|
||
|
<p>
|
||
|
 <tt> </tt> <tt> </tt> <tt> </tt><i>emit
|
||
|
</i>is the only stream-based output primitive.<tt> </tt>
|
||
|
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).<tt> </tt>
|
||
|
<i>emit
|
||
|
</i>is primarily used in situations where text has to
|
||
|
be output without rescanning it and without applying any
|
||
|
character translations.<tt> </tt>
|
||
|
It is also used from within the event procedures that are called
|
||
|
for their side-effects, for example, by the
|
||
|
<i>prolog
|
||
|
</i>and
|
||
|
<i>epilog
|
||
|
</i>event procedures to generate a header and trailer for each
|
||
|
output file.<tt> </tt>
|
||
|
The primitive returns the empty symbol so that it can be called
|
||
|
as the last form in an event procedure whose result is used.<tt> </tt>
|
||
|
<p>
|
||
|
 <tt> </tt> <tt> </tt> <tt> </tt>Example:
|
||
|
the new troff request for transparent output, as explained in the
|
||
|
<a href="./unroff.1.html">manual page</a>
|
||
|
<i>unroff</i>(1),
|
||
|
can be implement like this:
|
||
|
<dl><dt><dd>
|
||
|
<pre>
|
||
|
(defrequest '>>
|
||
|
(lambda (>> code)
|
||
|
(emit code #\newline)))
|
||
|
</pre>
|
||
|
</dl>
|
||
|
<h2>
|
||
|
(read-line)
|
||
|
</h2>
|
||
|
<p>
|
||
|
 <tt> </tt> <tt> </tt> <tt> </tt>This primitive reads the next input line from the current input
|
||
|
stream and returns it as a string.<tt> </tt>
|
||
|
An error is signaled if the current input stream has been bound
|
||
|
to #f, which is the case, for example, when
|
||
|
<i>unroff
|
||
|
</i>has been called with the option
|
||
|
<b>-t
|
||
|
</b>to start an interactive top level.<tt> </tt>
|
||
|
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.<tt> </tt>
|
||
|
Thus,
|
||
|
<i>read-line
|
||
|
</i>always returns at least a string containing a newline character.<tt> </tt>
|
||
|
<h2>
|
||
|
(read-line-expand)
|
||
|
</h2>
|
||
|
<p>
|
||
|
 <tt> </tt> <tt> </tt> <tt> </tt>This primitive is nothing more than an optimization for
|
||
|
<dl><dt><dd>
|
||
|
<pre>
|
||
|
(parse-expand (read-line))
|
||
|
</pre>
|
||
|
</dl>
|
||
|
which has been provided to speed up frequently used functions like
|
||
|
macro expansion.<tt> </tt>
|
||
|
<h2>
|
||
|
(unread-line <i>string</i>)
|
||
|
</h2>
|
||
|
<p>
|
||
|
 <tt> </tt> <tt> </tt> <tt> </tt>This primitive pushes back an input line to the current input
|
||
|
stream, which will then be returned by the next call to
|
||
|
<i>read-line
|
||
|
</i>or
|
||
|
<i>read-line-expand</i>,
|
||
|
or it will be read by the parser in the normal way when processing
|
||
|
the current input file.<tt> </tt>
|
||
|
<i>string
|
||
|
</i>need not have a terminating newline.<tt> </tt>
|
||
|
Strings pushed back by multiple calls to
|
||
|
<i>unread-line
|
||
|
</i>are coalesced and returned as a whole by the next input operation.<tt> </tt>
|
||
|
<h2>
|
||
|
(error-port)
|
||
|
</h2>
|
||
|
<p>
|
||
|
 <tt> </tt> <tt> </tt> <tt> </tt>Returns a Scheme output port that is bound to the program's
|
||
|
standard error output.<tt> </tt>
|
||
|
This primitive is used by the default Scheme error handler provided
|
||
|
by
|
||
|
<i>unroff
|
||
|
</i>and by the
|
||
|
<i>warn
|
||
|
</i>utility function<a href="m-notes.html#footnote4">[note 4]</a>
|
||
|
.<tt> </tt>
|
||
|
Note that
|
||
|
<i>error-port
|
||
|
</i>returns an ordinary Scheme port, not a stream.<tt> </tt>
|
||
|
<p><hr>
|
||
|
Markup created by <em>unroff</em> 1.0, <tt> </tt> <tt> </tt>March 21, 1996, <tt> </tt> <tt> </tt>net@informatik.uni-bremen.de</body>
|
||
|
</html>
|