PageRenderTime 56ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/brlcad/branches/STABLE/src/other/re2c/test/condition_15.csif.c

https://bitbucket.org/vrrm/brl-cad-copy-for-fast-history-browsing-in-git
C | 383 lines | 358 code | 22 blank | 3 comment | 47 complexity | 6cf0957ca9240033853a1dc14b3aaf34 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, LGPL-2.1, Apache-2.0, AGPL-3.0, LGPL-3.0, GPL-3.0, MPL-2.0-no-copyleft-exception, CC-BY-SA-3.0, 0BSD, BSD-3-Clause
  1. /* Generated by re2c */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #define BSIZE 8192
  6. enum ScanContition {
  7. EStateNormal,
  8. EStateComment,
  9. EStateSkiptoeol,
  10. EStateString,
  11. };
  12. typedef struct Scanner
  13. {
  14. FILE *fp;
  15. unsigned char *cur, *tok, *lim, *eof;
  16. unsigned char buffer[BSIZE];
  17. unsigned char yych;
  18. enum ScanContition cond;
  19. int state;
  20. } Scanner;
  21. size_t fill(Scanner *s, size_t len)
  22. {
  23. size_t got = ~0, cnt;
  24. if (!s->eof && s->lim - s->tok < len)
  25. {
  26. if (s->tok > s->buffer)
  27. {
  28. cnt = s->tok - s->buffer;
  29. memcpy(s->buffer, s->tok, s->lim - s->tok);
  30. s->tok -= cnt;
  31. s->cur -= cnt;
  32. s->lim -= cnt;
  33. cnt = &s->buffer[BSIZE] - s->lim;
  34. }
  35. else
  36. {
  37. cnt = BSIZE;
  38. }
  39. if ((got = fread(s->lim, 1, cnt, s->fp)) != cnt)
  40. {
  41. s->eof = &s->lim[got];
  42. }
  43. s->lim += got;
  44. }
  45. if (s->eof && s->cur + len > s->eof)
  46. {
  47. return ~0; /* not enough input data */
  48. }
  49. return got;
  50. }
  51. size_t init(Scanner *s)
  52. {
  53. s->cur = s->tok = s->lim = s->buffer;
  54. s->eof = 0;
  55. s->cond = EStateNormal;
  56. s->state = -1;
  57. return fill(s, 0);
  58. }
  59. void fputl(const char *s, size_t len, FILE *stream)
  60. {
  61. while(len-- > 0)
  62. {
  63. fputc(*s++, stream);
  64. }
  65. }
  66. void scan(Scanner *s)
  67. {
  68. s->tok = s->cur;
  69. switch (s->state) {
  70. default: goto yy0;
  71. case 0: goto yyFillLabel0;
  72. case 1: goto yyFillLabel1;
  73. case 2: goto yyFillLabel2;
  74. case 3: goto yyFillLabel3;
  75. }
  76. for(;;)
  77. {
  78. s->tok = s->cur;
  79. yy0:
  80. if (s->cond < 2) {
  81. if (s->cond < 1) {
  82. goto yyc_Normal;
  83. } else {
  84. goto yyc_Comment;
  85. }
  86. } else {
  87. if (s->cond < 3) {
  88. goto yyc_Skiptoeol;
  89. } else {
  90. goto yyc_String;
  91. }
  92. }
  93. /* *********************************** */
  94. yyc_Comment:
  95. s->state = 0;
  96. if ((s->lim - s->cur) < 2) if (fill(s, 2) == ~0) break;
  97. yyFillLabel0:
  98. s->yych = *s->cur;
  99. if (s->yych != '*') goto yy4;
  100. ++s->cur;
  101. if ((s->yych = *s->cur) == '/') goto yy5;
  102. yy3:
  103. continue;
  104. yy4:
  105. s->yych = *++s->cur;
  106. goto yy3;
  107. yy5:
  108. ++s->cur;
  109. s->cond = EStateNormal;
  110. continue;
  111. /* *********************************** */
  112. yyc_Normal:
  113. s->state = 1;
  114. if ((s->lim - s->cur) < 4) if (fill(s, 4) == ~0) break;
  115. yyFillLabel1:
  116. s->yych = *s->cur;
  117. if (s->yych <= '\'') {
  118. if (s->yych == '"') goto yy13;
  119. if (s->yych <= '&') goto yy15;
  120. goto yy12;
  121. } else {
  122. if (s->yych <= '/') {
  123. if (s->yych <= '.') goto yy15;
  124. goto yy11;
  125. } else {
  126. if (s->yych != '?') goto yy15;
  127. }
  128. }
  129. s->yych = *(s->tok = ++s->cur);
  130. if (s->yych == '?') goto yy26;
  131. yy10:
  132. fprintf(stderr, "Normal\n");
  133. fputc(s->cur[-1], stdout);
  134. continue;
  135. yy11:
  136. s->yych = *++s->cur;
  137. if (s->yych == '*') goto yy24;
  138. if (s->yych == '/') goto yy22;
  139. goto yy10;
  140. yy12:
  141. s->yych = *(s->tok = ++s->cur);
  142. if (s->yych == '"') goto yy16;
  143. if (s->yych == '\\') goto yy18;
  144. goto yy10;
  145. yy13:
  146. ++s->cur;
  147. s->cond = EStateString;
  148. fprintf(stderr, "Normal\n");
  149. fputc(s->cur[-1], stdout);
  150. continue;
  151. yy15:
  152. s->yych = *++s->cur;
  153. goto yy10;
  154. yy16:
  155. s->yych = *++s->cur;
  156. if (s->yych == '\'') goto yy20;
  157. yy17:
  158. s->cur = s->tok;
  159. goto yy10;
  160. yy18:
  161. s->yych = *++s->cur;
  162. if (s->yych != '"') goto yy17;
  163. s->yych = *++s->cur;
  164. if (s->yych != '\'') goto yy17;
  165. yy20:
  166. ++s->cur;
  167. fprintf(stderr, "Normal\n");
  168. fputl("'\"'", 3, stdout);
  169. continue;
  170. yy22:
  171. ++s->cur;
  172. s->cond = EStateSkiptoeol;
  173. continue;
  174. yy24:
  175. ++s->cur;
  176. s->cond = EStateComment;
  177. continue;
  178. yy26:
  179. s->yych = *++s->cur;
  180. switch (s->yych) {
  181. case '!': goto yy41;
  182. case '\'': goto yy39;
  183. case '(': goto yy27;
  184. case ')': goto yy29;
  185. case '-': goto yy43;
  186. case '/': goto yy37;
  187. case '<': goto yy31;
  188. case '=': goto yy35;
  189. case '>': goto yy33;
  190. default: goto yy17;
  191. }
  192. yy27:
  193. ++s->cur;
  194. fprintf(stderr, "Normal\n");
  195. fputc('[', stdout);
  196. continue;
  197. yy29:
  198. ++s->cur;
  199. fprintf(stderr, "Normal\n");
  200. fputc(']', stdout);
  201. continue;
  202. yy31:
  203. ++s->cur;
  204. fprintf(stderr, "Normal\n");
  205. fputc('{', stdout);
  206. continue;
  207. yy33:
  208. ++s->cur;
  209. fprintf(stderr, "Normal\n");
  210. fputc('}', stdout);
  211. continue;
  212. yy35:
  213. ++s->cur;
  214. fprintf(stderr, "Normal\n");
  215. fputc('#', stdout);
  216. continue;
  217. yy37:
  218. ++s->cur;
  219. fprintf(stderr, "Normal\n");
  220. fputc('\\', stdout);
  221. continue;
  222. yy39:
  223. ++s->cur;
  224. fprintf(stderr, "Normal\n");
  225. fputc('^', stdout);
  226. continue;
  227. yy41:
  228. ++s->cur;
  229. fprintf(stderr, "Normal\n");
  230. fputc('|', stdout);
  231. continue;
  232. yy43:
  233. ++s->cur;
  234. fprintf(stderr, "Normal\n");
  235. fputc('~', stdout);
  236. continue;
  237. /* *********************************** */
  238. yyc_Skiptoeol:
  239. s->state = 2;
  240. if ((s->lim - s->cur) < 5) if (fill(s, 5) == ~0) break;
  241. yyFillLabel2:
  242. s->yych = *s->cur;
  243. if (s->yych <= '\r') {
  244. if (s->yych == '\n') goto yy51;
  245. if (s->yych <= '\f') goto yy53;
  246. goto yy50;
  247. } else {
  248. if (s->yych <= '?') {
  249. if (s->yych <= '>') goto yy53;
  250. } else {
  251. if (s->yych == '\\') goto yy49;
  252. goto yy53;
  253. }
  254. }
  255. s->yych = *(s->tok = ++s->cur);
  256. if (s->yych == '?') goto yy60;
  257. yy48:
  258. continue;
  259. yy49:
  260. s->yych = *(s->tok = ++s->cur);
  261. if (s->yych == '\n') goto yy58;
  262. if (s->yych == '\r') goto yy56;
  263. goto yy48;
  264. yy50:
  265. s->yych = *++s->cur;
  266. if (s->yych == '\n') goto yy54;
  267. goto yy48;
  268. yy51:
  269. ++s->cur;
  270. s->cond = EStateNormal;
  271. fprintf(stderr, "Comment\n");
  272. fputc('\n', stdout);
  273. continue;
  274. yy53:
  275. s->yych = *++s->cur;
  276. goto yy48;
  277. yy54:
  278. ++s->cur;
  279. s->cond = EStateNormal;
  280. fprintf(stderr, "Comment\n");
  281. fputc('\r', stdout);
  282. fputc('\n', stdout);
  283. continue;
  284. yy56:
  285. s->yych = *++s->cur;
  286. if (s->yych == '\n') goto yy58;
  287. yy57:
  288. s->cur = s->tok;
  289. goto yy48;
  290. yy58:
  291. ++s->cur;
  292. continue;
  293. yy60:
  294. s->yych = *++s->cur;
  295. if (s->yych != '/') goto yy57;
  296. s->yych = *++s->cur;
  297. if (s->yych == '\n') goto yy63;
  298. if (s->yych != '\r') goto yy57;
  299. s->yych = *++s->cur;
  300. if (s->yych != '\n') goto yy57;
  301. yy63:
  302. ++s->cur;
  303. continue;
  304. /* *********************************** */
  305. yyc_String:
  306. s->state = 3;
  307. if ((s->lim - s->cur) < 2) if (fill(s, 2) == ~0) break;
  308. yyFillLabel3:
  309. s->yych = *s->cur;
  310. if (s->yych == '"') goto yy69;
  311. if (s->yych != '\\') goto yy71;
  312. ++s->cur;
  313. if ((s->yych = *s->cur) != '\n') goto yy72;
  314. yy68:
  315. fprintf(stderr, "Normal\n");
  316. fputc(s->cur[-1], stdout);
  317. continue;
  318. yy69:
  319. ++s->cur;
  320. s->cond = EStateNormal;
  321. fprintf(stderr, "Normal\n");
  322. fputc(s->cur[-1], stdout);
  323. continue;
  324. yy71:
  325. s->yych = *++s->cur;
  326. goto yy68;
  327. yy72:
  328. ++s->cur;
  329. fprintf(stderr, "Normal\n");
  330. fputl((const char*)s->cur-2, 2, stdout);
  331. continue;
  332. }
  333. }
  334. int main(int argc, char **argv)
  335. {
  336. Scanner in;
  337. if (argc != 2)
  338. {
  339. fprintf(stderr, "%s <file>\n", argv[0]);
  340. return 1;;
  341. }
  342. memset((char*) &in, 0, sizeof(in));
  343. if (!strcmp(argv[1], "-"))
  344. {
  345. in.fp = stdin;
  346. }
  347. else if ((in.fp = fopen(argv[1], "r")) == NULL)
  348. {
  349. fprintf(stderr, "Cannot open file '%s'\n", argv[1]);
  350. return 1;
  351. }
  352. if (init(&in) > 0)
  353. {
  354. scan(&in);
  355. }
  356. if (in.fp != stdin)
  357. {
  358. fclose(in.fp);
  359. }
  360. return 0;
  361. }