cpp.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #define INS 32768 /* input buffer */
  2. #define OBS 4096 /* outbut buffer */
  3. #define NARG 32 /* Max number arguments to a macro */
  4. #define NINCLUDE 32 /* Max number of include directories (-I) */
  5. #define NIF 32 /* depth of nesting of #if */
  6. #ifndef EOF
  7. #define EOF (-1)
  8. #endif
  9. #ifndef NULL
  10. #define NULL 0
  11. #endif
  12. #ifndef __alpha
  13. typedef unsigned char uchar;
  14. #endif
  15. enum toktype { END, UNCLASS, NAME, NUMBER, STRING, CCON, NL, WS, DSHARP,
  16. EQ, NEQ, LEQ, GEQ, LSH, RSH, LAND, LOR, PPLUS, MMINUS,
  17. ARROW, SBRA, SKET, LP, RP, DOT, AND, STAR, PLUS, MINUS,
  18. TILDE, NOT, SLASH, PCT, LT, GT, CIRC, OR, QUEST,
  19. COLON, ASGN, COMMA, SHARP, SEMIC, CBRA, CKET,
  20. ASPLUS, ASMINUS, ASSTAR, ASSLASH, ASPCT, ASCIRC, ASLSH,
  21. ASRSH, ASOR, ASAND, ELLIPS,
  22. DSHARP1, NAME1, DEFINED, UMINUS };
  23. enum kwtype { KIF, KIFDEF, KIFNDEF, KELIF, KELSE, KENDIF, KINCLUDE, KDEFINE,
  24. KUNDEF, KLINE, KERROR, KPRAGMA, KDEFINED,
  25. KLINENO, KFILE, KDATE, KTIME, KSTDC, KEVAL };
  26. #define ISDEFINED 01 /* has #defined value */
  27. #define ISKW 02 /* is PP keyword */
  28. #define ISUNCHANGE 04 /* can't be #defined in PP */
  29. #define ISMAC 010 /* builtin macro, e.g. __LINE__ */
  30. #define EOB 0xFE /* sentinel for end of input buffer */
  31. #define EOFC 0xFD /* sentinel for end of input file */
  32. #define XPWS 1 /* token flag: white space to assure token sep. */
  33. typedef struct token {
  34. unsigned char type;
  35. unsigned char flag;
  36. unsigned short hideset;
  37. unsigned int wslen;
  38. unsigned int len;
  39. uchar *t;
  40. } Token;
  41. typedef struct tokenrow {
  42. Token *tp; /* current one to scan */
  43. Token *bp; /* base (allocated value) */
  44. Token *lp; /* last+1 token used */
  45. int max; /* number allocated */
  46. } Tokenrow;
  47. typedef struct source {
  48. char *filename; /* name of file of the source */
  49. int line; /* current line number */
  50. int lineinc; /* adjustment for \\n lines */
  51. uchar *inb; /* input buffer */
  52. uchar *inp; /* input pointer */
  53. uchar *inl; /* end of input */
  54. int fd; /* input source */
  55. int ifdepth; /* conditional nesting in include */
  56. struct source *next; /* stack for #include */
  57. } Source;
  58. typedef struct nlist {
  59. struct nlist *next;
  60. uchar *name;
  61. int len;
  62. Tokenrow *vp; /* value as macro */
  63. Tokenrow *ap; /* list of argument names, if any */
  64. char val; /* value as preprocessor name */
  65. char flag; /* is defined, is pp name */
  66. } Nlist;
  67. typedef struct includelist {
  68. char deleted;
  69. char always;
  70. char *file;
  71. } Includelist;
  72. #define new(t) (t *)domalloc(sizeof(t))
  73. #define quicklook(a,b) (namebit[(a)&077] & (1<<((b)&037)))
  74. #define quickset(a,b) namebit[(a)&077] |= (1<<((b)&037))
  75. extern unsigned long namebit[077+1];
  76. enum errtype { WARNING, ERROR, FATAL };
  77. void expandlex(void);
  78. void fixlex(void);
  79. void setup(int, char **);
  80. int gettokens(Tokenrow *, int);
  81. int comparetokens(Tokenrow *, Tokenrow *);
  82. Source *setsource(char *, int, char *);
  83. void unsetsource(void);
  84. void puttokens(Tokenrow *);
  85. void process(Tokenrow *);
  86. void *domalloc(int);
  87. void dofree(void *);
  88. void error(enum errtype, char *, ...);
  89. void flushout(void);
  90. int fillbuf(Source *);
  91. int trigraph(Source *);
  92. int foldline(Source *);
  93. Nlist *lookup(Token *, int);
  94. void control(Tokenrow *);
  95. void dodefine(Tokenrow *);
  96. void doadefine(Tokenrow *, int);
  97. void doinclude(Tokenrow *);
  98. void doif(Tokenrow *, enum kwtype);
  99. void expand(Tokenrow *, Nlist *);
  100. void builtin(Tokenrow *, int);
  101. int gatherargs(Tokenrow *, Tokenrow **, int *);
  102. void substargs(Nlist *, Tokenrow *, Tokenrow **);
  103. void expandrow(Tokenrow *, char *);
  104. void maketokenrow(int, Tokenrow *);
  105. Tokenrow *copytokenrow(Tokenrow *, Tokenrow *);
  106. Token *growtokenrow(Tokenrow *);
  107. Tokenrow *normtokenrow(Tokenrow *);
  108. void adjustrow(Tokenrow *, int);
  109. void movetokenrow(Tokenrow *, Tokenrow *);
  110. void insertrow(Tokenrow *, int, Tokenrow *);
  111. void peektokens(Tokenrow *, char *);
  112. void doconcat(Tokenrow *);
  113. Tokenrow *stringify(Tokenrow *);
  114. int lookuparg(Nlist *, Token *);
  115. long eval(Tokenrow *, int);
  116. void genline(void);
  117. void setempty(Tokenrow *);
  118. void makespace(Tokenrow *);
  119. char *outnum(char *, int);
  120. int digit(int);
  121. uchar *newstring(uchar *, int, int);
  122. int checkhideset(int, Nlist *);
  123. void prhideset(int);
  124. int newhideset(int, Nlist *);
  125. int unionhideset(int, int);
  126. void iniths(void);
  127. void setobjname(char *);
  128. #define rowlen(tokrow) ((tokrow)->lp - (tokrow)->bp)
  129. extern char *outp;
  130. extern Token nltoken;
  131. extern Source *cursource;
  132. extern char *curtime;
  133. extern int incdepth;
  134. extern int ifdepth;
  135. extern int ifsatisfied[NIF];
  136. extern int Mflag;
  137. extern int skipping;
  138. extern int verbose;
  139. extern int Cplusplus;
  140. extern Nlist *kwdefined;
  141. extern Includelist includelist[NINCLUDE];
  142. extern char wd[];
  143. extern int creat(char *, int);
  144. extern int open(char *, int);
  145. extern int close(int);
  146. extern int dup2(int, int);
  147. extern int write(int, char *, size_t);
  148. extern int read(int, char *, size_t);