1 /* $MirOS: src/usr.bin/oldroff/nroff/ni.c,v 1.5 2008/11/08 23:04:42 tg Exp $ */ 2 3 /*- 4 * Copyright (c) 1979, 1980, 1981, 1986, 1988, 1990, 1991, 1992 5 * The Regents of the University of California. 6 * Copyright (C) Caldera International Inc. 2001-2002. 7 * Copyright (c) 2003, 2004 8 * Thorsten "mirabilos" Glaser <tg@mirbsd.org> 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, 12 * with or without modification, are permitted provided 13 * that the following conditions are met: 14 * 15 * Redistributions of source code and documentation must retain 16 * the above copyright notice, this list of conditions and the 17 * following disclaimer. Redistributions in binary form must 18 * reproduce the above copyright notice, this list of conditions 19 * and the following disclaimer in the documentation and/or other 20 * materials provided with the distribution. 21 * 22 * All advertising materials mentioning features or use of this 23 * software must display the following acknowledgement: 24 * This product includes software developed or owned by 25 * Caldera International, Inc. 26 * 27 * Neither the name of Caldera International, Inc. nor the names 28 * of other contributors may be used to endorse or promote products 29 * derived from this software without specific prior written permission. 30 * 31 * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA 32 * INTERNATIONAL, INC. AND CONTRIBUTORS "AS IS" AND ANY EXPRESS 33 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 34 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 35 * ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE 36 * LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR 37 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 38 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 39 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 40 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 41 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 42 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 43 */ 44 45 #ifndef lint 46 static char sccsid[] = "@(#)ni.c 4.5 (Berkeley) 4/18/91"; 47 #endif /* not lint */ 48 49 #include "tdef.h" 50 #include "pathnames.h" 51 char obuf[OBUFSZ]; 52 char *obufp = obuf; 53 int r[NN] = { 54 PAIR('%',0), 55 PAIR('n','l'), 56 PAIR('y','r'), 57 PAIR('h','p'), 58 PAIR('c','t'), 59 PAIR('d','n'), 60 PAIR('m','o'), 61 PAIR('d','y'), 62 PAIR('d','w'), 63 PAIR('l','n'), 64 PAIR('d','l'), 65 PAIR('s','t'), 66 PAIR('s','b'), 67 PAIR('c','.')}; 68 int pto = 10000; 69 int pfrom = 1; 70 int print = 1; 71 char nextf[NS] = _PATH_TMAC; 72 int nfi = sizeof(_PATH_TMAC) - 1; 73 #ifdef NROFF 74 char termtab[NS] = _PATH_TERM; 75 int tti = sizeof(_PATH_TERM) - 1; 76 #endif 77 #ifndef NROFF 78 int oldbits = -1; 79 #endif 80 int init = 1; 81 int fc = IMP; 82 int eschar = '\\'; 83 int pl = 11*INCH; 84 int po = PO; 85 int dfact = 1; 86 int dfactd = 1; 87 int res = 1; 88 int smnt = 4; 89 int ascii = ASCII; 90 int ptid = PTID; 91 char ptname[] = "/dev/cat"; 92 int lg = LG; 93 int pnlist[NPN] = {-1}; 94 int *pnp = pnlist; 95 int npn = 1; 96 int npnflg = 1; 97 int xflg = 1; 98 int dpn = -1; 99 int totout = 1; 100 int ulfont = 1; 101 int ulbit = 1<<9; 102 int tabch = TAB; 103 int ldrch = LEADER; 104 int xxx; 105 extern caseds(), caseas(), casesp(), caseft(), caseps(), casevs(), 106 casenr(), caseif(), casepo(), casetl(), casetm(), casebp(), casech(), 107 casepn(), tbreak(), caseti(), casene(), casenf(), casece(), casefi(), 108 casein(), caseli(), casell(), casens(), casemk(), casert(), caseam(), 109 casede(), casedi(), caseda(), casewh(), casedt(), caseit(), caserm(), 110 casern(), casead(), casers(), casena(), casepl(), caseta(), casetr(), 111 caseul(), caselt(), casenx(), caseso(), caseig(), casetc(), casefc(), 112 caseec(), caseeo(), caselc(), caseev(), caserd(), caseab(), casefl(), 113 done(), casess(), casefp(), casecs(), casebd(), caselg(), casehc(), 114 casehy(), casenh(), casenm(), casenn(), casesv(), caseos(), casels(), 115 casecc(), casec2(), caseem(), caseaf(), casehw(), casemc(), casepm(), 116 casecu(), casepi(), caserr(), caseuf(), caseie(), caseel(), casepc(), 117 caseht(); 118 #ifndef NROFF 119 extern casefz(); 120 #endif 121 extern casecf(); 122 struct contab { 123 int rq; 124 /* 125 union { 126 */ 127 int (*f)(); 128 /* 129 unsigned mx; 130 }x; 131 */ 132 }contab[NM]= { 133 PAIR('d','s'),caseds, 134 PAIR('a','s'),caseas, 135 PAIR('s','p'),casesp, 136 PAIR('f','t'),caseft, 137 PAIR('p','s'),caseps, 138 PAIR('v','s'),casevs, 139 PAIR('n','r'),casenr, 140 PAIR('i','f'),caseif, 141 PAIR('i','e'),caseie, 142 PAIR('e','l'),caseel, 143 PAIR('p','o'),casepo, 144 PAIR('t','l'),casetl, 145 PAIR('t','m'),casetm, 146 PAIR('b','p'),casebp, 147 PAIR('c','h'),casech, 148 PAIR('p','n'),casepn, 149 PAIR('b','r'),tbreak, 150 PAIR('t','i'),caseti, 151 PAIR('n','e'),casene, 152 PAIR('n','f'),casenf, 153 PAIR('c','e'),casece, 154 PAIR('f','i'),casefi, 155 PAIR('i','n'),casein, 156 PAIR('l','i'),caseli, 157 PAIR('l','l'),casell, 158 PAIR('n','s'),casens, 159 PAIR('m','k'),casemk, 160 PAIR('r','t'),casert, 161 PAIR('a','m'),caseam, 162 PAIR('d','e'),casede, 163 PAIR('d','i'),casedi, 164 PAIR('d','a'),caseda, 165 PAIR('w','h'),casewh, 166 PAIR('d','t'),casedt, 167 PAIR('i','t'),caseit, 168 PAIR('r','m'),caserm, 169 PAIR('r','r'),caserr, 170 PAIR('r','n'),casern, 171 PAIR('a','d'),casead, 172 PAIR('r','s'),casers, 173 PAIR('n','a'),casena, 174 PAIR('p','l'),casepl, 175 PAIR('t','a'),caseta, 176 PAIR('t','r'),casetr, 177 PAIR('u','l'),caseul, 178 PAIR('c','u'),casecu, 179 PAIR('l','t'),caselt, 180 PAIR('n','x'),casenx, 181 PAIR('s','o'),caseso, 182 PAIR('i','g'),caseig, 183 PAIR('t','c'),casetc, 184 PAIR('f','c'),casefc, 185 PAIR('e','c'),caseec, 186 PAIR('e','o'),caseeo, 187 PAIR('l','c'),caselc, 188 PAIR('e','v'),caseev, 189 PAIR('r','d'),caserd, 190 PAIR('a','b'),caseab, 191 PAIR('f','l'),casefl, 192 PAIR('e','x'),done, 193 PAIR('s','s'),casess, 194 PAIR('f','p'),casefp, 195 PAIR('c','s'),casecs, 196 PAIR('b','d'),casebd, 197 PAIR('l','g'),caselg, 198 PAIR('h','c'),casehc, 199 PAIR('h','y'),casehy, 200 PAIR('n','h'),casenh, 201 PAIR('n','m'),casenm, 202 PAIR('n','n'),casenn, 203 PAIR('s','v'),casesv, 204 PAIR('o','s'),caseos, 205 PAIR('l','s'),casels, 206 PAIR('c','c'),casecc, 207 PAIR('c','2'),casec2, 208 PAIR('e','m'),caseem, 209 PAIR('a','f'),caseaf, 210 PAIR('h','w'),casehw, 211 PAIR('m','c'),casemc, 212 PAIR('p','m'),casepm, 213 #ifdef NROFF 214 PAIR('p','i'),casepi, 215 #endif 216 PAIR('u','f'),caseuf, 217 PAIR('p','c'),casepc, 218 PAIR('h','t'),caseht, 219 #ifndef NROFF 220 PAIR('f','z'),casefz, 221 #endif 222 PAIR('c', 'f'),casecf, 223 }; 224 225 /* 226 troff environment block 227 */ 228 229 int block = 0; 230 int ics = ICS; 231 int ic = 0; 232 int icf = 0; 233 int chbits = 0; 234 int spbits = 0; 235 int nmbits = 0; 236 int apts = PS; 237 int apts1 = PS; 238 int pts = PS; 239 int pts1 = PS; 240 int font = FT; 241 int font1 = FT; 242 int sps = SPS; 243 int spacesz = SS; 244 int lss = VS; 245 int lss1 = VS; 246 int ls = 1; 247 int ls1 = 1; 248 int ll = LL; 249 int ll1 = LL; 250 int lt = LL; 251 int lt1 = LL; 252 int ad = 1; 253 int nms = 1; 254 int ndf = 1; 255 int fi = 1; 256 int cc = '.'; 257 int c2 = '\''; 258 int ohc = OHC; 259 int tdelim = IMP; 260 int hyf = 1; 261 int hyoff = 0; 262 int un1 = -1; 263 int tabc = 0; 264 int dotc = '.'; 265 int adsp = 0; 266 int adrem = 0; 267 int lastl = 0; 268 int nel = 0; 269 int admod = 0; 270 int *wordp = 0; 271 int spflg = 0; 272 int *linep = 0; 273 int *wdend = 0; 274 int *wdstart = 0; 275 int wne = 0; 276 int ne = 0; 277 int nc = 0; 278 int nb = 0; 279 int lnmod = 0; 280 int nwd = 0; 281 int nn = 0; 282 int ni = 0; 283 int ul = 0; 284 int cu = 0; 285 int ce = 0; 286 int in = 0; 287 int in1 = 0; 288 int un = 0; 289 int wch = 0; 290 int pendt = 0; 291 int *pendw = 0; 292 int pendnf = 0; 293 int spread = 0; 294 int it = 0; 295 int itmac = 0; 296 int lnsize = LNSIZE; 297 int *hyptr[NHYP] = {0}; 298 int tabtab[NTAB] = {DTAB,DTAB*2,DTAB*3,DTAB*4,DTAB*5,DTAB*6,DTAB*7,DTAB*8, 299 DTAB*9,DTAB*10,DTAB*11,DTAB*12,DTAB*13,DTAB*14,DTAB*15,0}; 300 int line[LNSIZE] = {0}; 301 int word[WDSIZE] = {0}; 302 int blockxxx[EVS-68-NHYP-NTAB-WDSIZE-LNSIZE] = {0}; 303 /*spare 5 words*/ 304 int oline[LNSIZE+1]; 305