1*433d6423SLionel Sambuc /* 2*433d6423SLionel Sambuc * store.c - cawf(1) storage areas 3*433d6423SLionel Sambuc */ 4*433d6423SLionel Sambuc 5*433d6423SLionel Sambuc /* 6*433d6423SLionel Sambuc * Copyright (c) 1991 Purdue University Research Foundation, 7*433d6423SLionel Sambuc * West Lafayette, Indiana 47907. All rights reserved. 8*433d6423SLionel Sambuc * 9*433d6423SLionel Sambuc * Written by Victor A. Abell <abe@mace.cc.purdue.edu>, Purdue 10*433d6423SLionel Sambuc * University Computing Center. Not derived from licensed software; 11*433d6423SLionel Sambuc * derived from awf(1) by Henry Spencer of the University of Toronto. 12*433d6423SLionel Sambuc * 13*433d6423SLionel Sambuc * Permission is granted to anyone to use this software for any 14*433d6423SLionel Sambuc * purpose on any computer system, and to alter it and redistribute 15*433d6423SLionel Sambuc * it freely, subject to the following restrictions: 16*433d6423SLionel Sambuc * 17*433d6423SLionel Sambuc * 1. The author is not responsible for any consequences of use of 18*433d6423SLionel Sambuc * this software, even if they arise from flaws in it. 19*433d6423SLionel Sambuc * 20*433d6423SLionel Sambuc * 2. The origin of this software must not be misrepresented, either 21*433d6423SLionel Sambuc * by explicit claim or by omission. Credits must appear in the 22*433d6423SLionel Sambuc * documentation. 23*433d6423SLionel Sambuc * 24*433d6423SLionel Sambuc * 3. Altered versions must be plainly marked as such, and must not 25*433d6423SLionel Sambuc * be misrepresented as being the original software. Credits must 26*433d6423SLionel Sambuc * appear in the documentation. 27*433d6423SLionel Sambuc * 28*433d6423SLionel Sambuc * 4. This notice may not be removed or altered. 29*433d6423SLionel Sambuc */ 30*433d6423SLionel Sambuc 31*433d6423SLionel Sambuc #include "cawf.h" 32*433d6423SLionel Sambuc 33*433d6423SLionel Sambuc struct rx Pat[] = { 34*433d6423SLionel Sambuc { "^[.'](i[ef]|el)", NULL}, /* 0 */ 35*433d6423SLionel Sambuc { "^[.']i[ef] !", NULL}, /* 1 */ 36*433d6423SLionel Sambuc { "^[.']i[ef] !?\\\\n\\(\\.\\$(>|>=|=|<|<=)[0-9] ", 37*433d6423SLionel Sambuc NULL}, /* 2 */ 38*433d6423SLionel Sambuc { "^[.']i[ef] !?'\\\\\\$[0-9]'[^']*' ", NULL}, /* 3 */ 39*433d6423SLionel Sambuc { "^[.']i[ef] !?[nt] ", NULL}, /* 4 */ 40*433d6423SLionel Sambuc { "\\\\\\$[0-9]", NULL}, /* 5 */ 41*433d6423SLionel Sambuc { "^[ \t]*$", NULL}, /* 6 */ 42*433d6423SLionel Sambuc { "\\\\|\t|-| ", NULL}, /* 7 */ 43*433d6423SLionel Sambuc { "[.!?:][]\\)'\\\"\\*]*$", NULL}, /* 8 */ 44*433d6423SLionel Sambuc { ",fP", NULL}, /* 9 */ 45*433d6423SLionel Sambuc { ",tP", NULL}, /* 10 */ 46*433d6423SLionel Sambuc { "^(ta|ll|ls|in|ti|po|ne|sp|pl|nr)", NULL}, /* 11 */ 47*433d6423SLionel Sambuc { "^(ll|ls|in|ti|po|pl)", NULL}, /* 12 */ 48*433d6423SLionel Sambuc { "[]\\)'\\\"\\*]", NULL}, /* 13 */ 49*433d6423SLionel Sambuc { "^(LH|CH|RH|LF|CF|RF)", NULL}, /* 14 */ 50*433d6423SLionel Sambuc { "^[.']i[ef]", NULL}, /* 15 */ 51*433d6423SLionel Sambuc { ",fR", NULL}, /* 16 */ 52*433d6423SLionel Sambuc { NULL, NULL} /* END */ 53*433d6423SLionel Sambuc }; 54*433d6423SLionel Sambuc 55*433d6423SLionel Sambuc int Adj = BOTHADJ; /* output line adjustment mode */ 56*433d6423SLionel Sambuc unsigned char *Aftnxt = NULL; /* action after next line */ 57*433d6423SLionel Sambuc unsigned char *Args[] = { NULL, NULL, /* 10 macro arguments */ 58*433d6423SLionel Sambuc NULL, NULL, 59*433d6423SLionel Sambuc NULL, NULL, 60*433d6423SLionel Sambuc NULL, NULL, 61*433d6423SLionel Sambuc NULL, NULL 62*433d6423SLionel Sambuc }; 63*433d6423SLionel Sambuc unsigned char *Argstack[10*MAXSP]; /* stack for Expand()'s "args[]" */ 64*433d6423SLionel Sambuc int Backc = 0; /* last word ended with '\\c' */ 65*433d6423SLionel Sambuc int Botmarg = 5; /* bottom margin */ 66*433d6423SLionel Sambuc int Centering = 0; /* centering count */ 67*433d6423SLionel Sambuc int Condstack[MAXSP]; /* stack for Expand()'s "cond" */ 68*433d6423SLionel Sambuc unsigned char *Cont = NULL; /* continue line append */ 69*433d6423SLionel Sambuc int Contlen = 0; /* continue line append length */ 70*433d6423SLionel Sambuc int Curmx = -1; /* current macro index */ 71*433d6423SLionel Sambuc char *Device = NULL; /* output device name */ 72*433d6423SLionel Sambuc char *Devconf = NULL; /* device configuration file path */ 73*433d6423SLionel Sambuc char *Devfont = NULL; /* output device font */ 74*433d6423SLionel Sambuc int Divert = 0; /* diversion status */ 75*433d6423SLionel Sambuc FILE *Efs = NULL; /* error file stream */ 76*433d6423SLionel Sambuc unsigned char *Eol = NULL; /* end of line information */ 77*433d6423SLionel Sambuc int Eollen = 0; /* end of line length */ 78*433d6423SLionel Sambuc int Err = 0; /* error flag */ 79*433d6423SLionel Sambuc unsigned char *F = NULL; /* field value */ 80*433d6423SLionel Sambuc struct fcode Fcode[] = { /* font codes */ 81*433d6423SLionel Sambuc { 'B', '\0'}, /* Bold */ 82*433d6423SLionel Sambuc { 'I', '\0'}, /* Italic */ 83*433d6423SLionel Sambuc { 'R', '\0'}, /* Roman */ 84*433d6423SLionel Sambuc { 'C', '\0'}, /* Courier */ 85*433d6423SLionel Sambuc { '\0', '\0'} 86*433d6423SLionel Sambuc }; 87*433d6423SLionel Sambuc int Fill = 0; /* fill status */ 88*433d6423SLionel Sambuc unsigned char Font[] = { '\0', '\0' }; /* current font */ 89*433d6423SLionel Sambuc int Fontctl; /* output font control */ 90*433d6423SLionel Sambuc char Fontstat = 'R'; /* output font status */ 91*433d6423SLionel Sambuc int Fph = 0; /* first page header status */ 92*433d6423SLionel Sambuc int Fsp = 0; /* files stack pointer (for .so) */ 93*433d6423SLionel Sambuc struct fontstr Fstr; /* font control strings */ 94*433d6423SLionel Sambuc unsigned char *Ftc = NULL; /* center footer */ 95*433d6423SLionel Sambuc unsigned char *Ftl = NULL; /* left footer */ 96*433d6423SLionel Sambuc unsigned char *Ftr = NULL; /* right footer */ 97*433d6423SLionel Sambuc unsigned char *Hdc = NULL; /* center header */ 98*433d6423SLionel Sambuc int Hdft = 0; /* header/footer status */ 99*433d6423SLionel Sambuc unsigned char *Hdl = NULL; /* left header */ 100*433d6423SLionel Sambuc unsigned char *Hdr = NULL; /* right header */ 101*433d6423SLionel Sambuc struct hytab Hychar[MAXHYCH]; /* hyphen characters */ 102*433d6423SLionel Sambuc FILE *Ifs = NULL; /* input file stream */ 103*433d6423SLionel Sambuc FILE *Ifs_stk[MAXFSTK]; /* Ifs stack */ 104*433d6423SLionel Sambuc int Ind = 0; /* indentation amount */ 105*433d6423SLionel Sambuc unsigned char *Inname = NULL; /* input file name */ 106*433d6423SLionel Sambuc unsigned char *Inn_stk[MAXFSTK]; /* Inname stack */ 107*433d6423SLionel Sambuc int LL = 78; /* line length (default) */ 108*433d6423SLionel Sambuc unsigned char Line[MAXLINE]; /* input line */ 109*433d6423SLionel Sambuc int Lockil = 0; /* pass 2 line number is locked 110*433d6423SLionel Sambuc * (processing is inside macro) */ 111*433d6423SLionel Sambuc int Marg = 0; /* macro argument - man, ms, etc. */ 112*433d6423SLionel Sambuc struct macro Macrotab[MAXMACRO]; /* macro table */ 113*433d6423SLionel Sambuc unsigned char *Macrotxt[MAXMTXT]; /* macro text */ 114*433d6423SLionel Sambuc int Mtx = 0; /* macro text index */ 115*433d6423SLionel Sambuc int Mxstack[MAXSP]; /* stack for Expand()'s "mx" */ 116*433d6423SLionel Sambuc int Nfc; /* number of font codes */ 117*433d6423SLionel Sambuc int Nhnr[MAXNHNR]; /* ".NH" numbers */ 118*433d6423SLionel Sambuc int Nhy = 0; /* number of Hychar[] entries */ 119*433d6423SLionel Sambuc int Nleftstack[MAXSP]; /* stack for Expand()'s "nleft" */ 120*433d6423SLionel Sambuc int Nmac = 0; /* number of macros */ 121*433d6423SLionel Sambuc int Nnr = 0; /* number of Numb[] entries */ 122*433d6423SLionel Sambuc int Nospmode = 1; /* no space mode */ 123*433d6423SLionel Sambuc int Nparms = 0; /* number of Parms[] entries */ 124*433d6423SLionel Sambuc int NR = 0; /* number of record ala awk */ 125*433d6423SLionel Sambuc int NR_stk[MAXFSTK]; /* NR stack */ 126*433d6423SLionel Sambuc int Nsch = 0; /* number of Schar[] entries */ 127*433d6423SLionel Sambuc int Nstr = 0; /* number of entries in Str[] */ 128*433d6423SLionel Sambuc int Ntabs = 0; /* number of TAB positions */ 129*433d6423SLionel Sambuc struct nbr Numb[MAXNR]; /* number registers */ 130*433d6423SLionel Sambuc int Nxtln = 1; /* next line number */ 131*433d6423SLionel Sambuc int Outll = -1; /* output line length */ 132*433d6423SLionel Sambuc unsigned char Outln[MAXOLL*2]; /* output line */ 133*433d6423SLionel Sambuc int Outlx = 0; /* output line index */ 134*433d6423SLionel Sambuc int P2il = 0; /* pass 2 input line number */ 135*433d6423SLionel Sambuc unsigned char *P2name = NULL; /* pass 2 input file name */ 136*433d6423SLionel Sambuc int P3fill = 1; /* pass 3 fill status */ 137*433d6423SLionel Sambuc int Padchar[MAXOLL]; /* padding character locations */ 138*433d6423SLionel Sambuc int Padfrom = PADLEFT; /* which end to pad from */ 139*433d6423SLionel Sambuc int Padx = 0; /* Padchar[] index */ 140*433d6423SLionel Sambuc struct parms Parms[] = { /* parameter registers */ 141*433d6423SLionel Sambuc { {'i', 'n'}, "indent", 0, 0 }, 142*433d6423SLionel Sambuc { {'l', 'l'}, "linelen", 0, 0 }, 143*433d6423SLionel Sambuc { {'l', 's'}, "vspace", 0, 0 }, 144*433d6423SLionel Sambuc { {'t', 'i'}, "tempindent", 0, 0 }, 145*433d6423SLionel Sambuc { {'p', 'o'}, "pageoffset", 0, 0 }, 146*433d6423SLionel Sambuc { {'p', 'l'}, "pagelen", 0, 0 }, 147*433d6423SLionel Sambuc { {'\0', '\0'}, NULL, 0, 0 } 148*433d6423SLionel Sambuc }; 149*433d6423SLionel Sambuc unsigned char Pass1ln[MAXLINE]; /* pass 1 output line */ 150*433d6423SLionel Sambuc unsigned char Pass2ln[MAXLINE]; /* pass 2 output line */ 151*433d6423SLionel Sambuc int Pglen = 66; /* page length */ 152*433d6423SLionel Sambuc int Pgoff = 0; /* page offset */ 153*433d6423SLionel Sambuc char *Pname = NULL; /* program name */ 154*433d6423SLionel Sambuc unsigned char Prevfont = '\0'; /* previous font */ 155*433d6423SLionel Sambuc int Ptrstack[MAXSP]; /* stack for Expand()'s "ptr" */ 156*433d6423SLionel Sambuc struct scale Scale[] = { /* scaling factors */ 157*433d6423SLionel Sambuc { 'i', (240.0) }, 158*433d6423SLionel Sambuc { 'c', ((240.0 * 50.0)/127.0) }, 159*433d6423SLionel Sambuc { 'P', (240.0/6.0) }, 160*433d6423SLionel Sambuc { 'p', (240.0/72.0) }, 161*433d6423SLionel Sambuc { 'u', (1.0) }, 162*433d6423SLionel Sambuc { 'm', (1.0) }, 163*433d6423SLionel Sambuc { 'n', (1.0) }, 164*433d6423SLionel Sambuc { 'v', (1.0) }, 165*433d6423SLionel Sambuc { '\0', (0.0) } 166*433d6423SLionel Sambuc }; 167*433d6423SLionel Sambuc double Scalen = 0.0; /* 'n' scaling factor */ 168*433d6423SLionel Sambuc double Scaleu = 0.0; /* 'u' scaling factor */ 169*433d6423SLionel Sambuc double Scalev = 0.0; /* 'v' scaling factor */ 170*433d6423SLionel Sambuc struct schtab Schar[MAXSCH]; /* special characters */ 171*433d6423SLionel Sambuc int Sp = -1; /* stack pointer */ 172*433d6423SLionel Sambuc struct str Str[MAXSTR]; /* ".ds" strings */ 173*433d6423SLionel Sambuc int Sx = -1; /* string index */ 174*433d6423SLionel Sambuc int Tabs[MAXEXP+1]; /* TAB positions */ 175*433d6423SLionel Sambuc int Thispg = 1; /* this page number */ 176*433d6423SLionel Sambuc int Tind = 0; /* temporary indentation amount */ 177*433d6423SLionel Sambuc int Topmarg = 5; /* top margin */ 178*433d6423SLionel Sambuc unsigned char *Trtbl = NULL; /* .tr table */ 179*433d6423SLionel Sambuc int Uhyph = 0; /* hyphen usage state */ 180*433d6423SLionel Sambuc int Vspace = 1; /* vertical (inter-text-line) spacing */ 181*433d6423SLionel Sambuc unsigned char Word[MAXLINE]; /* pass 2 word buffer */ 182*433d6423SLionel Sambuc int Wordl = 0; /* effective length of Word[] */ 183*433d6423SLionel Sambuc int Wordx = 0; /* Word[] index */ 184*433d6423SLionel Sambuc int Dowarn = 1; /* Enable warnings if true */ 185