ni.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <stdio.h>
  10. #include "tdef.h"
  11. #include "fns.h"
  12. #include "ext.h"
  13. char termtab[NS]; /* term type added in ptinit() */
  14. char fontdir[NS]; /* added in casefp; not used by nroff */
  15. char devname[20]; /* default output device */
  16. Numtab numtab[NN] = {
  17. { PAIR('%', 0) },
  18. { PAIR('n', 'l') },
  19. { PAIR('y', 'r') },
  20. { PAIR('h', 'p') },
  21. { PAIR('c', 't') },
  22. { PAIR('d', 'n') },
  23. { PAIR('m', 'o') },
  24. { PAIR('d', 'y') },
  25. { PAIR('d', 'w') },
  26. { PAIR('l', 'n') },
  27. { PAIR('d', 'l') },
  28. { PAIR('s', 't') },
  29. { PAIR('s', 'b') },
  30. { PAIR('c', '.') },
  31. { PAIR('$', '$') },
  32. };
  33. int alphabet = 256; /* latin-1 */
  34. int pto = 10000;
  35. int pfrom = 1;
  36. int print = 1;
  37. char nextf[NS] = TMACDIR;
  38. char mfiles[NMF][NS];
  39. int nmfi = 0;
  40. int oldbits = -1;
  41. int init = 1;
  42. int fc = IMP; /* field character */
  43. int eschar = '\\';
  44. int pl;
  45. int po;
  46. FILE *ptid = stdout;
  47. int dfact = 1;
  48. int dfactd = 1;
  49. int res = 1;
  50. int smnt = 0; /* beginning of special fonts */
  51. int ascii = 0; /* ascii normally off for troff, on for nroff; -a turns on */
  52. int lg;
  53. int pnlist[NPN] = { -1 };
  54. int *pnp = pnlist;
  55. int npn = 1;
  56. int npnflg = 1;
  57. int dpn = -1;
  58. int totout = 1;
  59. int ulfont = ULFONT;
  60. int tabch = TAB;
  61. int ldrch = LEADER;
  62. Contab contab[NM] = {
  63. C(PAIR('d', 's'), caseds),
  64. C(PAIR('a', 's'), caseas),
  65. C(PAIR('s', 'p'), casesp),
  66. C(PAIR('f', 't'), caseft),
  67. C(PAIR('p', 's'), caseps),
  68. C(PAIR('v', 's'), casevs),
  69. C(PAIR('n', 'r'), casenr),
  70. C(PAIR('i', 'f'), caseif),
  71. C(PAIR('i', 'e'), caseie),
  72. C(PAIR('e', 'l'), caseel),
  73. C(PAIR('p', 'o'), casepo),
  74. C(PAIR('t', 'l'), casetl),
  75. C(PAIR('t', 'm'), casetm),
  76. C(PAIR('f', 'm'), casefm),
  77. C(PAIR('b', 'p'), casebp),
  78. C(PAIR('c', 'h'), casech),
  79. C(PAIR('p', 'n'), casepn),
  80. C(PAIR('b', 'r'), tbreak),
  81. C(PAIR('t', 'i'), caseti),
  82. C(PAIR('n', 'e'), casene),
  83. C(PAIR('n', 'f'), casenf),
  84. C(PAIR('c', 'e'), casece),
  85. C(PAIR('f', 'i'), casefi),
  86. C(PAIR('i', 'n'), casein),
  87. C(PAIR('l', 'l'), casell),
  88. C(PAIR('n', 's'), casens),
  89. C(PAIR('m', 'k'), casemk),
  90. C(PAIR('r', 't'), casert),
  91. C(PAIR('a', 'm'), caseam),
  92. C(PAIR('d', 'e'), casede),
  93. C(PAIR('d', 'i'), casedi),
  94. C(PAIR('d', 'a'), caseda),
  95. C(PAIR('w', 'h'), casewh),
  96. C(PAIR('d', 't'), casedt),
  97. C(PAIR('i', 't'), caseit),
  98. C(PAIR('r', 'm'), caserm),
  99. C(PAIR('r', 'r'), caserr),
  100. C(PAIR('r', 'n'), casern),
  101. C(PAIR('a', 'd'), casead),
  102. C(PAIR('r', 's'), casers),
  103. C(PAIR('n', 'a'), casena),
  104. C(PAIR('p', 'l'), casepl),
  105. C(PAIR('t', 'a'), caseta),
  106. C(PAIR('t', 'r'), casetr),
  107. C(PAIR('u', 'l'), caseul),
  108. C(PAIR('c', 'u'), casecu),
  109. C(PAIR('l', 't'), caselt),
  110. C(PAIR('n', 'x'), casenx),
  111. C(PAIR('s', 'o'), caseso),
  112. C(PAIR('i', 'g'), caseig),
  113. C(PAIR('t', 'c'), casetc),
  114. C(PAIR('f', 'c'), casefc),
  115. C(PAIR('e', 'c'), caseec),
  116. C(PAIR('e', 'o'), caseeo),
  117. C(PAIR('l', 'c'), caselc),
  118. C(PAIR('e', 'v'), caseev),
  119. C(PAIR('r', 'd'), caserd),
  120. C(PAIR('a', 'b'), caseab),
  121. C(PAIR('f', 'l'), casefl),
  122. C(PAIR('e', 'x'), caseex),
  123. C(PAIR('s', 's'), casess),
  124. C(PAIR('f', 'p'), casefp),
  125. C(PAIR('c', 's'), casecs),
  126. C(PAIR('b', 'd'), casebd),
  127. C(PAIR('l', 'g'), caselg),
  128. C(PAIR('h', 'c'), casehc),
  129. C(PAIR('h', 'y'), casehy),
  130. C(PAIR('n', 'h'), casenh),
  131. C(PAIR('n', 'm'), casenm),
  132. C(PAIR('n', 'n'), casenn),
  133. C(PAIR('s', 'v'), casesv),
  134. C(PAIR('o', 's'), caseos),
  135. C(PAIR('l', 's'), casels),
  136. C(PAIR('c', 'c'), casecc),
  137. C(PAIR('c', '2'), casec2),
  138. C(PAIR('e', 'm'), caseem),
  139. C(PAIR('a', 'f'), caseaf),
  140. C(PAIR('h', 'a'), caseha),
  141. C(PAIR('h', 'w'), casehw),
  142. C(PAIR('m', 'c'), casemc),
  143. C(PAIR('p', 'm'), casepm),
  144. C(PAIR('p', 'i'), casepi),
  145. C(PAIR('u', 'f'), caseuf),
  146. C(PAIR('p', 'c'), casepc),
  147. C(PAIR('h', 't'), caseht),
  148. C(PAIR('c', 'f'), casecf),
  149. C(PAIR('s', 'y'), casesy),
  150. C(PAIR('l', 'f'), caself),
  151. C(PAIR('p', 't'), casept),
  152. C(PAIR('g', 'd'), casegd),
  153. };
  154. Tbuf _oline;
  155. /*
  156. * troff environment block
  157. */
  158. Env env[NEV] = { { /* this sets up env[0] */
  159. /* int ics */ 0, /* insertion character space, set by .mc */
  160. /* int sps */ 0,
  161. /* int spacesz */ 0,
  162. /* int lss */ 0,
  163. /* int lss1 */ 0,
  164. /* int ll */ 0,
  165. /* int ll1 */ 0,
  166. /* int lt */ 0,
  167. /* int lt1 */ 0,
  168. /* Tchar ic */ 0, /* insertion character (= margin character) */
  169. /* int icf */ 0, /* insertion character flag */
  170. /* Tchar chbits */ 0, /* size+font bits for current character */
  171. /* Tchar spbits */ 0,
  172. /* Tchar nmbits */ 0, /* size+font bits for number from .nm */
  173. /* int apts */ PS, /* actual point size -- as requested by user */
  174. /* int apts1 */ PS, /* need not match an existent size */
  175. /* int pts */ PS, /* hence, this is the size that really exists */
  176. /* int pts1 */ PS,
  177. /* int font */ FT,
  178. /* int font1 */ FT,
  179. /* int ls */ 1,
  180. /* int ls1 */ 1,
  181. /* int ad */ 1,
  182. /* int nms */ 1, /* .nm multiplier */
  183. /* int ndf */ 1, /* .nm separator */
  184. /* int nmwid */ 3, /* max width of .nm numbers */
  185. /* int fi */ 1,
  186. /* int cc */ '.',
  187. /* int c2 */ '\'',
  188. /* int ohc */ OHC,
  189. /* int tdelim */ IMP,
  190. /* int hyf */ 1,
  191. /* int hyoff */ 0,
  192. /* int hyphalg */ HYPHALG,
  193. /* int un1 */ -1,
  194. /* int tabc */ 0,
  195. /* int dotc */ '.',
  196. /* int adsp */ 0, /* add this much space to each padding point */
  197. /* int adrem */ 0, /* excess space to add until it runs out */
  198. /* int lastl */ 0, /* last text on current output line */
  199. /* int nel */ 0, /* how much space left on current output line */
  200. /* int admod */ 0, /* adjust mode */
  201. /* Tchar *wordp */ 0,
  202. /* int spflg */ 0, /* probably to indicate space after punctuation needed */
  203. /* Tchar *linep */ 0,
  204. /* Tchar *wdend */ 0,
  205. /* Tchar *wdstart */ 0,
  206. /* int wne */ 0,
  207. /* int ne */ 0, /* how much space taken on current output line */
  208. /* int nc */ 0, /* #characters (incl blank) on output line */
  209. /* int nb */ 0,
  210. /* int lnmod */ 0, /* line number mode, set by .nm */
  211. /* int nwd */ 0, /* number of words on current output line */
  212. /* int nn */ 0, /* from .nn command */
  213. /* int ni */ 0, /* indent of .nm numbers, probably */
  214. /* int ul */ 0,
  215. /* int cu */ 0,
  216. /* int ce */ 0,
  217. /* int in */ 0, /* indent and previous value */
  218. /* int in1 */ 0,
  219. /* int un */ 0, /* unindent of left margin in some way */
  220. /* int wch */ 0,
  221. /* int pendt */ 0,
  222. /* Tchar *pendw */ (Tchar *)0,
  223. /* int pendnf */ 0,
  224. /* int spread */ 0,
  225. /* int it */ 0, /* input trap count */
  226. /* int itmac */ 0,
  227. } };
  228. Env *envp = env; /* start off in env 0 */
  229. Numerr numerr;
  230. Stack *frame, *stk, *ejl;
  231. Stack *nxf;
  232. int pipeflg;
  233. int hflg; /* used in nroff only */
  234. int eqflg; /* used in nroff only */
  235. int xpts;
  236. int ppts;
  237. int pfont;
  238. int mpts;
  239. int mfont;
  240. int cs;
  241. int ccs;
  242. int bd;
  243. int stdi;
  244. int quiet;
  245. int stop;
  246. char ibuf[IBUFSZ];
  247. char xbuf[IBUFSZ];
  248. char *ibufp;
  249. char *xbufp;
  250. char *eibuf;
  251. char *xeibuf;
  252. Tchar pbbuf[NC]; /* pushback buffer for arguments, \n, etc. */
  253. Tchar *pbp = pbbuf; /* next free slot in pbbuf */
  254. Tchar *lastpbp = pbbuf; /* pbp in previous stack frame */
  255. int nx;
  256. int mflg;
  257. Tchar ch = 0;
  258. int ibf;
  259. int ifi;
  260. int iflg;
  261. int rargc;
  262. char **argp;
  263. Ushort trtab[NTRTAB];
  264. int lgf;
  265. int copyf;
  266. Offset ip;
  267. int nlflg;
  268. int donef;
  269. int nflush;
  270. int nfo;
  271. int padc;
  272. int raw;
  273. int flss;
  274. int nonumb;
  275. int trap;
  276. int tflg;
  277. int ejf;
  278. int dilev;
  279. Offset offset;
  280. int em;
  281. int ds;
  282. Offset woff;
  283. int app;
  284. int ndone;
  285. int lead;
  286. int ralss;
  287. Offset nextb;
  288. Tchar nrbits;
  289. int nform;
  290. int oldmn;
  291. int newmn;
  292. int macerr;
  293. Offset apptr;
  294. int diflg;
  295. int evi;
  296. int vflag;
  297. int noscale;
  298. int po1;
  299. int nlist[NTRAP];
  300. int mlist[NTRAP];
  301. int evlist[EVLSZ];
  302. int ev;
  303. int tty;
  304. int sfont = FT; /* appears to be "standard" font; used by .ul */
  305. int sv;
  306. int esc;
  307. int widthp;
  308. int xfont;
  309. int setwdf;
  310. int over;
  311. int nhyp;
  312. Tchar **hyp;
  313. Tchar *olinep;
  314. int dotT;
  315. char *unlkp;
  316. Wcache widcache[NWIDCACHE];
  317. Diver d[NDI];
  318. Diver *dip;
  319. int c_hyphen;
  320. int c_emdash;
  321. int c_rule;
  322. int c_minus;
  323. int c_fi;
  324. int c_fl;
  325. int c_ff;
  326. int c_ffi;
  327. int c_ffl;
  328. int c_acute;
  329. int c_grave;
  330. int c_under;
  331. int c_rooten;
  332. int c_boxrule;
  333. int c_lefthand;
  334. int c_dagger;
  335. int c_isalnum;
  336. Spnames spnames[] =
  337. {
  338. &c_hyphen, "hy",
  339. &c_emdash, "em",
  340. &c_rule, "ru",
  341. &c_minus, "\\-",
  342. &c_fi, "fi",
  343. &c_fl, "fl",
  344. &c_ff, "ff",
  345. &c_ffi, "Fi",
  346. &c_ffl, "Fl",
  347. &c_acute, "aa",
  348. &c_grave, "ga",
  349. &c_under, "ul",
  350. &c_rooten, "rn",
  351. &c_boxrule, "br",
  352. &c_lefthand, "lh",
  353. &c_dagger, "dg", /* not in nroff?? */
  354. &c_isalnum, "__",
  355. 0, 0
  356. };
  357. Tchar (*hmot)(void);
  358. Tchar (*makem)(int i);
  359. Tchar (*setabs)(void);
  360. Tchar (*setch)(int c);
  361. Tchar (*sethl)(int k);
  362. Tchar (*setht)(void);
  363. Tchar (*setslant)(void);
  364. Tchar (*vmot)(void);
  365. Tchar (*xlss)(void);
  366. int (*findft)(int i);
  367. int (*width)(Tchar j);
  368. void (*mchbits)(void);
  369. void (*ptlead)(void);
  370. void (*ptout)(Tchar i);
  371. void (*ptpause)(void);
  372. void (*setfont)(int a);
  373. void (*setps)(void);
  374. void (*setwd)(void);