home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume26 / wroff / part02 < prev    next >
Encoding:
Text File  |  1991-12-11  |  54.3 KB  |  2,244 lines

  1. Newsgroups: comp.sources.misc
  2. From: bkw@uecok.ECOK.EDU (Bill Walker)
  3. Subject:  v26i098:  wroff - text formatter for HP LaserJet with PDS 25-font cartridge, Part02/05
  4. Message-ID: <1991Dec10.063550.9672@sparky.imd.sterling.com>
  5. X-Md4-Signature: 85237917b80e5e5f836c6c820aab5975
  6. Date: Tue, 10 Dec 1991 06:35:50 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: bkw@uecok.ECOK.EDU (Bill Walker)
  10. Posting-number: Volume 26, Issue 98
  11. Archive-name: wroff/part02
  12. Environment: SCO, HPUX, MS-DOS, CPM-68K
  13.  
  14. #! /bin/sh
  15. # into a shell via "sh file" or similar.  To overwrite existing files,
  16. # type "sh file -c".
  17. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  18. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  19. # Contents:  Fonts/lex.yy.c HPUX.make TestData/sampler source/command.c
  20. #   source/init.c source/io.c source/util.c
  21. # Wrapped by kent@sparky on Tue Dec 10 00:26:38 1991
  22. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  23. echo If this archive is complete, you will see the following message:
  24. echo '          "shar: End of archive 2 (of 5)."'
  25. if test -f 'Fonts/lex.yy.c' -a "${1}" != "-c" ; then 
  26.   echo shar: Will not clobber existing file \"'Fonts/lex.yy.c'\"
  27. else
  28.   echo shar: Extracting \"'Fonts/lex.yy.c'\" \(6297 characters\)
  29.   sed "s/^X//" >'Fonts/lex.yy.c' <<'END_OF_FILE'
  30. X# include "stdio.h"
  31. X# define U(x) x
  32. X# define NLSTATE yyprevious=YYNEWLINE
  33. X# define BEGIN yybgin = yysvec + 1 +
  34. X# define INITIAL 0
  35. X# define YYLERR yysvec
  36. X# define YYSTATE (yyestate-yysvec-1)
  37. X# define YYOPTIM 1
  38. X# define YYLMAX 200
  39. X# define output(c) putc(c,yyout)
  40. X# define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):getc(yyin))==10?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)
  41. X# define unput(c) {yytchar= (c);if(yytchar=='\n')yylineno--;*yysptr++=yytchar;}
  42. X# define yymore() (yymorfg=1)
  43. X# define ECHO fprintf(yyout, "%s",yytext)
  44. X# define REJECT { nstr = yyreject(); goto yyfussy;}
  45. Xint yyleng; extern char yytext[];
  46. Xint yymorfg;
  47. Xextern char *yysptr, yysbuf[];
  48. Xint yytchar;
  49. XFILE *yyin ={stdin}, *yyout ={stdout};
  50. Xextern int yylineno;
  51. Xstruct yysvf { 
  52. X    struct yywork *yystoff;
  53. X    struct yysvf *yyother;
  54. X    int *yystops;};
  55. Xstruct yysvf *yyestate;
  56. Xextern struct yysvf yysvec[], *yybgin;
  57. X#undef ECHO;
  58. X#define ECHO;
  59. X
  60. X# define YYNEWLINE 10
  61. Xyylex(){
  62. Xint nstr; extern int yyprevious;
  63. Xwhile((nstr = yylook()) >= 0)
  64. Xyyfussy: switch(nstr){
  65. Xcase 0:
  66. Xif(yywrap()) return(0); break;
  67. Xcase 1:
  68. X            {putchar('E');}
  69. Xbreak;
  70. Xcase -1:
  71. Xbreak;
  72. Xdefault:
  73. Xfprintf(yyout,"bad switch yylook %d",nstr);
  74. X} return(0); }
  75. X/* end of yylex */
  76. Xint yyvstop[] ={
  77. X0,
  78. X
  79. X1,
  80. X0,
  81. X0};
  82. X# define YYTYPE char
  83. Xstruct yywork { YYTYPE verify, advance; } yycrank[] ={
  84. X0,0,    0,0,    0,0,    0,0,    
  85. X0,0,    0,0,    0,0,    0,0,    
  86. X0,0,    0,0,    0,0,    0,0,    
  87. X0,0,    0,0,    0,0,    0,0,    
  88. X0,0,    0,0,    0,0,    0,0,    
  89. X0,0,    0,0,    0,0,    0,0,    
  90. X0,0,    0,0,    0,0,    0,0,    
  91. X1,3,    0,0,    0,0,    0,0,    
  92. X0,0};
  93. Xstruct yysvf yysvec[] ={
  94. X0,    0,    0,
  95. Xyycrank+1,    0,        0,    
  96. Xyycrank+0,    yysvec+1,    0,    
  97. Xyycrank+0,    0,        yyvstop+1,
  98. X0,    0,    0};
  99. Xstruct yywork *yytop = yycrank+28;
  100. Xstruct yysvf *yybgin = yysvec+1;
  101. Xchar yymatch[] ={
  102. X00  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
  103. X01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
  104. X01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
  105. X01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
  106. X01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
  107. X01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
  108. X01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
  109. X01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
  110. X01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
  111. X01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
  112. X01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
  113. X01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
  114. X01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
  115. X01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
  116. X01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
  117. X01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
  118. X0};
  119. Xchar yyextra[] ={
  120. X0,0,0,0,0,0,0,0,
  121. X0};
  122. Xint yylineno =1;
  123. X# define YYU(x) x
  124. X# define NLSTATE yyprevious=YYNEWLINE
  125. Xchar yytext[YYLMAX];
  126. Xstruct yysvf *yylstate [YYLMAX], **yylsp, **yyolsp;
  127. Xchar yysbuf[YYLMAX];
  128. Xchar *yysptr = yysbuf;
  129. Xint *yyfnd;
  130. Xextern struct yysvf *yyestate;
  131. Xint yyprevious = YYNEWLINE;
  132. Xyylook(){
  133. X    register struct yysvf *yystate, **lsp;
  134. X    register struct yywork *yyt;
  135. X    struct yysvf *yyz;
  136. X    int yych;
  137. X    struct yywork *yyr;
  138. X# ifdef LEXDEBUG
  139. X    int debug;
  140. X# endif
  141. X    char *yylastch;
  142. X    /* start off machines */
  143. X# ifdef LEXDEBUG
  144. X    debug = 0;
  145. X# endif
  146. X    if (!yymorfg)
  147. X        yylastch = yytext;
  148. X    else {
  149. X        yymorfg=0;
  150. X        yylastch = yytext+yyleng;
  151. X        }
  152. X    for(;;){
  153. X        lsp = yylstate;
  154. X        yyestate = yystate = yybgin;
  155. X        if (yyprevious==YYNEWLINE) yystate++;
  156. X        for (;;){
  157. X# ifdef LEXDEBUG
  158. X            if(debug)fprintf(yyout,"state %d\n",yystate-yysvec-1);
  159. X# endif
  160. X            yyt = yystate->yystoff;
  161. X            if(yyt == yycrank){        /* may not be any transitions */
  162. X                yyz = yystate->yyother;
  163. X                if(yyz == 0)break;
  164. X                if(yyz->yystoff == yycrank)break;
  165. X                }
  166. X            *yylastch++ = yych = input();
  167. X        tryagain:
  168. X# ifdef LEXDEBUG
  169. X            if(debug){
  170. X                fprintf(yyout,"char ");
  171. X                allprint(yych);
  172. X                putchar('\n');
  173. X                }
  174. X# endif
  175. X            yyr = yyt;
  176. X            if ( (int)yyt > (int)yycrank){
  177. X                yyt = yyr + yych;
  178. X                if (yyt <= yytop && yyt->verify+yysvec == yystate){
  179. X                    if(yyt->advance+yysvec == YYLERR)    /* error transitions */
  180. X                        {unput(*--yylastch);break;}
  181. X                    *lsp++ = yystate = yyt->advance+yysvec;
  182. X                    goto contin;
  183. X                    }
  184. X                }
  185. X# ifdef YYOPTIM
  186. X            else if((int)yyt < (int)yycrank) {        /* r < yycrank */
  187. X                yyt = yyr = yycrank+(yycrank-yyt);
  188. X# ifdef LEXDEBUG
  189. X                if(debug)fprintf(yyout,"compressed state\n");
  190. X# endif
  191. X                yyt = yyt + yych;
  192. X                if(yyt <= yytop && yyt->verify+yysvec == yystate){
  193. X                    if(yyt->advance+yysvec == YYLERR)    /* error transitions */
  194. X                        {unput(*--yylastch);break;}
  195. X                    *lsp++ = yystate = yyt->advance+yysvec;
  196. X                    goto contin;
  197. X                    }
  198. X                yyt = yyr + YYU(yymatch[yych]);
  199. X# ifdef LEXDEBUG
  200. X                if(debug){
  201. X                    fprintf(yyout,"try fall back character ");
  202. X                    allprint(YYU(yymatch[yych]));
  203. X                    putchar('\n');
  204. X                    }
  205. X# endif
  206. X                if(yyt <= yytop && yyt->verify+yysvec == yystate){
  207. X                    if(yyt->advance+yysvec == YYLERR)    /* error transition */
  208. X                        {unput(*--yylastch);break;}
  209. X                    *lsp++ = yystate = yyt->advance+yysvec;
  210. X                    goto contin;
  211. X                    }
  212. X                }
  213. X            if ((yystate = yystate->yyother) && (yyt= yystate->yystoff) != yycrank){
  214. X# ifdef LEXDEBUG
  215. X                if(debug)fprintf(yyout,"fall back to state %d\n",yystate-yysvec-1);
  216. X# endif
  217. X                goto tryagain;
  218. X                }
  219. X# endif
  220. X            else
  221. X                {unput(*--yylastch);break;}
  222. X        contin:
  223. X# ifdef LEXDEBUG
  224. X            if(debug){
  225. X                fprintf(yyout,"state %d char ",yystate-yysvec-1);
  226. X                allprint(yych);
  227. X                putchar('\n');
  228. X                }
  229. X# endif
  230. X            ;
  231. X            }
  232. X# ifdef LEXDEBUG
  233. X        if(debug){
  234. X            fprintf(yyout,"stopped at %d with ",*(lsp-1)-yysvec-1);
  235. X            allprint(yych);
  236. X            putchar('\n');
  237. X            }
  238. X# endif
  239. X        while (lsp-- > yylstate){
  240. X            *yylastch-- = 0;
  241. X            if (*lsp != 0 && (yyfnd= (*lsp)->yystops) && *yyfnd > 0){
  242. X                yyolsp = lsp;
  243. X                if(yyextra[*yyfnd]){        /* must backup */
  244. X                    while(yyback((*lsp)->yystops,-*yyfnd) != 1 && lsp > yylstate){
  245. X                        lsp--;
  246. X                        unput(*yylastch--);
  247. X                        }
  248. X                    }
  249. X                yyprevious = YYU(*yylastch);
  250. X                yylsp = lsp;
  251. X                yyleng = yylastch-yytext+1;
  252. X                yytext[yyleng] = 0;
  253. X# ifdef LEXDEBUG
  254. X                if(debug){
  255. X                    fprintf(yyout,"\nmatch ");
  256. X                    sprint(yytext);
  257. X                    fprintf(yyout," action %d\n",*yyfnd);
  258. X                    }
  259. X# endif
  260. X                return(*yyfnd++);
  261. X                }
  262. X            unput(*yylastch);
  263. X            }
  264. X        if (yytext[0] == 0  /* && feof(yyin) */)
  265. X            {
  266. X            yysptr=yysbuf;
  267. X            return(0);
  268. X            }
  269. X        yyprevious = yytext[0] = input();
  270. X        if (yyprevious>0)
  271. X            output(yyprevious);
  272. X        yylastch=yytext;
  273. X# ifdef LEXDEBUG
  274. X        if(debug)putchar('\n');
  275. X# endif
  276. X        }
  277. X    }
  278. Xyyback(p, m)
  279. X    int *p;
  280. X{
  281. Xif (p==0) return(0);
  282. Xwhile (*p)
  283. X    {
  284. X    if (*p++ == m)
  285. X        return(1);
  286. X    }
  287. Xreturn(0);
  288. X}
  289. X    /* the following are only used in the lex library */
  290. Xyyinput(){
  291. X    return(input());
  292. X    }
  293. Xyyoutput(c)
  294. X  int c; {
  295. X    output(c);
  296. X    }
  297. Xyyunput(c)
  298. X   int c; {
  299. X    unput(c);
  300. X    }
  301. END_OF_FILE
  302.   if test 6297 -ne `wc -c <'Fonts/lex.yy.c'`; then
  303.     echo shar: \"'Fonts/lex.yy.c'\" unpacked with wrong size!
  304.   fi
  305.   # end of 'Fonts/lex.yy.c'
  306. fi
  307. if test -f 'HPUX.make' -a "${1}" != "-c" ; then 
  308.   echo shar: Will not clobber existing file \"'HPUX.make'\"
  309. else
  310.   echo shar: Extracting \"'HPUX.make'\" \(5399 characters\)
  311.   sed "s/^X//" >'HPUX.make' <<'END_OF_FILE'
  312. XFrom uokmax!servalan!chinet!nucsrl!marcal!marc Mon Sep 16 01:00:10 1991
  313. XReceived: by uecok.ECOK.EDU (smail2.5)
  314. X    id AA21001; 16 Sep 91 01:00:10 CDT (Mon)
  315. XReceived: by uokmax.ecn.uoknor.edu id AA24045
  316. X  (5.65c/IDA-1.4.4 for uecok!bw); Sat, 14 Sep 1991 15:58:58 -0500
  317. XReceived: by servalan.UUCP (smail2.5+apb/mje900117)
  318. X    id AA02142; Sat, 14 Sep 91 15:41:05 CDT
  319. XReceived: by chinet.chi.il.us (/\==/\ Smail3.1.22.1 #22.1)
  320. X    id <m0kLVGc-00025WC@chinet.chi.il.us>; Sat, 14 Sep 91 03:22 CDT
  321. XReceived: from sol by delta.nucsrl.uucp id aa26410; 13 Sep 91 21:48 CDT
  322. XReceived: from mcdchg.UUCP by vistatech.com (4.0/SMI-4.0)
  323. X    id AA08664; Fri, 13 Sep 91 21:40:51 CDT
  324. XReceived: by mcdchg.chg.mcd.mot.com (/\=-/\ Smail3.1.18.1 #18.4)
  325. X    id <m0kLLrj-0000u2C@mcdchg.chg.mcd.mot.com>; Fri, 13 Sep 91 18:19 EDT
  326. XMessage-Id: <m0kLLrj-0000u2C@mcdchg.chg.mcd.mot.com>
  327. XReceived: by marcal.marcal.com
  328. X    (15.11.1.6/15.6) id AA24271; Fri, 13 Sep 91 16:53:36 -0500
  329. XFrom: Marc Veeneman <uokmax!marcal!marc>
  330. XSubject: Wroff changes
  331. XTo: uecok!bw
  332. XDate: Fri, 13 Sep 91 16:53:33 CDT
  333. XMailer: Elm [revision: 64.9]
  334. XStatus: RO
  335. X
  336. XThank you much for keeping me up-to-date, Bill.
  337. X
  338. XI'm sending you the Makefile, as revised, which works with
  339. Xmy machine.  This is HP-UX, version 7.02, on the 800 series
  340. Xof HP's 9000s.  The 800 series is meant to be a multiple
  341. Xuser box, not the 300,400,500,700 etc. machines which are
  342. Xsold as personal workstations.  Much of the difference, of
  343. Xcourse, is in the interfaces available, not in the CPU.  In
  344. Xfact 700s and 800s have the same RISC heart beating inside.
  345. X
  346. XHere's the Makefile:
  347. X------------------------------------------------------------------------
  348. X# First make a.out, the make manpage and make tut.
  349. X# THEN you may make install.
  350. X
  351. X# this is the command to print something on your laser printer
  352. XPRINT=lp
  353. X
  354. X# the owner of the system files --- need not be root
  355. XOWNER=root
  356. X
  357. X# directory to contain the font tables
  358. X# leave as it is for testing, but change it for production
  359. X#FONTS='"./Fonts"'
  360. X#here's where we keep it, but you will want to change it.
  361. X# Note: Change the occurrences of ECU to local
  362. XFONTS='"/usr/local/Fonts"'
  363. X# Note: HP-UX make cannot make sense out of $(FONTSDIR)
  364. X#       so define it outside the cc argument.
  365. XFONTSDIR=/usr/local/Fonts
  366. X
  367. X#source is located in this directory
  368. XSOURCE=./source
  369. X
  370. X#documentation is contained in this directory
  371. XDOCDIR=./doc
  372. X
  373. X#local bin directory
  374. X#leave it as is for testing, but change it for actual installation
  375. X#BINDIR=./bin
  376. X# we use this, but again you will certainly want to change it
  377. X# Note: Change the occurrences of ECU to local
  378. XBINDIR=/usr/local/bin
  379. X
  380. X# Note: HP-UX cc didn't understand -i option, so it ignored it: 
  381. X#CFLAGS = -DFONTSDIR='"$(FONTS)"' -i -DUNIX -g
  382. XCFLAGS = -DFONTSDIR='"$(FONTS)"' -DUNIX -g
  383. X
  384. X
  385. Xa.out : 
  386. X        cd source; make -f makefile -k "CC=$(CC)" "CFLAGS=$(CFLAGS)"; \
  387. X             mv a.out ../a.out
  388. X
  389. X
  390. X# be sure you have write permission whereever these directories are
  391. Xinstall :
  392. X        strip a.out
  393. X        mv a.out $(BINDIR)/wroff
  394. X        cp ./Fonts/* $(FONTSDIR)
  395. X# Note: this looks like a simple typo, chmod instead of chown:  
  396. X#       chmod $(OWNER) $(FONTSDIR)/*
  397. X        chown $(OWNER) $(FONTSDIR)/*
  398. X        chmod u+r $(FONTSDIR)/*
  399. X        chmod go+rx $(BINDIR)/wroff
  400. X        chown $(OWNER) $(BINDIR)/wroff
  401. X
  402. X
  403. X# make "manual page" documentation for wroff -- it is stored under DOCDIR
  404. X# note that we assume that the (unstripped) wroff executable is named "a.out"
  405. X# Note: Change a.out in manpage  and tut to ./a.out
  406. X#       For security reasons, never have local pwd
  407. X#       in your path.
  408. X
  409. Xmanpage : 
  410. X        ./a.out $(DOCDIR)/macs.w $(DOCDIR)/wroff.1.w -p -k -o $(DOCDIR)/doc.pr
  411. X
  412. X# make a tutorial for wroff -- store it in the DOCDIR
  413. X# note that we assume that the (unstripped) wroff executable is named "a.out"
  414. X
  415. Xtut :
  416. X        ./a.out $(DOCDIR)/macs.w $(DOCDIR)/wroff.tut.w -p -k -o $(DOCDIR)/tut.pr
  417. X
  418. X
  419. X#clean up the mess
  420. Xclean:
  421. X        rm $(SOURCE)/*.o
  422. X
  423. X
  424. X# this will test wroff to see if it works at all
  425. Xtest :
  426. X        $(BINDIR)/wroff $(DOCDIR)/welcome
  427. X        $(BINDIR)/wroff $(DOCDIR)/welcome | $(PRINT)
  428. X
  429. X
  430. X# this will print a convenient "sampler" to demonstrate the available fonts
  431. Xsampler:
  432. X        $(BINDIR)/wroff TestData/sampler | $(PRINT)
  433. X
  434. X-------------------------------------------------------------------------
  435. X
  436. XNow I'm going to go looking for WalkerTBL, but I don't think I've seen
  437. Xit come in.  Did you send me a copy?  If not, please do.  I needed
  438. Xto format some number columns the other day and ended up frustrated.
  439. XI supposed you could pipe tbl output to WalkerROFF, but I'm always
  440. Xin too much of a hurry to learn new tricks.  
  441. X
  442. XAnother little frustration came when our client jammed a full page
  443. Xof 12 point verbage in the monthly letter.  Turns out I was unable
  444. Xto adjust the LineLength, ala nroff, to make a narrower right margin,
  445. Xand I couldn't figure out how to make the bottom margin smaller.
  446. X
  447. XOn the other hand, a longer tutorial may not be desirable either.  I
  448. Xalways keep in mind that this is wonderful because it is simple, the
  449. Xvery thing that (supposedly) made U*ix popular.
  450. X
  451. XMostly, Bill, I'm delighted to see you breathing life into wroff.
  452. XYour students will benefit from ANYTHING, I suppose, but unnamed folks
  453. Xaround the world will benefit from wroff.
  454. X--
  455. XMarc Veeneman           Marcal Systems Corporation    voice:    1 708 516 4555
  456. Xmarcal.uucp!marc         Custom Financial Service       fax:    1 708 516 4411
  457. X
  458. END_OF_FILE
  459.   if test 5399 -ne `wc -c <'HPUX.make'`; then
  460.     echo shar: \"'HPUX.make'\" unpacked with wrong size!
  461.   fi
  462.   # end of 'HPUX.make'
  463. fi
  464. if test -f 'TestData/sampler' -a "${1}" != "-c" ; then 
  465.   echo shar: Will not clobber existing file \"'TestData/sampler'\"
  466. else
  467.   echo shar: Extracting \"'TestData/sampler'\" \(4919 characters\)
  468.   sed "s/^X//" >'TestData/sampler' <<'END_OF_FILE'
  469. X.fm RESET
  470. X\fMFont RESET will clear the printer to default\fP
  471. X.sp
  472. XThis is a print sampler.
  473. X.sp 4
  474. X.fm LGN9.5A
  475. X\fMFont LGN9.5A is Letter Gothic, Normal, 9.5 point, ASCII\fP
  476. X.sp
  477. X.fm LGN14L
  478. X\fMFont LGN14L is Letter Gothic, Norman, 14 point, LEGAL\fP
  479. X.sp
  480. X.fm TMN10B
  481. XFont TMN10B is a math font: \fM abcdefgh\fP
  482. X.sp
  483. X.fm PAFS4.8_12
  484. X\fMFont\fP PAFS4.8_12 \fM is PDP AFS 4.8 point, 12 lpi\fP
  485. X.sp 
  486. X.fm PAFS4.8_16
  487. X\fMFont\fP PAFS4.8_16 \fM is PDP AFS 4.8 point, 16 lpi\fP
  488. X.sp
  489. X.fm PCLine14
  490. XFont PCLine14 is a line drawing font: \fM0123456789\fP
  491. X.sp
  492. X.fm TaxB12
  493. XFont TaxB12 is a tax form font, boldfaced: \fMabcdefgh\fP
  494. X.sp
  495. X.fm LineDraw12
  496. XFont LineDraw12 is a line drawing font: \fMabcdefgh\fP
  497. X.sp
  498. X.fm LGN14A
  499. X\fMFont LGN14A is Letter Gothic, Normal, 14 point, ASCII\fP
  500. X.sp
  501. X.fm LGB12A
  502. X\fMFont LGB12A is Letter Gothic, Bold, 12 point, ASCII\fP
  503. X.sp
  504. X.fm LP8.5PC
  505. X\fMFont LP8.5PC is Line Printer, 8.5 point, PC\fP
  506. X.sp
  507. X.fm ci12
  508. X\fMFont ci12 is Courier, Italic, 12 point, ASCII\fP
  509. X.sp
  510. X.fm cn12
  511. X\fMFont cn12 is Courier, Normal, 12 point, ASCII\fP
  512. X.sp
  513. X.fm pen7
  514. X\fMFont pen7 is Prestige Elite, Normal, 7 point, ASCII\fP
  515. X.sp
  516. X.fm lp8.5
  517. X\fMFont lp8.5 is a Line Printer, 8.5 point, ASCII\fP
  518. X.sp
  519. X.fm pb18
  520. X\fMFont pb18 is Presentation, Bold, 18 point, ASCII\fP
  521. X.sp
  522. X.fm pb16a
  523. X\fMFont pb16a is Presentation, Bold, 16 point, ASCII\fP
  524. X.sp
  525. X.fm pei10.l
  526. X\fMFont pei10.l is Prestige Elite, Italic, 10 point, Legal\fP
  527. X.sp
  528. X.fm pen10.l
  529. X\fMFont pen10.l is Prestige Elite, Normal, 10 point, Legal\fP
  530. X.sp
  531. X.fm peb10.l
  532. X\fMFont peb10.l is Prestige Elite, Bold, 10 point, Legal\fP
  533. X.sp
  534. X.fm ct12r-8
  535. X\fMFont ct12r-8 is Courier, Italic, 12 point, Roman-8\fP
  536. X.sp
  537. X.fm pb14
  538. X\fMFont pb14 is Presentation, Bold, 14 points, ASCII\fP
  539. X.sp
  540. X.fm HB14ECMA
  541. X\fMFont HB14ECMA is Helvetica, Bold, 14 point, ECMA, 10 series\fP
  542. X.sp
  543. X.fm TMN8A
  544. XFont TMN8A is Times Math, Normal, 8 point, MATH A  \fMabcdefg1234567\fP
  545. X.sp
  546. X.fm HN10
  547. X\fMFont HN10 is Helvetica, Normal, 10 point, ASCII\fP
  548. X.sp
  549. X.fm HI10
  550. X\fMFont HI10 is Helvetica, Italic, 10 point, ASCII\fP
  551. X.sp
  552. X.fm HB8
  553. X\fMFont HB8 is Helvetica, Bold, 8 point, ASCII\fP
  554. X.sp
  555. X.fm HN8
  556. X\fMFont HN8 is Helvetica, Normal, 8 point, ASCII\fP
  557. X.sp
  558. X.fm HN6
  559. X\fMFont HN6 is Helvetic, Normal, 6 point, ASCII\fP
  560. X.sp
  561. X.fm trn12
  562. X\fMFont trn12 is Times Roman, Normal, 12 point, ASCII\fP
  563. X.sp
  564. X.fm trb12
  565. X\fMFont trb12 is Times Roman, Bold, 12 point, ASCII\fP
  566. X.sp
  567. X.fm tri12
  568. X\fMFont tri12 is Times Roman, Italic, 12 point, ASCII\fP
  569. X.sp
  570. X.fm trn8
  571. X\fMFont trn8 is Times Roman, Normal, 8 point, ASCII\fP
  572. X.sp
  573. X.fm tri10
  574. X\fMFont tri10 is Times Roman, Italic, 10 point, ASCII\fP
  575. X.sp
  576. X.fm trn10
  577. X\fMFont trn10 is Times Roman, Normal, 10 point, ASCII\fP
  578. X.sp 
  579. X.fm trb10
  580. X\fMFont trb10 is Times Roman, Bold, 10 point, ASCII\fP
  581. X.sp
  582. X.fm lgn12
  583. X\fMFont lgn12 is Letter Gothic, Normal, 12 point, ASCII\fP
  584. X.sp
  585. X.fm lgi12
  586. X\fMFont lgi12 is Letter Gothic, Italic, 12 point, ASCII\fP
  587. X.sp 
  588. X.fm PB18L
  589. X\fMFont PB18L is Presentation, Bold, 18 point, Legal\fP
  590. X.sp
  591. X.fm PB16L
  592. X\fMFont PB16L is Presentation, Bold, 16 point, Legal\fP
  593. X.sp
  594. X.fm PB14L
  595. X\fMFont PB14L is Presentation, Bold, 14 point, Legal\fP
  596. X.sp
  597. X.fm HB14
  598. X\fMFont HB14 is Helvetica, Bold, 14 point, ASCII\fP
  599. X.sp
  600. X.fm TMN8B
  601. XFont TMN8B is Times Math, Normal, 8 point, MATH B  \fMabcdef123456\fP
  602. X.sp
  603. X.fm HB12
  604. X\fMFont HB12 is Helvetica, Bold, 12 point, ASCII\fP
  605. X.sp
  606. X.fm HN12
  607. X\fMFont HN12 is Helvetica, Normal, 12 point, ASCII\fP
  608. X.sp
  609. X.fm HI12
  610. X\fMFont HI12 is Helvetica, Italic, 12 point, ASCII\fP
  611. X.sp
  612. X.fm HB10
  613. X\fMFont HB10 is Helvetica, Bold, 10 point, ASCII\fP
  614. X.sp
  615. X.fm PEN7L
  616. X\fMFont PEN7L is Prestige Elite, Normal, 7 point, Legal\fP
  617. X.sp
  618. X.fm LGN12H
  619. X\fMFont LGN12H is Letter Gothic, Normal, 12 point, ASCII, Prints sideways\fP
  620. X.sp
  621. X.fm pen10h
  622. X\fMFont pen10h is Prestige Elite, Normal, 10 point, ASCII, Prints sideways\fP
  623. X.sp
  624. X.fm PB14
  625. X\fMFont PB14 is Presentation, Bold, 14 points, ASCII, Prints sideways\fP
  626. X.sp
  627. X.fm PEN7H
  628. X\fMFont PEN7H is Prestige Elite, Normal, 7 point, ASCII, Prints sideways\fP
  629. X.sp
  630. X.fm lgn14
  631. X\fMFont lgn14 is Letter Gothic, Normal, 14 point, Print sideways\fP
  632. X.sp
  633. X.fm pcln14.l
  634. XFont pcln14.l is PC Line, Normal, 14 point, PC Line, Prints sideways  \fMabcdefg\fP
  635. X.sp
  636. X.fm  pdp4.812.l
  637. X\fMFont pdp4.812.l is PDP AFS, 4.8 point, 12 lpi, LICS, Prints sideways\fP
  638. X.sp
  639. X.fm pdp4.816.l
  640. X\fMFont pdp4.816.l is PDP AFS, 4.8 point, 16 lpi, LICS, Prints sideways\fP
  641. X.sp
  642. X.fm HN6H
  643. X\fMFont HN6H is Helvetica, Normal, 6 point, ASCII, Prints sideways\fP
  644. X.sp
  645. X.fm TRN10H
  646. X\fMFont TRN10H is Times Roman, Normal, 10 point, ASCII, Prints sideways\fP 
  647. X.sp
  648. X.fm PEN7LH
  649. X\fMFont PEN7LH is Prestige Elite, Normal, 7 point, Legal, Prints sideways\fP
  650. X.sp
  651. X.fm LGN9.5H
  652. X\fMFont LGN9.5H is LtrGothic Nm 9.5 point, ASCII, Prints sideways\fP
  653. X.sp
  654. X.fm Line8.5H
  655. X\fMFont Line8.5H is LinePrinter 8.5 point, ASCII, Prints sideways\fP
  656. X.sp
  657. X.fm HB12H
  658. X\fMFont HB12H is Helvetica, Bold, 12 point, ASCII, Prints sideways\fP
  659. X.sp
  660. X.fm HB10H
  661. X\fMFont HB10H is Helvetica, Bold, 10 point, ASCII, Prints sideways\fP
  662. X.sp
  663. X.fm HN8H
  664. X\fMFont HN8H is Helvetica, Normal, 8 point, ASCII, Prints sideways\fP
  665. END_OF_FILE
  666.   if test 4919 -ne `wc -c <'TestData/sampler'`; then
  667.     echo shar: \"'TestData/sampler'\" unpacked with wrong size!
  668.   fi
  669.   # end of 'TestData/sampler'
  670. fi
  671. if test -f 'source/command.c' -a "${1}" != "-c" ; then 
  672.   echo shar: Will not clobber existing file \"'source/command.c'\"
  673. else
  674.   echo shar: Extracting \"'source/command.c'\" \(13945 characters\)
  675.   sed "s/^X//" >'source/command.c' <<'END_OF_FILE'
  676. X#include <stdio.h>
  677. X#include <ctype.h>
  678. X
  679. X#include "defs.h"
  680. X#include "externs.c"
  681. X
  682. Xextern FILE *fopen();
  683. Xextern struct machead *findmac();
  684. Xextern struct traphead *findtrap();
  685. X
  686. X/* this file contains the command processor */
  687. X
  688. X
  689. Xcommand(s,ifile,ofile)
  690. Xchar s[];
  691. XFILE *ifile,*ofile;
  692. X{
  693. X    char cmd[MAXCMD][SHORTSTR];
  694. X    int i,j,k,l;
  695. X    int cmdnbr;
  696. X    int atype,value;
  697. X    char tempcmd[SHORTSTR], stopcmd[SHORTSTR];
  698. X    char templine[MAXSTR];
  699. X    char restofline[MAXSTR];
  700. X    char temp1line[MAXSTR];
  701. X    char temp2line[MAXSTR];
  702. X    char tempfont[MAXSTR];
  703. X    int quitadding;
  704. X    int cnt;
  705. X    int wordlength, chcnt;
  706. X    FILE *tempfile,*fontfile;
  707. X
  708. X    /* we have a command line.  It may still have white
  709. X        space at the front.  It has a null at the end.
  710. X        It has had nothing else done to it */
  711. X
  712. X    /* first we parse the command line into its parts */
  713. X    /* it may have a command name, and several arguments */
  714. X
  715. X    /* first eat off any white space */
  716. X    j = 0;
  717. X    while (s[j] != '\0' && isspace(s[j]) ) j++;
  718. X
  719. X    /* now skip the command character */
  720. X    j++;
  721. X
  722. X    /* clean off the command strings -- all of them ! */
  723. X    for (cmdnbr = 0; cmdnbr < MAXCMD; cmdnbr++)
  724. X        cmd[cmdnbr][0] = '\0';
  725. X
  726. X    /* now copy into the cmd strings */
  727. X    cmdnbr = 0;
  728. X
  729. X    /* restofline contains all but the command */
  730. X    k = j;
  731. X    while (s[k] != '\0' && isspace(s[k]) ) k++;
  732. X    while (s[k] != '\0' && !isspace(s[k]) ) k++;
  733. X    while (s[k] != '\0' && isspace(s[k]) ) k++;
  734. X    l = 0;
  735. X    while (s[k] != '\0') {
  736. X        restofline[l] = s[k];
  737. X        k++;
  738. X        l++;
  739. X    }
  740. X    restofline[l] = '\0';
  741. X
  742. X    while ( s[j] != '\0') {
  743. X
  744. X        /* first eat off any white space */
  745. X        while (s[j] != '\0' && isspace(s[j]) ) j++;
  746. X
  747. X        /* now copy into the command */
  748. X        i = 0;
  749. X        while ( s[j] != '\0' && !isspace(s[j]) ) {
  750. X            cmd[cmdnbr][i] = s[j];
  751. X            j++;
  752. X            i++;
  753. X        }
  754. X        cmd[cmdnbr] [i] = '\0';
  755. X        cmdnbr++;
  756. X    }
  757. X    /* now cmd[0] is the command name, and the rest are the arguments */
  758. X
  759. X    /* we must now select the command, and take some action */
  760. X    /* a finite state machine would be too cumbersome to
  761. X       modify, so we just slug it out the hard way */
  762. X
  763. X    atype = argtype(cmd[1]);
  764. X    expndreg(templine,cmd[1]);  /* expand any registers in cmd[1] */
  765. X    value = argval(templine);
  766. X
  767. X    if (streq(cmd[0],"bd") ) {  /* boldface next n lines */
  768. X        setparm(&BOLDCNT,atype,value,DEFCOUNT,0,HUGE);
  769. X    }
  770. X    else if (streq(cmd[0],"bp") ) {  /* break page, number next n */
  771. X        brek(ifile,ofile);
  772. X        brpage(ifile,ofile);
  773. X        setparm(&NEXTPAGE,atype,value,CURRPAGE + 1,1,HUGE);
  774. X    }
  775. X    else if (streq(cmd[0],"br") ) { /* break */
  776. X        brek(ifile,ofile);
  777. X    }
  778. X    else if (streq(cmd[0],"cc") ) {   /* change command character */
  779. X        CMDCHAR = cmd[1][0];
  780. X    }
  781. X    else if (streq(cmd[0],"ce") ) {   /* center next n lines */
  782. X        brek(ifile,ofile);
  783. X        setparm(&CNTRCNT,atype,value,DEFCOUNT,0,HUGE);
  784. X    }
  785. X    else if (streq(cmd[0],"dc") ) {   /* title delimiter */
  786. X        TDLIM = cmd[1][0];
  787. X    }
  788. X    else if (streq(cmd[0],"de") ) {   /* define macro */
  789. X        /* cmd[1] is the macro name */
  790. X        defmac(cmd[1],¯olist);
  791. X        /* now get lines from the file and add them to
  792. X           this macro -- since the macro list is a stack,
  793. X           the macrolist pointer points to the macro that
  794. X           needs the lines added to it */
  795. X        /* first build a string that can be used to stop
  796. X           fetching lines */
  797. X        sprintf(stopcmd,"%cen",CMDCHAR);
  798. X        quitadding = FALSE;
  799. X        while (! quitadding ) {
  800. X            /* get a line */
  801. X            getline(templine,ifile);
  802. X            /* strip off the leading white space */
  803. X            i = 0;
  804. X            while (templine[i] != '\0' && isspace(templine[i]) ) i++;
  805. X            /* copy into tempcmd */
  806. X            j = 0;
  807. X            while (templine[i] != '\0' && !isspace(templine[i])) {
  808. X                tempcmd[j] = templine[i];
  809. X                i++;
  810. X                j++;
  811. X            }
  812. X            tempcmd[j] = '\0';
  813. X            if (streq(tempcmd,stopcmd) ) {
  814. X                quitadding = TRUE;
  815. X            }
  816. X            else {
  817. X                macaddline(macrolist,templine);
  818. X            }
  819. X
  820. X        }
  821. X
  822. X    }
  823. X    else if (streq(cmd[0],"di") ) {   /* start diversion */
  824. X        defmac(cmd[1],¯olist);
  825. X        InDiversion = TRUE;
  826. X        DivStart = CURRY;
  827. X    }
  828. X    else if (streq(cmd[0],"ed") ) {   /* end diversion */
  829. X        REG('D') = CURRY - DivStart;
  830. X        CURRY = DivStart;
  831. X        InDiversion = FALSE;
  832. X    }
  833. X    else if (streq(cmd[0],"en") ) {   /* end macro */
  834. X        /* this should never be encountered */
  835. X        fprintf(stderr,"end of macro encountered without a .de\n");
  836. X        exit(1);
  837. X    }
  838. X    else if (streq(cmd[0],"et") ) {   /* end transparent mode */
  839. X        brek(ifile,ofile);
  840. X        outselect = 'f';
  841. X    }
  842. X    else if (streq(cmd[0],"ex") ) {
  843. X        brek(ifile,ofile);
  844. X        brpage(ifile,ofile);
  845. X        exit(0);
  846. X    }
  847. X    else if (streq(cmd[0],"fi") ) {   /* start fill */
  848. X        brek(ifile,ofile);
  849. X        FILLMODE = TRUE;
  850. X    }
  851. X    else if (streq(cmd[0],"fm") ) {   /* mount a font */
  852. X        /* font name is in cmd[1] */
  853. X        strcpy(tempfont,FONTSDIR);
  854. X        strcat(tempfont,"/%s");
  855. X
  856. X        sprintf(tempcmd,tempfont,cmd[1]);
  857. X        fontfile = fopen(tempcmd,"r");
  858. X        if (fontfile == NULL) {
  859. X            fprintf(stderr,"font %s not found\n",tempcmd);
  860. X            exit(1);
  861. X        }
  862. X        fscanf(fontfile,"%s",Pres);
  863. X        /* note: the string Pres contains the letter E in several
  864. X         places, which must be replaced with the ESC character */
  865. X        i = 0;
  866. X        while (Pres[i] != '\0') {
  867. X            if (Pres[i] == 'E')
  868. X                Pres[i] = ESC;
  869. X            i++;
  870. X        }
  871. X
  872. X
  873. X        
  874. X        for (i = 32; i <= 126; i++) 
  875. X            fscanf(fontfile,"%d",&P18bl[i]);
  876. X        
  877. X        fclose(fontfile); 
  878. X
  879. X    }
  880. X    else if (streq(cmd[0],"fo") ) {   /* define footer */
  881. X        strcpy(footer,restofline);
  882. X    }
  883. X    else if (streq(cmd[0],"gx") ) {   /* go to  X  */
  884. X        expndreg(templine,cmd[1]);
  885. X        gotoX(ifile,ofile,templine);
  886. X    }
  887. X    else if (streq(cmd[0],"gy") ) {  /* goto y */
  888. X        expndreg(templine,cmd[1]);
  889. X        gotoY(ifile,ofile,templine);
  890. X    }
  891. X    else if (streq(cmd[0],"he") ) {   /* define header */
  892. X        strcpy(header,restofline);
  893. X    }
  894. X    else if (streq(cmd[0],"hr") ) {   /* horizontal rule */
  895. X        fprintf(stderr,"horizontal rule not yet implemented\n");
  896. X        exit(1);
  897. X    }
  898. X    else if (streq(cmd[0],"if") ) {   /* if test */
  899. X        /* we have two expressions, and an operator, or maybe
  900. X            only one expression, which is either 0 (TRUE)
  901. X            or non-zero (FALSE) --- we need to parse this
  902. X            mess to find out what it is */
  903. X        /* everything is in restofline */
  904. X        /* first extract the condition */
  905. X        i = 0;
  906. X        while (restofline[i] != '\0' && restofline[i] != '(') i++;
  907. X        i++; /* to skip the '(' */
  908. X        j = 0;
  909. X        while (restofline[i] != ')' ) {
  910. X            templine[j] = restofline[i];
  911. X            i++;
  912. X            j++;
  913. X        }
  914. X        templine[j] = '\0';
  915. X        /* i is at the ')' in restofline */
  916. X        /* templine contains the condition */
  917. X        i++;
  918. X        j = 0;
  919. X        while (restofline[i] != '\0') {
  920. X            temp1line[j] = restofline[i];
  921. X            i++;
  922. X            j++;
  923. X        }
  924. X        temp1line[j] = '\0';
  925. X        /* now temp1line contains the macro to be executed if
  926. X           the condition is true */
  927. X        if (Beval(templine))
  928. X            procmacro (temp1line,ifile,ofile);
  929. X
  930. X    }
  931. X    else if (streq(cmd[0],"in") ) {   /* left margin */
  932. X        brek(ifile,ofile);
  933. X        setparm(&LMARGIN,atype,DOTSCHAR*value,DEFLMARGIN,0,HUGE);
  934. X    }
  935. X    else if (streq(cmd[0],"it") ) {   /* italicize */
  936. X        setparm(&ITALCNT,atype,value,DEFCOUNT,0,HUGE);
  937. X    }
  938. X    else if (streq(cmd[0],"ju") ) {   /* right justify */
  939. X        brek(ifile,ofile);
  940. X        RJUSTIFY = TRUE;
  941. X    }
  942. X    else if (streq(cmd[0],"lp") ) {   /* label paragraph */
  943. X        brek(ifile,ofile);
  944. X        /* the label is in cmd[1] */
  945. X            i = 0;
  946. X            getword(templine,cmd[1],&i);
  947. X            parseword(temp1line,templine,&wordlength,&chcnt,ifile,ofile);
  948. X            i = 0;
  949. X            j = 0;
  950. X            while (temp1line[i] != '\0') {
  951. X                if (temp1line[i] != SHIFTOUT) {
  952. X                    temp1line[j] = temp1line[i];
  953. X                    j++;
  954. X                }
  955. X                i++;
  956. X            }
  957. X            temp1line[j] = '\0';
  958. X            if ( ShouldPrint ) {
  959. X                if (FONTCHANGE)  {
  960. X                  sprintf(temp2line,"%c*p%dX%s",ESC, TEMPINDENT + LMARGIN  - IPARA,temp1line);
  961. X                  addbuf(temp2line);
  962. X                  sprintf(temp2line,"%c*p%dX",ESC, TEMPINDENT + LMARGIN );
  963. X                  addbuf(temp2line);
  964. X                  shadd = FALSE;
  965. X                }
  966. X                else {
  967. X                    sprintf(temp2line,"%s ",temp1line);
  968. X                    addbuf(temp2line);
  969. X                    shadd = FALSE;
  970. X                }
  971. X            }
  972. X    }
  973. X    else if (streq(cmd[0],"ls") ) {   /* line spacing */
  974. X        brek(ifile,ofile);
  975. X        setparm (&LSPACE,atype,value,DEFLSPACE,0,HUGE);
  976. X    }
  977. X    else if (streq(cmd[0],"m2") ) {   /* margin after header */
  978. X        setparm(&MTWO,atype,value,48,0,HUGE);
  979. X    }
  980. X    else if (streq(cmd[0],"m3") ) {   /* margin before footer */
  981. X        setparm(&MTHREE,atype,value,24,0,HUGE);
  982. X    }
  983. X    else if (streq(cmd[0],"ne") ) {   /* need valuen  lines */
  984. X        if (CURRY  + MTHREE + value * VSPACE * LSPACE  > (PAGELENGTH - BOTTOMMARGIN)) {
  985. X            brek(ifile,ofile);
  986. X            brpage(ifile,ofile);
  987. X        }
  988. X    }
  989. X    else if (streq(cmd[0],"nf") ) {   /* no fill mode */
  990. X        brek(ifile,ofile);
  991. X        FILLMODE = FALSE;
  992. X    }
  993. X    else if (streq(cmd[0],"nj") ) {   /* do not justify right margin */
  994. X        brek(ifile,ofile);
  995. X        RJUSTIFY = FALSE;
  996. X    }
  997. X    else if (streq(cmd[0],"pc") ) {   /* page character to c */
  998. X        PAGECHAR = cmd[1][0];
  999. X    }
  1000. X    else if (streq(cmd[0],"pl") ) {   /* page length */
  1001. X        setparm(&PAGELENGTH,atype,value,DEFPAGELENGTH,0,HUGE);
  1002. X    }
  1003. X    else if (streq(cmd[0],"pm") ) {  /* set paragraph label margin */
  1004. X        brek(ifile,ofile);
  1005. X        setparm(&IPARA,atype,value * DOTSCHAR,10*DOTSCHAR,0,HUGE);
  1006. X    }
  1007. X    else if (streq(cmd[0],"rj") ) {/* right margin justified, left ragged */
  1008. X        fprintf(stderr,"right margin justified, left ragged not yet implemented\n");
  1009. X        exit(1);
  1010. X        brek(ifile,ofile);
  1011. X    }
  1012. X    else if (streq(cmd[0],"rm") ) {   /* set right margin */
  1013. X        brek(ifile,ofile);
  1014. X        setparm(&RMARGIN,atype,DOTSCHAR*value,DEFRMARGIN,0,HUGE);
  1015. X    }
  1016. X    else if (streq(cmd[0],"rt") ) {   /* reset traps */
  1017. X        cleantraps();
  1018. X    }
  1019. X    else if (streq(cmd[0],"so") ) {   /* source a file */
  1020. X            tempfile = fopen(cmd[1],"r");
  1021. X            if (tempfile == NULL) {
  1022. X                fprintf(stderr,"error in 'so' command: file %s not found\n",cmd[1]);
  1023. X                exit(1);
  1024. X            }
  1025. X            else {
  1026. X                procfile(tempfile,ofile);
  1027. X                fclose(tempfile);
  1028. X            }
  1029. X    }
  1030. X    else if (streq(cmd[0],"sp") ) {   /* space value lines */
  1031. X        brek(ifile,ofile);
  1032. X        if (CLEANPAGE)
  1033. X            puthead(ifile,ofile);
  1034. X        if (value == 0)
  1035. X            value = 1;
  1036. X        for (i = 1; i <= value; i++) 
  1037. X            finishline(ifile,ofile);
  1038. X    }
  1039. X    else if (streq(cmd[0],"ti") ) {   /* temporary indent */
  1040. X        brek(ifile,ofile);
  1041. X        setparm(&TEMPINDENT,atype,DOTSCHAR*value,0,-HUGE,HUGE);
  1042. X    }
  1043. X    else if (streq(cmd[0],"tl") ) {  /* define title string */
  1044. X        expand(temp1line,restofline);
  1045. X        title(templine,temp1line,LMARGIN,RMARGIN,TDLIM,&cnt,tfor,ifile,ofile);
  1046. X        /* just interpolate it in for now */
  1047. X        append(templine,cnt);
  1048. X    }
  1049. X    else if (streq(cmd[0],"tf") ) {  /* redefine title string */
  1050. X        for (l = 0; l < FNUMBER; l++)
  1051. X            tfor[l] = 'x';
  1052. X        if (cmd[1][0] == '\0') { /* return to default */
  1053. X            strcpy(tfor,"lcr");
  1054. X        }
  1055. X        else {  /* get it from the arguments */
  1056. X            l = 1;
  1057. X            while (cmd[l][0] != '\0') {
  1058. X                tfor[l - 1] = cmd[l][0];
  1059. X                l++;
  1060. X            }
  1061. X            tfor[l - 1] = '\0';
  1062. X            
  1063. X        }
  1064. X    }
  1065. X    else if (streq(cmd[0],"tm") ) {  /* transparent mode */
  1066. X        brek(ifile,ofile);
  1067. X        outselect = 't';
  1068. X/* transparent mode */
  1069. X{
  1070. X    char xch;
  1071. X    int xquit; 
  1072. X
  1073. X    xquit = FALSE;
  1074. X
  1075. X    while ( (xch = getc(ifile)) != EOF && !xquit) {
  1076. X     if (xch == '\n') {  /* we have a newline, so must check what comes next */
  1077. X       xch = getc(ifile);  
  1078. X       /* it could be EOF !*/
  1079. X       if (xch == EOF) {  /* the file ended with a newline */
  1080. X        fprintf(ofile,"\n");
  1081. X        xquit = TRUE;
  1082. X       }
  1083. X       else if (xch == CMDCHAR ){  /* if we have a CMDCHAR we may be in business */
  1084. X         xch = getc(ifile);
  1085. X         /* be sure it isn't an EOF */
  1086. X         if (xch == EOF) {  /* file ended with "\nCMDCHAR" */
  1087. X        fprintf(ofile,"\n%c",CMDCHAR);
  1088. X        xquit = TRUE;
  1089. X         }
  1090. X         else {  /* we now have "\nCMDCHAR" followed by something real */
  1091. X           if (xch == 'e')  {  /* wow --- getting close */
  1092. X         xch = getc(ifile);
  1093. X         /* is it? is it? a "t" ?*/
  1094. X         if (xch == EOF) { /* nuts */
  1095. X           fprintf(ofile,"\n%ce",CMDCHAR);
  1096. X           xquit = TRUE;
  1097. X         }
  1098. X         else if (xch == 't') { /* GOT IT!  Yea! */
  1099. X
  1100. X            xquit = TRUE;
  1101. X         }
  1102. X         else {  /* gloom! */
  1103. X            fprintf(ofile,"\n%ce%c",CMDCHAR,xch);
  1104. X         }
  1105. X           }
  1106. X           else { /* broken heart */
  1107. X         fprintf(ofile,"\n%c%c",CMDCHAR,xch);
  1108. X           }
  1109. X         }
  1110. X
  1111. X       }
  1112. X       else { /* not a CMDCHAR -- just copy \n and the char to the output */
  1113. X        fprintf(ofile,"\n%c",xch);
  1114. X       }
  1115. X     }
  1116. X     else {  /* just copy the character to output */
  1117. X       putc(xch,ofile);
  1118. X     }
  1119. X     
  1120. X    }  /* of while loop */
  1121. X
  1122. X    /* at end of the loop output a newline */
  1123. X    putc('\n',ofile);
  1124. X
  1125. X    
  1126. X
  1127. X}
  1128. X /* end of transparent mode */
  1129. X        outselect = 'f';
  1130. X    }
  1131. X    else if (streq(cmd[0],"vr") ) {  /* vertical rule */
  1132. X        fprintf(stderr,"vertical rule not yet implemented\n");
  1133. X        exit(1);
  1134. X    }
  1135. X    else if (streq(cmd[0],"vs") ) {  /* set vertical spacing */
  1136. X        brek(ifile,ofile);
  1137. X        setparm(&VSPACE,atype,value,10,0,HUGE);
  1138. X        if (FONTCHANGE) {
  1139. X            sprintf(temp2line,"%c&l%dC",ESC,VSPACE);
  1140. X            putout(ofile,temp2line);
  1141. X        }
  1142. X    }
  1143. X    else if (streq(cmd[0],"ul") ) {  /* underline n lines */
  1144. X        setparm(&ULCOUNT,atype,value,DEFCOUNT,0,HUGE);
  1145. X    }
  1146. X    else if (streq(cmd[0],"wh") ) {  /* set trap */
  1147. X        /* cmd[1] has the location, and
  1148. X           cmd[2] has the name of the macro to invoke at
  1149. X           that location */
  1150. X        /* compute the locations as measured in 'dots' */
  1151. X        /* so that ".wh 48 NP" sets a trap (NP) 48 dots (1 inch)
  1152. X           from the top */
  1153. X        atype = argtype(cmd[1]);
  1154. X        expndreg(templine,cmd[1]);
  1155. X        value = argval(templine);
  1156. X        if (atype == -1)
  1157. X            value = PAGELENGTH - BOTTOMMARGIN - value;
  1158. X        else
  1159. X            value = TOPMARGIN + value;
  1160. X        deftrap(cmd[2], value, &traplist);
  1161. X    }
  1162. X    else if (streq(cmd[0],".") ) {   /* a comment */
  1163. X    }
  1164. X    else  {  /* maybe it's a macro */
  1165. X        procmacro(s,ifile,ofile);
  1166. X    }
  1167. X
  1168. X
  1169. X
  1170. X
  1171. X
  1172. X}  /* of command processor */
  1173. X
  1174. X
  1175. X/* this function determines the type of an argument in a command line */
  1176. X/* if the argument represents a relative change, it returns
  1177. X   1 or -1.  If the argument is absolute, it returns 0.
  1178. X   If the argument is null, it returns -2.  */
  1179. X
  1180. Xint argtype (s)
  1181. Xchar s[];
  1182. X{
  1183. X    if (s[0] == '+')
  1184. X        return 1;
  1185. X    else if (s[0] == '-')
  1186. X        return -1;
  1187. X    else if (s[0] == '\0')
  1188. X        return -2;   /* argument not present */
  1189. X    else
  1190. X        return 0;
  1191. X}
  1192. X
  1193. X/* function to get the absolute value of the numeric value of an argument */
  1194. Xint argval(s)
  1195. X{
  1196. X    int v;
  1197. X    v = atoi(s);
  1198. X    if (v < 0)
  1199. X        v = -v;
  1200. X    return v;
  1201. X}
  1202. X
  1203. X/* function to set parameters */
  1204. Xint setparm(sparm,satype,svalue,sdflt,smin,smax)
  1205. Xint *sparm,satype,svalue,sdflt,smin,smax;
  1206. X{
  1207. X    if (satype == 1)
  1208. X        *sparm = *sparm + svalue;
  1209. X    else if (satype == -1)
  1210. X        *sparm = *sparm - svalue;
  1211. X    else if (satype == -2) /* not present */
  1212. X        *sparm = sdflt;
  1213. X    else if (satype == 0 )
  1214. X        *sparm = svalue;
  1215. X    *sparm = (*sparm > smax ? smax : *sparm);
  1216. X    *sparm = (*sparm < smin ? smin : *sparm);
  1217. X
  1218. X}
  1219. END_OF_FILE
  1220.   if test 13945 -ne `wc -c <'source/command.c'`; then
  1221.     echo shar: \"'source/command.c'\" unpacked with wrong size!
  1222.   fi
  1223.   # end of 'source/command.c'
  1224. fi
  1225. if test -f 'source/init.c' -a "${1}" != "-c" ; then 
  1226.   echo shar: Will not clobber existing file \"'source/init.c'\"
  1227. else
  1228.   echo shar: Extracting \"'source/init.c'\" \(5910 characters\)
  1229.   sed "s/^X//" >'source/init.c' <<'END_OF_FILE'
  1230. X/* this file contains all initializations */
  1231. X
  1232. X#include <stdio.h>
  1233. X
  1234. X#include <ctype.h>
  1235. X
  1236. X#include "defs.h"
  1237. X#include "externs.c"
  1238. XFILE *tempfile,*fopen();
  1239. X
  1240. XVOID init()
  1241. X{
  1242. X
  1243. X    int i;
  1244. X    char filename[50];
  1245. X    char dummy[50];
  1246. X
  1247. X    FONTCHANGE = TRUE;    /* do emit all font changes */
  1248. X    FIRSTPAGE = 1;         /* first page to print */
  1249. X    LASTPAGE = HUGE;    /* last page to print */
  1250. X    FORMFEED = TRUE;    /* use formfeeds to go to next page */
  1251. X    SCANONLY = FALSE;    /* do not just scan the text for errors */
  1252. X    TABSTOPS = 8;        /* tabs every 8 spaces */
  1253. X    outbuf[0] = '\0';    /* initialize the buffer */
  1254. X    obufpos = 0;
  1255. X    macline[0] = '\0';
  1256. X    expstr[0] = '\0';
  1257. X
  1258. X    /* registers */
  1259. X    REG('#') =  1;    /* start at page 1 */
  1260. X    REG('A') =  2;    /* the next page */
  1261. X    REG('B') = 24;    /* bottom margin of 24 dots */
  1262. X    REG('C') = 0;   /* center this many lines */
  1263. X    REG('D') = 0;    /* vertical length of last diversion */
  1264. X    REG('E') = 0;      /* italicize next n lines */
  1265. X    REG('F') = 0;    /* current font */
  1266. X    REG('G') = 0;    /* boldface next n lines */
  1267. X    REG('H') = TRUE; /* justify lines */
  1268. X    REG('I') = TRUE;  /* start in FILLMODE = TRUE */
  1269. X    REG('J') = '/';    /* a SLASH mark */
  1270. X    REG('L') = 300;    /* left margin of 300 dots  - 1 inch */
  1271. X    REG('M') = 0;   /* temporary indent */
  1272. X    REG('O') = '#';  /* page character */
  1273. X    REG('P') = 480;    /* page length */
  1274. X    REG('Q') = 0;    /* number of printable characters in outbuf */
  1275. X    REG('R') = 2100;    /* right margin of 2100 dots - 7 inches */
  1276. X    REG('S') = 1;    /* line spacing */
  1277. X    REG('T') = 0;    /* top margin of 0 dots */
  1278. X    REG('U') = 30;   /* width of a space character in dots */
  1279. X    REG('V') = 10;    /* current vertical spacing */
  1280. X    REG('W') = 10 * DOTSCHAR; /* indented paragraph start  in characters */
  1281. X    REG('X') = 0;    /* current horizontal position */
  1282. X    REG('Y') = REG('T');    /* current vertical position */
  1283. X    REG('Z') = FALSE;    /* underline state */
  1284. X    REG('!') = 8;    /* tabstops every 8 characters */
  1285. X    REG('_') = 24;    /* margin before footer */
  1286. X    REG('^') = 48;  /* margin after header */
  1287. X
  1288. X    /* initialize the macro list */
  1289. X    macrolist = NULL;
  1290. X
  1291. X
  1292. X
  1293. X    /* define headers and footers */
  1294. X    /* default title formats */
  1295. X    for (i = 0; i < FNUMBER; i++)
  1296. X        tfor[i] = 'x';
  1297. X    tfor[0] = 'l';
  1298. X    tfor[1] = 'c';
  1299. X    tfor[2] = 'r';
  1300. X    strcpy(header," ");
  1301. X    strcpy(footer,"/page #/");
  1302. X
  1303. X
  1304. X    outselect = 'f';    /* select forprint as the output function */
  1305. X
  1306. X/* fonts */
  1307. X
  1308. X/* printer initialization to Times Roman Normal 12 point */
  1309. Xstrcpy(filename,FONTSDIR);
  1310. X#ifdef UNIX
  1311. Xstrcat(filename,"/trn12");
  1312. X#else
  1313. Xstrcat(filename,"\\trn12");
  1314. X#endif
  1315. X
  1316. Xtempfile = fopen(filename,"r");
  1317. Xfscanf(tempfile,"%s",prinit);
  1318. X/* note, each font initialization string contains several
  1319. X    letters 'E', which must be replaced by ESC characters */
  1320. Xi = 0;
  1321. Xwhile (prinit[i] != '\0') {
  1322. X    if (prinit[i] == 'E')
  1323. X        prinit[i] = ESC;
  1324. X    i++;
  1325. X}
  1326. X
  1327. Xstrcpy(cfont,prinit);
  1328. Xfor (i = 32; i <= 126; i++) 
  1329. X    fscanf(tempfile,"%d",&H12nl[i]);
  1330. Xfclose(tempfile);
  1331. X
  1332. X
  1333. X/* Times Roman 12 point bold character length array */
  1334. Xstrcpy(filename,FONTSDIR);
  1335. X#ifdef UNIX
  1336. Xstrcat(filename,"/trb12");
  1337. X#else
  1338. Xstrcat(filename,"\\trb12");
  1339. X#endif
  1340. X
  1341. Xtempfile = fopen(filename,"r");
  1342. Xfscanf(tempfile,"%s",dummy);
  1343. Xfor (i = 32; i <= 126; i++)
  1344. X    fscanf(tempfile,"%d",&H12bl[i]);
  1345. Xfclose(tempfile);
  1346. X
  1347. X
  1348. X
  1349. X/* character length array for Times Roman 12 point italics */
  1350. Xstrcpy(filename,FONTSDIR);
  1351. X#ifdef UNIX
  1352. Xstrcat(filename,"/tri12");
  1353. X#else
  1354. Xstrcat(filename,"\\tri12");
  1355. X#endif
  1356. Xtempfile = fopen(filename,"r");
  1357. Xfscanf(tempfile,"%s",dummy);
  1358. Xfor (i = 32; i <= 126; i++)
  1359. X    fscanf(tempfile,"%d",&H12il[i]);
  1360. Xfclose(tempfile);
  1361. X
  1362. X
  1363. X /* fixed Courier 12 point */
  1364. Xfor (i = 32; i <= 126; i++)
  1365. X    C12nl[i] = 30;
  1366. X
  1367. X
  1368. X/* Presentation 18 point */
  1369. Xfor (i = 32; i <= 126; i++)
  1370. X    P18bl[i] = 46;
  1371. X
  1372. Xsprintf(Pres,"%c&10O%c(0U%c(sp6.5h18vs1b11T",ESC,ESC,ESC);
  1373. X
  1374. X/* Helv Nm 6 point */
  1375. X
  1376. XH6nl[32] = 6; /* ' ' */
  1377. XH6nl[33] = 11; /* '!' */
  1378. XH6nl[34] = 9; /* '"' */
  1379. XH6nl[35] = 16; /* '#' */
  1380. XH6nl[36] = 15; /* '$' */
  1381. XH6nl[37] = 23; /* % */
  1382. XH6nl[38] = 18; /* & */
  1383. XH6nl[39] = 6;  /* single quote */
  1384. XH6nl[40] = 7; /* ( */
  1385. XH6nl[41] = 7; /* ) */
  1386. XH6nl[42] = 10; /* * */
  1387. XH6nl[43] = 15; /* + */
  1388. XH6nl[44] = 8; /* , */
  1389. XH6nl[45] = 15; /* - */
  1390. XH6nl[46] = 8; /* . */
  1391. XH6nl[47] = 11; /* / */
  1392. XH6nl[48] = 15; /* 0 */
  1393. XH6nl[49] = 15; /* 1 */
  1394. XH6nl[50] = 15; /* 2 */
  1395. XH6nl[51] = 15; /* 3 */
  1396. XH6nl[52] = 15; /* 4 */
  1397. XH6nl[53] = 15; /* 5 */
  1398. XH6nl[54] = 15; /* 6 */
  1399. XH6nl[55] = 15; /* 7 */
  1400. XH6nl[56] = 15; /* 8 */
  1401. XH6nl[57] = 15; /* 9 */
  1402. XH6nl[58] = 8; /* : */
  1403. XH6nl[59] = 8; /* ; */
  1404. XH6nl[60] = 15; /* < */
  1405. XH6nl[61] = 15; /* = */
  1406. XH6nl[62] = 15; /* > */
  1407. XH6nl[63] = 16; /* ? */
  1408. XH6nl[64] = 24; /* @ */
  1409. XH6nl[65] = 18; /* A */
  1410. XH6nl[66] = 21; /* B */
  1411. XH6nl[67] = 20; /* C */
  1412. XH6nl[68] = 22; /* D */
  1413. XH6nl[69] = 19; /* E */
  1414. XH6nl[70] = 17; /* F */
  1415. XH6nl[71] = 21; /* G */
  1416. XH6nl[72] = 22; /* H */
  1417. XH6nl[73] = 8; /* I */
  1418. XH6nl[74] = 16; /* J */
  1419. XH6nl[75] = 17; /* K */
  1420. XH6nl[76] = 17; /* L */
  1421. XH6nl[77] = 25; /* M */
  1422. XH6nl[78] = 20; /* N */
  1423. XH6nl[79] = 20; /* O */
  1424. XH6nl[80] = 17; /* P */
  1425. XH6nl[81] = 20; /* Q */
  1426. XH6nl[82] = 20; /* R */
  1427. XH6nl[83] = 18; /* S */
  1428. XH6nl[84] = 16; /* T */
  1429. XH6nl[85] = 20; /* U */
  1430. XH6nl[86] = 18; /* V */
  1431. XH6nl[87] = 26; /* W */
  1432. XH6nl[88] = 17; /* X */
  1433. XH6nl[89] = 16; /* Y */
  1434. XH6nl[90] = 18; /* Z */
  1435. XH6nl[91] = 8; /* [ */
  1436. XH6nl[92] = 11; /* \ */
  1437. XH6nl[93] = 8; /* ] */
  1438. XH6nl[94] = 14; /* ^ */
  1439. XH6nl[95] = 14; /* _ */
  1440. XH6nl[96] = 6; /* ` */
  1441. XH6nl[97] = 14; /* a */
  1442. XH6nl[98] = 17; /* b */
  1443. XH6nl[99] = 14; /* c */
  1444. XH6nl[100] =17; /* d */
  1445. XH6nl[101] = 15; /* e */
  1446. XH6nl[102] = 11; /* f */
  1447. XH6nl[103] = 15; /* g */
  1448. XH6nl[104] = 18; /* h */
  1449. XH6nl[105] = 7; /* i */
  1450. XH6nl[106] = 8; /* j */
  1451. XH6nl[107] = 15; /* k */
  1452. XH6nl[108] = 7; /* l */
  1453. XH6nl[109] = 22; /* m */
  1454. XH6nl[110] = 15; /* n */
  1455. XH6nl[111] = 16; /* o */
  1456. XH6nl[112] = 16; /* p */
  1457. XH6nl[113] = 17; /* q */
  1458. XH6nl[114] = 10; /* r */
  1459. XH6nl[115] = 14; /* s */
  1460. XH6nl[116] = 10; /* t */
  1461. XH6nl[117] = 15; /* u */
  1462. XH6nl[118] = 14; /* v */
  1463. XH6nl[119] = 22; /* w */
  1464. XH6nl[120] = 14; /* x */
  1465. XH6nl[121] = 15; /* y */
  1466. XH6nl[122] = 13; /* z */
  1467. XH6nl[123] = 15; /* { */
  1468. XH6nl[124] = 0; /* | */
  1469. XH6nl[125] = 15; /* } */
  1470. XH6nl[126] = 0; /* ~ */
  1471. X
  1472. X
  1473. Xdefl = &H12nl[0];
  1474. Xclen = defl;
  1475. X
  1476. X}
  1477. X
  1478. X
  1479. END_OF_FILE
  1480.   if test 5910 -ne `wc -c <'source/init.c'`; then
  1481.     echo shar: \"'source/init.c'\" unpacked with wrong size!
  1482.   fi
  1483.   # end of 'source/init.c'
  1484. fi
  1485. if test -f 'source/io.c' -a "${1}" != "-c" ; then 
  1486.   echo shar: Will not clobber existing file \"'source/io.c'\"
  1487. else
  1488.   echo shar: Extracting \"'source/io.c'\" \(7600 characters\)
  1489.   sed "s/^X//" >'source/io.c' <<'END_OF_FILE'
  1490. X/* this file contains the output function */
  1491. X
  1492. X#include <stdio.h>
  1493. X#include <ctype.h>
  1494. X#include "defs.h"
  1495. X#include "externs.c"
  1496. X
  1497. Xchar temp3line[MAXSTR];
  1498. X
  1499. X
  1500. X
  1501. X
  1502. X
  1503. X/* transparent print function */
  1504. XVOID tprint(ifile,ofile,diff)
  1505. XFILE *ifile,*ofile;
  1506. Xint diff;
  1507. X{
  1508. X    int i;
  1509. X    char temp2line[MAXSTR];
  1510. X
  1511. X
  1512. X    if (ShouldPrint && FONTCHANGE && ((TEMPINDENT + LMARGIN) > 0) ) {
  1513. X        sprintf(temp2line,"%c*p+%dX",ESC,TEMPINDENT+LMARGIN);
  1514. X        putout(ofile,temp2line);
  1515. X    }
  1516. X    TEMPINDENT = 0;
  1517. X
  1518. X    i = 0;
  1519. X    while (ShouldPrint && outbuf[i] != '\0') {
  1520. X        if (outbuf[i] != SHIFTOUT)
  1521. X            putit(outbuf[i],ofile);
  1522. X        i++;
  1523. X    }
  1524. X    finishline(ifile,ofile);
  1525. X}
  1526. X
  1527. X
  1528. X
  1529. X/* function to get a whole line from the input file */
  1530. XVOID getline(s,f)
  1531. Xchar s[];
  1532. XFILE *f;
  1533. X{
  1534. X    int count;
  1535. X    char c;
  1536. X    char temp[MAXSTR];
  1537. X    int i,j;
  1538. X    int where;
  1539. X
  1540. X    count = 0;
  1541. X    while ( ((c = getc(f)) != '\n') && c != EOF) {
  1542. X        s[count] = c;
  1543. X        count++;
  1544. X    }
  1545. X    s[count] = '\0';
  1546. X    strcpy(temp,s);
  1547. X
  1548. X    /* remove any tabs if we should */
  1549. X    if ( TABSTOPS > 0 ) {
  1550. X        i = 0;
  1551. X        j = 0;
  1552. X        where = 0;
  1553. X        while (s[i] != '\0') {
  1554. X            if (s[i] == 0x09) {
  1555. X                if (where % TABSTOPS  == 0 ) {
  1556. X                    temp[j] = ' ';
  1557. X                    j++;
  1558. X                    where++;
  1559. X                }
  1560. X                while (where % TABSTOPS  != 0) {
  1561. X                    temp[j] = ' ';
  1562. X                    j++;
  1563. X                    where++;
  1564. X                }
  1565. X            }
  1566. X            else {
  1567. X                temp[j] = s[i];
  1568. X                j++;
  1569. X                where++;
  1570. X            }
  1571. X            i++;
  1572. X        }
  1573. X        temp[j] = '\0';
  1574. X    }
  1575. X    strcpy(s,temp);
  1576. X
  1577. X    if (c == EOF)
  1578. X        return EOF;
  1579. X    else
  1580. X        return count;
  1581. X}
  1582. X
  1583. X
  1584. X/* function to end a line */
  1585. XVOID endln()
  1586. X{
  1587. X    int i;
  1588. X
  1589. X    /* eat any white space off the right hand end of outbuf */
  1590. X    i = obufpos - 1;
  1591. X    while (i > 0 && ( isspace(outbuf[i]) || outbuf[i] == SHIFTOUT)  ) {
  1592. X        if (outbuf[i] != SHIFTOUT) {
  1593. X            CURRX = CURRX - length(outbuf[i]);
  1594. X            CHARCNT = CHARCNT - 1;
  1595. X        }
  1596. X        obufpos--;
  1597. X        i--;
  1598. X    }
  1599. X
  1600. X    outbuf[obufpos] = '\0';  /* be sure to end the buffer properly */
  1601. X}
  1602. X
  1603. X
  1604. X/* print the output buffer, spreading it out by diff */
  1605. XVOID forprint(ifile,f,diff)
  1606. XFILE *ifile,*f;
  1607. Xint diff;
  1608. X{
  1609. X    int perchar,more,extra, thismany;
  1610. X    int i;
  1611. X    char temp2line[MAXSTR];
  1612. X
  1613. X
  1614. X    i = 0;
  1615. X
  1616. X    /* the line length we desire is diff */
  1617. X
  1618. X    /* number of extra dots that need to be placed with each character */
  1619. X    extra = diff - CURRX;  /* we need this many extra dots */
  1620. X    more = 0;
  1621. X    if (CHARCNT >  1)  {
  1622. X        perchar = extra/(CHARCNT - 1);
  1623. X        more = extra - (extra/(CHARCNT -1)) * (CHARCNT -1);  /* the left over few */
  1624. X    }
  1625. X    else
  1626. X        perchar = 0;
  1627. X
  1628. X    if ((FILLMODE == FALSE) || (RJUSTIFY == FALSE) ) {
  1629. X        more = 0;
  1630. X        perchar = 0;
  1631. X    }
  1632. X    
  1633. X
  1634. X    /* first output the left margin and the temporary indent, if any */
  1635. X    if (ShouldPrint && FONTCHANGE && ( (TEMPINDENT + LMARGIN) > 0) ) {
  1636. X        sprintf(temp2line,"%c*p%dX",ESC,TEMPINDENT+LMARGIN);
  1637. X        putout(f,temp2line);
  1638. X    }
  1639. X    TEMPINDENT = 0;
  1640. X    if (perchar < 0 )
  1641. X        perchar = 0;
  1642. X    i = 0;
  1643. X    while (ShouldPrint && outbuf[i] != '\0') {
  1644. X
  1645. X        if (outbuf[i] == SHIFTOUT) {
  1646. X            /* this many extra */
  1647. X            thismany = perchar;
  1648. X            if (more > 0 ) {
  1649. X                /* one more dot */
  1650. X                thismany++;
  1651. X                more--;
  1652. X            }
  1653. X            if (FONTCHANGE  && thismany > 0) {
  1654. X                sprintf(temp2line,"%c*p+%dX",ESC,thismany);
  1655. X                putout(f,temp2line);
  1656. X            }
  1657. X        }
  1658. X        else
  1659. X            if (outbuf[i] != ANCHOR) putit(outbuf[i],f);
  1660. X        i++;
  1661. X    }
  1662. X
  1663. X    if (outbuf[0] != '\0' ) finishline(ifile,f);
  1664. X    CURRX = 0;
  1665. X    diff = 0;
  1666. X}
  1667. X
  1668. X/* turn up a new page */
  1669. XVOID brpage(ifile,f) 
  1670. XFILE *ifile,*f;
  1671. X{
  1672. X    /* check for traps between here and end of page */
  1673. X    checktraps(PAGELENGTH - BOTTOMMARGIN,ifile,f); 
  1674. X    putfoot(ifile,f);
  1675. X    if ( FORMFEED) 
  1676. X        if (ShouldPrint) putit(FF,f);
  1677. X    else {
  1678. X        if (ShouldPrint) {
  1679. X            while (CURRY <= PAGELENGTH ) {
  1680. X                putit('\n',f);
  1681. X                CURRY = CURRY + VSPACE;
  1682. X            }
  1683. X            CURRY = 0;
  1684. X            while (CURRY < TOPMARGIN) {
  1685. X                putit('\n',f);
  1686. X                CURRY = CURRY + VSPACE;
  1687. X            }
  1688. X        }
  1689. X    }
  1690. X    cleantraps();
  1691. X    CURRY = TOPMARGIN;
  1692. X    CURRPAGE = CURRPAGE + 1;
  1693. X    if (CURRPAGE > LASTPAGE) exit(0);
  1694. X    CLEANPAGE = TRUE;
  1695. X    if (CURRPAGE >= FIRSTPAGE) ShouldPrint = TRUE;
  1696. X    NEXTPAGE = CURRPAGE + 1;
  1697. X}
  1698. X
  1699. X
  1700. XVOID nullprint(ifile,ofile,diff)
  1701. XFILE *ifile,*ofile;
  1702. Xint diff;
  1703. X{
  1704. X    /* do nothing */
  1705. X}
  1706. X
  1707. X
  1708. XgotoXY(ifile,ofile,x,y)
  1709. XFILE *ifile,*ofile;
  1710. Xint x,y;
  1711. X{
  1712. X        /* x is measured in dots, 300 per inch, horizontally,
  1713. X           y is measured in dots, 48 per vertical inch */
  1714. X       /* measured from absolute top left margin */
  1715. X
  1716. X        char str[MAXSTR];
  1717. X        int j;
  1718. X
  1719. X        str[0] = '\0';
  1720. X
  1721. X    if (FONTCHANGE)
  1722. X            sprintf(str,"%c&a%dV%c*p%dX",ESC,y*15,ESC,x);
  1723. X    j = 0;
  1724. X    while (str[j] != '\0') {
  1725. X        outbuf[obufpos] = str[j];
  1726. X        j++;
  1727. X        obufpos++;
  1728. X    }
  1729. X
  1730. X        CURRY = y;
  1731. X    CURRX = x;
  1732. X}
  1733. X   
  1734. X
  1735. X
  1736. X
  1737. XgotoX(ifile,ofile,s)
  1738. XFILE *ifile,*ofile;
  1739. Xchar s[];
  1740. X{
  1741. X        /* x is measured in dots, 300 per inch, horizontally */
  1742. X       
  1743. X
  1744. X        char str[MAXSTR];
  1745. X        int j;
  1746. X
  1747. X    j = abs(atoi(s));
  1748. X        str[0] = '\0';
  1749. X
  1750. X    if (s[0] == '-')
  1751. X            sprintf(str,"%c*p-%dX",ESC,j);
  1752. X    else if (s[0] == '+')
  1753. X        sprintf(str,"%c*p+%dX",ESC,j);
  1754. X    else
  1755. X        sprintf(str,"%c*p%dX",ESC,j);
  1756. X    j = 0;
  1757. X    if (!FONTCHANGE)
  1758. X        str[0] = '\0';
  1759. X    while (str[j] != '\0') {
  1760. X        outbuf[obufpos] = str[j];
  1761. X        j++;
  1762. X        obufpos++;
  1763. X    }
  1764. X
  1765. X}
  1766. X   
  1767. X
  1768. X
  1769. X
  1770. X
  1771. X
  1772. XgotoY(ifile,ofile,s)
  1773. XFILE *ifile,*ofile;
  1774. Xchar s[];
  1775. X{
  1776. X        /* y is measured in dots, 48 per inch, vertically */
  1777. X       
  1778. X
  1779. X        char str[MAXSTR];
  1780. X        int j;
  1781. X
  1782. X    j = abs(atoi(s)) * 15;
  1783. X        str[0] = '\0';
  1784. X
  1785. X    if (s[0] == '-')
  1786. X            sprintf(str,"%c&a-%dV",ESC,j);  /* the command is in decipoints */
  1787. X    else if (s[0] == '+')
  1788. X        sprintf(str,"%c&a+%dV",ESC,j);
  1789. X    else
  1790. X        sprintf(str,"%c&a%dV",ESC,j);
  1791. X    j = 0;
  1792. X    if (!FONTCHANGE)
  1793. X        str[0] = '\0';
  1794. X    while (str[j] != '\0') {
  1795. X        outbuf[obufpos] = str[j];
  1796. X        j++;
  1797. X        obufpos++;
  1798. X    }
  1799. X
  1800. X}
  1801. X   
  1802. X
  1803. X
  1804. X/* put the footer on the page */
  1805. Xputfoot(ifile,ofile)
  1806. XFILE *ifile,*ofile;
  1807. X{
  1808. X    char temp[MAXSTR], temp1[MAXSTR];
  1809. X    int tcnt;
  1810. X    tcnt = 0;
  1811. X    temp1[0] = '\0';
  1812. X    if (footer[0] != '\0') {
  1813. X        brek(ifile,ofile);
  1814. X        gotoXY(ifile,ofile,LMARGIN,PAGELENGTH - BOTTOMMARGIN );
  1815. X        expand(temp,footer);
  1816. X        title(temp1,temp,LMARGIN,RMARGIN,TDLIM,&tcnt,"l c r",ifile,ofile);
  1817. X        append(temp1,tcnt);
  1818. X        outbuf[obufpos] = '\0';
  1819. X        CURRY = 0;
  1820. X        output(ifile,ofile,0);
  1821. X    }
  1822. X}
  1823. X
  1824. X
  1825. X/* put the header on the page */
  1826. X
  1827. Xputhead(ifile,ofile)
  1828. XFILE *ifile, *ofile;
  1829. X{
  1830. X    char temp[MAXSTR],temp1[MAXSTR];
  1831. X    int tcnt;
  1832. X
  1833. X    CLEANPAGE = FALSE;
  1834. X    temp1[0] = '\0';
  1835. X    tcnt = 0;
  1836. X    CURRY = TOPMARGIN;
  1837. X    if (header[0] != '\0' && ShouldPrint && FONTCHANGE) {
  1838. X        sprintf(temp1,"%c*p%dX",ESC,LMARGIN);
  1839. X        rawout(ofile,temp1);
  1840. X        sprintf(temp1,"%c&a%dV",ESC,15 * TOPMARGIN);
  1841. X        rawout(ofile,temp1);
  1842. X        expand(temp,header);
  1843. X        title(temp1,temp,LMARGIN,RMARGIN,TDLIM,&tcnt,"l c r",ifile,ofile);
  1844. X        rawout(ofile,temp1);
  1845. X        sprintf(temp1,"\n");
  1846. X        rawout(ofile,temp1);
  1847. X        CURRY = CURRY + VSPACE;
  1848. X    }
  1849. X    if (MTWO != 0 && ShouldPrint && FONTCHANGE) {
  1850. X        sprintf(temp1,"%c*p%dX",ESC,LMARGIN);
  1851. X        rawout(ofile,temp1);
  1852. X        CURRY = CURRY + MTWO ;
  1853. X    }
  1854. X    if (ShouldPrint && FONTCHANGE)  {
  1855. X       sprintf(temp1,"%c&a%dV",ESC,15 * CURRY);
  1856. X       rawout(ofile,temp1);
  1857. X    }
  1858. X}
  1859. X
  1860. XVOID output(ifile,ofile,n)
  1861. XFILE *ifile,*ofile;
  1862. Xint n;
  1863. X{
  1864. X    if (CLEANPAGE) {
  1865. X        CLEANPAGE = FALSE;
  1866. X        puthead(ifile,ofile);
  1867. X    }
  1868. X
  1869. X    if (outselect == 'f') {        /* formatted print */
  1870. X        forprint(ifile,ofile,n);
  1871. X    }
  1872. X    else if (outselect == 't') {  /* transparent print */
  1873. X        tprint(ifile,ofile,n);
  1874. X    }
  1875. X    else if (outselect == 'n' ) {  /* null print */
  1876. X        nullprint(ifile,ofile,n);
  1877. X    }
  1878. X    else if (outselect == 'd') {    /* diversion */
  1879. X    }
  1880. X    else {   /* default is formatted print */
  1881. X        forprint(ifile,ofile,n);
  1882. X    }
  1883. X
  1884. X}
  1885. X
  1886. X
  1887. XVOID putout(f,s)
  1888. XFILE *f;
  1889. Xchar s[];
  1890. X{
  1891. X    int i;
  1892. X    i = 0;
  1893. X    while (s[i] != '\0') {
  1894. X        putit(s[i],f);
  1895. X        i++;
  1896. X    }
  1897. X
  1898. X}
  1899. X
  1900. XVOID putit(c,f)
  1901. Xchar c;
  1902. XFILE *f; 
  1903. X{
  1904. X    
  1905. X    if (InDiversion) {
  1906. X        temp3line[tplace] = c;
  1907. X        tplace++;
  1908. X        if (c == '\n') {
  1909. X            tplace--;
  1910. X            temp3line[tplace] = '\0';
  1911. X            macaddline(macrolist,temp3line);
  1912. X            tplace = 0;
  1913. X        }
  1914. X    }
  1915. X    else
  1916. X        putc(c,f);
  1917. X}
  1918. X
  1919. X
  1920. XVOID rawout(f,s)
  1921. XFILE *f;
  1922. Xchar s[];
  1923. X{
  1924. X    int i;
  1925. X    i = 0;
  1926. X    while (s[i] != '\0') {
  1927. X        if (s[i] != SHIFTOUT)
  1928. X            putc(s[i],f);
  1929. X        i++;
  1930. X    }
  1931. X    s[0] = '\0';
  1932. X}
  1933. X
  1934. END_OF_FILE
  1935.   if test 7600 -ne `wc -c <'source/io.c'`; then
  1936.     echo shar: \"'source/io.c'\" unpacked with wrong size!
  1937.   fi
  1938.   # end of 'source/io.c'
  1939. fi
  1940. if test -f 'source/util.c' -a "${1}" != "-c" ; then 
  1941.   echo shar: Will not clobber existing file \"'source/util.c'\"
  1942. else
  1943.   echo shar: Extracting \"'source/util.c'\" \(4912 characters\)
  1944.   sed "s/^X//" >'source/util.c' <<'END_OF_FILE'
  1945. X/* this file is all of the utility stuff */
  1946. X
  1947. X#include <stdio.h>
  1948. X#include <ctype.h>
  1949. X#include "defs.h"
  1950. X#include "externs.c"
  1951. X
  1952. X
  1953. X/* function to return the first printable character in a string */
  1954. Xchar First(s)
  1955. Xchar s[];
  1956. X{
  1957. X    int i;
  1958. X    i = 0;
  1959. X    while ( (s[i] != '\0')  && isspace(s[i] ) ) 
  1960. X        i++;
  1961. X    return s[i];
  1962. X}
  1963. X
  1964. X
  1965. X
  1966. X/* compares two strings and returns TRUE if equal, FALSE if not */
  1967. Xint streq(s,t)
  1968. Xchar s[],t[];
  1969. X{
  1970. X    return (strcmp(s,t) == 0);
  1971. X}
  1972. X
  1973. X
  1974. X
  1975. X/* function to print error messages */
  1976. XVOID error(s)
  1977. Xchar s[];
  1978. X{
  1979. X    fprintf(stderr,"ERROR: %s\n",s);
  1980. X}
  1981. X
  1982. X
  1983. X/* function to return whether or not a string is blank */
  1984. Xint isblank(s)
  1985. Xchar s[];
  1986. X{
  1987. X    int i;
  1988. X        i = 0;
  1989. X        while (s[i] != '\0' && isspace(s[i]) && s[i] != EOF) {
  1990. X            i++;
  1991. X        }
  1992. X        return (s[i] == '\0' || s[i] == EOF);
  1993. X
  1994. X}
  1995. X
  1996. X
  1997. X/* add the string sf to the front of a string, and the string sb to the
  1998. X    back of a string */
  1999. XVOID addstr(s,sf,sb)
  2000. Xchar s[],sf[],sb[];
  2001. X{
  2002. X    char tempstr[MAXSTR];
  2003. X    tempstr[0] = '\0';
  2004. X    strcat(tempstr,sf);
  2005. X    strcat(tempstr,s);
  2006. X    strcat(tempstr,sb);
  2007. X    strcpy(s,tempstr);
  2008. X}
  2009. X
  2010. X
  2011. X/* this function takes a string, searches for the TDELIM, determines
  2012. X    how many fields there are in the string, and then forms a new
  2013. X    string within the given left and right margins.  This new
  2014. X    string will have the left field left-justified, the right
  2015. X    field right-justified, and the center fields centered in
  2016. X    their respective spaces.  May be a bear.  */
  2017. XVOID title(ostr,istr,lmargin,rmargin,delim,tcnt,fstr,ifile,f)
  2018. Xchar ostr[],istr[];
  2019. Xint lmargin,rmargin;
  2020. Xchar delim;
  2021. Xint *tcnt;
  2022. XFILE *ifile, *f;
  2023. Xchar fstr[];  /* the format string */
  2024. X{
  2025. X    int i,j,k,l;  /* for indexes */
  2026. X    int nbrfields, fnbr;
  2027. X    int width, extra;
  2028. X    int wlen, cnt;
  2029. X    int x;
  2030. X    char tstring[MAXSTR]; /* a temporary string */
  2031. X    char t2str[MAXSTR];   /* another temporary string */
  2032. X    char word[SHORTSTR], word1[SHORTSTR];
  2033. X    char tform[FNUMBER];
  2034. X
  2035. X    ostr[0] = '\0';
  2036. X    *tcnt = 0;
  2037. X        for (l = 0; l < FNUMBER; l++)
  2038. X            tform[l] = 'x';
  2039. X        if (fstr[0] == '\0') { /* return to default */
  2040. X            tform[0] = 'l'; 
  2041. X            tform[1] = 'c'; 
  2042. X            tform[2] = 'r';
  2043. X        }
  2044. X        else {  /* get it from fstr */
  2045. X            l = 0;
  2046. X            k = 0;
  2047. X            while (fstr[l] != '\0') {
  2048. X                while (isspace(fstr[l]) ) l++;
  2049. X                tform[k] = fstr[l];
  2050. X                k++;
  2051. X                l++;
  2052. X            }
  2053. X            
  2054. X        }
  2055. X
  2056. X    /* find out how many fields there are by looking in tform */
  2057. X    nbrfields = 0;
  2058. X    i = 0;
  2059. X    while ( tform[i] != 'x' ) {
  2060. X        nbrfields++;
  2061. X        i++;
  2062. X    }
  2063. X
  2064. X    width = (rmargin - lmargin) / nbrfields;  /* width of each field */
  2065. X    extra = (rmargin - lmargin) - width * nbrfields;  /* extra dots left over*/
  2066. X
  2067. X    /* for each field, compute its length, do what I should with it,
  2068. X       and cat it to the ostr */
  2069. X        i = 0;
  2070. X        fnbr = 1;
  2071. X        while (istr[i] != '\0') {
  2072. X
  2073. X            j = 0;
  2074. X            while (istr[i] != '\0' &&  istr[i] != delim) {
  2075. X                tstring[j] = istr[i];
  2076. X                i++;
  2077. X                j++;
  2078. X            }
  2079. X            tstring[j] = '\0';
  2080. X            x = width;
  2081. X            t2str[0] = '\0';
  2082. X
  2083. X            j = 0;
  2084. X            while (tstring[j] != '\0') {
  2085. X                getword(word,tstring,&j);
  2086. X                parseword(word1,word,&wlen,&cnt,ifile,f);
  2087. X                *tcnt = *tcnt + cnt + 1;
  2088. X                x = x - wlen - length(' ');
  2089. X                strcat(t2str,word1);
  2090. X                strcat(t2str," ");
  2091. X            }
  2092. X
  2093. X
  2094. X            switch(tform[fnbr - 1]) {
  2095. X              case 'l': /* left justify */
  2096. X                sprintf(tstring,"%c*p+%dX",ESC,x);
  2097. X                strcat(ostr,t2str);
  2098. X                if (FONTCHANGE)
  2099. X                    strcat(ostr,tstring);
  2100. X                break;
  2101. X
  2102. X              case 'r':  /* right justify */
  2103. X                sprintf(tstring,"%c*p+%dX",ESC,x);
  2104. X                if (FONTCHANGE)
  2105. X                    strcat(ostr,tstring);
  2106. X                strcat(ostr,t2str);
  2107. X                break;
  2108. X
  2109. X             case 'c':
  2110. X             default:    /* center */
  2111. X                sprintf(tstring,"%c*p+%dX",ESC,x/2);
  2112. X                if (!FONTCHANGE)
  2113. X                    tstring[0] = '\0';
  2114. X                strcat(ostr,tstring);
  2115. X                strcat(ostr,t2str);
  2116. X                strcat(ostr,tstring);
  2117. X                break;
  2118. X
  2119. X            } /* of switch */
  2120. X
  2121. X            if (istr[i] == delim) {
  2122. X                fnbr++;
  2123. X                i++; /* to skip the delimiter */
  2124. X            }
  2125. X        }
  2126. X
  2127. X
  2128. X
  2129. X} /* of title */
  2130. X
  2131. X
  2132. X/* this function expands a line to take into account 
  2133. X   the page character */
  2134. XVOID expand(tempstr,s)
  2135. Xchar tempstr[];
  2136. Xchar s[];
  2137. X{
  2138. X    char str[SHORTSTR];
  2139. X    int i,j,k;
  2140. X
  2141. X    i = 0;
  2142. X    j = 0;
  2143. X    while (s[i] != '\0') {
  2144. X        if (s[i] == PAGECHAR) {
  2145. X            sprintf(str,"%d",CURRPAGE);
  2146. X            k = 0;
  2147. X            while (str[k] != '\0') {
  2148. X                tempstr[j] = str[k];
  2149. X                k++;
  2150. X                j++;
  2151. X            }
  2152. X            j--;
  2153. X
  2154. X        }
  2155. X        else
  2156. X            tempstr[j] = s[i];
  2157. X        i++;
  2158. X        j++;
  2159. X    }
  2160. X    tempstr[j] = '\0';
  2161. X}
  2162. X
  2163. X
  2164. X
  2165. X/* this function expands any registers in a string */
  2166. Xexpndreg(cmd1,cmd2)
  2167. Xchar cmd1[],cmd2[];
  2168. X{
  2169. X    int i, j, k;
  2170. X    char hold[SHORTSTR];
  2171. X    i = 0;
  2172. X    j = 0;
  2173. X    while (cmd2[i] != '\0') {
  2174. X        if (cmd2[i] == '\\' && cmd2[i+1] == '(') {
  2175. X            i++;
  2176. X            if (cmd2[i] != '\0' && cmd2[i] == '(') {  /* its a register */
  2177. X                i++; 
  2178. X                while (cmd2[i] != '\0' && isspace(cmd2[i])) i++;
  2179. X                sprintf(hold,"%d",REG(cmd2[i]));
  2180. X                k = 0;
  2181. X                while (hold[k] != '\0') {
  2182. X                    cmd1[j] = hold[k];
  2183. X                    k++;
  2184. X                    j++;
  2185. X                }
  2186. X
  2187. X            }
  2188. X            else { /* who knows -- just copy it ! */
  2189. X                cmd1[j] = cmd2[i];
  2190. X                i++;
  2191. X                j++;
  2192. X            }
  2193. X        }
  2194. X        else {
  2195. X            cmd1[j] = cmd2[i];
  2196. X            i++;
  2197. X            j++;
  2198. X        }
  2199. X    }
  2200. X    cmd1[j] = '\0';
  2201. X}
  2202. X
  2203. X
  2204. Xaddbuf(s)
  2205. Xchar s[];
  2206. X{
  2207. X    int i;
  2208. X    i = 0;
  2209. X    while (s[i] != '\0') {
  2210. X        outbuf[obufpos] = s[i];
  2211. X        obufpos++;
  2212. X        i++;
  2213. X    }
  2214. X}
  2215. X
  2216. END_OF_FILE
  2217.   if test 4912 -ne `wc -c <'source/util.c'`; then
  2218.     echo shar: \"'source/util.c'\" unpacked with wrong size!
  2219.   fi
  2220.   # end of 'source/util.c'
  2221. fi
  2222. echo shar: End of archive 2 \(of 5\).
  2223. cp /dev/null ark2isdone
  2224. MISSING=""
  2225. for I in 1 2 3 4 5 ; do
  2226.     if test ! -f ark${I}isdone ; then
  2227.     MISSING="${MISSING} ${I}"
  2228.     fi
  2229. done
  2230. if test "${MISSING}" = "" ; then
  2231.     echo You have unpacked all 5 archives.
  2232.     rm -f ark[1-9]isdone
  2233. else
  2234.     echo You still must unpack the following archives:
  2235.     echo "        " ${MISSING}
  2236. fi
  2237. exit 0
  2238. exit 0 # Just in case...
  2239. -- 
  2240. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  2241. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  2242. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  2243. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  2244.