📄 tdef.h
字号:
#include <stdio.h>#include <stdlib.h>#include <limits.h>#include <ctype.h>#include <string.h>#define NROFF (!TROFF)/* Site dependent definitions */#ifndef TMACDIR#define TMACDIR "lib/tmac/tmac."#endif#ifndef FONTDIR#define FONTDIR "lib/font"#endif#ifndef NTERMDIR#define NTERMDIR "lib/term/tab."#endif#ifndef TDEVNAME#define TDEVNAME "post"#endif#ifndef NDEVNAME#define NDEVNAME "37"#endif#ifndef TEXHYPHENS#define TEXHYPHENS "/usr/lib/tex/macros/hyphen.tex"#endif#ifndef ALTHYPHENS#define ALTHYPHENS "lib/tmac/hyphen.tex" /* another place to look */#endiftypedef unsigned char Uchar;typedef unsigned short Ushort;typedef /*unsigned*/ long Tchar;typedef struct Blockp Blockp;typedef struct Diver Diver;typedef struct Stack Stack;typedef struct Divsiz Divsiz;typedef struct Contab Contab;typedef struct Numtab Numtab;typedef struct Numerr Numerr;typedef struct Env Env;typedef struct Term Term;typedef struct Chwid Chwid;typedef struct Font Font;typedef struct Spnames Spnames;typedef struct Wcache Wcache;typedef struct Tbuf Tbuf;/* this simulates printf into a buffer that gets flushed sporadically *//* the BSD goo is because SunOS sprintf doesn't return anything useful */#ifdef BSD4_2#define OUT (obufp += strlen(sprintf(obufp,#define PUT ))) > obuf+BUFSIZ ? flusho() : 1#else#define OUT (obufp += sprintf(obufp,#define PUT )) > obuf+BUFSIZ ? flusho() : 1#endif#define oputs(a) OUT "%s", a PUT#define oput(c) ( *obufp++ = (c), obufp > obuf+BUFSIZ ? flusho() : 1 )extern char errbuf[];#define ERROR sprintf(errbuf,#define WARN ), errprint()#define FATAL ), errprint(), exit(1)/* starting values for typesetting parameters: */#define PS 10 /* default point size */#define FT 1 /* default font position */#define ULFONT 2 /* default underline font */#define BDFONT 3 /* default emboldening font */#define BIFONT 4 /* default bold italic font */#define LL (unsigned) 65*INCH/10 /* line length; 39picas=6.5in */#define VS ((12*INCH)/72) /* initial vert space */#define EMPTS(pts) (((long)Inch*(pts) + 36) / 72)#define EM (TROFF? EMPTS(pts): t.Em)#define INCH (TROFF? Inch: 240)#define HOR (TROFF? Hor: t.Adj)#define VERT (TROFF? Vert: t.Vert)#define PO (TROFF? Inch: 0)#define SPS (TROFF? EMPTS(pts)/3: INCH/10)#define SS (TROFF? 12: INCH/10)#define ICS (TROFF? EMPTS(pts): 2*INCH/10)#define DTAB (TROFF? (INCH/2): 0)/* These "characters" are used to encode various internal functions/* Some make use of the fact that most ascii characters between/* 0 and 040 don't have any graphic or other function./* The few that do have a purpose (e.g., \n, \b, \t, .../* are avoided by the ad hoc choices here./* See ifilt[] in n1.c for others -- 1, 2, 3, 5, 6, 7, 010, 011, 012 */#define LEADER 001#define IMP 004 /* impossible char; glues things together */#define TAB 011#define RPT 014 /* next character is to be repeated many times */#define CHARHT 015 /* size field sets character height */#define SLANT 016 /* size field sets amount of slant */#define DRAWFCN 017 /* next several chars describe arb drawing fcns */# define DRAWLINE 'l' /* line: 'l' dx dy char */# define DRAWCIRCLE 'c' /* circle: 'c' r */# define DRAWELLIPSE 'e' /* ellipse: 'e' rx ry */# define DRAWARC 'a' /* arc: 'a' dx dy dx dy */# define DRAWSPLINE '~' /* quadratic B spline: '~' dx dy dx dy ... */ /* other splines go thru too *//* NOTE: the use of ~ is a botch since it's often used in .tr commands *//* better to use a letter like s, but change it in the postprocessors too *//* for now, this is taken care of in n9.c and t10.c */# define DRAWBUILD 'b' /* built-up character (e.g., { */#define LEFT 020 /* \{ */#define RIGHT 021 /* \} */#define FILLER 022 /* \& and similar purposes */#define XON 023 /* \X'...' starts here */#define OHC 024 /* optional hyphenation character \% */#define CONT 025 /* \c character */#define PRESC 026 /* printable escape */#define UNPAD 027 /* unpaddable blank */#define XPAR 030 /* transparent mode indicator */#define FLSS 031 /* next Tchar contains vertical space */ /* used when recalling diverted text */#define WORDSP 032 /* paddable word space */#define ESC 033 /* current escape character */#define XOFF 034 /* \X'...' ends here */ /* matches XON, but they will probably never nest */ /* so could drop this when another control is needed */#define HX 035 /* next character is value of \x'...' */#define MOTCH 036 /* this "character" is really motion; used by cbits() */#define HYPHEN c_hyphen#define EMDASH c_emdash /* \(em */#define RULE c_rule /* \(ru */#define MINUS c_minus /* minus sign on current font */#define LIG_FI c_fi /* \(ff */#define LIG_FL c_fl /* \(fl */#define LIG_FF c_ff /* \(ff */#define LIG_FFI c_ffi /* \(Fi */#define LIG_FFL c_ffl /* \(Fl */#define ACUTE c_acute /* acute accent \(aa */#define GRAVE c_grave /* grave accent \(ga */#define UNDERLINE c_under /* \(ul */#define ROOTEN c_rooten /* root en \(rn */#define BOXRULE c_boxrule /* box rule \(br */#define LEFTHAND c_lefthand /* left hand for word overflow */#define DAGGER c_dagger /* dagger for end of sentence/footnote */#define HYPHALG 1 /* hyphenation algorithm: 0=>good old troff, 1=>tex *//* array sizes, and similar limits: */#define MAXFONTS 99 /* Maximum number of fonts in fontab */#define NM 90 /* requests + macros */#define NN NNAMES /* number registers */#define NNAMES 15 /* predefined reg names */#define NIF 15 /* if-else nesting */#define NS 128 /* name buffer */#define NTM 1024 /* tm buffer */#define NEV 3 /* environments */#define EVLSZ 10 /* size of ev stack */#define STACKSIZE (12*1024) /* stack for macros and strings in progress */#define NHYP 10 /* max hyphens per word */#define NHEX 512 /* byte size of exception word list */#define NTAB 100 /* tab stops */#define NSO 5 /* "so" depth */#define NMF 5 /* number of -m flags */#define WDSIZE 500 /* word buffer click size */#define LNSIZE 4000 /* line buffer click size */#define OLNSIZE 5000 /* output line buffer click; bigger for 'w', etc. */#define NDI 5 /* number of diversions */#define ALPHABET alphabet /* number of characters in basic alphabet. */ /* 128 for parochial USA 7-bit ascii, */ /* 256 for "European" mode with e.g., Latin-1 */ /* NCHARS must be greater than ALPHABET (ascii stuff) + total number of distinct char names from all fonts that will be run in this job (including unnamed ones and \N's) */#define NCHARS (8*1024) /* maximum size of troff character set*/ /* However for nroff you want only : 1. number of special codes in charset of DESC, which ends up being the value of nchtab and which must be less than 512. 2. ALPHABET, which apparently is the size of the portion of the tables reserved for special control symbols Apparently the max N of \N is irrelevant; */ /* to allow \N of up to 254 with up to 338 special characters you need NCHARS of 338 + ALPHABET = 466 */#define NROFFCHARS 1024 /* maximum size of nroff character set */#define NTRTAB NCHARS /* number of items in trtab[] */#define NWIDCACHE NCHARS /* number of items in widcache[] */#define NTRAP 20 /* number of traps */#define NPN 20 /* numbers in "-o" */#define FBUFSZ 512 /* field buf size words */#define IBUFSZ 4096 /* bytes */#define NC 1024 /* cbuf size words */#define NOV 10 /* number of overstrike chars */#define NPP 10 /* pads per field *//* Internal character representation: Internally, every character is carried around as a 32 bit cookie, called a "Tchar" (typedef long). Bits are numbered 31..0 from left to right. If bit 15 is 1, the character is motion, with if bit 16 it's vertical motion if bit 17 it's negative motion If bit 15 is 0, the character is a real character. if bit 31 zero motion bits 30..24 size bits 23..16 font*//* in the following, "L" should really be a Tchar, but ... *//* numerology leaves room for 16 bit chars */#define MOT (01uL << 16) /* motion character indicator */#define VMOT (01uL << 30) /* vertical motion bit */#define NMOT (01uL << 29) /* negative motion indicator *//* #define MOTV (MOT|VMOT|NMOT) /* motion flags *//* #define MAXMOT (~MOTV) /* maximum motion permitted */#define MAXMOT 0xFFFF#define ismot(n) ((n) & MOT)#define isvmot(n) (((n) & (MOT|VMOT)) == (MOT|VMOT)) /* must have tested MOT previously */#define isnmot(n) (((n) & (MOT|NMOT)) == (MOT|NMOT)) /* ditto */#define absmot(n) ((n) & 0xFFFF)#define ZBIT (01uL << 31) /* zero width char */#define iszbit(n) ((n) & ZBIT)#define FSHIFT 17#define SSHIFT (FSHIFT+7)#define SMASK (0177uL << SSHIFT) /* 128 distinct sizes */#define FMASK (0177uL << FSHIFT) /* 128 distinct fonts */#define SFMASK (SMASK|FMASK) /* size and font in a Tchar */#define sbits(n) (((n) >> SSHIFT) & 0177)#define fbits(n) (((n) >> FSHIFT) & 0177)#define sfbits(n) (((n) & SFMASK) >> FSHIFT)#define cbits(n) ((n) & 0x1FFFF) /* isolate character bits, */ /* but don't include motions */extern int realcbits(Tchar);#define setsbits(n,s) n = (n & ~SMASK) | (Tchar)(s) << SSHIFT#define setfbits(n,f) n = (n & ~FMASK) | (Tchar)(f) << FSHIFT#define setsfbits(n,sf) n = (n & ~SFMASK) | (Tchar)(sf) << FSHIFT#define setcbits(n,c) n = (n & ~0xFFFFuL | (c)) /* set character bits */#define BYTEMASK 0377#define BYTE 8#define SHORTMASK 0XFFFF#define SHORT 16#define TABMASK ((unsigned) INT_MAX >> 1)#define RTAB ((TABMASK << 1) & ~TABMASK)#define CTAB (RTAB << 1)#define TABBIT 02 /* bits in gchtab */#define LDRBIT 04#define FCBIT 010#define PAIR(A,B) (A|(B<<SHORT))extern int Inch, Hor, Vert, Unitwidth;struct Spnames{ int *n; char *v;};extern Spnames spnames[];/* String and macro definitions are stored conceptually in a giant array indexed by type Offset. In olden times, this array was real, and thus both huge and limited in size, leading to the "Out of temp file space" error. In this version, the array is represented by a list of blocks, pointed to by blist[].bp. Each block is of size BLK Tchars, and BLK MUST be a power of 2 for the macros below to work. The blocks associated with a particular string or macro are chained together in the array blist[]. Each blist[i].nextoff contains the Offset associated with the next block in the giant array, or -1 if this is the last block in the chain. If .nextoff is 0, the block is free. To find the right index in blist for an Offset, divide by BLK.*/#define NBLIST 2048 /* starting number of blocks in all definitions */#define BLK 128 /* number of Tchars in a block; must be 2^N with defns below */#define rbf0(o) (blist[bindex(o)].bp[boffset(o)])#define bindex(o) ((o) / BLK)#define boffset(o) ((o) & (BLK-1))#define pastend(o) (((o) & (BLK-1)) == 0)/* #define incoff(o) ( (++o & (BLK-1)) ? o : blist[bindex(o-1)].nextoff ) */#define incoff(o) ( (((o)+1) & (BLK-1)) ? o+1 : blist[bindex(o)].nextoff )#define skipline(f) while (getc(f) != '\n')#define is(s) (strcmp(cmd, s) == 0)#define eq(s1, s2) (strcmp(s1, s2) == 0)typedef unsigned long Offset; /* an offset in macro/string storage */struct Blockp { /* info about a block: */ Tchar *bp; /* the data */ Offset nextoff; /* offset of next block in a chain */};extern Blockp *blist;#define RD_OFFSET (1 * BLK) /* .rd command uses block 1 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -