cb.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. #define IF 1
  10. #define ELSE 2
  11. #define CASE 3
  12. #define TYPE 4
  13. #define DO 5
  14. #define STRUCT 6
  15. #define OTHER 7
  16. #define ALWAYS 01
  17. #define NEVER 02
  18. #define SOMETIMES 04
  19. #define YES 1
  20. #define NO 0
  21. #define KEYWORD 1
  22. #define DATADEF 2
  23. #define SINIT 3
  24. #define CLEVEL 200
  25. #define IFLEVEL 100
  26. #define DOLEVEL 100
  27. #define OPLENGTH 100
  28. #define LINE 2048
  29. #define LINELENG 2048
  30. #define MAXTABS 8
  31. #define TABLENG 8
  32. #define TEMP 20480
  33. #define OUT outs(clev->tabs); Bputc(output, '\n');opflag = lbegin = 1; count = 0
  34. #define OUTK OUT; keyflag = 0;
  35. #define BUMP clev->tabs++; clev->pdepth++
  36. #define UNBUMP clev->tabs -= clev->pdepth; clev->pdepth = 0
  37. #define eatspace() while((cc=getch()) == ' ' || cc == '\t'); unget(cc)
  38. #define eatallsp() while((cc=getch()) == ' ' || cc == '\t' || cc == '\n'); unget(cc)
  39. struct indent { /* one for each level of { } */
  40. int tabs;
  41. int pdepth;
  42. int iflev;
  43. int ifc[IFLEVEL];
  44. int spdepth[IFLEVEL];
  45. } ind[CLEVEL];
  46. struct indent *clev = ind;
  47. struct keyw {
  48. char *name;
  49. char punc;
  50. char type;
  51. } key[] = {
  52. "switch", ' ', OTHER,
  53. "do", ' ', DO,
  54. "while", ' ', OTHER,
  55. "if", ' ', IF,
  56. "for", ' ', OTHER,
  57. "else", ' ', ELSE,
  58. "case", ' ', CASE,
  59. "default", ' ', CASE,
  60. "char", '\t', TYPE,
  61. "int", '\t', TYPE,
  62. "short", '\t', TYPE,
  63. "long", '\t', TYPE,
  64. "unsigned", '\t', TYPE,
  65. "float", '\t', TYPE,
  66. "double", '\t', TYPE,
  67. "struct", ' ', STRUCT,
  68. "union", ' ', STRUCT,
  69. "enum", ' ', STRUCT,
  70. "extern", ' ', TYPE,
  71. "register", ' ', TYPE,
  72. "static", ' ', TYPE,
  73. "typedef", ' ', TYPE,
  74. 0, 0, 0
  75. };
  76. struct op {
  77. char *name;
  78. char blanks;
  79. char setop;
  80. } op[] = {
  81. "+=", ALWAYS, YES,
  82. "-=", ALWAYS, YES,
  83. "*=", ALWAYS, YES,
  84. "/=", ALWAYS, YES,
  85. "%=", ALWAYS, YES,
  86. ">>=", ALWAYS, YES,
  87. "<<=", ALWAYS, YES,
  88. "&=", ALWAYS, YES,
  89. "^=", ALWAYS, YES,
  90. "|=", ALWAYS, YES,
  91. ">>", ALWAYS, YES,
  92. "<<", ALWAYS, YES,
  93. "<=", ALWAYS, YES,
  94. ">=", ALWAYS, YES,
  95. "==", ALWAYS, YES,
  96. "!=", ALWAYS, YES,
  97. "=", ALWAYS, YES,
  98. "&&", ALWAYS, YES,
  99. "||", ALWAYS, YES,
  100. "++", NEVER, NO,
  101. "--", NEVER, NO,
  102. "->", NEVER, NO,
  103. "<", ALWAYS, YES,
  104. ">", ALWAYS, YES,
  105. "+", ALWAYS, YES,
  106. "/", ALWAYS, YES,
  107. "%", ALWAYS, YES,
  108. "^", ALWAYS, YES,
  109. "|", ALWAYS, YES,
  110. "!", NEVER, YES,
  111. "~", NEVER, YES,
  112. "*", SOMETIMES, YES,
  113. "&", SOMETIMES, YES,
  114. "-", SOMETIMES, YES,
  115. "?", ALWAYS,YES,
  116. ":", ALWAYS,YES,
  117. 0, 0,0
  118. };
  119. Biobuf *input;
  120. Biobuf *output;
  121. int strict = 0;
  122. int join = 0;
  123. int opflag = 1;
  124. int keyflag = 0;
  125. int paren = 0;
  126. int split = 0;
  127. int folded = 0;
  128. int dolevel =0;
  129. int dotabs[DOLEVEL];
  130. int docurly[DOLEVEL];
  131. int dopdepth[DOLEVEL];
  132. int structlev = 0;
  133. int question = 0;
  134. char string[LINE];
  135. char *lastlook;
  136. char *p = string;
  137. char temp[TEMP];
  138. char *tp;
  139. int err = 0;
  140. char *lastplace = temp;
  141. char *tptr = temp;
  142. int maxleng = LINELENG;
  143. int maxtabs = MAXTABS;
  144. int count = 0;
  145. char next = '\0';
  146. int inswitch =0;
  147. int lbegin = 1;
  148. int lineno = 0;
  149. void work(void);
  150. void gotif(void);
  151. void gotelse(void);
  152. int checkif(char *);
  153. void gotdo(void);
  154. void resetdo(void);
  155. void gottype(struct keyw *lptr);
  156. void gotstruct(void);
  157. void gotop(int);
  158. void keep(struct op *);
  159. int getnl(void);
  160. void ptabs(int);
  161. void outs(int);
  162. void putch(char, int);
  163. struct keyw *lookup(char *, char *);
  164. int comment(int);
  165. void putspace(char, int);
  166. int getch(void);
  167. void unget(char);
  168. char *getnext(int);
  169. void copy(char *);
  170. void clearif(struct indent *);
  171. char puttmp(char, int);
  172. void error(char *);
  173. int cpp_comment(int);