home *** CD-ROM | disk | FTP | other *** search
Text File | 1983-09-02 | 35.4 KB | 1,390 lines |
- -h- break.fmt 321
- { break -- end current filled line }
- procedure lbreak;
- var
- i : integer;
- begin
- if (outp > 0) then begin
- if outbuf[outp] <> BLANK then outp := outp + 1;
- outbuf[outp] := NEWLINE;
- outbuf[outp+1] := ENDSTR;
- put(outbuf);
- for i := 1 to BIGSTR do outbuf[i] := BLANK;
- end;
- outp := 0;
- outw := 0;
- outwds := 0
- end;
- -h- center.fmt 144
- { center -- center a line by setting tival }
- procedure center (var buf : sstring);
- begin
- tival := imax((rmval+tival-width(buf)) div 2, 0)
- end;
- -h- command.fmt 2686
- { command -- perform formatting command }
- procedure command (var buf : sstring);
- var
- cmd : cmdtype;
- lin : string;
- fd : filedesc;
- mptr: ndptr;
- fvar: fonttype;
- i, j, argtype, spval, val, sfval, hdlvl: integer;
- begin
- cmd := getcmd(buf);
- if (cmd <> UNKNOWN) then
- val := getval(buf, argtype);
- case cmd of
- FI: begin
- lbreak;
- fill := true
- end;
- NF: begin
- lbreak;
- fill := false
- end;
- JU: begin
- lbreak;
- just := true
- end;
- NJ: begin
- lbreak;
- just := false
- end;
- BR:
- lbreak;
- LS:
- setparam(lsval, val, argtype, 1, 1, HUGE);
- CE: begin
- lbreak;
- setparam(ceval, val, argtype, 1, 0, HUGE)
- end;
- UL:
- setparam(ulval, val, argtype, 1, 0, HUGE);
- HE: begin
- gettl(buf, header);
- hefont := font;
- end;
- FO: begin
- gettl(buf, footer);
- fofont := font;
- end;
- BP: begin
- page;
- setparam(curpage,val,argtype,curpage+1,-HUGE,HUGE);
- newpage := curpage
- end;
- SP: begin
- setparam(spval, val, argtype, 1, 0, HUGE);
- space(spval)
- end;
- IND:
- setparam(inval, val, argtype, 0, 0, rmval-1);
- RM:
- setparam(rmval, val, argtype, PAGEWIDTH,
- inval+tival+1, HUGE);
- TI: begin
- lbreak;
- setparam(tival, val, argtype, 0, -HUGE, rmval)
- end;
- PL: begin
- setparam(plval, val, argtype, PAGELEN,
- m1val+m2val+m3val+m4val+1, HUGE);
- bottom := plval - m3val - m4val
- end;
- SF: begin
- setparam(sfval, val, argtype, SFNORM, SFNORM, SFUND);
- if sfval = SFNORM then
- font := [SFNORM] {reset current font flag}
- else begin
- fvar := font;
- font := [sfval];
- font := fvar + font; {add new value to set}
- end;
- setfont(font,1);
- end;
- SX: begin
- lbreak;
- gettl(buf,lin);
- put(lin);
- end;
- DM: begin
- defmac(buf);
- end;
- HD: begin
- lbreak;
- setparam(hdlvl, val, argtype, -1, 0, 4);
- if (hdlvl = -1) then
- errmsg('Invalid .hd level ignored')
- else
- puthd(buf,hdlvl);
- end;
- CP: begin
- lbreak;
- spval := 0;
- setparam(spval, val, argtype, 0, 0, HUGE);
- if ((bottom+1-lineno) < spval) then begin;
- page;
- curpage := curpage + 1;
- newpage := curpage;
- end;
- end;
- IM: begin
- if inmac then
- errmsg('Sorry, cannot use .im in a macro')
- else begin
- i := 1;
- while (not (buf[i] in [BLANK,TAB])) do i := i + 1; {skip over .command}
- while ( (buf[i] in [BLANK,TAB])) do i := i + 1;
- j := 1;
- while (not (buf[i] in [BLANK,TAB,NEWLINE,ENDSTR])) do begin
- lin[j] := buf[i];
- i := i + 1;
- j := j + 1;
- end;
- lin[j] := ENDSTR;
- fd := mustopen(lin, IOREAD);
- imbed(fd,lin);
- xclose(fd);
- end;
- end;
- COMMENT: ;
- UNKNOWN: begin
- scopy(buf,2,buf,1); {shift off the leading '.'}
- mptr := macloc(buf);
- if mptr <> NIL then
- maccall(mptr,buf)
- else
- errmsg('Unknown command.');
- end;
- end
- end;
- -h- defmac.fmt 1462
- { defmac -- put macro definition into ndblock linked list }
- procedure defmac (var buf : sstring);
- var
- i,j : integer;
- mnam : smlstring; {macro name}
- mdel : character; {delimiter character}
- mptr,cptr : ndptr;
- begin
- i := 1;
- while (not (buf[i] in [BLANK,TAB])) do i := i + 1; {skip over .command}
- while ( (buf[i] in [BLANK,TAB])) do i := i + 1;
- if not (isletter(buf[i])) then begin
- errmsg('Invalid macro name');
- return;
- end;
- j := 1;
- while (isalphanum(buf[i])) do begin
- if isupper(buf[i]) then
- mnam[j] := buf[i] + 32
- else
- mnam[j] := buf[i];
- i := i + 1;
- j := j + 1;
- end;
- mnam[j] := ENDSTR;
- while (buf[i] in [BLANK,TAB]) do i := i + 1;
- if (buf[i] in [NEWLINE,ENDSTR]) then begin
- errmsg('Invalid macro definition');
- return;
- end;
- mdel := buf[i];
- mptr := macloc(mnam);
- { if name already exists, just replace it, otherwise create new defn }
- if mptr = NIL then begin
- mptr := mactop;
- while (mptr <> NIL) do begin
- cptr := mptr;
- mptr := cptr^.next;
- end;
- new(mptr);
- if mactop = NIL then
- mactop := mptr
- else
- cptr^.next := mptr;
- mptr^.next := NIL;
- end;
- scopy(mnam,1,mptr^.name,1);
- j := 1;
- while (not (buf[i] in [NEWLINE,ENDSTR])) do begin
- mptr^.defn[j] := buf[i];
- i := i + 1;
- j := j + 1;
- end;
- if mptr^.defn[j-1] <> mdel then begin {add delimiter to end if they forgot}
- mptr^.defn[j] := mdel;
- j := j + 1;
- end;
- mptr^.defn[j] := ENDSTR;
- end;
- -h- errmsg.fmt 650
- { errmsg -- write error message and return }
- { note: string is not terminated by normal ENDSTR delimiter }
- procedure errmsg (const msg : lstring);
- var
- i, nd : integer;
- s : string;
- begin
- putcf(LETF,STDERR);
- putcf(LETI,STDERR);
- putcf(LETL,STDERR);
- putcf(LETE,STDERR);
- putcf(BLANK,STDERR);
- putstr(curname,STDERR);
- putcf(BLANK,STDERR);
- putcf(LETL,STDERR);
- putcf(LETI,STDERR);
- putcf(LETN,STDERR);
- putcf(LETE,STDERR);
- putcf(BLANK,STDERR);
- nd := itoc(inline, s, 1);
- for i := 1 to nd-1 do
- putcf(s[i],STDERR);
- putcf(COLON,STDERR);
- putcf(BLANK,STDERR);
- for i := 1 to ord(msg[0]) do putcf(ord(msg[i]),STDERR);
- putcf(NEWLINE,STDERR);
- end;
- -h- fmtcons.fmt 607
- { fmtcons -- constants for format }
- const
- CMD = PERIOD;
- PAGENUM = SHARP;
- PAGEWIDTH = 60;
- PAGELEN = 66;
- HUGE = 10000;
- SFNORM = 0; { Valid arguments to the 'setfont' command }
- SFDBLS = 1;
- SFEMP = 2;
- SFITAL = 3;
- SFDBLW = 4;
- SFCOMP = 5;
- SFUND = 6;
- L0SBF = 3; { Spaces before and after a level 0 header }
- L0SAF = 1;
- L1SBF = 3; { Spaces before and after a level 1 header }
- L1SAF = 1;
- L2SBF = 3; { Spaces before and after a level 2 header }
- L2SAF = 1;
- L3SBF = 3; { Spaces before and after a level 3 header }
- L3SAF = 1;
- L4SBF = 3; { Spaces before and after a level 4 header }
- L4SAF = 1;
- -h- fmtproc.fmt 912
- { fmtproc -- procedures needed for format }
- {$include:'errmsg.fmt' }
- {$include:'skipbl.fmt' }
- {$include:'skip.fmt' }
- {$include:'getcmd.fmt' }
- {$include:'setparam.fmt'}
- {$include:'getval.fmt' }
- {$include:'gettl.fmt' }
- {$include:'puttl.fmt' }
- {$include:'setfont.fmt' }
- {$include:'puthead.fmt' }
- {$include:'putfoot.fmt' }
- {$include:'width.fmt' }
- {$include:'put.fmt' }
- {$include:'break.fmt' }
- {$include:'space.fmt' }
- {$include:'page.fmt' }
- {$include:'puthd.fmt' }
- {$include:'leadbl.fmt' }
- {$include:'spread.fmt' }
- {$include:'putword.fmt' }
- {$include:'getword.fmt' }
- {$include:'center.fmt' }
- {$include:'underln.fmt' }
- {$include:'initfmt.fmt' }
- {$include:'macloc.fmt' }
- {$include:'defmac.fmt' }
- {$include:'maccall.fmt' }
- {$include:'getfmtl.fmt' }
- procedure imbed (fd : filedesc; var name : sstring); forward;
- {$include:'command.fmt' }
- {$include:'text.fmt' }
- {$include:'imbed.fmt' }
- -h- fmttype.fmt 363
- type
- cmdtype = (BP, BR, CE, FI, FO, HE, IND, LS, NF, PL,
- RM, SP, TI, UL, SF, HD, SX, IM, DM, CP, NJ, JU, UNKNOWN, COMMENT);
- fonttype = set of SFNORM..SFUND;
- fontrang = SFNORM..SFUND;
- ndptr = ^ndblock;
- ndblock =
- record { macro definition block }
- name : smlstring; { name of macro }
- defn : bigstring; { body of macro }
- next : ndptr;
- end;
- -h- fmtvars.fmt 2404
- var
- { page parameters }
- curpage : integer; { current output page number; init = 0 }
- newpage : integer; { next output page number; init = 1 }
- lineno : integer; { next line to be printed; init = 0 }
- plval : integer; { page length in lines; init = PAGELEN = 66 }
- m1val : integer; { margin before and including header }
- m2val : integer; { margin after header }
- m3val : integer; { margin after last text line }
- m4val : integer; { bottom margin, including footer }
- bottom : integer; { last live line on page, = plval-m3val-m4val }
- header : string; { top of page title; init = NEWLINE }
- footer : string; { bottom of page title; init = NEWLINE }
- font : fonttype; { current font settings }
- hefont : fonttype; { current header font settings }
- fofont : fonttype; { current footer font settings }
-
- { global parameters }
- fill : boolean; { fill if true; init = true }
- just : boolean; { right justify if true; init = true }
- lsval : integer; { current line spacing; init = 1 }
- spval : integer; { next space }
- inval : integer; { current indent; >= 0; init = 0 }
- rmval : integer; { current right margin; init = PAGEWIDTH = 60 }
- tival : integer; { current temporary indent; init = 0 }
- ceval : integer; { number of lines to center; init = 0 }
- ulval : integer; { number of lines to underline; init = 0 }
- hdlvl1: integer; { value of current level 1 numbered heading }
- hdlvl2: integer; { value of current level 2 numbered heading }
- hdlvl3: integer; { value of current level 3 numbered heading }
- hdlvl4: integer; { value of current level 4 numbered heading }
- hidblank: character; { special character to hide blank from spreading }
-
- { output area }
- outp : integer; { last char position in outbuf; init = 0 }
- outw : integer; { width of text currently in outbuf; init = 0 }
- outwds : integer; { number of words in outbuf; init = 0 }
- outbuf : bigstring; { lines to be filled collect here }
-
- inline : integer; { current input file line number }
- curname: string; { current input file name }
- inmac : boolean; { flag tells if we are within a macro or not }
- mactop : ndptr; { pointer to top of macro definition linked list }
- curmac : bigstring; { current macro definition, if any }
- curmacp: integer; { points to current position in current macro }
- curmacd: character; { delimiter character in current macro }
- macarg: array[0..9] of string; {buffer for macro arguments }
- dir : 0..1;
- -h- format.fmt 715
- { format -- text formatter main program }
- procedure format;
- {$include:'fmtcons.fmt'}
- {$include:'fmttype.fmt'}
- {$include:'fmtvars.fmt'}
- iarg : integer;
- argv : string;
- infil: filedesc;
- outpflag [extern] : outptype;
- {$include:'fmtproc.fmt'}
- begin
- initfmt;
- iarg := 0;
- infil := STDIN;
- while (iarg = 0) or (iarg < nargs) do begin
- iarg := iarg + 1;
- if (getarg(iarg,argv,MAXSTR)) then begin
- if argv[1]=DASH then begin
- case argv[2] of
- LETP: outpflag := STDPRT;
- otherwise
- message ('Unknown control argument ignored.');
- end;
- cycle;
- end;
- infil := mustopen(argv,IOREAD)
- end
- else
- scopy(curname,1,argv,1);
- imbed(infil,argv);
- xclose(infil);
- page;
- end;
- end;
- -h- getcmd.fmt 1436
- { getcmd -- decode command type }
- function getcmd (var buf : sstring) : cmdtype;
- var
- cmd : packed array [1..2] of char;
- begin
- if (isupper(buf[2]))
- then cmd[1] := chr(buf[2] + 32)
- else cmd[1] := chr(buf[2]);
- if (isupper(buf[3]))
- then cmd[2] := chr(buf[3] + 32)
- else cmd[2] := chr(buf[3]);
- if (cmd[1] = '*') then
- getcmd := COMMENT
- else if isalphanum(buf[4]) then { character after 2 letters is alphanum }
- { then probably a macro invokation }
- getcmd := UNKNOWN
- else if (cmd = 'fi') then
- getcmd := FI
- else if (cmd = 'nf') then
- getcmd := NF
- else if (cmd = 'br') then
- getcmd := BR
- else if (cmd = 'ls') then
- getcmd := LS
- else if (cmd = 'bp') then
- getcmd := BP
- else if (cmd = 'sp') then
- getcmd := SP
- else if (cmd = 'in') then
- getcmd := IND
- else if (cmd = 'rm') then
- getcmd := RM
- else if (cmd = 'ti') then
- getcmd := TI
- else if (cmd = 'ce') then
- getcmd := CE
- else if (cmd = 'ul') then
- getcmd := UL
- else if (cmd = 'he') then
- getcmd := HE
- else if (cmd = 'fo') then
- getcmd := FO
- else if (cmd = 'pl') then
- getcmd := PL
- else if (cmd = 'hd') then
- getcmd := HD
- else if (cmd = 'sf') then
- getcmd := SF
- else if (cmd = 'sx') then
- getcmd := SX
- else if (cmd = 'im') then
- getcmd := IM
- else if (cmd = 'cp') then
- getcmd := CP
- else if (cmd = 'dm') then
- getcmd := DM
- else if (cmd = 'ju') then
- getcmd := JU
- else if (cmd = 'nj') then
- getcmd := NJ
- else
- getcmd := UNKNOWN
- end;
- -h- getfmtl.fmt 1232
- { getfmtl -- get next format line, either from macro or current file }
- function getfmtl(var s : sstring; fd : filedesc; maxsize : integer): boolean;
- var
- i,j : integer;
- n : integer;
- begin
- if (inmac) and (curmac[curmacp] <> ENDSTR) then begin
- i := 1;
- { curmacp points to beginning of next command string }
- while (curmac[curmacp] <> curmacd) do begin
- if (curmac[curmacp] = PERCENT) then begin {expand argument}
- curmacp := curmacp + 1;
- if (curmac[curmacp] = PERCENT) then s[i] := curmac[curmacp]
- else
- if not (isdigit(curmac[curmacp])) then
- errmsg('Invalid argument digit')
- else begin
- n := ord(curmac[curmacp]) - 48; {very ASCII dependent}
- j := 1;
- while (macarg[n,j] <> ENDSTR) do begin
- s[i] := macarg[n,j];
- i := i + 1;
- j := j + 1;
- end;
- i := i - 1; {went one too far}
- end;
- end
- else {normal character}
- s[i] := curmac[curmacp];
- i := i + 1;
- curmacp := curmacp + 1;
- end;
- curmacp := curmacp + 1; {advance past delimiter}
- s[i] := NEWLINE;
- s[i+1] := ENDSTR;
- if (i >= maxsize) then error('macro expand overflow');
- end
- else begin
- inmac := FALSE;
- getfmtl := getline(s, fd, maxsize);
- inline := inline + 1;
- end;
- end;
- -h- gettl.fmt 1514
- { gettl -- create line with text adjusted /left/middle/right/ }
- procedure gettl (var buf,lin : sstring);
- label err;
- var
- i,j,k : integer;
- delim : character; {delimiter, normally /}
- begin
- i := 1;
- while (not (buf[i] in [BLANK,TAB])) do i := i + 1; {skip over .command}
- while ( (buf[i] in [BLANK,TAB])) do i := i + 1;
- delim := buf[i];
- for j := 1 to rmval do lin[j] := BLANK; {init lin to blanks}
- lin[rmval+1] := NEWLINE;
- lin[rmval+2] := ENDSTR;
- i := i + 1;
- j := 1;
- while (buf[i] <> delim) do begin {move left portion}
- if (buf[i] = NEWLINE) or (j > rmval) then goto err;
- lin[j] := buf[i];
- i := i + 1;
- j := j + 1;
- end;
- i := i + 1;
- j := i;
- while (buf[j] <> delim) do begin {get length of middle}
- if (buf[j] = NEWLINE) then goto err;
- j := j + 1;
- end;
- k := j - i;
- j := imax((rmval-k) div 2, 0);
- while (buf[i] <> delim) do begin {move middle portion}
- if (buf[i] = NEWLINE) or (j > rmval) then goto err;
- lin[j] := buf[i];
- i := i + 1;
- j := j + 1;
- end;
- i := i + 1;
- while (buf[i] <> delim) do begin {find end of buf}
- if (buf[i] = NEWLINE) then goto err;
- i := i + 1;
- end;
- i := i - 1;
- j := rmval;
- while (buf[i] <> delim) do begin {move right portion}
- lin[j] := buf[i];
- i := i - 1;
- j := j - 1;
- end;
- i := 1; { remove any hidden blank characters }
- while (buf[i] <> ENDSTR) do begin
- if (buf[i] = hidblank) then buf[i] := BLANK;
- i := i + 1;
- end;
- return;
-
- err: errmsg('Invalid /l/m/r/ syntax.');
- end;
- -h- getval.fmt 390
- { getval -- evaluate optional numeric argument }
- function getval (var buf : sstring;
- var argtype : integer) : integer;
- var
- i : integer;
- begin
- i := 1; { skip over command name }
- while (not (buf[i] in [BLANK, TAB, NEWLINE])) do
- i := i + 1;
- skipbl(buf, i); { find argument }
- argtype := buf[i];
- if (argtype = PLUS) or (argtype = MINUS) then
- i := i + 1;
- getval := ctoi(buf, i)
- end;
- -h- getword.fmt 408
- { getword -- get word from s[i] into out }
- function getword (var s : sstring; i : integer;
- var out : sstring) : integer;
- var
- j : integer;
- begin
- while (s[i] in [BLANK, TAB, NEWLINE]) do
- i := i + 1;
- j := 1;
- while (not (s[i] in [ENDSTR,BLANK,TAB,NEWLINE])) do begin
- out[j] := s[i];
- i := i + 1;
- j := j + 1
- end;
- out[j] := ENDSTR;
- if (s[i] = ENDSTR) then
- getword := 0
- else
- getword := i
- end;
- -h- imbed.fmt 722
- { imbed -- format given file }
- { had to comment out arguments since it is forward declared }
- { because it is called recursively }
- procedure imbed { (fd : filedesc; var name : sstring) };
- var
- inbuf : bigstring; { input line }
- oname : smlstring; { previous filename, saved and restored on return }
- oline : integer; { previous line number }
- begin
- scopy (curname,1,oname,1); {save current name}
- scopy (name,1,curname,1); {put into global for error messages}
- oline := inline;
- inline := 0;
- while (getfmtl(inbuf, fd, BIGSTR)) do begin
- if (inbuf[1] = CMD) then
- command(inbuf)
- else
- text(inbuf);
- end;
- scopy (oname,1,curname,1); {restore old name}
- inline := oline; {and line number }
- end;
- -h- initfmt.fmt 883
- { initfmt -- set format parameters to default values }
- procedure initfmt;
- begin
- inline := 0;
- curname[1] := ord('S');
- curname[2] := ord('T');
- curname[3] := ord('D');
- curname[4] := ord('I');
- curname[5] := ord('N');
- curname[6] := ENDSTR;
- inmac := FALSE;
- mactop := NIL;
- curmacp := 1;
- font := [SFNORM]; setfont(font,0);
- hidblank := ATSIGN;
- fill := true;
- just := true;
- dir := 0;
- inval := 0;
- rmval := PAGEWIDTH;
- tival := 0;
- lsval := 1;
- spval := 0;
- ceval := 0;
- ulval := 0;
- lineno := 0;
- curpage := 0;
- newpage := 1;
- plval := PAGELEN;
- m1val := 3; m2val := 2; m3val := 2; m4val := 3;
- bottom := plval - m3val - m4val;
- header[1] := NEWLINE; { initial titles }
- header[2] := ENDSTR;
- hefont := [SFNORM];
- footer[1] := NEWLINE;
- footer[2] := ENDSTR;
- fofont := [SFNORM];
- outp := 0;
- outw := 0;
- outwds := 0;
- hdlvl1 := 0;
- hdlvl2 := 0;
- hdlvl3 := 0;
- hdlvl4 := 0;
- end;
- -h- leadbl.fmt 331
- { leadbl -- delete leading blanks, set tival }
- procedure leadbl (var buf : sstring);
- var
- i, j : integer;
- begin
- lbreak;
- i := 1;
- while (buf[i] = BLANK) do { find 1st non-blank }
- i := i + 1;
- if (buf[i] <> NEWLINE) then
- tival := tival + i - 1;
- for j := i to length(buf)+1 do { move line to left }
- buf[j-i+1] := buf[j]
- end;
- -h- maccall.fmt 1498
- { maccall -- call the given macro }
- procedure maccall (mptr: ndptr; var cbuf : sstring);
- var
- i,j,k : integer;
- inarg : boolean;
- c : character;
- begin
- if inmac then begin
- errmsg('Sorry, cannot nest macro calls');
- return;
- end;
- inmac := TRUE;
- scopy(mptr^.defn,1,curmac,1);
- curmacd := curmac[1];
- curmacp := 2;
- for i := 1 to 9 do macarg[i,1] := ENDSTR; {init arguments}
- k := 1; {current pos in cbuf}
- j := 0; {current pos in current argument}
- i := 0; {current arg number}
- inarg := FALSE;
- while (cbuf[k] <> ENDSTR) do begin
- c := cbuf[k];
- case c of
- BLANK,TAB,ENDSTR,NEWLINE: begin
- if inarg then begin
- j := j + 1;
- macarg[i,j] := ENDSTR;
- i := i + 1;
- if i > 9 then return;
- end;
- j := 0;
- inarg := FALSE;
- if cbuf[k] in [ENDSTR,NEWLINE] then return;
- end;
- BACKSLASH: begin {just pass following char without interpreting it}
- k := k + 1;
- if not (cbuf[k] in [ENDSTR,NEWLINE]) then begin
- j := j + 1;
- macarg[i,j] := cbuf[k];
- end
- else k := k - 1;
- inarg := TRUE;
- end;
- SQUOTE,DQUOTE: begin {whole string of stuff is escaped}
- k := k + 1;
- while (cbuf[k] <> c) do begin
- if (cbuf[k] in [ENDSTR,NEWLINE]) then break;
- j := j + 1;
- macarg[i,j] := cbuf[k];
- k := k + 1;
- end;
- if cbuf[k] <> c then k := k - 1; { oops, went one too far }
- inarg := TRUE;
- end;
- OTHERWISE
- inarg := TRUE;
- j := j + 1;
- macarg[i,j] := c;
- end; {of case, that is}
- k := k + 1;
- end; {of while}
- end;
- -h- macloc.fmt 554
- { macloc -- locate macro name in ndblock linked list }
- function macloc (var buf : sstring): ndptr;
- var
- i,j : integer;
- mnam : smlstring; {macro name}
- mptr : ndptr;
- begin
- i := 1;
- j := 1;
- while (isalphanum(buf[i])) do begin
- if isupper(buf[i]) then
- mnam[j] := buf[i] + 32
- else
- mnam[j] := buf[i];
- i := i + 1;
- j := j + 1;
- end;
- mnam[j] := ENDSTR;
- mptr := mactop;
- macloc := NIL;
- while (mptr <> NIL) do begin
- if equal(mptr^.name, mnam) then begin
- macloc := mptr;
- break;
- end;
- mptr := mptr^.next;
- end;
- end;
- -h- page.fmt 176
- { page -- get to top of new page }
- procedure page;
- begin
- lbreak;
- if (lineno > 0) and (lineno <= bottom) then begin
- skip(bottom+1-lineno);
- putfoot
- end;
- lineno := 0
- end;
- -h- put.fmt 725
- { put -- put out line with proper spacing and indenting }
- procedure put (var buf : sstring);
- var
- i : integer;
- begin
- if (lineno <= 0) or (lineno > bottom) then
- puthead;
- for i := 1 to inval + tival do { indenting }
- putc(BLANK);
- tival := 0;
- { put out line. special cases 1) 255 is translated to 0 so we can write }
- { NULL to the printer. 2) backslash is ignored. 3) ATSIGN = BLANK }
- i := 1;
- while (buf[i] <> ENDSTR) do begin
- case buf[i] of
- BACKSLASH: begin
- i := i + 1;
- putc(buf[i]);
- end;
- ATSIGN: putc(BLANK);
- 255: putc(0);
- OTHERWISE
- putc(buf[i]);
- end;
- i := i + 1;
- end;
- skip(imin(lsval-1, bottom-lineno));
- lineno := lineno + lsval;
- if (lineno > bottom) then
- putfoot
- end;
- -h- putfoot.fmt 211
- { putfoot -- put out page footer }
- procedure putfoot;
- var
- i : integer;
- begin
- skip(m3val);
- if (m4val > 0) then begin
- setfont(fofont,0);
- puttl(footer, curpage);
- setfont(font,0);
- skip(m4val-1)
- end
- end;
- -h- puthd.fmt 2248
- { puthd -- output a level n numbered heading }
- procedure puthd (var buf : sstring; hdlvl : integer);
- var
- hed : string;
- fsave : fonttype;
- i : integer;
- begin
- fsave := font; { save font, then reset to header value, just in case }
- { the space or put routines decide to reset the font. }
- i := 1;
- while (not (buf[i] in [BLANK,TAB])) do i := i + 1; {skip over .hd n}
- while ( (buf[i] in [BLANK,TAB])) do i := i + 1;
- while (not (buf[i] in [BLANK,TAB])) do i := i + 1;
- while ( (buf[i] in [BLANK,TAB])) do i := i + 1;
- scopy(buf,i,buf,1);
- case hdlvl of
- 0: begin {unnumbered heading}
- font := [SFNORM,SFEMP,SFUND];
- setfont(font,0);
- space(L0SBF);
- put(buf);
- space(L0SAF);
- end;
- 1: begin
- font := [SFNORM,SFEMP,SFUND];
- setfont(font,0);
- hdlvl1 := hdlvl1 + 1;
- hdlvl2 := 0;
- hdlvl3 := 0;
- hdlvl4 := 0;
- space(L1SBF);
- i := 1;
- i := itoc(hdlvl1,hed,i ); hed[i] := PERIOD;
- i := itoc(hdlvl2,hed,i+1); hed[i] := BLANK;
- i := i + 1;
- scopy(buf,1,hed,i);
- put(hed);
- space(L1SAF);
- end;
- 2: begin
- font := [SFNORM,SFDBLS,SFUND];
- setfont(font,0);
- hdlvl2 := hdlvl2 + 1;
- hdlvl3 := 0;
- hdlvl4 := 0;
- space(L2SBF);
- i := 1;
- i := itoc(hdlvl1,hed,i ); hed[i] := PERIOD;
- i := itoc(hdlvl2,hed,i+1); hed[i] := BLANK;
- i := i + 1;
- scopy(buf,1,hed,i);
- put(hed);
- space(L2SAF);
- end;
- 3: begin
- font := [SFNORM,SFEMP];
- setfont(font,0);
- hdlvl3 := hdlvl3 + 1;
- hdlvl4 := 0;
- space(L3SBF);
- i := 1;
- i := itoc(hdlvl1,hed,i ); hed[i] := PERIOD;
- i := itoc(hdlvl2,hed,i+1); hed[i] := PERIOD;
- i := itoc(hdlvl3,hed,i+1); hed[i] := BLANK;
- i := i + 1;
- scopy(buf,1,hed,i);
- put(hed);
- space(L3SAF);
- end;
- 4: begin
- font := [SFNORM,SFDBLS];
- setfont(font,0);
- hdlvl4 := hdlvl4 + 1;
- space(L4SBF);
- i := 1;
- i := itoc(hdlvl1,hed,i ); hed[i] := PERIOD;
- i := itoc(hdlvl2,hed,i+1); hed[i] := PERIOD;
- i := itoc(hdlvl3,hed,i+1); hed[i] := PERIOD;
- i := itoc(hdlvl4,hed,i+1); hed[i] := BLANK;
- i := i + 1;
- scopy(buf,1,hed,i);
- put(hed);
- space(L4SAF);
- end;
- end;
- font := fsave;
- setfont(font,0); { reset font to what it was }
- end;
- -h- puthead.fmt 288
- { puthead -- put out page header }
- procedure puthead;
- var
- i : integer;
- begin
- curpage := newpage;
- newpage := newpage + 1;
- if (m1val > 0) then begin
- skip(m1val-1);
- setfont(hefont,0);
- puttl(header, curpage);
- setfont(font,0);
- end;
- skip(m2val);
- lineno := m1val + m2val + 1
- end;
- -h- puttl.fmt 399
- { puttl -- put out title line with optional page number }
- procedure puttl (var buf : sstring; pageno : integer);
- var
- i : integer;
- begin
- i := 1;
- while (buf[i] <> ENDSTR) do begin
- case buf[i] of
- BACKSLASH: begin
- i := i + 1;
- putc(buf[i]);
- end;
- ATSIGN: putc(BLANK);
- 255: putc(0);
- PAGENUM: putdec(pageno, 1);
- OTHERWISE
- putc(buf[i]);
- end;
- i := i + 1;
- end;
- end;
- -h- putword.fmt 771
- { putword -- put word in outbuf; does margin justification }
- procedure putword (var wordbuf : sstring);
- var
- last, llval, nextra, w : integer;
- i : integer;
- begin
- w := width(wordbuf);
- last := length(wordbuf) + outp + 1; { new end of outbuf }
- llval := rmval - tival - inval;
- if (outp > 0)
- and ((outw+w > llval) or (last >= upper(outbuf))) then begin
- last := last - outp; { remember end of wordbuf }
- nextra := llval - outw + 1;
- if (just) and (nextra > 0) and (outwds > 1) then begin
- spread(outbuf, outp, nextra, outwds);
- outp := outp + nextra
- end;
- lbreak { flush previous line }
- end;
- scopy(wordbuf, 1, outbuf, outp+1);
- outp := last;
- outbuf[outp] := BLANK; { blank between words }
- outw := outw + w + 1; { 1 for blank }
- outwds := outwds + 1
- end;
- -h- putwordx.fmt 562
- { putword -- put word in outbuf }
- procedure putword (var wordbuf : string);
- var
- last, llval, nextra, w : integer;
- begin
- w := width(wordbuf);
- last := length(wordbuf) + outp + 1; { new end of outbuf }
- llval := rmval - tival - inval;
- if (outp > 0)
- and ((outw+w > llval) or (last >= MAXSTR)) then begin
- last := last - outp; { remember end of wordbuf }
- lbreak { flush previous line }
- end;
- scopy(wordbuf, 1, outbuf, outp+1);
- outp := last;
- outbuf[outp] := BLANK; { blank between words }
- outw := outw + w + 1; { 1 for blank }
- outwds := outwds + 1
- end;
- -h- setfont.fmt 3803
- Type
- prtrs_type = array[1..100] of character; { to set a special font }
-
- { initfont -- initialize the prtrs array with codes to make printer }
- { do it's wonderous font changes. }
- { See file for description of file format. }
- procedure initfont (var prtrs: prtrs_type; var resloc : integer);
- var
- line : string;
- fd : filedesc;
- bool : boolean;
- i,lcnt,cnt,sp : integer;
- Begin
- line[1] := LETF; line[2] := LETM; line[3] := LETT;
- line[4] := PERIOD;
- line[5] := LETF; line[6] := LETN; line[7] := LETT;
- line[8] := ENDSTR;
- fd := mustopen(line, IOREAD);
- for i := 1 to 7 do bool := getline(line, fd, MAXSTR); { skip header lines }
- sp := 0;
- for i := 1 to 12 do prtrs[i] := 0;
- resloc := 1;
- lcnt := 0;
- cnt := 0;
- while (getline(line, fd, MAXSTR)) do begin
- lcnt := lcnt + 1;
- cnt := 0;
- sp := sp + 1; { make room for count we will know later }
- i := 1;
- while (line[i] <> ENDSTR) and (line[i] <> NEWLINE) do
- case line[i] of
- BLANK,TAB,COMMA : i := i + 1;
- NUM0..NUM9 : begin
- cnt := cnt + 1;
- sp := sp + 1;
- prtrs[sp] := ctoi(line, i);
- end;
- LBRACE : begin { skip past comment }
- repeat
- i := i + 1
- until (line[i]=ENDSTR) or (line[i]=RBRACE);
- if line[i]=ENDSTR then error('fmt.fnt: reached EOL in comment');
- i := i + 1;
- end;
- OTHERWISE
- error('fmt.fnt: invalid character found');
- end;
- prtrs[sp-cnt] := cnt;
- if lcnt=7 then resloc := sp-cnt;
- end;
- if lcnt <> 12 then error('fmt.fnt: invalid line count');
- xclose(fd);
- End;
-
- { outfont -- writes out font for given font type }
- procedure outfont (fnum: fontrang; fun: integer; const OnOff: boolean);
- var
- prtrs [static] : prtrs_type;
- resloc [static] : integer;
- fcall [static] : boolean;
- i,j : integer;
- value
- fcall := TRUE;
- begin
- if fcall then begin
- fcall := FALSE;
- initfont(prtrs, resloc);
- end;
- { Scan 'set' or 'reset' table, based on OnOff flag }
- { The scan is slow of course, but we assume table is small, plus }
- { fonts aren't defined that often. }
- if OnOff then j := 1 else j := resloc;
- i := 1;
- while (i <> fnum) do begin
- i := i + 1;
- j := prtrs[j] + j + 1;
- end;
- if fun = 0 then
- for i := 1 to prtrs[j] do putc(prtrs[i+j])
- else
- for i := 1 to prtrs[j] do begin
- outp := outp + 1;
- outbuf[outp] := prtrs[i+j];
- { talk about kludges! the following statement sets a 0 value to 255 }
- { and the 'put' routine resets it to 0 on output, so we don't think }
- { the zero is the ENDSTR character }
- if outbuf[outp] = 0 then outbuf[outp] := 255;
- end;
- end;
-
- { setfont -- setup current output font, using features of printer hardware }
- { fun=0 to do immediate putc of font characters }
- { fun=1 to put characters into outbuf array }
- { seems pretty kludgy, but haven't got time to do it right }
- procedure setfont (const cfont : fonttype; fun: integer);
- var
- outpflag [extern] : outptype;
- lfont [static] : fonttype; { save this so we know current state }
- fnum: integer;
- value
- lfont := [SFDBLS,SFEMP,SFITAL,SFDBLW,SFCOMP,SFUND]; {init to all so we reset}
- {all on first call }
- begin
- if (outpflag = STDCONS) or (lfont = cfont) then return;
- if cfont = [SFNORM] then begin { reset printer back to normal state }
- for fnum := SFDBLS to SFUND do
- if (fnum in lfont) then
- outfont(fnum, fun, FALSE);
- end
- else begin
- for fnum := SFDBLS to SFUND do { add/delete fonts as given }
- if (fnum in cfont) and (not (fnum in lfont)) then {font added}
- outfont(fnum, fun, TRUE)
- else if (fnum in lfont) and (not (fnum in cfont)) then {font deleted}
- outfont(fnum, fun, FALSE);
- end;
- lfont := cfont;
- end;
- -h- setparam.fmt 447
- { setparam -- set parameter and check range }
- procedure setparam (var param : integer;
- val, argtype, defval, minval, maxval : integer);
- begin
- if (argtype = NEWLINE) then { defaulted }
- param := defval
- else if (argtype = PLUS) then { relative + }
- param := param + val
- else if (argtype = MINUS) then { relative - }
- param := param - val
- else { absolute }
- param := val;
- param := imin(param, maxval);
- param := imax(param, minval)
- end;
- -h- settext.fmt 1361
- { settext -- create line with text adjusted /left/middle/right/ }
- procedure settext (var buf,lin : sstring);
- label err;
- var
- i : integer;
- delim : character; {delimiter, normally /}
- begin
- i := 1;
- while (not (buf[i] in [BLANK,TAB])) do i := i + 1; {skip over .command}
- while ( (buf[i] in [BLANK,TAB])) do i := i + 1;
- delim := buf[i];
- for j := 1 to rmval do lin[j] := BLANK; {init lin to blanks}
- lin[rmval+1] := NEWLINE;
- lin[rmval+2] := ENDSTR;
- i := i + 1;
- j := 1;
- while (buf[i] <> delim) do begin {move left portion}
- if (buf[i] = NEWLINE) or (j > rmval) then goto err;
- lin[j] := buf[i];
- i := i + 1;
- j := j + 1;
- end;
- i := i + 1;
- j := i;
- while (buf[j] <> delim) do begin {get length of middle}
- if (buf[j] = NEWLINE) then goto err;
- j := j + 1;
- end;
- k := j - i;
- j := imax((rmval-k) div 2, 0)
- while (buf[i] <> delim) do begin {move middle portion}
- if (buf[i] = NEWLINE) or (j > rmval) then goto err;
- lin[j] := buf[i];
- i := i + 1;
- j := j + 1;
- end;
- i := i + 1;
- while (buf[i] <> delim) do begin {find end of buf}
- if (buf[i] = NEWLINE) then goto err;
- i := i + 1;
- end;
- i := i - 1;
- j := rmval;
- while (buf[i] <> delim) do begin {move right portion}
- lin[j] := buf[i];
- i := i - 1;
- j := j - 1;
- end;
- return;
-
- err: error('***Invalid settext syntax');
- end;
- -h- skip.fmt 130
- { skip -- output n blank lines }
- procedure skip (n : integer);
- var
- i : integer;
- begin
- for i := 1 to n do
- putc(NEWLINE)
- end;
- -h- skipbl.fmt 164
- { skipbl -- skip blanks and tabs at s[i]... }
- procedure skipbl (var s : sstring; var i : integer);
- begin
- while (s[i] = BLANK) or (s[i] = TAB) do
- i := i + 1
- end;
- -h- space.fmt 271
- { space -- space n lines or to bottom of page }
- procedure space (n : integer);
- begin
- lbreak;
- if (lineno <= bottom) then begin
- if (lineno <= 0) then
- puthead;
- skip(imin(n, bottom+1-lineno));
- lineno := lineno + n;
- if (lineno > bottom) then
- putfoot
- end
- end;
- -h- spread.fmt 745
- { spread -- spread words to justify right margin }
- procedure spread (var buf : sstring;
- outp, nextra, outwds : integer);
- var
- i, j, nb, nholes : integer;
- begin
- if (nextra > 0) and (outwds > 1) then begin
- dir := 1 - dir; { reverse previous direction }
- nholes := outwds - 1;
- i := outp - 1;
- j := imin(BIGSTR-2, i+nextra); { room for NEWLINE }
- while (i < j) do begin { and ENDSTR }
- buf[j] := buf[i];
- if (buf[i] = BLANK) then begin
- if (dir = 0) then
- nb := (nextra-1) div nholes + 1
- else
- nb := nextra div nholes;
- nextra := nextra - nb;
- nholes := nholes - 1;
- while (nb > 0) do begin
- j := j - 1;
- buf[j] := BLANK;
- nb := nb - 1
- end
- end;
- i := i - 1;
- j := j - 1
- end
- end
- end;
- -h- text.fmt 690
- { text -- process text lines (final version) }
- procedure text (var inbuf : sstring);
- var
- wordbuf : string;
- i : integer;
- begin
- if (inbuf[1] = BLANK) or (inbuf[1] = NEWLINE) then
- leadbl(inbuf); { move left, set tival }
- if (ulval > 0) then begin { underlining }
- underln(inbuf, BIGSTR);
- ulval := ulval - 1
- end;
- if (ceval > 0) then begin { centering }
- center(inbuf);
- put(inbuf);
- ceval := ceval - 1
- end
- else if (inbuf[1] = NEWLINE) then { all-blank line }
- put(inbuf)
- else if (not fill) then { unfilled text }
- put(inbuf)
- else begin { filled text }
- i := 1;
- repeat
- i := getword(inbuf, i, wordbuf);
- if (i > 0) then
- putword(wordbuf)
- until (i = 0)
- end
- end;
- -h- underln.fmt 485
- { underln -- underline a line }
- procedure underln (var buf : sstring; size : integer);
- var
- i, j : integer;
- tbuf : bigstring;
- begin
- j := 1; { expand into tbuf }
- i := 1;
- while (buf[i] <> NEWLINE) and (j < size-1) do begin
- if (isalphanum(buf[i])) then begin
- tbuf[j] := UNDERLINE;
- tbuf[j+1] := BACKSPACE;
- j := j + 2
- end;
- tbuf[j] := buf[i];
- j := j + 1;
- i := i + 1
- end;
- tbuf[j] := NEWLINE;
- tbuf[j+1] := ENDSTR;
- scopy(tbuf, 1, buf, 1) { copy it back to buf }
- end;
- -h- width.fmt 365
- { width -- compute width of character string }
- function width (var buf : sstring) : integer;
- var
- i, w : integer;
- begin
- w := 0;
- i := 1;
- while (buf[i] <> ENDSTR) do begin
- case buf[i] of
- BACKSPACE: w := w - 1;
- NEWLINE: ;
- BACKSLASH: begin
- i := i + 1;
- w := w + 1;
- end;
- OTHERWISE
- w := w + 1;
- end;
- i := i + 1
- end;
- width := w
- end;
- -h- fmt.pas 846
- {$debug-}
- program outer (input,output);
-
- {$include:'globcons.inc'}
- {$include:'globtyps.inc'}
-
- {$include:'initio.dcl'}
- {$include:'flush.dcl' }
-
- {$include:'isalphan.dcl'}
- {$include:'isupper.dcl' }
- {$include:'isdigit.dcl' }
- {$include:'isletter.dcl'}
- {$include:'message.dcl' }
- {$include:'error.dcl' }
- {$include:'getline.dcl' }
- {$include:'getcf.dcl' }
- {$include:'getc.dcl' }
- {$include:'putstr.dcl' }
- {$include:'putdec.dcl' }
- {$include:'putcf.dcl' }
- {$include:'putc.dcl' }
- {$include:'ctoi.dcl' }
- {$include:'itoc.dcl' }
- {$include:'length.dcl' }
- {$include:'imin.dcl' }
- {$include:'imax.dcl' }
- {$include:'getarg.dcl' }
- {$include:'nargs.dcl' }
- {$include:'scopy.dcl' }
- {$include:'equal.dcl' }
- {$include:'mustopen.dcl'}
- {$include:'close.dcl' }
-
- {$include:'format.fmt' }
- BEGIN
- minitio; initio;
- format;
- flush(0);
- END.
- -h- fmt.mak 191
- fmt+initio+getfcb+error+getarg+nargs+length+isalphan+
- message+getline+getcf+getc+putstr+putdec+putc+imin+imax+
- ctoi+itoc+putcf+scopy+flush+isupper+isdigit+isletter+
- open+close+mustopen+equal