DVIDOC for Pyramid OSx (Part 2 of 2)

Scott Simpson simpson at trwrb.UUCP
Thu Sep 11 05:13:21 AEST 1986


X\.{DVIDOC} output will vary depending on some
Xoptions that the user must specify: The typeout can be confined to a
Xrestricted subset of the pages by specifying the desired starting page and
Xthe maximum number of pages. Furthermore there is an option to specify the
Xhorizontal and vertical
Xresolution of the printer or display; and there is an option to override the
Xmagnification factor that is stated in the \.{DVI} file.
X
XThe starting page is specified by giving a sequence of 1 to 10 numbers or
Xasterisks separated by dots. For example, the specification `\.{1.*.-5}'
Xcan be used to refer to a page output by \TeX\ when $\.{\\count0}=1$
Xand $\.{\\count2}=-5$. (Recall that |bop| commands in a \.{DVI} file
Xare followed by ten `count' values.) An asterisk matches any number,
Xso the `\.*' in `\.{1.*.-5}' means that \.{\\count1} is ignored when
Xspecifying the first page. If several pages match the given specification,
X\.{DVIDOC} will begin with the earliest such page in the file. The
Xdefault specification `\.*' (which matches all pages) therefore denotes
Xthe page at the beginning of the file.
X
XWhen \.{DVIDOC} begins, it engages the user in a brief dialog so that the
Xoptions will be specified. This part of \.{DVIDOC} requires nonstandard
X\PASCAL\ constructions to handle the online interaction.
X
X@<Glob...@>=
X@!max_pages:integer; {at most this many |bop..eop| pages will be printed}
X@!horiz_resolution:real; {pixels per inch}
X@!vert_resolution:real; {pixels per inch}
X@!new_mag:integer; {if positive, overrides the postamble's magnification}
X
X@ The starting page specification is recorded in two global arrays called
X|start_count| and |start_there|. For example, `\.{1.*.-5}' is represented
Xby |start_there[0]=true|, |start_count[0]=1|, |start_there[1]=false|,
X|start_there[2]=true|, |start_count[2]=-5|.
XWe also set |start_vals=2|, to indicate that count 2 was the last one
Xmentioned. The other values of |start_count| and |start_there| are not
Ximportant, in this example.
X
X@<Glob...@>=
X@!start_count:array[0..9] of integer; {count values to select starting page}
X@!start_there:array[0..9] of boolean; {is the |start_count| value relevant?}
X@!start_vals:0..9; {the last count considered significant}
X@!count:array[0..9] of integer; {the count values on the current page}
X
X@ @<Set init...@>=
Xmax_pages:=1000000; start_vals:=0; start_there[0]:=false;
X
X@ Here is a simple subroutine that tests if the current page might be the
Xstarting page.
X
X at p function start_match:boolean; {does |count| match the starting spec?}
Xvar k:0..9;  {loop index}
X@!match:boolean; {does everything match so far?}
Xbegin match:=true;
Xfor k:=0 to start_vals do
X  if start_there[k]and(start_count[k]<>count[k]) then match:=false;
Xstart_match:=match;
Xend;
X
X@ The |input_ln| routine waits for the user to type a line at his or her
Xterminal; then it puts ascii-code equivalents for the characters on that line
Xinto the |buffer| array. 
X
X@<Glob...@>=
X@!buffer:array[0..terminal_line_length] of ascii_code;
X
X@ Since the terminal is being used for both input and output, some systems
Xneed a special routine to make sure that the user can see a prompt message
Xbefore waiting for input based on that message. (Otherwise the message
Xmay just be sitting in a hidden buffer somewhere, and the user will have
Xno idea what the program is waiting for.) We shall call a system-dependent
Xsubroutine |update_terminal| in order to avoid this problem.
X
X at d update_terminal == flush(term_out) {empty the terminal output buffer}
X
X@ During the dialog, \.{DVIDOC} will treat the first blank space in a
Xline as the end of that line. Therefore |input_ln| makes sure that there
Xis always at least one blank space in |buffer|.
X
X at p procedure input_ln; {inputs a line from the terminal}
Xvar k:0..terminal_line_length;
Xbegin update_terminal;
Xif eoln(term_in) then read_ln(term_in);
Xk:=0;
Xwhile (k<terminal_line_length)and not eoln(term_in) do
X  begin buffer[k]:=xord[term_in^]; incr(k); get(term_in);
X  end;
Xbuffer[k]:=" ";
Xend;
X
X@ The global variable |buf_ptr| is used while scanning each line of input;
Xit points to the first unread character in |buffer|.
X
X@<Glob...@>=
X@!buf_ptr:0..terminal_line_length; {the number of characters read}
X
X@ Here is a routine that scans a (possibly signed) integer and computes
Xthe decimal value. If no decimal integer starts at |buf_ptr|, the
Xvalue 0 is returned. The integer should be less than $2^{31}$ in
Xabsolute value.
X
X at p function get_integer:integer;
Xvar x:integer; {accumulates the value}
X@!negative:boolean; {should the value be negated?}
Xbegin if buffer[buf_ptr]="-" then
X  begin negative:=true; incr(buf_ptr);
X  end
Xelse negative:=false;
Xx:=0;
Xwhile (buffer[buf_ptr]>="0")and(buffer[buf_ptr]<="9") do
X  begin x:=10*x+buffer[buf_ptr]-"0"; incr(buf_ptr);
X  end;
Xif negative then get_integer:=-x @+ else get_integer:=x;
Xend;
X
X@ The selected options are put into global variables by the |dialog|
Xprocedure, which is called just as \.{DVIDOC} begins.
X
X at p procedure dialog;
Xlabel 1,2,3,4,5;
Xvar k:integer; {loop variable}
Xbegin
Xwrite_ln(term_out,banner);
X@<Determine the desired |start_count| values@>;
X@<Determine the desired |max_pages|@>;
X@<Determine the desired |horiz_resolution|@>;
X@<Determine the desired |vert_resolution|@>;
X@<Determine the desired |new_mag|@>;
Xend;
X
X@ @<Determine the desired |start...@>=
X2: write(term_out,'Starting page (default=*): ');
Xstart_vals:=0; start_there[0]:=false;
Xinput_ln; buf_ptr:=0; k:=0;
Xif buffer[0]<>" " then
X  repeat if buffer[buf_ptr]="*" then
X    begin start_there[k]:=false; incr(buf_ptr);
X    end
X  else  begin start_there[k]:=true; start_count[k]:=get_integer;
X    end;
X  if (k<9)and(buffer[buf_ptr]=".") then
X    begin incr(k); incr(buf_ptr);
X    end
X  else if buffer[buf_ptr]=" " then start_vals:=k
X  else  begin write(term_out,'Type, e.g., 1.*.-5 to specify the ');
X    write_ln(term_out,'first page with \count0=1, \count2=-5.');
X    goto 2;
X    end;
X  until start_vals=k
X
X@ @<Determine the desired |max_pages|@>=
X3: write(term_out,'Maximum number of pages (default=1000000): ');
Xmax_pages:=1000000; input_ln; buf_ptr:=0;
Xif buffer[0]<>" " then
X  begin max_pages:=get_integer;
X  if max_pages<=0 then
X    begin write_ln(term_out,'Please type a positive number.');
X    goto 3;
X    end;
X  end
X
X@ @<Determine the desired |horiz_resolution|@>=
X1: write(term_out,'Horizontal resolution');
Xwrite(term_out,' in characters per inch (default=10/1): ');
Xhoriz_resolution:=10.0; input_ln; buf_ptr:=0;
Xif buffer[0]<>" " then
X  begin k:=get_integer;
X  if (k>0)and(buffer[buf_ptr]="/")and
X    (buffer[buf_ptr+1]>"0")and(buffer[buf_ptr+1]<="9") then
X    begin incr(buf_ptr); horiz_resolution:=k/get_integer;
X    end
X  else  begin write(term_out,'Type a ratio of positive integers;');
X    write_ln(term_out,' (1 character per mm would be 254/10).');
X    goto 1;
X    end;
X  end
X
X@ @<Determine the desired |vert_resolution|@>=
X4: write(term_out,'Vertical resolution');
Xwrite(term_out,' in lines per inch (default=6/1): ');
Xvert_resolution:=6.0; input_ln; buf_ptr:=0;
Xif buffer[0]<>" " then
X  begin k:=get_integer;
X  if (k>0)and(buffer[buf_ptr]="/")and
X    (buffer[buf_ptr+1]>"0")and(buffer[buf_ptr+1]<="9") then
X    begin incr(buf_ptr); vert_resolution:=k/get_integer;
X    end
X  else  begin write(term_out,'Type a ratio of positive integers;');
X    write_ln(term_out,' (1 line per mm would be 254/10).');
X    goto 4;
X    end;
X  end
X
X@ @<Determine the desired |new_mag|@>=
X5: write(term_out,'New magnification (default=0 to keep the old one): ');
Xnew_mag:=0; input_ln; buf_ptr:=0;
Xif buffer[0]<>" " then
X  if (buffer[0]>="0")and(buffer[0]<="9") then new_mag:=get_integer
X  else  begin write(term_out,'Type a positive integer to override ');
X    write_ln(term_out,'the magnification in the DVI file.');
X    goto 5;
X    end
X
X@* Defining fonts.
X\.{DVIDOC} reads the postamble first and loads
Xall of the donts defined there; then it processes the pages. In this
Xcase, a \\{fnt\_def} command should match a previous definition if and only
Xif the \\{fnt\_def} being processed is not in the postamble. 
X
XA global variable |in_postamble| is provided to tell whether we are
Xprocessing the postamble or not.
X
X@<Glob...@>=
X@!in_postamble:boolean; {are we reading the postamble?}
X
X@ @<Set init...@>=
Xin_postamble:=false;
X
X@ The following subroutine does the necessary things when a \\{fnt\_def}
Xcommand is being processed.
X
X at p procedure define_font(@!e:integer); {|e| is an external font number}
Xvar f:0..max_fonts;
X@!p:integer; {length of the area/directory spec}
X@!n:integer; {length of the font name proper}
X@!c,@!q,@!d:integer; {check sum, scaled size, and design size}
X@!r:0..name_length; {index into |cur_name|}
X@!j,@!k:0..name_size; {indices into |names|}
X@!mismatch:boolean; {do names disagree?}
Xbegin if nf=max_fonts then abort('DVIDOC capacity exceeded (max fonts=',
X    max_fonts:0,')!');
X at .DVIDOC capacity exceeded...@>
Xfont_num[nf]:=e; f:=0;
Xwhile font_num[f]<>e do incr(f);
X@<Read the font parameters into position for font |nf|, and
X  print the font name@>;
Xif in_postamble then
X  begin if f<nf then write_ln(term_out,'---this font was already defined!');
X at .this font was already defined@>
X  end
Xelse  begin if f=nf then write_ln(term_out,'---this font wasn''t loaded before!');
X at .this font wasn't loaded before@>
X  end;
Xif f=nf then @<Load the new font, unless there are problems@>
Xelse @<Check that the current font definition matches the old one@>;
Xend;
X
X@ @<Check that the current...@>=
Xbegin if font_check_sum[f]<>c then
X  write_ln(term_out,'---check sum doesn''t match previous definition!');
X at .check sum doesn't match@>
Xif font_scaled_size[f]<>q then
X  write_ln(term_out,'---scaled size doesn''t match previous definition!');
X at .scaled size doesn't match@>
Xif font_design_size[f]<>d then
X  write_ln(term_out,'---design size doesn''t match previous definition!');
X at .design size doesn't match@>
Xj:=font_name[f]; k:=font_name[nf]; mismatch:=false;
Xwhile j<font_name[f+1] do
X  begin if names[j]<>names[k] then mismatch:=true;
X  incr(j); incr(k);
X  end;
Xif k<>font_name[nf+1] then mismatch:=true;
Xif mismatch then write_ln(term_out,'---font name doesn''t match previous definition!');
X at .font name doesn't match@>
Xwrite_ln(term_out)
Xend
X
X@ @<Read the font parameters into position for font |nf|...@>=
Xc:=signed_quad; font_check_sum[nf]:=c;@/
Xq:=signed_quad; font_scaled_size[nf]:=q;@/
Xd:=signed_quad; font_design_size[nf]:=d;@/
Xp:=get_byte; n:=get_byte;
Xif font_name[nf]+n+p>name_size then
X  abort('DVIDOC capacity exceeded (name size=',name_size:0,')!');
X at .DVIDOC capacity exceeded...@>
Xfont_name[nf+1]:=font_name[nf]+n+p;
Xwrite(term_out,'Font ',e:0,': ');
Xif n+p=0 then write(term_out,'null font name!')
X at .null font name@>
Xelse for k:=font_name[nf] to font_name[nf+1]-1 do names[k]:=get_byte;
Xincr(nf); print_font(nf-1); decr(nf)
X
X@ @<Load the new font, unless there are problems@>=
Xbegin @<Move font name into the |cur_name| string@>;
Xopen_tfm_file;
Xif eof(tfm_file) then
X  write(term_out,'---not loaded, TFM file can''t be opened!')
X at .TFM file can\'t be opened@>
Xelse  begin if (q<=0)or(q>=@'1000000000) then
X    write(term_out,'---not loaded, bad scale (',q:0,')!')
X at .bad scale@>
X  else if (d<=0)or(d>=@'1000000000) then
X    write(term_out,'---not loaded, bad design size (',d:0,')!')
X at .bad design size@>
X  else if in_TFM(q) then @<Finish loading the new font info@>;
X  end;
Xwrite_ln(term_out,' ');
Xend
X
X@ @<Finish loading...@>=
Xbegin font_space[nf]:=q div 6; {this is a 3-unit ``thin space''}
Xif (c<>0)and(tfm_check_sum<>0)and(c<>tfm_check_sum) then
X  begin write_ln(term_out,'---beware: check sums do not agree!');
X at .beware: check sums do not agree@>
X at .check sums do not agree@>
X  write_ln(term_out,'   (',c:0,' vs. ',tfm_check_sum:0,')');
X  write(term_out,'   ');
X  end;
Xwrite(term_out,'---loaded at size ',q:0,' DVI units');
Xd:=trunc((100.0*horiz_conv*q)/(true_horiz_conv*d)+0.5);
Xif d<>100 then
X  begin write_ln(term_out,' '); write(term_out,' (this font is magnified ',d:0,'%)');
X  end;
X at .this font is magnified@>
Xincr(nf); {now the new font is officially present}
Xend
X
X@ If |p=0|, i.e., if no font directory has been specified, \.{DVIDOC}
Xis supposed to use the default font directory, which is a
Xsystem-dependent place where the standard fonts are kept.
XThe string variable |default_directory| contains the name of this area.
X@^changed module@>
X
X at d default_directory_name=='TEXFONTS:' {changed to the correct name}
X at d default_directory_name_length=9 {changed to the correct length}
X
X@<Glob...@>=
X@!default_directory:packed array[1..default_directory_name_length] of char;
X
X@ @<Set init...@>=
Xdefault_directory:=default_directory_name;
X
X@ The string |cur_name| is supposed to be set to the external name of the
X\.{TFM} file for the current font. This usually means that we need to,
Xat most sites, append the
Xsuffix ``.tfm''.
X
X@<Move font name into the |cur_name| string@>=
Xfor k:=1 to name_length do cur_name[k]:=' ';
Xr:=0;
Xfor k:=font_name[nf] to font_name[nf+1]-1 do
X  begin incr(r);
X  if r+4>name_length then
X    abort('DVIDOC capacity exceeded (max font name length=',
X      name_length:0,')!');
X at .DVIDOC capacity exceeded...@>
X    cur_name[r]:=xchr[names[k]];
X    end;
Xcur_name[r+1]:='.'; cur_name[r+2]:='t'; cur_name[r+3]:='f'; cur_name[r+4]:='m'
X
X@* Low level output routines.
XCharacters set by the \.{DVI} file are placed in |page_buffer|, a two
Xdimensional array of characters with one element for each print
Xposition on the page.  The |page_buffer| is cleared at the beginning
Xof each page and printed at the end of each page.  
X|doc_file|, the file to which the document is destined, is an ordinary text
Xfile.
X
XTo optimize the initialization and printing of |page_buffer|, a high
Xwater mark line number, |page_hwm|, is kept to indicate the last line
Xthat contains any printable characters, and for each line a high water
Xmark character number, |line_hwm|, is kept to indicate the location of
Xthe last printable character in the line.
X
X@<Glob...@>=
X@!doc_file:text_file;
X@!page_buffer:packed array[1..page_width_max,1..page_length_max] of ascii_code;
X                 {storage for a document page}
X@!line_hwm:array[1..page_length_max] of 0..page_width_max;
X                 {high water marks for each line}
X@!page_hwm: 0..page_length_max;  {high water mark for page}
X
X@ |doc_file| needs to be opened.
X
X@<Set initial values@>=
Xargv(2, cur_name);
Xif test_access(write_access_mode, no_file_path) then
Xrewrite(doc_file, cur_name)
Xelse begin
Xerror('Cannot write output file');
Xgoto done;
Xend;
X
X@ The |flush_page| procedure will print the |page_buffer|.
X
X at p procedure flush_page;
Xvar i:0..page_width_max; j:0..page_length_max;
Xbegin
X  for j := 1 to page_hwm do begin
X    for i := 1 to line_hwm[j] do
X      write (doc_file, xchr[page_buffer[i,j]]);
X    write_ln (doc_file) end;
X  write (doc_file, chr(12))  {end the page with a form feed}  
Xend;
X
X@ The |empty_page| procedure will empty the |page_buffer| data structure.
X
X at p procedure empty_page;
Xbegin page_hwm := 0 end;
X
X@ And the |out_char| procedure puts something into it.  The usual printable
Xascii characters will be put into the buffer as is.  Non-printable characters,
Xincluding the blank, will be put into the buffer as question mark chracters.
X
X at p procedure out_char(p,hh,vv:integer);
Xvar i:1..page_width_max; j:1..page_length_max;
X     {|hh| and |vv| range from zero up while |i| and |j| range from one up.}
X    k: integer;
X    c: ascii_code;
Xbegin
X  if 
X    (p>" ")and(p<="~") then c:=p
X    else c:=xord['?'];
X  if 
X    (hh>page_width_max-1) or (vv>page_length_max-1) then begin 
X      write_ln (term_out);
X      write (term_out, 'Character "', xchr[c], '" set at column ', hh+1:0);
X      write_ln (term_out, ' and row ', vv+1:0, ',');
X      write (term_out, 'outside the range of DVIDOC (');
X at .outside the range of DVIDOC@>
X      write (term_out, page_width_max:0, ',', page_length_max:0, ').');
X      write_ln (term_out) end
X    else begin
X      i := hh + 1;
X      j := vv + 1;
X      if j>page_hwm then begin {initialize any as yet untouched lines}
X        for k := page_hwm+1 to j do line_hwm[k]:=0;
X        page_hwm := j end;
X      if i>line_hwm[j] then begin {initialize any as yet untouched characters}
X        for k := line_hwm[j]+1 to i do page_buffer[k,j] := xord[' '];
X        line_hwm[j] := i end;
X      page_buffer[i,j] := c {put the character in its place}  end
Xend;
X
X@* Translation to symbolic form.
XThe main work of \.{DVIDOC} is accomplished by the |do_page| procedure,
Xwhich produces the output for an entire page, assuming that the |bop|
Xcommand for that page has already been processed. This procedure is
Xessentially an interpretive routine that reads and acts on the \.{DVI}
Xcommands.
X
X@ The definition of \.{DVI} files refers to six registers,
X$(h,v,w,x,y,z)$, which hold integer values in \.{DVI} units.  In practice,
Xwe also need registers |hh| and |vv|, the pixel analogs of $h$ and $v$,
Xsince it is not always true that |hh=horiz_pixel_round(h)| or
X|vv=vert_pixel_round(v)|.
X
XThe stack of $(h,v,w,x,y,z)$ values is represented by eight arrays
Xcalled |hstack|, \dots, |zstack|, |hhstack|, and |vvstack|.
X
X@<Glob...@>=
X@!h,@!v,@!w,@!x,@!y,@!z,@!hh,@!vv:integer; {current state values}
X@!hstack,@!vstack,@!wstack,@!xstack,@!ystack,@!zstack:
X  array [0..stack_size] of integer; {pushed down values in \.{DVI} units}
X@!hhstack,@!vvstack:
X  array [0..stack_size] of integer; {pushed down values in pixels}
X
X@ Three characteristics of the pages (their |max_v|, |max_h|, and
X|max_s|) are specified in the postamble, and a warning message
Xis printed if these limits are exceeded. Actually |max_v| is set to
Xthe maximum height plus depth of a page, and |max_h| to the maximum width,
Xfor purposes of page layout. Since characters can legally be set outside
Xof the page boundaries, it is not an error when |max_v| or |max_h| is
Xexceeded. But |max_s| should not be exceeded.
X
XThe postamble also specifies the total number of pages; \.{DVIDOC}
Xchecks to see if this total is accurate.
X
X@<Glob...@>=
X@!max_v:integer; {the value of |abs(v)| should probably not exceed this}
X@!max_h:integer; {the value of |abs(h)| should probably not exceed this}
X@!max_s:integer; {the stack depth should not exceed this}
X@!max_v_so_far,@!max_h_so_far,@!max_s_so_far:integer; {the record high levels}
X@!total_pages:integer; {the stated total number of pages}
X@!page_count:integer; {the total number of pages seen so far}
X
X@ @<Set init...@>=
Xmax_v:=@'17777777777; max_h:=@'17777777777; max_s:=stack_size+1;@/
Xmax_v_so_far:=0; max_h_so_far:=0; max_s_so_far:=0; page_count:=0;
X
X@ Before we get into the details of |do_page|, it is convenient to
Xconsider a simpler routine that computes the first parameter of each
Xopcode.
X
X at d four_cases(#)==#,#+1,#+2,#+3
X at d eight_cases(#)==four_cases(#),four_cases(#+4)
X at d sixteen_cases(#)==eight_cases(#),eight_cases(#+8)
X at d thirty_two_cases(#)==sixteen_cases(#),sixteen_cases(#+16)
X at d sixty_four_cases(#)==thirty_two_cases(#),thirty_two_cases(#+32)
X
X at p function first_par(o:eight_bits):integer;
Xbegin case o of
Xsixty_four_cases(set_char_0),sixty_four_cases(set_char_0+64):
X  first_par:=o-set_char_0;
Xset1,put1,fnt1,xxx1,fnt_def1: first_par:=get_byte;
Xset1+1,put1+1,fnt1+1,xxx1+1,fnt_def1+1: first_par:=get_two_bytes;
Xset1+2,put1+2,fnt1+2,xxx1+2,fnt_def1+2: first_par:=get_three_bytes;
Xright1,w1,x1,down1,y1,z1: first_par:=signed_byte;
Xright1+1,w1+1,x1+1,down1+1,y1+1,z1+1: first_par:=signed_pair;
Xright1+2,w1+2,x1+2,down1+2,y1+2,z1+2: first_par:=signed_trio;
Xset1+3,set_rule,put1+3,put_rule,right1+3,w1+3,x1+3,down1+3,y1+3,z1+3,
X  fnt1+3,xxx1+3,fnt_def1+3: first_par:=signed_quad;
Xnop,bop,eop,push,pop,pre,post,post_post,undefined_commands: first_par:=0;
Xw0: first_par:=w;
Xx0: first_par:=x;
Xy0: first_par:=y;
Xz0: first_par:=z;
Xsixty_four_cases(fnt_num_0): first_par:=o-fnt_num_0;
Xend;
Xend;
X
X@ Here are two other subroutines that we need: They compute the number of
Xpixels in the height or width of a rule. Characters and rules will line up
Xproperly if the sizes are computed precisely as specified here.  (Since
X|horiz_conv| and |vert_conv| 
Xare computed with some floating-point roundoff error, in a
Xmachine-dependent way, format designers who are tailoring something for a
Xparticular resolution should not plan their measurements to come out to an
Xexact integer number of pixels; they should compute things so that the
Xrule dimensions are a little less than an integer number of pixels, e.g.,
X4.99 instead of 5.00.)
X
X at p function horiz_rule_pixels(x:integer):integer;
X  {computes $\lceil|horiz_conv|\cdot x\rceil$}
Xvar n:integer;
Xbegin n:=trunc(horiz_conv*x);
Xif n<horiz_conv*x then horiz_rule_pixels:=n+1 @+ else horiz_rule_pixels:=n;
Xend;
X
Xfunction vert_rule_pixels(x:integer):integer;
X  {computes $\lceil|vert_conv|\cdot x\rceil$}
Xvar n:integer;
Xbegin n:=trunc(vert_conv*x);
Xif n<vert_conv*x then vert_rule_pixels:=n+1 @+ else vert_rule_pixels:=n;
Xend;
X
X@ Strictly speaking, the |do_page| procedure is really a function with
Xside effects, not a `\&{procedure}'; it returns the value |false| if
X\.{DVIDOC} should be aborted because of some unusual happening. The
Xsubroutine is organized as a typical interpreter, with a multiway branch
Xon the command code followed by |goto| statements leading to routines that
Xfinish up the activities common to different commands. We will use the
Xfollowing labels:
X
X at d fin_set=41 {label for commands that set or put a character}
X at d fin_rule=42 {label for commands that set or put a rule}
X at d move_right=43 {label for commands that change |h|}
X at d move_down=44 {label for commands that change |v|}
X at d show_state=45 {label for commands that change |s|}
X at d change_font=46 {label for commands that change |cur_font|}
X
X@ Some \PASCAL\ compilers severely restrict the length of procedure bodies,
Xso we shall split |do_page| into two parts, one of which is
Xcalled |special_cases|. The different parts communicate with each other
Xvia the global variables mentioned above, together with the following ones:
X
X@<Glob...@>=
X@!s:integer; {current stack size}
X@!ss:integer; {stack size to print}
X@!cur_font:integer; {current internal font number}
X
X@ Here is the overall setup.
X
X at p @<Declare the function called |special_cases|@>@;
Xfunction do_page:boolean;
Xlabel fin_set,fin_rule,move_right,show_state,done,9998,9999;
Xvar o:eight_bits; {operation code of the current command}
X@!p,@!q:integer; {parameters of the current command}
X@!a:integer; {byte number of the current command}
Xi,j:integer; {for loop indices for setting rules}
Xbegin empty_page; cur_font:=nf; {set current font undefined}
Xs:=0; h:=0; v:=0; w:=0; x:=0; y:=0; z:=0; hh:=0; vv:=0;
X  {initialize the state variables}
Xwhile true do @<Translate the next command in the \.{DVI} file;
X    |goto 9999| with |do_page=true| if it was |eop|;
X    |goto 9998| if premature termination is needed@>;
X9998: write_ln(term_out,'!'); do_page:=false;
X9999: end;
X
X@ 
X
X@<Translate the next command...@>=
Xbegin a:=cur_loc; 
Xo:=get_byte; p:=first_par(o);
Xif eof(dvi_file) then abort('the file ended prematurely!');
X at .the file ended prematurely@>
X@<Start translation of command |o| and |goto| the appropriate label to
X  finish the job@>;
Xfin_set: @<Finish a command that either sets or puts a character, then
X    |goto move_right| or |done|@>;
Xfin_rule: @<Finish a command that either sets or puts a rule, then
X    |goto move_right| or |done|@>;
Xmove_right: @<Finish a command that sets |h:=h+q|, then |goto done|@>;
Xshow_state: ;
Xdone: ;
Xend
X
X@ The multiway switch in |first_par|, above, was organized by the length
Xof each command; the one in |do_page| is organized by the semantics.
X
X@<Start translation...@>=
Xif o<set_char_0+128 then @<Translate a |set_char| command@>
Xelse case o of
X  four_cases(set1): begin out_char(p,hh,vv); goto fin_set;
X    end;
X  set_rule: begin goto fin_rule;
X    end;
X  put_rule: begin goto fin_rule;
X    end;
X  @t\4@>@<Cases for commands |nop|, |bop|, \dots, |pop|@>@;
X  @t\4@>@<Cases for horizontal motion@>@;
X  othercases if special_cases(o,p,a) then goto done at +else goto 9998
X  endcases
X
X@ @<Declare the function called |special_cases|@>=
Xfunction special_cases(@!o:eight_bits;@!p,@!a:integer):boolean;
Xlabel change_font,move_down,done,9998;
Xvar q:integer; {parameter of the current command}
X@!k:integer; {loop index}
X@!bad_char:boolean; {has a non-ascii character code appeared in this \\{xxx}?}
X@!pure:boolean; {is the command error-free?}
Xbegin pure:=true;
Xcase o of
Xfour_cases(put1): begin goto done;
X  end;
X at t\4@>@<Cases for vertical motion@>@;
X at t\4@>@<Cases for fonts@>@;
Xfour_cases(xxx1): @<Translate an |xxx| command and |goto done|@>;
Xpre: begin error('preamble command within a page!'); goto 9998;
X  end;
X at .preamble command within a page@>
Xpost,post_post: begin error('postamble command within a page!'); goto 9998;
X at .postamble command within a page@>
X  end;
Xothercases begin error('undefined command ',o:0,'!');
X  goto done;
X at .undefined command@>
X  end
Xendcases;
Xmove_down: @<Finish a command that sets |v:=v+p|, then |goto done|@>;
Xchange_font: @<Finish a command that changes the current font,
X  then |goto done|@>;
X9998: pure:=false;
Xdone: special_cases:=pure;
Xend;
X
X@ @<Cases for commands |nop|, |bop|, \dots, |pop|@>=
Xnop: begin goto done;
X  end;
Xbop: begin error('bop occurred before eop'); goto 9998;
X at .bop occurred before eop@>
X  end;
Xeop: begin 
X  if s<>0 then error('stack not empty at end of page (level ',
X    s:0,')!');
X at .stack not empty...@>
X  do_page:=true; flush_page; goto 9999;
X  end;
Xpush: begin 
X  if s=max_s_so_far then
X    begin max_s_so_far:=s+1;
X    if s=max_s then error('deeper than claimed in postamble!');
X at .deeper than claimed...@>
X at .push deeper than claimed...@>
X    if s=stack_size then
X      begin error('DVIDOC capacity exceeded (stack size=',
X        stack_size:0,')'); goto 9998;
X      end;
X    end;
X  hstack[s]:=h; vstack[s]:=v; wstack[s]:=w;
X  xstack[s]:=x; ystack[s]:=y; zstack[s]:=z;
X  hhstack[s]:=hh; vvstack[s]:=vv; incr(s); ss:=s-1; goto show_state;
X  end;
Xpop: begin 
X  if s=0 then error('Pop illegal at level zero!')
X  else  begin decr(s); hh:=hhstack[s]; vv:=vvstack[s];
X    h:=hstack[s]; v:=vstack[s]; w:=wstack[s];
X    x:=xstack[s]; y:=ystack[s]; z:=zstack[s];
X    end;
X  ss:=s; goto show_state;
X  end;
X
X@ Rounding to the nearest pixel is best done in the manner shown here, so as
Xto be inoffensive to the eye: When the horizontal motion is small, like a
Xkern, |hh| changes by rounding the kern; but when the motion is large, |hh|
Xchanges by rounding the true position |h| so that accumulated rounding errors
Xdisappear.
X
X
X at d out_space==if abs(p)>=font_space[cur_font] then
X    begin hh:=horiz_pixel_round(h+p);
X    end
X  else hh:=hh+horiz_pixel_round(p);
X  q:=p; goto move_right
X
X@<Cases for horizontal motion@>=
Xfour_cases(right1):begin out_space;
X  end;
Xw0,four_cases(w1):begin w:=p; out_space;
X  end;
Xx0,four_cases(x1):begin x:=p; out_space;
X  end;
X
X@ Vertical motion is done similarly, but with the threshold between
X``small'' and ``large'' increased by a factor of five. The idea is to make
Xfractions like ``$1\over2$'' round consistently, but to absorb accumulated
Xrounding errors in the baseline-skip moves.
X
X at d out_vmove==if abs(p)>=5*font_space[cur_font] then vv:=vert_pixel_round(v+p)
X  else vv:=vv+vert_pixel_round(p);
X  goto move_down
X
X@<Cases for vertical motion@>=
Xfour_cases(down1):begin out_vmove;
X  end;
Xy0,four_cases(y1):begin y:=p; out_vmove;
X  end;
Xz0,four_cases(z1):begin z:=p; out_vmove;
X  end;
X
X@ @<Cases for fonts@>=
Xsixty_four_cases(fnt_num_0): begin 
X  goto change_font;
X  end;
Xfour_cases(fnt1): begin 
X  goto change_font;
X  end;
Xfour_cases(fnt_def1): begin 
X  define_font(p); goto done;
X  end;
X
X@ @<Translate an |xxx| command and |goto done|@>=
Xbegin write(term_out,'xxx'''); bad_char:=false;
Xfor k:=1 to p do
X  begin 
X    q:=get_byte;
X    if 
X      (q>="!")and(q<="~") then write(term_out,xchr[q])
X      else bad_char:=true
X  end;
Xwrite(term_out,'''');
Xif bad_char then error('non-ascii character in xxx command!');
X at .non-ascii character...@>
Xgoto done;
Xend
X
X@ @<Translate a |set_char|...@>=
Xbegin 
X      out_char(p,hh,vv)  
Xend
X
X@ @<Finish a command that either sets or puts a character...@>=
Xif font_ec[cur_font]=256 then p:=256; {width computation for oriental fonts}
Xif (p<font_bc[cur_font])or(p>font_ec[cur_font]) then q:=invalid_width
Xelse q:=char_width(cur_font)(p);
Xif q=invalid_width then
X  begin error('character ',p:0,' invalid in font ');
X at .character $c$ invalid...@>
X  print_font(cur_font);
X  if cur_font<>nf then write(term_out,'!');
X  end;
Xif o>=put1 then goto done;
Xif q=invalid_width then q:=0
Xelse hh:=hh+char_pixel_width(cur_font)(p);
Xgoto move_right
X
X@ @<Finish a command that either sets or puts a rule...@>=
Xq:=signed_quad;
Xif (p>0) and (q>0) then
X  for i:=hh to hh+horiz_rule_pixels(q)-1 do
X    for j:=vv downto vv-vert_rule_pixels(p)+1 do
X      out_char(xord['-'],i,j);
Xif o=put_rule then goto done;
Xhh:=hh+horiz_rule_pixels(q); goto move_right
X
X@ Since \.{DVIDOC} is intended to diagnose strange errors, it checks
Xcarefully to make sure that |h| and |v| do not get out of range.
XNormal \.{DVI}-reading programs need not do this.
X
X at d infinity==@'17777777777 {$\infty$ (approximately)}
X
X@<Finish a command that sets |h:=h+q|, then |goto done|@>=
Xif (h>0)and(q>0) then if h>infinity-q then
X  begin error('arithmetic overflow! parameter changed from ',
X at .arithmetic overflow...@>
X    q:0,' to ',infinity-h:0);
X  q:=infinity-h;
X  end;
Xif (h<0)and(q<0) then if -h>q+infinity then
X  begin error('arithmetic overflow! parameter changed from ',
X    q:0, ' to ',(-h)-infinity:0);
X  q:=(-h)-infinity;
X  end;
Xh:=h+q;
Xif abs(h)>max_h_so_far then
X  begin max_h_so_far:=abs(h);
X  if abs(h)>max_h then error('warning: |h|>',max_h_so_far:0,'!');
X at .warning: |h|...@>
X  end;
Xgoto done
X
X@ @<Finish a command that sets |v:=v+p|, then |goto done|@>=
Xif (v>0)and(p>0) then if v>infinity-p then
X  begin error('arithmetic overflow! parameter changed from ',
X at .arithmetic overflow...@>
X    p:0,' to ',infinity-v:0);
X  p:=infinity-v;
X  end;
Xif (v<0)and(p<0) then if -v>p+infinity then
X  begin error('arithmetic overflow! parameter changed from ',
X    p:0, ' to ',(-v)-infinity:0);
X  p:=(-v)-infinity;
X  end;
Xv:=v+p;
Xif abs(v)>max_v_so_far then
X  begin max_v_so_far:=abs(v);
X  if abs(v)>max_v then error('warning: |v|>',max_v_so_far:0,'!');
X at .warning: |v|...@>
X  end;
Xgoto done
X
X@ @<Finish a command that changes the current font...@>=
Xfont_num[nf]:=p; cur_font:=0;
Xwhile font_num[cur_font]<>p do incr(cur_font);
Xgoto done
X
X@* Skipping pages.
X@ Global variables called |old_backpointer| and |new_backpointer|
Xare used to check whether the back pointers are properly set up.
XAnother one tells whether we have already found the starting page.
X
X@<Glob...@>=
X@!old_backpointer:integer; {the previous |bop| command location}
X@!new_backpointer:integer; {the current |bop| command location}
X@!started:boolean; {has the starting page been found?}
X
X@ @<Set init...@>=
Xold_backpointer:=-1; started:=false;
X
X@ @<Pass a |bop| command, setting up the |count| array@>=
Xnew_backpointer:=cur_loc-1; incr(page_count);
Xfor k:=0 to 9 do count[k]:=signed_quad;
Xif signed_quad<>old_backpointer
X  then write_ln(term_out,'backpointer in byte ',cur_loc-4:0,
X    ' should be ',old_backpointer:0,'!');
X at .backpointer...should be p@>
Xold_backpointer:=new_backpointer
X
X@* Using the backpointers.
XFirst comes a routine that illustrates how to find the postamble quickly.
X
X@<Find the postamble, working back from the end@>=
Xn:=dvi_length;
Xif n<57 then bad_dvi('only ',n:0,' bytes long');
X at .only n bytes long@>
Xm:=n-4;
Xrepeat if m=0 then bad_dvi('all 223s');
X at .all 223s@>
Xmove_to_byte(m); k:=get_byte; decr(m);
Xuntil k<>223;
Xif k<>id_byte then bad_dvi('ID byte is ',k:0);
X at .ID byte is wrong@>
Xmove_to_byte(m-3); q:=signed_quad;
Xif (q<0)or(q>m-36) then bad_dvi('post pointer ',q:0,' at byte ',m-3:0);
X at .post pointer is wrong@>
Xmove_to_byte(q); k:=get_byte;
Xif k<>post then bad_dvi('byte ',q:0,' is not post');
X at .byte n is not post@>
Xpost_loc:=q; first_backpointer:=signed_quad
X
X@ Note that the last steps of the above code save the locations of the
Xthe |post| byte and the final |bop|.  We had better declare these global
Xvariables, together with another one that we will need shortly.
X
X@<Glob...@>=
X@!post_loc:integer; {byte location where the postamble begins}
X@!first_backpointer:integer; {the pointer following |post|}
X@!start_loc:integer; {byte location of the first page to process}
X
X@ The next little routine shows how the backpointers can be followed
Xto move through a \.{DVI} file in reverse order. Ordinarily a \.{DVI}-reading
Xprogram would do this only if it wants to print the pages backwards or
Xif it wants to find a specified starting page that is not necessarily the
Xfirst page in the file; otherwise it would of course be simpler and faster
Xjust to read the whole file from the beginning.
X
X@<Count the pages and move to the starting page@>=
Xq:=post_loc; p:=first_backpointer; start_loc:=-1;
Xif p>=0 then
X  repeat {now |q| points to a |post| or |bop| command; |p>=0| is prev pointer}
X  if p>q-46 then
X    bad_dvi('page link ',p:0,' after byte ',q:0);
X at .page link wrong...@>
X  q:=p; move_to_byte(q); k:=get_byte;
X  if k=bop then incr(page_count)
X  else bad_dvi('byte ',q:0,' is not bop');
X at .byte n is not bop@>
X  for k:=0 to 9 do count[k]:=signed_quad;
X  if start_match then start_loc:=q;
X  p:=signed_quad;
X  until p<0;
Xif start_loc<0 then abort('starting page number could not be found!');
Xmove_to_byte(start_loc+1); old_backpointer:=start_loc;
Xfor k:=0 to 9 do count[k]:=signed_quad;
Xp:=signed_quad; started:=true
X
X@* Reading the postamble.
XNow imagine that we are reading the \.{DVI} file and positioned just
Xfour bytes after the |post| command. That, in fact, is the situation,
Xwhen the following part of \.{DVIDOC} is called upon to read, translate,
Xand check the rest of the postamble.
X
X at p procedure read_postamble;
Xvar k:integer; {loop index}
X@!p,@!q,@!m:integer; {general purpose registers}
Xbegin 
Xmove_to_byte(cur_loc+12); {skip over numerator, denominator, and magnification}
Xmax_v:=signed_quad; max_h:=signed_quad;@/
Xmax_s:=get_two_bytes; total_pages:=get_two_bytes;@/
X@<Process the font definitions of the postamble@>;
X@<Make sure that the end of the file is well-formed@>;
Xend;
X
X@ When we get to the present code, the |post_post| command has
Xjust been read.
X
X@<Make sure that the end of the file is well-formed@>=
Xq:=signed_quad;
Xm:=get_byte;
Xk:=cur_loc; m:=223;
Xwhile (m=223)and not eof(dvi_file) do m:=get_byte;
Xif not eof(dvi_file) then abort('signature in byte ',cur_loc-1:0,
X at .signature...should be...@>
X    ' should be 223!')
Xelse if cur_loc<k+4 then
X  write_ln(term_out,'not enough signature bytes at end of file (',
X at .not enough signature bytes...@>
X    cur_loc-k:0,')');
X
X@ @<Process the font definitions...@>=
Xrepeat k:=get_byte;
Xif (k>=fnt_def1)and(k<fnt_def1+4) then
X  begin p:=first_par(k); define_font(p); write_ln(term_out,' '); k:=nop;
X  end;
Xuntil k<>nop
X
X@* The main program.
XNow we are ready to put it all together. This is where \.{DVIDOC} starts,
Xand where it ends.
X
X at p begin 
Xif (argc <> 3) then
X    begin
X    error('Usage: dvidoc <dvi-file> <doc-file>');
X    goto done;
X    end;
Xinitialize; {get all variables initialized}
Xdialog; {set up all the options}
X@<Process the preamble@>;
X@<Find the postamble, working back from the end@>;
Xin_postamble:=true; read_postamble; in_postamble:=false;
X@<Count the pages and move to the starting page@>;
Xif not in_postamble then @<Translate up to |max_pages| pages@>;
Xfinal_end:end.
X
X@ The main program needs a few global variables in order to do its work.
X
X@<Glob...@>=
X@!k,@!m,@!n,@!p,@!q:integer; {general purpose registers}
X
X@ A \.{DVI}-reading program that reads the postamble first need not look at the
Xpreamble; but \.{DVIDOC} looks at the preamble in order to do error
Xchecking, and to display the introductory comment.
X
X@<Process the preamble@>=
Xopen_dvi_file;
Xp:=get_byte; {fetch the first byte}
Xif p<>pre then bad_dvi('First byte isn''t start of preamble!');
X at .First byte isn't...@>
Xp:=get_byte; {fetch the identification byte}
X@<Compute the conversion factor@>;
Xp:=get_byte; {fetch the length of the introductory comment}
Xwrite(term_out,'''');
Xwhile p>0 do
X  begin decr(p); write(term_out,xchr[get_byte]);
X  end;
Xwrite_ln(term_out,'''')
X
X@ The conversion factors |horiz_conv| and 
X|vert_conv| are figured as follows: There are exactly
X|n/d| \.{DVI} units per decimicron, and 254000 decimicrons per inch,
Xand |horiz_resolution| or |vert_resolution| characters per inch. Then we have to adjust this
Xby the stated amount of magnification.
X
X@<Compute the conversion factor@>=
Xnumerator:=signed_quad; denominator:=signed_quad;
Xif numerator<=0 then bad_dvi('numerator is ',numerator:0);
X at .numerator is wrong@>
Xif denominator<=0 then bad_dvi('denominator is ',denominator:0);
X at .denominator is wrong@>
Xhoriz_conv:=(numerator/254000.0)*(horiz_resolution/denominator);
Xvert_conv:=(numerator/254000.0)*(vert_resolution/denominator);
Xmag:=signed_quad;
Xif new_mag>0 then mag:=new_mag
Xelse if mag<=0 then bad_dvi('magnification is ',mag:0);
X at .magnification is wrong@>
Xtrue_horiz_conv:=horiz_conv; horiz_conv:=true_horiz_conv*(mag/1000.0);
Xtrue_vert_conv:=vert_conv; vert_conv:=true_vert_conv*(mag/1000.0);
X
X@ The code shown here uses a convention that has proved to be useful:
XIf the starting page was specified as, e.g., `\.{1.*.-5}', then
Xall page numbers in the file are displayed by showing the values of
Xcounts 0, 1, and@@2, separated by dots. Such numbers can, for example,
Xbe displayed on the console of a printer when it is working on that
Xpage.
X
X@<Translate up to...@>=
Xbegin while max_pages>0 do
X  begin decr(max_pages);
X  write_ln(term_out); write(term_out,'Beginning of page ');
X  for k:=0 to start_vals do
X    begin write(term_out,count[k]:0);
X    if k<start_vals then write(term_out,'.')
X    else write_ln(term_out);
X    end;
X  if not do_page then abort('page ended unexpectedly!');
X at .page ended unexpectedly@>
X  repeat k:=get_byte;
X  if (k>=fnt_def1)and(k<fnt_def1+4) then
X    begin p:=first_par(k); define_font(p); k:=nop;
X    end;
X  until k<>nop;
X  if k=post then
X    begin in_postamble:=true; goto done;
X    end;
X  if k<>bop then bad_dvi('byte ',cur_loc-1:0,' is not bop');
X at .byte n is not bop@>
X  @<Pass a |bop|...@>;
X  end;
Xdone:end
X
X@* System-dependent changes.
XThis module should be replaced, if necessary, by changes to the program
Xthat are necessary to make \.{DVIDOC} work at a particular installation.
XIt is usually best to design your change file so that all changes to
Xprevious modules preserve the module numbering; then everybody's version
Xwill be consistent with the printed program. More extensive changes,
Xwhich introduce new modules, can be inserted here; then only the index
Xitself will get a new module number.
X
X@* Index.
XPointers to error messages appear here together with the section numbers
Xwhere each ident\-i\-fier is used.
!FaR!OuT!
if [ ! -d dvidoc ]
then
	mkdir dvidoc
	echo mkdir dvidoc
fi
echo x - dvidoc/dvityext.c
sed -e 's/^X//' > dvidoc/dvityext.c << '!FaR!OuT!'
X/* External procedures for dvitype				*/
X/*   Written by: H. Trickey, 2/19/83 (adapted from TeX's ext.c) */
X
X#include "texpaths.h"		/* defines default TEXFONTS path */
X#include "h00vars.h"		/* defines Pascal I/O structure */
X
Xchar *fontpath;
X
Xchar *getenv();
X
X/*
X * setpaths is called to set up the pointer fontpath
X * as follows:  if the user's environment has a value for TEXFONTS
X * then use it;  otherwise, use defaultfontpath.
X */
Xsetpaths()
X{
X	register char *envpath;
X	
X	if ((envpath = getenv("TEXFONTS")) != NULL)
X	    fontpath = envpath;
X	else
X	    fontpath = defaultfontpath;
X}
X
X#define namelength 100   /* should agree with dvitype.ch */
Xextern char curname[],realnameoffile[]; /* these have size namelength */
X
X/*
X *	testaccess(amode,filepath)
X *
X *  Test whether or not the file whose name is in the global curname
X *  can be opened for reading (if mode=READACCESS)
X *  or writing (if mode=WRITEACCESS).
X *
X *  The filepath argument is one of the ...FILEPATH constants defined below.
X *  If the filename given in curname does not begin with '/', we try 
X *  prepending all the ':'-separated areanames in the appropriate path to the
X *  filename until access can be made, if it ever can.
X *
X *  The realnameoffile global array will contain the name that yielded an
X *  access success.
X */
X
X#define READACCESS 4
X#define WRITEACCESS 2
X
X#define NOFILEPATH 0
X#define FONTFILEPATH 3
X
Xbool
Xtestaccess(amode,filepath)
X    int amode,filepath;
X{
X    register bool ok;
X    register char *p;
X    char *curpathplace;
X    int f;
X    
X    switch(filepath) {
X	case NOFILEPATH: curpathplace = NULL; break;
X	case FONTFILEPATH: curpathplace = fontpath; break;
X	}
X    if (curname[0]=='/')	/* file name has absolute path */
X	curpathplace = NULL;
X    do {
X	packrealnameoffile(&curpathplace);
X	if (amode==READACCESS)
X	    /* use system call "access" to see if we could read it */
X	    if (access(realnameoffile,READACCESS)==0) ok = TRUE;
X	    else ok = FALSE;
X	else {
X	    /* WRITEACCESS: use creat to see if we could create it, but close
X	    the file again if we're OK, to let pc open it for real */
X	    f = creat(realnameoffile,0666);
X	    if (f>=0) ok = TRUE;
X	    else ok = FALSE;
X	    if (ok)
X		close(f);
X	    }
X    } while (!ok && curpathplace != NULL);
X    if (ok) {  /* pad realnameoffile with blanks, as Pascal wants */
X	for (p = realnameoffile; *p != '\0'; p++)
X	    /* nothing: find end of string */ ;
X	while (p < &(realnameoffile[namelength]))
X	    *p++ = ' ';
X	}
X    return (ok);
X}
X
X/*
X * packrealnameoffile(cpp) makes realnameoffile contain the directory at *cpp,
X * followed by '/', followed by the characters in curname up until the
X * first blank there, and finally a '\0'.  The cpp pointer is left pointing
X * at the next directory in the path.
X * But: if *cpp == NULL, then we are supposed to use curname as is.
X */
Xpackrealnameoffile(cpp)
X    char **cpp;
X{
X    register char *p,*realname;
X    
X    realname = realnameoffile;
X    if ((p = *cpp)!=NULL) {
X	while ((*p != ':') && (*p != '\0')) {
X	    *realname++ = *p++;
X	    if (realname == &(realnameoffile[namelength-1]))
X		break;
X	    }
X	if (*p == '\0') *cpp = NULL; /* at end of path now */
X	else *cpp = p+1; /* else get past ':' */
X	*realname++ = '/';  /* separate the area from the name to follow */
X	}
X    /* now append curname to realname... */
X    p = curname;
X    while (*p != ' ') {
X	if (realname >= &(realnameoffile[namelength-1])) {
X	    fprintf(stderr,"! Full file name is too long\n");
X	    break;
X	    }
X	*realname++ = *p++;
X	}
X    *realname = '\0';
X}
!FaR!OuT!
if [ ! -d dvidoc ]
then
	mkdir dvidoc
	echo mkdir dvidoc
fi
echo x - dvidoc/dvityext.h
sed -e 's/^X//' > dvidoc/dvityext.h << '!FaR!OuT!'
Xprocedure setpaths;
X    external;
X
Xfunction testaccess(accessmode:integer; filepath:integer): boolean;
X    external;
!FaR!OuT!
if [ ! -d dvidoc ]
then
	mkdir dvidoc
	echo mkdir dvidoc
fi
echo x - dvidoc/h00vars.h
sed -e 's/^X//' > dvidoc/h00vars.h << '!FaR!OuT!'
X/* Copyright (c) 1979 Regents of the University of California */
X
X/* sccsid[] = "@(#)h00vars.h 1.10 1/10/83"; */
X
X#include <stdio.h>
X#include "whoami.h"
X
X#define PXPFILE		"pmon.out"
X#define	BITSPERBYTE	8
X#define	BITSPERLONG	(BITSPERBYTE * sizeof(long))
X#define LG2BITSBYTE	03
X#define MSKBITSBYTE	07
X#define LG2BITSLONG	05
X#define MSKBITSLONG	037
X#define HZ		60
X#define	MAXLVL		20
X#define MAXERRS		75
X#define NAMSIZ		76
X#define MAXFILES	32
X#define PREDEF		2
X#define STDLVL	((struct iorec *)(0xc00cc001))
X#define GLVL	((struct iorec *)(0xc00cc000))
X#define FILNIL		((struct iorec *)(0))
X#define INPUT		((struct iorec *)(&input))
X#define OUTPUT		((struct iorec *)(&output))
X#define ERR		((struct iorec *)(&_err))
Xtypedef enum {FALSE, TRUE} bool;
X
X/*
X * runtime display structure
X */
Xstruct display {
X	char	*ap;
X	char	*fp;
X};
X
X/*
X * formal routine structure
X */
Xstruct formalrtn {
X	long		(*fentryaddr)();	/* formal entry point */
X	long		fbn;			/* block number of function */
X	struct display	fdisp[ MAXLVL ];	/* saved at first passing */
X};
X
X/*
X * program variables
X */
Xextern struct display	_disply[MAXLVL];/* runtime display */
Xextern int		_argc;		/* number of passed args */
Xextern char		**_argv;	/* values of passed args */
Xextern long		_stlim;		/* statement limit */
Xextern long		_stcnt;		/* statement count */
Xextern long		_seed;		/* random number seed */
Xextern char		*_maxptr;	/* maximum valid pointer */
Xextern char		*_minptr;	/* minimum valid pointer */
Xextern long		_pcpcount[];	/* pxp buffer */
X
X/*
X * file structures
X */
Xstruct iorechd {
X	char		*fileptr;	/* ptr to file window */
X	long		lcount;		/* number of lines printed */
X	long		llimit;		/* maximum number of text lines */
X	FILE		*fbuf;		/* FILE ptr */
X	struct iorec	*fchain;	/* chain to next file */
X	struct iorec	*flev;		/* ptr to associated file variable */
X	char		*pfname;	/* ptr to name of file */
X	short		funit;		/* file status flags */
X	unsigned short	fblk;		/* index into active file table */
X	long		fsize;		/* size of elements in the file */
X	char		fname[NAMSIZ];	/* name of associated UNIX file */
X};
X
Xstruct iorec {
X	char		*fileptr;	/* ptr to file window */
X	long		lcount;		/* number of lines printed */
X	long		llimit;		/* maximum number of text lines */
X	FILE		*fbuf;		/* FILE ptr */
X	struct iorec	*fchain;	/* chain to next file */
X	struct iorec	*flev;		/* ptr to associated file variable */
X	char		*pfname;	/* ptr to name of file */
X	short		funit;		/* file status flags */
X	unsigned short	fblk;		/* index into active file table */
X	long		fsize;		/* size of elements in the file */
X	char		fname[NAMSIZ];	/* name of associated UNIX file */
X	char		buf[BUFSIZ];	/* I/O buffer */
X	char		window[1];	/* file window element */
X};
X
X/*
X * unit flags
X */
X#define SPEOLN	0x100	/* 1 => pseudo EOLN char read at EOF */
X#define	FDEF	0x080	/* 1 => reserved file name */
X#define	FTEXT	0x040	/* 1 => text file, process EOLN */
X#define	FWRITE	0x020	/* 1 => open for writing */
X#define	FREAD	0x010	/* 1 => open for reading */
X#define	TEMP	0x008	/* 1 => temporary file */
X#define	SYNC	0x004	/* 1 => window is out of sync */
X#define	EOLN	0x002	/* 1 => at end of line */
X#define	EOFF	0x001	/* 1 => at end of file */
X
X/*
X * file routines
X */
Xextern struct iorec	*GETNAME();
Xextern char		*MKTEMP();
Xextern char		*PALLOC();
X
X/*
X * file record variables
X */
Xextern struct iorechd	_fchain;	/* head of active file chain */
Xextern struct iorec	*_actfile[];	/* table of active files */
Xextern long		_filefre;	/* last used entry in _actfile */
X
X/*
X * standard files
X */
Xextern struct iorechd	input;
Xextern struct iorechd	output;
Xextern struct iorechd	_err;
X
X/*
X * seek pointer struct for TELL, SEEK extensions
X */
Xstruct seekptr {
X	long	cnt;
X};
!FaR!OuT!
if [ ! -d dvidoc ]
then
	mkdir dvidoc
	echo mkdir dvidoc
fi
echo x - dvidoc/texpaths.h
sed -e 's/^X//' > dvidoc/texpaths.h << '!FaR!OuT!'
X/*
X * This file defines the default paths that will be used for TeX software.
X * (These paths are used if the user's environment doesn't specify paths.)
X *
X * Paths should be colon-separated and no longer than MAXINPATHCHARS-1
X * (for defaultinputpath) or MAXOTHPATHCHARS (for other default paths).
X */
X
X#define MAXINPATHCHARS  700	/* maximum number of chars in an input path */
X
X#define defaultinputpath  ".:/usr/new/lib/tex/macros"
X    /* this should always start with "." */
X
X#define MAXOTHPATHCHARS 100     /* other paths should be much shorter */
X
X#define defaultfontpath   "/usr/local/lib/tex/fonts"
X    /* it is probably best not to include "." here to prevent confusion
X       by spooled device drivers that think they know where the fonts
X       really are */
X#define defaultformatpath ".:/usr/new/lib/tex/macros"
X#define defaultpoolpath   ".:/usr/new/lib/tex"
X
!FaR!OuT!
if [ ! -d dvidoc ]
then
	mkdir dvidoc
	echo mkdir dvidoc
fi
echo x - dvidoc/whoami.h
sed -e 's/^X//' > dvidoc/whoami.h << '!FaR!OuT!'
!FaR!OuT!
exit
-- 
		Scott Simpson
		TRW Electronics and Defense Sector
		...{decvax,ihnp4,ucbvax}!trwrb!simpson



More information about the Comp.sources.unix mailing list