113915Sslatteng #include <signal.h> 213915Sslatteng 313915Sslatteng #define MAXPTR (char *)-1 /* max value of any pointer variable */ 413915Sslatteng /* likely to be machine-dependent */ 513915Sslatteng 613915Sslatteng /* starting values for typesetting parameters: */ 713915Sslatteng 813915Sslatteng #define PS 10 /* default point size */ 913915Sslatteng #define FT 1 /* default font position */ 1016390Sslatteng #define ST 1 /* default stipple */ 1113915Sslatteng #define LL (unsigned) 65*INCH/10 /* line length; 39picas=6.5in */ 1213915Sslatteng #define VS ((12*INCH)/72) /* initial vert space */ 1313915Sslatteng 1413915Sslatteng #ifdef NROFF 1513915Sslatteng # define EM t.Em 1613915Sslatteng # define HOR t.Hor 1713915Sslatteng # define VERT t.Vert 1813915Sslatteng # define INCH 240 /* increments per inch */ 1913915Sslatteng # define SPS INCH/10 /* space size */ 2013915Sslatteng # define SS INCH/10 /* " */ 2113915Sslatteng # define TRAILER 0 2213915Sslatteng # define UNPAD 0227 2313915Sslatteng # define PO 0 /* page offset */ 2413915Sslatteng # define ASCII 1 2513915Sslatteng # define PTID 1 2613915Sslatteng # define LG 0 2713915Sslatteng # define DTAB 0 /* set at 8 Ems at init time */ 2813915Sslatteng # define ICS 2*SPS 2913915Sslatteng #endif 3013915Sslatteng #ifndef NROFF /* TROFF */ 3113915Sslatteng /* Inch is set by ptinit() when troff started. 3213915Sslatteng /* all derived values set then too 3313915Sslatteng */ 3413915Sslatteng # define INCH Inch /* troff resolution -- number of goobies/inch */ 3513915Sslatteng # define POINT (INCH/72) /* goobies per point (1/72 inch) */ 3613915Sslatteng # define HOR Hor /* horizontal resolution in goobies */ 3713915Sslatteng # define VERT Vert /* vertical resolution in goobies */ 3813915Sslatteng # define SPS (EM/3) /* space size */ 3913915Sslatteng # define SS 12 /* space size in 36ths of an em */ 4013915Sslatteng # define UNPAD 027 4113915Sslatteng # define PO (INCH - INCH/27) /* page offset 26/27ths inch */ 4213915Sslatteng /* # define EM (POINT * pts) */ 4313915Sslatteng #define EM (((long) INCH * pts + 36) / 72) /* don't lose significance */ 4413915Sslatteng #define EMPTS(pts) (((long) INCH * (pts) + 36) / 72) 4513915Sslatteng # define ASCII 0 4613915Sslatteng # define PTID 1 4713915Sslatteng # define LG 1 4813915Sslatteng # define DTAB (INCH/2) 4913915Sslatteng # define ICS 3*SPS 5013915Sslatteng #endif 5113915Sslatteng 5213915Sslatteng /* These "characters" are used to encode various internal functions 5313915Sslatteng /* Some make use of the fact that most ascii characters between 5413915Sslatteng /* 0 and 040 don't have any graphic or other function. 5513915Sslatteng /* The few that do have a purpose (e.g., \n, \b, \t, ... 5613915Sslatteng /* are avoided by the ad hoc choices here. 5713915Sslatteng /* See ifilt[] in n1.c for others -- 1, 2, 3, 5, 6, 7, 010, 011, 012 5813915Sslatteng */ 5913915Sslatteng 6013915Sslatteng #define LEADER 001 6113915Sslatteng #define IMP 004 /* impossible char; glues things together */ 6213915Sslatteng #define TAB 011 6313915Sslatteng #define RPT 014 /* next character is to be repeated many times */ 6413915Sslatteng #define CHARHT 015 /* size field sets character height */ 6513915Sslatteng #define SLANT 016 /* size field sets amount of slant */ 6613915Sslatteng #define DRAWFCN 017 /* next several chars describe arb drawing fcn */ 6714157Sslatteng /* style: 's' m */ 6814157Sslatteng /* thickness: 't' w */ 6913915Sslatteng /* line: 'l' dx dy char */ 7013915Sslatteng /* circle: 'c' r */ 7113915Sslatteng /* ellipse: 'e' rx ry */ 7213915Sslatteng /* arc: 'a' dx dy r */ 7313915Sslatteng /* wiggly line '~' x y x y ... */ 7414157Sslatteng /* or 'g' x y x y ... */ 7514157Sslatteng #define DRAWTHICK 't' 7614157Sslatteng #define DRAWSTYLE 's' 7713915Sslatteng #define DRAWLINE 'l' 7813915Sslatteng #define DRAWCIRCLE 'c' /* circle */ 7913915Sslatteng #define DRAWELLIPSE 'e' 8013915Sslatteng #define DRAWARC 'a' /* arbitrary arc */ 8114157Sslatteng #define DRAWCURVE 'g' /* gremlin spline */ 8213915Sslatteng #define DRAWWIG '~' /* wiggly line with spline */ 8316390Sslatteng #define DRAWPOLY 'p' /* polygon with stipples */ 8416542Sslatteng #define DRAWUBPOLY 'P' /* polygon, stipples, no border */ 8513915Sslatteng 8613915Sslatteng #define LEFT 020 /* \{ */ 8713915Sslatteng #define RIGHT 021 /* \} */ 8813915Sslatteng #define FILLER 022 /* \& and similar purposes */ 8913915Sslatteng #define OHC 024 /* optional hyphenation character \% */ 9013915Sslatteng #define CONT 025 /* \c character */ 9113915Sslatteng #define PRESC 026 /* printable escape */ 9213915Sslatteng #define XPAR 030 /* transparent mode indicator */ 9313915Sslatteng #define FLSS 031 9413915Sslatteng #define WORDSP 032 /* paddable word space */ 9513915Sslatteng #define ESC 033 9613915Sslatteng 9713915Sslatteng /* there are several tests (using iscontrol()) 9813915Sslatteng /* that rely on these having 034 true. 9913915Sslatteng */ 10013915Sslatteng #define iscontrol(n) (n>=034 && n<=037) /* used to test the next two */ 10113915Sslatteng #define HX 035 /* next character is value of \x'...' */ 10213915Sslatteng #define FONTPOS 036 /* position of font \f(XX encoded in top */ 10313915Sslatteng #define FONTNAME 037 /* name of font in \f(XX in top */ 10413915Sslatteng /* have to appear in this order */ 10513915Sslatteng 10613915Sslatteng #define HYPHEN c_hyphen 10713915Sslatteng #define EMDASH c_emdash /* \(em */ 10813915Sslatteng #define RULE c_rule /* \(ru */ 10913915Sslatteng #define MINUS c_minus /* minus sign on current font */ 11013915Sslatteng #define NARSP c_narsp /* narrow space \|: fake character */ 11113915Sslatteng #define HNARSP c_hnarsp /* half narrow space \^: fake character */ 11213915Sslatteng #define LIG_FI c_fi /* \(ff */ 11313915Sslatteng #define LIG_FL c_fl /* \(fl */ 11413915Sslatteng #define LIG_FF c_ff /* \(ff */ 11513915Sslatteng #define LIG_FFI c_ffi /* \(Fi */ 11613915Sslatteng #define LIG_FFL c_ffl /* \(Fl */ 11713915Sslatteng #define ACUTE c_acute /* acute accent \(aa */ 11813915Sslatteng #define GRAVE c_grave /* grave accent \(ga */ 11913915Sslatteng #define UNDERLINE c_under /* \(ul */ 12013915Sslatteng #define ROOTEN c_rooten /* root en \(rn */ 12113915Sslatteng #define BOXRULE c_boxrule /* box rule \(br */ 12213915Sslatteng #define LEFTHAND c_lefthand 12313915Sslatteng 12413915Sslatteng /* array sizes, and similar limits: */ 12513915Sslatteng 12614330Sslatteng #define NFONT 60 /* maximum number of fonts (including specials) */ 12713915Sslatteng #define EXTRAFONT 500 /* extra space for swapping a font */ 12813915Sslatteng #define NN 300 /* number registers */ 12913915Sslatteng #define NNAMES 15 /* predefined reg names */ 13013915Sslatteng #define NIF 15 /* if-else nesting */ 13113915Sslatteng #define NS 64 /* name buffer */ 13213915Sslatteng #define NTM 256 /* tm buffer */ 13313915Sslatteng #define NEV 3 /* environments */ 13413915Sslatteng #define EVLSZ 10 /* size of ev stack */ 13513915Sslatteng #define DSIZE 512 /* disk sector size in chars */ 13613915Sslatteng 13713915Sslatteng /* the following defines the size of the infamous environment block. 13813915Sslatteng this macro is guaranteed to blow older C preprocessors out of the 139*27076Sslatteng water. Any additions to ni.c between "block" and the end of the 140*27076Sslatteng data space affects this macro. 14113915Sslatteng */ 14213915Sslatteng 14313915Sslatteng #define EVUSED \ 144*27076Sslatteng (61 * sizeof(int) /* integers in env block */ \ 145*27076Sslatteng + 4 * sizeof(tchar) /* tchars in env block */ \ 146*27076Sslatteng + 5 * sizeof(tchar *) /* tchar pointers in env block */ \ 147*27076Sslatteng + NHYP * sizeof(tchar *)/* hytab */ \ 14813915Sslatteng + NTAB * sizeof(int) /* tabtab */ \ 14913915Sslatteng + (LNSIZE+WDSIZE) * sizeof(tchar)) /* line+word */ 15013915Sslatteng 15113915Sslatteng #define EVSPARE DSIZE - EVUSED % DSIZE /* number of leftover chars */ 15213915Sslatteng #define EVS (EVUSED + EVSPARE) /* should be a multiple of DSIZE */ 15315895Srrh #define NM 500 /* requests + macros */ 15413915Sslatteng #define DELTA 1024 /* delta core bytes */ 15513915Sslatteng #define NHYP 10 /* max hyphens per word */ 15613915Sslatteng #define NHEX 128 /* byte size of exception word list */ 15713915Sslatteng #define NTAB 35 /* tab stops */ 15813915Sslatteng #define NSO 5 /* "so" depth */ 15913915Sslatteng #define WDSIZE 270 /* word buffer size */ 16013915Sslatteng #define LNSIZE 680 /* line buffer size */ 16113915Sslatteng #define NDI 5 /* number of diversions */ 16213915Sslatteng #define NTRTAB 350 /* number of items in trtab[] */ 16313915Sslatteng #define NTRAP 20 /* number of traps */ 16413915Sslatteng #define NPN 20 /* numbers in "-o" */ 16513915Sslatteng #define FBUFSZ 256 /* field buf size words */ 16613915Sslatteng #define OBUFSZ 512 /* bytes */ 16713915Sslatteng #define IBUFSZ 512 /* bytes */ 16813915Sslatteng #define NC 256 /* cbuf size words */ 16913915Sslatteng #define NOV 10 /* number of overstrike chars */ 17013915Sslatteng #define NPP 10 /* pads per field */ 17113915Sslatteng 17213915Sslatteng /* 17313915Sslatteng Internal character representation: 17413915Sslatteng Internally, every character is carried around as 17513915Sslatteng a 32 bit cookie, called a "tchar" (typedef long). 17613915Sslatteng Bits are numbered 31..0 from left to right. 17713915Sslatteng If bit 15 is 1, the character is motion, with 17813915Sslatteng if bit 16 it's vertical motion 17913915Sslatteng if bit 17 it's negative motion 18013915Sslatteng If bit 15 is 0, the character is a real character. 18113915Sslatteng if bit 31 zero motion 18213915Sslatteng bits 30..24 size 18313915Sslatteng bits 23..16 font 18413915Sslatteng */ 18513915Sslatteng 18613915Sslatteng /* in the following, "L" should really be a tchar, but ... */ 18713915Sslatteng 18813915Sslatteng #define MOT (unsigned short)(01<<15) /* motion character indicator */ 18913915Sslatteng #define MOTV (07L<<15) /* clear for motion part */ 19013915Sslatteng #define VMOT (01L<<16) /* vert motion bit */ 19113915Sslatteng #define NMOT (01L<<17) /* negative motion indicator*/ 19213915Sslatteng #define MAXMOT 32767 /* bad way to write this!!! */ 19313915Sslatteng #define ismot(n) ((unsigned short)(n) & MOT) /* (short) is a cheap mask */ 19413915Sslatteng #define isvmot(n) ((n) & VMOT) /* must have tested MOT previously */ 19513915Sslatteng #define isnmot(n) ((n) & NMOT) /* ditto */ 19613915Sslatteng #define absmot(n) ((unsigned short)(n) & ~MOT) /* (short) is cheap mask */ 19713915Sslatteng 19813915Sslatteng #define ZBIT (01L << 31) /* zero width char */ 19913915Sslatteng #define iszbit(n) ((n) & ZBIT) 20013915Sslatteng 20113915Sslatteng #define SMASK (0177L << 24) 20213915Sslatteng #define FMASK (0377L << 16) 20313915Sslatteng #define SFMASK (SMASK|FMASK) /* size and font in a tchar */ 20413915Sslatteng #define CMASK ~MOT /* clears MOT */ 20513915Sslatteng #define CMASKL 077777L 20613915Sslatteng #define sbits(n) ((unsigned short)((n) >> 24) & 0177) 20713915Sslatteng #define fbits(n) ((unsigned short)((n) >> 16) & 0377) 20813915Sslatteng #define sfbits(n) ((unsigned short)(((n) & SFMASK) >> 16)) 20913915Sslatteng #define cbits(n) (unsigned short)(n) /* isolate bottom 16 bits */ 21013915Sslatteng #define setsbits(n,s) n = (n & ~SMASK) | (tchar)(s) << 24 21113915Sslatteng #define setfbits(n,f) n = (n & ~FMASK) | (tchar)(f) << 16 21213915Sslatteng #define setsfbits(n,sf) n = (n & ~SFMASK) | (tchar)(sf) << 16 21313915Sslatteng #define setcbits(n,c) n = (n & ~CMASKL | (c)) /* set character bits */ 21413915Sslatteng 21513915Sslatteng #define MMASK 0100000 /* macro mask indicator */ 21613915Sslatteng #define BMASK 0377 21713915Sslatteng #define BYTE 8 21813915Sslatteng 21913915Sslatteng #define ZONE 5 /* 5 hrs for EST */ 22013915Sslatteng #define TMASK 037777 22113915Sslatteng #define RTAB (unsigned) 0100000 22213915Sslatteng #define CTAB 040000 22313915Sslatteng 22413915Sslatteng #define PAIR(A,B) (A|(B<<BYTE)) 22513915Sslatteng 22613915Sslatteng typedef unsigned filep; 22713915Sslatteng #define BLK 128 /* alloc block tchars */ 22813915Sslatteng #define NBLIST 1024 /* allocation list */ 22913915Sslatteng /* previous values were BLK 256 NBLIST 512 */ 23013915Sslatteng /* it seems good to keep the product constant */ 23113915Sslatteng /* BLK*NBLIST<=65536 words, if filep=unsigned */ 23213915Sslatteng 23313915Sslatteng typedef long tchar; /* as an experiment */ 23413915Sslatteng 23513915Sslatteng extern tchar getch(), getch0(); 23613915Sslatteng extern tchar rbf(), rbf0(); 23713915Sslatteng extern tchar mot(), hmot(), vmot(); 23813915Sslatteng extern tchar makem(), sethl(); 23913915Sslatteng extern tchar popi(); 24013915Sslatteng extern tchar getlg(); 24113915Sslatteng extern tchar xlss(); 24213915Sslatteng extern tchar setfield(); 24313915Sslatteng extern tchar setz(); 24413915Sslatteng extern tchar setch(), absch(); 24513915Sslatteng extern tchar setht(), setslant(); 24613915Sslatteng 24713915Sslatteng #define atoi(i) ((int) atoi0(i)) 24813915Sslatteng extern long atoi0(); 24913915Sslatteng 25013915Sslatteng extern int Inch, Hor, Vert, Unitwidth; 25113915Sslatteng 25213915Sslatteng /* these characters are used as various signals or values 25313915Sslatteng /* in miscellaneous places. 25413915Sslatteng /* values are set in specnames in t10.c 25513915Sslatteng */ 25613915Sslatteng 25713915Sslatteng extern int c_hyphen; 25813915Sslatteng extern int c_emdash; 25913915Sslatteng extern int c_rule; 26013915Sslatteng extern int c_minus; 26113915Sslatteng extern int c_narsp; 26213915Sslatteng extern int c_hnarsp; 26313915Sslatteng extern int c_fi; 26413915Sslatteng extern int c_fl; 26513915Sslatteng extern int c_ff; 26613915Sslatteng extern int c_ffi; 26713915Sslatteng extern int c_ffl; 26813915Sslatteng extern int c_acute; 26913915Sslatteng extern int c_grave; 27013915Sslatteng extern int c_under; 27113915Sslatteng extern int c_rooten; 27213915Sslatteng extern int c_boxrule; 27313915Sslatteng extern int c_lefthand; 27413915Sslatteng 27513915Sslatteng extern int stderr; /* this is NOT the stdio value! */ 276