This change file is for the TOPS-20 version of TeX. Copyright (C) 1983 by David Fuchs. All rights are reserved. Problem areas are marked with `fix me'. Please report any bugs to DRF@SU-AI and DRF@SU-SCORE. This file makes an INITeX. To get a production TeX, change the INIT and TINI macros to @{ and @}, respectively, and likewise for DEBUG and GUBED. You may also wish to decrease |trie_size| to about 6000 for English. @x [0] Tell WEAVE to print only the changes: \def\?##1]{\hbox to 1in{\hfil##1.\ }} } @y \def\?##1]{\hbox{Changes to \hbox to 1em{\hfil##1}.\ }} } \let\maybe=\iffalse \def\ttw{{\mc TOPS-20}} \def\title{\TeX82 changes for \ttw} @z @x [1] TOPS-20's banner: @d banner=='This is TeX, Version 2.991' {printed when \TeX\ starts} @y Comments on the \ttw\ implementation (by David Fuchs) of \TeX\ follow: @^Fuchs, David Raymond@> Firstly, input files are considered to have pages, which are delimited with form-feeds. All error messages give the page number, along with the line number on that page (if the page number is one, then the page number is not printed, to avoid confusing people who do not use form-feeds). Secondly, the areas \.{TeX:}, \.{TeXFormats:}, \.{TeXFonts:}, and \.{TeXInputs:} are where \TeX\ looks for \.{.pool}, \.{.fmt}, \.{.tfm}, and \.{.tex} files, respectively. In all but the last case, \TeX\ prepends the logical name to the name supplied by the user, and if the open fails, then \TeX\ tries to use the supplied file name unadorned; while in the case of {.tex} files, first the file is looked for as specified, and if it is not found, \.{TeXInputs:} is prepended). Thirdly, \TeX\ reads your \ttw\ command line that invoked it, and uses everything after the command name as input. For instance, you might say `\.{TeX\ foo}' to \ttw, and \TeX\ will act the same as if you had started it and then said `\.{foo}' to the initial \.{**} prompt. You can also say more complicated things, like `\.{TeX\ \&myfmt\ \\def\\foo\{T\}\ \\input bar}'. Moreover, \TeX\ tries to remember your entire incantation, so that the next time you can simply say `\.{TeX}', and \TeX\ will pretend you had repeated the stuff you said last time. Note that if you give a new, nonempty command line, it will be paid attention to, and the new command line will then be remembered for next time. If you want to get a \TeX\ that ignores any previous command line, say `\.{TeX\ \\}' to \ttw, and \TeX\ will totally forget any old command line you gave it. The command line memory is implemented with logical names $\hbox{TeXMEM}x,\,x\in\{0,1,\ldots\}$, so when you log out, the memory fades. Fourthly, the interrupt feature is activated by typing control-G. Fifthly, \TeX\ will suggest a spooling command when it is done with your job. It will `STI' the line `\.{TeXSpool:\ FOO.DVI.1}' if it wrote said dvi file; thus users can send their output by default to their favorite device by appropriatly defining \.{TeXSpool:}. Sixthly, \TeX\ allows you to use logical names where file names normally go; for instance you can say `\.{TeX Foo:}' when you've already done a \.{DEFINE FOO: BAR} or \.{DEF FOO: ADISK:X.TEX} or even \.{DEF FOO: BAR:} followed by \.{DEF BAR: X}. Don't expect \.{TeX Foo:.X} to work, though. Lastly, \TeX\ tries to be smart about swapping to your favorite editor when you reply `E' to one of its error messages. Unfortunatly, there is no good system interface for doing this sort of thing, so the technique is both fallible, and special code needs to be added for each editor supported (currently, EMACS, EDIT, TVEDIT and ZED). \TeX\ looks at the logical name \.{EDITOR:} and tries to figure out which one you've got so that it can \.{STI} the appropriate commands. @d banner=='This is TeX, Tops-20 Version 2.991' {printed when \TeX\ starts} @d max_TOPS20_file_name_length = 300 {That ought to be big enough} @z @x [1] Switches for debugging and statistics: @d debug==@{ {change this to `$\\{debug}\equiv\null$' when debugging} @d gubed==@t@>@} {change this to `$\\{gubed}\equiv\null$' when debugging} @f debug==begin @f gubed==end @# @d stat==@{ {change this to `$\\{stat}\equiv\null$' when gathering usage statistics} @d tats==@t@>@} {change this to `$\\{tats}\equiv\null$' when gathering usage statistics} @f stat==begin @f tats==end @y @d debug== @d gubed== @f debug==begin @f gubed==end @# @d stat== @d tats== @f stat==begin @f tats==end @z @x [1] The INITeX switch: @d init== {change this to `$\\{init}\equiv\.{@@\{}$' in the production version} @d tini== {change this to `$\\{tini}\equiv\.{@@\}}$' in the production version} @y @d init== @d tini== @z @x [1] Compiler directives: @{@&$C-,A+,D-@} {no range check, catch arithmetic overflow, no debug overhead} @!debug @{@&$C+,D+@}@+ gubed {but turn everything on when debugging} @y The space after the B is due to a compiler bug. @{@&$C-,A+,D-,P:520000@&B@= @>@} {no range check, catch arithmetic overflow, no debug overhead, move the code up to make room for the global data in production} @!debug @{@&$C+,D+,X+,P:400000@&B@= @>@}@+ gubed {we turn everything on when debugging and we use extended addressing (otherwise there's not enough room with all the debug stuff)} @z @x [1] Compile-time constants: @!mem_max=30000; {greatest index in \TeX's internal |mem| array; must be strictly less than |max_halfword|; must be equal to |mem_top| in \.{INITEX}, otherwise |>=mem_top|} @!mem_min=0; {smallest index in \TeX's internal |mem| array; must be |min_halfword| or more; must be equal to |mem_bot| in \.{INITEX}, otherwise |<=mem_bot|} @!buf_size=500; {maximum number of characters simultaneously present in current lines of open files and in control sequences between \.{\\csname} and \.{\\endcsname}; must not exceed |max_halfword|} @!error_line=72; {width of context lines on terminal error messages} @!half_error_line=42; {width of first lines of contexts in terminal error messages; should be between 30 and |error_line-15|} @!max_print_line=79; {width of longest text lines output; should be at least 60} @!stack_size=200; {maximum number of simultaneous input sources} @!max_in_open=6; {maximum number of input files and error insertions that can be going on simultaneously} @!font_max=75; {maximum internal font number; must not exceed |max_quarterword| and must be at most |font_base+256|} @!font_mem_size=20000; {number of words of |font_info| for all fonts} @!param_size=60; {maximum number of simultaneous macro parameters} @!nest_size=40; {maximum number of semantic levels simultaneously active} @!max_strings=3000; {maximum number of strings; must not exceed |max_halfword|} @!string_vacancies=8000; {the minimum number of characters that should be available for the user's control sequences and font names, after \TeX's own error messages are stored} @!pool_size=32000; {maximum number of characters in strings, including all error messages and help texts, and the names of all fonts and control sequences; must exceed |string_vacancies| by the total length of \TeX's own strings, which is currently about 23000} @!save_size=600; {space for saving values outside of current group; must be at most |max_halfword|} @!trie_size=8000; {space for hyphenation patterns; should be larger for \.{INITEX} than it is in production versions of \TeX} @!dvi_buf_size=800; {size of the output buffer; must be a multiple of 8} @!file_name_size=40; {file names shouldn't be longer than this} @!pool_name='TeXformats:TEX.POOL '; {string of length |file_name_size|; tells where the string pool appears} @y @!mem_max=65500; {greatest index in \TeX's internal |mem| array; must be strictly less than |max_halfword|; must be equal to |mem_top| in \.{INITEX}, otherwise |>=mem_top|} @!mem_min=0; {smallest index in \TeX's internal |mem| array; must be |min_halfword| or more; must be equal to |mem_bot| in \.{INITEX}, otherwise |<=mem_bot|} @!buf_size=500; {maximum number of characters simultaneously present in current lines of open files and in control sequences between \.{\\csname} and \.{\\endcsname}; must not exceed |max_halfword|} @!error_line=79; {width of context lines on terminal error messages} @!half_error_line=50; {width of first lines of contexts in terminal error messages; should be between 30 and |error_line-15|} @!max_print_line=79; {width of longest text lines output; should be at least 60} @!stack_size=200; {maximum number of simultaneous input sources} @!max_in_open=6; {maximum number of input files and error insertions that can be going on simultaneously} @!font_max=100; {maximum internal font number; must not exceed |max_quarterword|} @!font_mem_size=35000; {number of words of |font_info| for all fonts} @!param_size=60; {maximum number of simultaneous macro parameters} @!nest_size=40; {maximum number of semantic levels simultaneously active} @!max_strings=5400; {maximum number of strings} @!string_vacancies=26000; {the minimum number of characters that should be available for the user's control sequences and font names, after \TeX's own error messages are stored} @!pool_size=65500; {maximum number of characters in strings, including all error messages and help texts, and the names of all fonts and control sequences; must exceed |string_vacancies| by the total length of \TeX's own strings, which is currently about 23000} @!save_size=600; {space for saving values outside of current group; must be at most |max_halfword|} @!trie_size=8000; {space for hyphenation patterns; should be larger for \.{INITEX} than it is in production versions of \TeX} @!dvi_buf_size=800; {size of the output buffer; must be a multiple of 8} @!file_name_size=69; {file names shouldn't be longer than this} @!pool_name= 'TeX:TeX.POOL '; {string of length |file_name_size|; tells where the string pool appears} @!max_rescan=500; {maximum length of the rescan buffer} @z @x [1] TANGLE-time constants: @d mem_bot=0 {smallest index in the |mem| array dumped by \.{INITEX}; must not be less than |mem_min|} @d mem_top==30000 {largest index in the |mem| array dumped by \.{INITEX}; must be substantially larger than |mem_bot| and not greater than |mem_max|} @d font_base=0 {smallest internal font number; must not be less than |min_quarterword|} @d hash_size=2100 {maximum number of control sequences; it should be at most about |(mem_max-mem_min)/10|, but 2100 is already quite generous} @d hash_prime=1777 {a prime number equal to about 85\% of |hash_size|} @d hyph_size=307 {another prime; the number of \.{\\hyphenation} exceptions} @y @d mem_bot=0 {smallest index in the |mem| array dumped by \.{INITEX}; must not be less than |mem_min|} @d mem_top==65500 {largest index in the |mem| array dumped by \.{INITEX}; must be substantially larger than |mem_bot| and not greater than |mem_max|} @d font_base=0 {smallest internal font number; must not be less than |min_quarterword|} @d hash_size=3300 {maximum number of control sequences; it should be at most about |(mem_max-mem_min)/10|, but 2100 is already quite generous} @d hash_prime=2803 {a prime number equal to about 85\% of |hash_size|} @d hyph_size=307 {another prime; the number of \.{\\hyphenation} exceptions} @z @x [2] System-dependent character set changes: @^character set dependencies@> @^system dependencies@> @= for i:=1 to @'37 do xchr[i]:=' '; @y @^character set dependencies@> @^system dependencies@> The code shown here is intended to be used on \ttw\ systems, and at other installations where only the printable ASCII set, plus |carriage_return|, |tab|, and |form_feed| will show up in text files. All |line_feed| and |null| characters are skipped. Note that |form_feed|'s are considered to be page delimiters, and this version of \TeX\ will keep track of which page of input it is on, for use in error messages, as well as in swapping to various editors. @d form_feed=@'14 {ASCII code used at end of a page} @d tab=@'11 @= for i:=1 to @'37 do xchr[i]:=' '; xchr[form_feed]:=chr(form_feed); xchr[tab]:=chr(tab); @z @x [3] Opening files: @d reset_OK(#)==erstat(#)=0 @d rewrite_OK(#)==erstat(#)=0 @p function a_open_in(var f:alpha_file):boolean; {open a text file for input} begin reset(f,name_of_file,'/O'); a_open_in:=reset_OK(f); end; @# function a_open_out(var f:alpha_file):boolean; {open a text file for output} begin rewrite(f,name_of_file,'/O'); a_open_out:=rewrite_OK(f); end; @# function b_open_in(var f:byte_file):boolean; {open a binary file for input} begin reset(f,name_of_file,'/O'); b_open_in:=reset_OK(f); end; @# function b_open_out(var f:byte_file):boolean; {open a binary file for output} begin rewrite(f,name_of_file,'/O'); b_open_out:=rewrite_OK(f); end; @# function w_open_in(var f:word_file):boolean; {open a word file for input} begin reset(f,name_of_file,'/O'); w_open_in:=reset_OK(f); end; @# function w_open_out(var f:word_file):boolean; {open a word file for output} begin rewrite(f,name_of_file,'/O'); w_open_out:=rewrite_OK(f); end; @y @d reset_OK(#)==(erstat(#)=0) or (erstat(#)=@'0600220) {empty file} @d rewrite_OK(#)==erstat(#)=0 @p function erstat(var f:file):integer; extern; {in the runtime library} function a_open_in(var f:alpha_file):boolean; {open a text file for input} begin reset(f,name_of_file,'/E/O'); {the \.{/E} switch distinguishes |form_feed| from |carriage_return|; the \.{/O} switch gives error control to us} a_open_in:=reset_OK(f); end; @# function a_open_out(var f:alpha_file):boolean; {open a text file for output} begin rewrite(f,name_of_file,'/O'); a_open_out:=rewrite_OK(f); end; @# function b_open_in(var f:byte_file):boolean; {open a binary file for input} begin reset(f,name_of_file,'/B:8/O'); b_open_in:=reset_OK(f); end; {the \.{/B} switch is necessary to get byte packing} @# function b_open_out(var f:byte_file):boolean; {open a binary file for output} begin rewrite(f,name_of_file,'/B:8/O'); b_open_out:=rewrite_OK(f); end; @# function w_open_in(var f:word_file):boolean; {open a word file for input} begin reset(f,name_of_file,'/O'); w_open_in:=reset_OK(f); end; @# function w_open_out(var f:word_file):boolean; {open a word file for output} begin rewrite(f,name_of_file,'/O'); w_open_out:=rewrite_OK(f); end; @z @x [3] New input_ln: representing the beginning and ending of a line of text. @= @y representing the beginning and ending of a line of text. We will read the lines first into an auxiliary buffer, in order to save the running time of procedure-call overhead. This uses a nice feature of \ph\ that Knuth chose not to mention in \TeX82. @^Knuth, Donald Ervin@> On \ttw\ we want to recognize page marks (indicated by |form_feed| characters), and keep track of the current page number. EDIT-type line number are skipped over automatically. @d aux_buf_len=80 {length of the auxiliary buffer} @= @!aux_buf:array[0..aux_buf_len-1] of text_char; {where the characters go first} @^system dependencies@> @z @x @p function input_ln(var f:alpha_file;@!bypass_eoln:boolean):boolean; {inputs the next line or returns |false|} var last_nonblank:0..buf_size; {|last| with trailing blanks removed} begin if bypass_eoln then if not eof(f) then get(f); {input the first character of the line into |f^|} last:=first; {cf.\ Matthew 19\thinspace:\thinspace30} if eof(f) then input_ln:=false else begin last_nonblank:=first; while not eoln(f) do begin if last>=max_buf_stack then begin max_buf_stack:=last+1; if max_buf_stack=buf_size then overflow("buffer size",buf_size); @:TeX capacity exceeded buffer size}{\quad buffer size@> end; buffer[last]:=xord[f^]; get(f); incr(last); if buffer[last-1]<>" " then last_nonblank:=last; end; last:=last_nonblank; input_ln:=true; end; end; @y On \ttw, we do just that, using |aux_buf|. @p function input_ln(var f:alpha_file;@!bypass_eoln:boolean):boolean; {inputs the next line or returns |false|} label 1,done; var n: integer; @!k,@!m: 0..buf_size; {indices into |buffer|} @!more: boolean; {is there more on the line that didn't get into |aux_buf|?} begin if bypass_eoln then {input the first character of the line into |f^|} begin if not eof(f) then get(f); if not eof(f) then if f^=chr(@'12) then get(f); {skip past a |line_feed|} end; last:=first; if eof(f) then input_ln:=false else begin read(f,aux_buf:n); more:=n=aux_buf_len+1; if more then n:=aux_buf_len; 1: if last+n>max_buf_stack then if last+n>=buf_size then begin max_buf_stack:=buf_size; overflow("buffer size",buf_size); @:TeX capacity exceeded buffer size}{\quad buffer size@> end else max_buf_stack:=last+n; if n>0 then begin m:=last; last:=m+n; for k:=m to last-1 do buffer[k]:=xord[aux_buf[k-m]]; if more then begin read(f,aux_buf:n); more:=n=aux_buf_len+1; if more then n:=aux_buf_len; goto 1; end; end; if (f^<>chr(carriage_return)) and (not eof(f)) then begin if f^=chr(form_feed) then begin page:=page+1; line:=0; end; aux_buf[0]:=f^; n:=1; more:=true; get(f); goto 1; end; loop@+ begin if last=first then goto done; if buffer[last-1]<>" " then goto done; decr(last); end; done: input_ln:=true; end; end; @^system dependencies@> @z @x [3] Terminal I/O: is considered an output file the file variable is |term_out|. @^system dependencies@> @= @!term_in:alpha_file; {the terminal as an input file} @!term_out:alpha_file; {the terminal as an output file} @ Here is how to open the terminal files in \ph. The `\.{/I}' switch suppresses the first |get|. @^system dependencies@> @d t_open_in==reset(term_in,'TTY:','/O/I') {open the terminal for text input} @d t_open_out==rewrite(term_out,'TTY:','/O') {open the terminal for text output} @y is considered an output file the file variable is |term_out|. On \ttw, this point is moot, since we use the built-in |TTY| file. @^system dependencies@> @d term_in==TTY {the terminal as an input file} @d term_out==TTY {the terminal as an output file} @ Here is how to open the terminal files on \ttw: we don't do anything, since |TTY| is always open. Note that |eoln(term_in)| is initially |true|. (Acutally, some very picky people might want to be able to distinguish between different |eoln| characters on terminal input, so we have to re-reset the |term_in| file with a few magic switches) @^system dependencies@> @d t_open_in == reset(term_in,'','/I/E') {distinguish |eoln| characters} @d t_open_out==do_nothing {open the terminal for text output} @z @x [3] Special terminal controls: @d update_terminal == break(term_out) {empty the terminal output buffer} @d clear_terminal == break_in(term_in,true) {clear the terminal input buffer} @d wake_up_terminal == do_nothing {cancel the user's cancellation of output} @y @d CFIBF=@'100 {Clear File Input BuFfer JSYS} @d PRIIN=@'100 {PRImary INput JFN JSYS} @d PRIOUT=@'101 {PRImary OUTput JFN JSYS} @d RFMOD=@'107 {Return File MODe word JSYS} @d SFMOD=@'110 {Set File MODe word JSYS} @# @d update_terminal == {the terminal output buffer is always emptied} @d clear_terminal == jsys(CFIBF;PRIIN) {clear the terminal input buffer} @d wake_up_terminal == begin {cancel the user's cancellation of output} jsys(RFMOD;PRIOUT;wake_up_junk,wake_up_junk); wake_up_junk:=wake_up_junk-[0]; {turn off TT\%OSP} jsys(SFMOD;PRIOUT,wake_up_junk); end @^system dependencies@> @= @!wake_up_junk: set of 0..35; @z @x [3] Initializing the terminal: @ The following program does the required initialization without retrieving a possible command line. It should be clear how to modify this routine to deal with command lines, if the system permits them. @^system dependencies@> @p function init_terminal:boolean; {gets the terminal input started} label exit; begin t_open_in; loop@+begin wake_up_terminal; write(term_out,'**'); update_terminal; @.**@> if not input_ln(term_in,true) then {this shouldn't happen} begin write_ln(term_out); write(term_out,'! End of file on the terminal... why?'); @.End of file on the terminal@> init_terminal:=false; return; end; loc:=first; while (loc @p function init_terminal:boolean; {gets the terminal input started} label exit,done; {|done| is for the command line code} var @@/ @!line_found:boolean; {is there a spceial command line?} begin t_open_in; @; last:=first; {|buffer| empty} @; line_found:=(last>first); {did we put anything into |buffer|?} loop@+ begin loc:=first; while (loc if not input_ln(term_in,true) then {this shouldn't happen} begin write_ln(term_out); write(term_out,'! End of file on the terminal... why?'); @.End of file on the terminal@> init_terminal:=false; return; end; line_found:=true; end; exit:end; @z @x [6] The `E' option: line ready to be edited. But such an extension requires some system wizardry, so the present implementation simply types out what file should be edited and the relevant line number. @y line ready to be edited. The present implementation does this by loading the line editor with the appropriate call to the editor. We treat `\.T' the same as `\.E', because other programs invoke the editor when the user says `\.T'. @z @x "E": if base_ptr>0 then begin print_nl("You want to edit file "); @.You want to edit file x@> print(input_stack[base_ptr].name_field); print(" at line "); print_int(line); interaction:=scroll_mode; jump_out; end; @y "E","T": if base_ptr>0 then begin set_pseudo_to_edit_commands; jump_out; end; @z @x [8] Changes for 36-bit machines: The values defined here are recommended for most 32-bit computers. @d min_quarterword=0 {smallest allowable value in a |quarterword|} @d max_quarterword=255 {largest allowable value in a |quarterword|} @d min_halfword==0 {smallest allowable value in a |halfword|} @d max_halfword==65535 {largest allowable value in a |halfword|} @y The values defined here are recommended for most 36-bit computers. @d min_quarterword=0 {smallest allowable value in a |quarterword|} @d max_quarterword=511 {largest allowable value in a |quarterword|} @d min_halfword==0 {smallest allowable value in a |halfword|} @d max_halfword==262143 {largest allowable value in a |halfword|} @z @x [6] Eliminating addition/subtraction of zero: The inner loop of \TeX\ will run faster with respect to compilers that don't optimize expressions like `|x+0|' and `|x-0|', if these macros are simplified in the obvious way when |min_quarterword=0|. @^inner loop@>@^system dependencies@> @d qi(#)==#+min_quarterword {to put an |eight_bits| item into a quarterword} @d qo(#)==#-min_quarterword {to take an |eight_bits| item out of a quarterword} @d hi(#)==#+min_halfword {to put a sixteen-bit item into a halfword} @d ho(#)==#-min_halfword {to take a sixteen-bit item from a halfword} @y The inner loop of \TeX\ will run faster with respect to compilers that don't optimize expressions like `|x+0|' and `|x-0|', if these macros are simplified in the obvious way when |min_quarterword=0|. So they have been simplified here in the obvious way. @^inner loop@>@^system dependencies@> @d qi(#)==# {to put an |eight_bits| item into a quarterword} @d qo(#)==# {to take an |eight_bits| item from a quarterword} @d hi(#)==# {to put a sixteen-bit item into a halfword} @d ho(#)==# {to take a sixteen-bit item from a halfword} @z @x [17] Special form_feed initialization: cat_code("\"):=escape; cat_code("%"):=comment; @y cat_code("\"):=escape; cat_code("%"):=comment; cat_code(form_feed):=car_ret; @z @x [17] Date and time: Since standard \PASCAL\ cannot provide such information, something special is needed. The program here simply specifies July 4, 1776, at noon; but users probably want a better approximation to the truth. @p procedure fix_date_and_time; begin time:=12*60; {minutes since midnight} day:=4; {fourth day of the month} month:=7; {seventh month of the year} year:=1776; {Anno Domini} end; @y It uses a \ttw\ monitor call that returns various data and time information in three variables. @d ODCNV=@'222 {Output Date and time CoNVersion JSYS} @p procedure fix_date_and_time; var y,d,t:integer; {raw year/month, day and time} g:integer; {garbage} begin jsys(ODCNV;0,-1,0,0;g,y,d,t); year:=y div @'1000000; {year in left half-word} month:=(y mod @'1000000)+1; {month in right half-word, zero means January} day:=(d div @'1000000)+1; {day in left half-word, zero means the first of the month} time:=((t+@'377777*@'1000000) mod @'1000000) div 60; {sign bit was on} end; @^system dependencies@> @z @x [22] Page number maintenance: If more information about the input state is needed, it can be included in small arrays like those shown here. For example, the current page or segment number in the input file might be put into a variable |@!page|, maintained for enclosing levels in `\ignorespaces|@!page_stack:array[1..max_in_open] of integer|\unskip' by analogy with |line_stack|. @y Similarly, we maintain a global variable |page| and a corresponding |page_stack|. @z @x @!line_stack : array[1..max_in_open] of integer; @y @!line_stack : array[1..max_in_open] of integer; @!page : integer; {current page number in the current source file} @!page_stack : array[1..max_in_open] of integer; @z @x [22] Printing the page number: else begin print_nl("l."); print_int(line); @y else begin if page>1 then begin print_nl("p."); print_int(page); print(",l."); end else print_nl("l."); print_int(line); @z @x [23] More page number maintenance: or |limit| or |line|. @y or |limit| or |line| or |page|. @z @x line_stack[index]:=line; start:=first; state:=mid_line; @y line_stack[index]:=line; start:=first; state:=mid_line; page_stack[index]:=page; @z @x begin first:=start; line:=line_stack[index]; @y begin first:=start; page:=page_stack[index]; line:=line_stack[index]; @z @x [24] More page number printing: print("; all text was ignored after line "); print_int(skip_line); @y print("; all text was ignored after line "); print_int(skip_line); if skip_page>1 then begin print(", p."); print_int(skip_page); end; @z @x where skipping began, for use in error messages. @= @!skip_line:integer; {skipping began here} @y where skipping began, for use in error messages. Also the page number. @= @!skip_line,@!skip_page:integer; {skipping began here} @z @x skip_line:=line; @y skip_line:=line; skip_page:=page; @z @x [29] Logical name translation: @ The third. @^system dependencies@> @p procedure end_name; begin if str_ptr+3>max_strings then overflow("number of strings",max_strings-init_str_ptr); @:TeX capacity exceeded number of strings}{\quad number of strings@> if area_delimiter=0 then cur_area:="" else begin cur_area:=str_ptr; incr(str_ptr); str_start[str_ptr]:=area_delimiter+1; end; if ext_delimiter=0 then begin cur_ext:=""; cur_name:=make_string; end else begin cur_name:=str_ptr; incr(str_ptr); str_start[str_ptr]:=ext_delimiter; cur_ext:=make_string; end; end; @y @ The third. We have to check to see if a logical name has been referred to, and if so, translate it. @^system dependencies@> @d LNMST=@'504 {convert Logical NaMe to STring JSYS} @p procedure end_name; label restart,exit; var s,t:packed array[1..max_TOPS20_file_name_length+1] of char; @!LNMST_return: integer; {which skip return did the LNMST jsys take?} @!i:pool_pointer; begin restart: if (str_pool[area_delimiter]=":") and (pool_ptr=area_delimiter+1) then begin cur_area:=make_string; for i:=1 to length(cur_area)-1 do s[i]:=xchr[str_pool[str_start[cur_area]+i-1]]; s[length(cur_area)]:=chr(0); {ASCIZ it} jsys(LNMST,-2,LNMST_return;0,s,t); {job-wide} if LNMST_return<>2 then jsys(LNMST,-2,LNMST_return;1,s,t); {system-wide} if LNMST_return<>2 then begin cur_ext:=""; cur_name:=""; {silly case} return; end; flush_string; {needn't remember logical name in |cur_area|} begin_name; i:=1; while ord(t[i])>0 do if more_name(xord[t[i]]) then incr(i) else goto restart; goto restart; {heavy!} end; if str_ptr+3>max_strings then overflow("number of strings",max_strings-init_str_ptr); @:TeX capacity exceeded number of strings}{\quad number of strings@> if area_delimiter=0 then cur_area:="" else begin cur_area:=str_ptr; incr(str_ptr); str_start[str_ptr]:=area_delimiter+1; end; if ext_delimiter=0 then begin cur_ext:=""; cur_name:=make_string; end else begin cur_name:=str_ptr; incr(str_ptr); str_start[str_ptr]:=ext_delimiter; cur_ext:=make_string; end; exit: end; @z @x [29] The real file names: @ Operating systems often make it possible to determine the exact name (and possible version number) of a file that has been opened. The following routine, which simply makes a \TeX\ string from the value of |name_of_file|, should ideally be changed to deduce the full name of file~|f|, which is the file most recently opened, if it is possible to do this in a \PASCAL\ program. @^system dependencies@> This routine might be called after string memory has overflowed, hence we dare not use `|str_room|'. @p function make_name_string:str_number; var k:1..file_name_size; {index into |name_of_file|} begin if (pool_ptr+name_length>pool_size)or(str_ptr=max_strings)or (cur_length>0) then make_name_string:="?" else begin for k:=1 to name_length do append_char(xord[name_of_file[k]]); make_name_string:=make_string; end; end; function a_make_name_string(var f:alpha_file):str_number; begin a_make_name_string:=make_name_string; end; function b_make_name_string(var f:byte_file):str_number; begin b_make_name_string:=make_name_string; end; function w_make_name_string(var f:word_file):str_number; begin w_make_name_string:=make_name_string; end; @y @ Operating systems often make it possible to determine the exact name (and possible version number) of a file that has been opened. The following routine, shows how to deduce the full name of file~|f|, which is the file most recently opened, using \ttw\ system calls. @^system dependencies@> This routine might be called after string memory has overflowed, hence we dare not use `|str_room|'. @d JFNS=@'30 {translage JFN to String JSYS} @p function make_name_string(var f:f@&i@&l@&e):str_number; var s:packed array[1..max_TOPS20_file_name_length+1] of char; @!j,k:1..max_TOPS20_file_name_length; begin jsys(JFNS;s,0:f,@'111110:1); j:=1; while (ord(s[j+1])<>0) and (jpool_size)or(str_ptr=max_strings)or (cur_length>0) then make_name_string:="?" else begin for k:=1 to j do append_char(xord[s[k]]); make_name_string:=make_string; end; end; function a_make_name_string(var f:alpha_file):str_number; begin a_make_name_string:=make_name_string(f); end; function b_make_name_string(var f:byte_file):str_number; begin b_make_name_string:=make_name_string(f); end; function w_make_name_string(var f:word_file):str_number; begin w_make_name_string:=make_name_string(f); end; @z @x [29] LST instead of LOG: @p procedure pack_job_name(@!s:str_number); {|s = ".log"|, |".dvi"|, or @y @p procedure pack_job_name(@!s:str_number); {|s = ".lst"|, |".dvi"|, or @z @x pack_job_name(".log"); @y pack_job_name(".lst"); @z @x prompt_file_name("transcript file name",".log"); @y prompt_file_name("transcript file name",".lst"); @z @x [29] Start page number at 1: first:=limit+1; loc:=start; line:=1; @y first:=limit+1; loc:=start; line:=1; page:=1; @z @x [32] Pack dvi_buf @!dvi_buf:array[dvi_index] of eight_bits; {buffer for \.{DVI} output} @y @!dvi_buf:packed array [dvi_index] of eight_bits; {buffer for \.{DVI} output} @z @x [32] "TeXspool": b_close(dvi_file); @y b_close(dvi_file); if pseudo_typein=0 then begin k:=selector; selector:=new_string; pool_ptr:=str_start[str_ptr]; print("TeXspool: "); print(output_file_name); selector:=k; if (pool_ptr1 then begin print(", p."); print_int(page); end; @z @x print_int(line); @y print_int(line); if page>1 then begin print(", p."); print_int(page); end; @z @x [51] The endgame: @ Here we do whatever is needed to complete \TeX's job gracefully on the local operating system. The code here might come into play after a fatal error; it must therefore consist entirely of ``safe'' operations that cannot produce error messages. For example, it would be a mistake to call |str_room| or |make_string| at this time, because a call on |overflow| might lead to an infinite loop. @^system dependencies@> Actually there's one way to get error messages, via |prepare_mag|; but that can't cause infinite recursion. This program doesn't bother to close the input files that may still be open. @= procedure close_files_and_terminate; var k:integer; {all-purpose index} begin @; @!stat if tracing_stats>0 then @;@;@+tats@/ wake_up_terminal; @; if log_opened then begin wlog_cr; a_close(log_file); selector:=selector-2; if selector=term_only then begin print_nl("Transcript written on "); @.Transcript written...@> print(log_name); print_char("."); end; end; end; @y @ Here we do whatever is needed to complete \TeX's job gracefully on \ttw. The code here might come into play after a fatal error; it must therefore consist entirely of ``safe'' operations that cannot produce error messages. For example, it would be a mistake to call |str_room| or |make_string| without checking, because a call on |overflow| might lead to an infinite loop. @^system dependencies@> Actually there's one way to get error messages, via |prepare_mag|; but that can't cause infinite recursion. This program doesn't bother to close the input files that may still be open. @d STI=@'114 {Simulate Terminal Input JSYS} @d SIBE=@'102 {See If Buffer Empty JSYS} @= procedure close_files_and_terminate; label done; var j,@!k:integer; {all-purpose index} @!SIBE_return: integer; {did the SIBE skip?} @!temp_file: alpha_file; {read unbuffered from |term_in|} @!old_mode,@!new_mode:set of 0..35; {a word by the bits} begin @; @!stat if tracing_stats>0 then @;@;@+tats@/ wake_up_terminal; @; if job_name>0 then begin wlog_cr; a_close(log_file); selector:=selector-2; if selector=term_only then begin print_nl("Transcript written on "); print(log_name); print_char("."); end; end; {note we don't use |xchr[str_pool[k]]| here because of ESC and CR characters} if (pseudo_typein<>0) and (interaction>batch_mode) then begin j:=str_start[pseudo_typein+1]-1; {last character to STI} jsys(SIBE,2,SIBE_return;PRIIN); if SIBE_return<>1 then goto done; reset(temp_file,'tty:','/I/M:1'); {read unbuffered from the terminal} jsys(RFMOD;PRIIN;old_mode); {get terminal mode} new_mode:=old_mode-[24]; {TT\%ECO bit} jsys(SFMOD;PRIIN;new_mode); {turn off echo} while SIBE_return=1 do begin get(temp_file); {there must be user input} incr(j); if eoln(temp_file) then str_pool[j]:=13 else str_pool[j]:=ord(temp_file^); jsys(SIBE,2,SIBE_return;PRIIN); end; done: jsys(SFMOD;PRIIN;old_mode); {turn echo back on} for k:=str_start[pseudo_typein] to j do jsys(STI;PRIIN,str_pool[k]); end; end; @z @x [54] Final system-dependent changes: This section should be replaced, if necessary, by changes to the program that are necessary to make \TeX\ work at a particular installation. It is usually best to design your change file so that all changes to previous sections preserve the section numbering; then everybody's version will be consistent with the published program. More extensive changes, which introduce new sections, can be inserted here; then only the index itself will get a new section number. @^system dependencies@> @y Here are the remaining things needed to make the implementation complete on \ttw. @^system dependencies@> @d ESC=@'33 @d CR=@'15 @d control_R=@'22 @d control_Z=@'32 @= procedure@?set_pseudo_to_edit_commands; forward;@t\2@>@/ @ The |pseudo_typein| variable is set nonzero if the |error| routine uses the `\.E' option to exit and edit. @= @!pseudo_typein:str_number; @ @= pseudo_typein:=0; page:=0; @ This procedure gets called when the user wants to set up to swap to the editor upon seeing an error. It figures out which editor the user wants, and then prints the proper command to start up that editor on the correct file at the correct position. @d edit_file==input_stack[base_ptr] {file to edit} @= procedure set_pseudo_to_edit_commands; label done; var @!LNMST_return: integer; {which skip return did the LNMST jsys take?} @!edit_name: packed array[1..max_TOPS20_file_name_length] of ASCII_code; @!short_name: str_number; {|edit_name| with directory, etc. removed} @!from_here, @!to_there, @!i: integer; {help turn |edit_name| into |shorname|} begin selector:=new_string; pool_ptr:=str_start[str_ptr]; @; @; @; with edit_file do {avoid typeing |edit_file| alot} if str_eq_str(short_name,"EMACS") then @ else if str_eq_str(short_name,"TVEDIT") then @ else if str_eq_str(short_name,"EDIT") then @ else if str_eq_str(short_name,"ZED") then @ else @; done: pseudo_typein:=make_string; selector:=term_and_log; interaction:=scroll_mode; end; @ There is a bug here if the logical name for the editor points to another logical name which then points to the real editor name. @= logical_name:='EDITOR '; logical_name[7]:=chr(0); {ASCIZ it} jsys(LNMST,-2,LNMST_return;0,logical_name,edit_name); {job-wide} if LNMST_return<>2 then jsys(LNMST,-2,LNMST_return;1,logical_name,edit_name); {system-wide} if LNMST_return<>2 then begin print("; You must DEFINE EDITOR: before TeX knows who to swap to."); print_char(CR); goto done; end; @ @= from_here:=1; i:=1; while edit_name[i]>0 do begin if (edit_name[i]=":") or (edit_name[i]=">") then from_here:=i+1; incr(i); end; decr(i); to_there:=i; while i>from_here do begin if edit_name[i]="." then to_there:=i-1; decr(i); end; @ @= str_room(to_there-from_here+1); for i:=from_here to to_there do append_char(edit_name[i]); short_name:=make_string; @ @= begin print("; Sorry, but TeX doesn't know about EDITOR: "); print(short_name); print_char(CR); print("; You want to edit file "); print(name_field); print(" on page "); print_int(page); print(", line "); print_int(line); print_char("."); print_char(CR); end @ @= begin print("EDIT"); print_char(CR); print_char(control_Z); print("x^r execute minibuffer"); print_char(CR); print("mmFind file"); print_char(ESC); jsys(JFNS;edit_name,0:input_file[index_field],@'221100:1); {Get file name without device and directory if possible, and no version number} i:=1; while edit_name[i]>0 do begin print_char(edit_name[i]); incr(i); end; print_char(ESC); print_char(CR); print_int(curpos(input_file[index_field])-(limit_field-loc_field)-1); print_char("j"); print_char(control_Z); print_char(control_Z); end @ @= begin print("EDIT "); print(name_field); print_char(CR); print("XTECO"); print_char(ESC); print_int(curpos(input_file[index_field])-(limit_field-loc_field)-1); print_char("j"); print_char(control_R); print_char(control_Z); end @ @= begin print("EDIT "); print(name_field); print_char(CR); print_char(ESC); print_char(ESC); print_int(page); print_char("."); print_int(line); print_char("G"); {diabolical!} if loc_field>start_field then begin print_char(ESC); print_char(ESC); print_int(loc_field-start_field); print_char(" "); end; end @ @= begin print("EDIT "); print(name_field); print_char(CR); {fix me -- there's a bug if EDIT decides to split a very large page} print("P^+"); print_int(line-1); if page>1 then begin print_char("/"); print_int(page); end; print_char(CR); end @ This is the actual Control-G interrupt routine, and two system routines used to enable it. We have to put them somewhere, so pardon the little lie\dots @= procedure cntl_G; begin interrupt:=interrupt+1; end; {non-interruptable} procedure psidefine(chan,level:integer;procedure p); extern; @t\2@>@; procedure psienable(chan:integer); extern; @t\2@>@; @ This code sets things up such that each time the user types control-G, the procedure |cntl_G| gets called, and |interrupt| gets incremented. The program can change |interrupt| whenever it wants to, but |interrupt| had better be a global variable. @d ATI=@'137 {Assign Terminal code to Interrupt channel JSYS} @d cntl_G_chan=34 {Channel for Control-G interrupts} @= begin psidefine(cntl_G_chan,1,cntl_G); {call |cntl_G| on interrupt, level 1} psienable(cntl_G_chan); {turn on those interrupts} jsys(ATI;7:cntl_G_chan); {assign control-G to channel} end @ Here is the code that does all the command line system magic. @d RSCAN=@'500 {ReSCAN buffer JSYS} @d CRLNM=@'502 {CReate Logical NaMe JSYS} @= @!ac1: integer; {AC1 from Rescan} @!rescan: packed array[1..max_rescan] of char; {rescan buffer} @!rescan_len: integer; {amount of |rescan| used} @!definition: packed array [1..79] of char; {ASCIZ, with control-V's} @!i,@!j: integer; {temporary} @ The array |logical_name| holds the logical name that we use to implement \TeX's memory from run to run. Actually, we may have to use a series of logical names, since we only get to save 39 characters in each one. @d next_logical_name==logical_name[7]:=chr(ord(logical_name[7])+1) @= @!logical_name: packed array[1..8] of char; {ASCIZ ``TeXMEMx'', x=0,1,etc.} @ @= logical_name:='TeXMEM0 '; logical_name[8]:=chr(0); {ASCIZ it} @ \ttw\ puts the user command line into the so-called rescan buffer. Actually, we have to use a real hack to see if it's a bogus Execute, Start, Continue, Debug, etc.\ command, in which case we should pretend there was no command line, since the command line that was there was not intended for \TeX. @= jsys(RSCAN,1,i;0;ac1); {put the command line into the |TTY| input buffer} if (i<>2) or (ac1<=0) then goto done; {RSCAN failed, somehow} if eoln(term_in) then read_ln(term_in); {for some TOPS-20's} read(term_in,rescan:rescan_len); {read in rescan buffer} if rescan_len>max_rescan then begin write_ln(term_out,'Command line longer than ',max_rescan:0, 'characters, so I''m ignoring it'); read_ln(term_in); goto done; end; @/{The following line is based upon experimentation with \ttw!} if rescan_len=ac1-2 then goto done; {EX, ST, DEB commands} @ Now that we have a command line, we have to strip off the TeX command and see if there is a lone backslash (which means that the user wanted us to ignore the stuff in the logical name memory. @= i:=1; while rescan[i]>' ' do incr(i); {skip the command name, presumably TeX}@/ while (i<=rescan_len) and (rescan[i]=' ') do incr(i); {skip spaces}@/ if (i=rescan_len) and (rescan[i]='\') then begin @; goto done; end; {escape to ignore memory} @ Here's where we actually do the command line stuff. Various parts of the code go to the label |done| if they realize that no special command line processing should happen. @= @; @; if i<=rescan_len then @ else @; done: @ We get here if there was command text for \TeX. It gets put into |buffer| and into the logical name(s). We need to intersperse the characters with Control-V's so that they don't get capitalized and so that non-alphabetic characters get remembered properly. `Why doesn't \ttw\ have variables that can be defined?' you may ask; and well you may. @= begin j:=1; while i<=rescan_len do begin buffer[last]:=xord[rescan[i]]; incr(last); definition[j]:=chr(@'26); {control-V} incr(j); definition[j]:=rescan[i]; incr(j); incr(i); if (j=79) or (i>rescan_len) then begin definition[j]:=chr(0); jsys(CRLNM,2,j;4,logical_name,definition;ac1); if j=1 then write_ln(term_out,'CRLNM returned ',ac1:12:O); j:=1; next_logical_name; end; end; @; {In case the old one was longer than this one.} end @ We get here if we should put the memorized command line into |buffer|. @= loop@+begin jsys(LNMST,2,j;0,logical_name,definition); if j<>2 then goto done; j:=1; while (definition[j]<>chr(0)) do begin buffer[last]:=xord[definition[j]]; incr(last); incr(j); end; next_logical_name; end @ This code makes \TeX\ wipe out all logical names beginnig with the current one. @= repeat jsys(CRLNM,2,j;0,logical_name); next_logical_name; until j<>2 @z