| 1 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2 |
% |
| 3 |
% Module: ZzTeX I/O Facilities |
| 4 |
% |
| 5 |
% Synopsis: |
| 6 |
% |
| 7 |
% Author: Paul C. Anagnostopoulos |
| 8 |
% Created: 9 September 1989 |
| 9 |
% |
| 10 |
% Copyright 1989--2020 by Paul C. Anagnostopoulos |
| 11 |
% under The MIT License (opensource.org/licenses/MIT) |
| 12 |
% |
| 13 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 14 |
|
| 15 |
% Terminal & Log I/O |
| 16 |
% -------- - --- --- |
| 17 |
|
| 18 |
% \message writes to the terminal and the log file, without newlines. |
| 19 |
% This macro adds a newline feature: |
| 20 |
|
| 21 |
\def \messagenl #1{% {text} |
| 22 |
{\newlinechar = `\_% |
| 23 |
\message{#1}}} |
| 24 |
|
| 25 |
% This macro writes a line to the log file, with a newline at the end. |
| 26 |
|
| 27 |
\def \writelog {\immediate\write -1} |
| 28 |
|
| 29 |
% \ask combines a prompt using \messagenl with a read from the terminal. |
| 30 |
|
| 31 |
\def \ask #1#2{% {\result-macro}{question} |
| 32 |
{\messagenl{_#2}% |
| 33 |
\endlinechar = -1 |
| 34 |
\global\read 16 to #1}} |
| 35 |
|
| 36 |
% Including Files |
| 37 |
% --------- ----- |
| 38 |
|
| 39 |
|
| 40 |
\def \include #1{% {file} |
| 41 |
{\checkfile{\zifile}{#1}% |
| 42 |
\if \zifile |
| 43 |
\gdef \znext {\input #1\relax}% |
| 44 |
\else |
| 45 |
\warning{noinclfile}{File `#1' does not exist}% |
| 46 |
\ask{\newfile}{Enter a new file name, or a period (.) to skip it.}% |
| 47 |
\stringeql{\znext}{\newfile}{.}% |
| 48 |
\if \znext |
| 49 |
\xdef \znext {}% |
| 50 |
\else |
| 51 |
\xdef \znext {\noexpand\include{\newfile}}% |
| 52 |
\fi |
| 53 |
\fi}% |
| 54 |
\znext |
| 55 |
\endgraf} |
| 56 |
|
| 57 |
\def \zportionid {} |
| 58 |
|
| 59 |
\def \includeportion #1#2{% {file}{portion-id} |
| 60 |
\gdef \zportionid {#2}% |
| 61 |
\include{#1}% |
| 62 |
\gdef \zportionid {}} |
| 63 |
|
| 64 |
\def \portion #1{% {portion-id} |
| 65 |
\stringeql{\znext}{#1}{\zportionid}% |
| 66 |
\if \znext} |
| 67 |
|
| 68 |
\let \endportion = \fi |
| 69 |
|
| 70 |
\def \includeifexists #1{% {file} |
| 71 |
\checkfile{\zifile}{#1}% |
| 72 |
\if \zifile |
| 73 |
\input #1\relax |
| 74 |
\endgraf |
| 75 |
\fi} |
| 76 |
|
| 77 |
% Utilities |
| 78 |
% --------- |
| 79 |
|
| 80 |
|
| 81 |
\def \checkfile #1#2{% {\result-flag}{file} |
| 82 |
\openin \zreada #2\relax |
| 83 |
\setflag #1= {\notp{\eofp{\zreada}}}% |
| 84 |
\closein \zreada} |