un.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /* A recursive-descent parser generated by peg 0.1.1 */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #define YYRULECOUNT 1
  6. #include <unistd.h>
  7. #ifndef YY_VARIABLE
  8. #define YY_VARIABLE(T) static T
  9. #endif
  10. #ifndef YY_LOCAL
  11. #define YY_LOCAL(T) static T
  12. #endif
  13. #ifndef YY_ACTION
  14. #define YY_ACTION(T) static T
  15. #endif
  16. #ifndef YY_RULE
  17. #define YY_RULE(T) static T
  18. #endif
  19. #ifndef YY_PARSE
  20. #define YY_PARSE(T) T
  21. #endif
  22. #ifndef YYPARSE
  23. #define YYPARSE yyparse
  24. #endif
  25. #ifndef YYPARSEFROM
  26. #define YYPARSEFROM yyparsefrom
  27. #endif
  28. #ifndef YY_INPUT
  29. #define YY_INPUT(buf, result, max_size) \
  30. { \
  31. int yyc= getchar(); \
  32. result= (EOF == yyc) ? 0 : (*(buf)= yyc, 1); \
  33. yyprintf((stderr, "<%c>", yyc)); \
  34. }
  35. #endif
  36. #ifndef YY_BEGIN
  37. #define YY_BEGIN ( yybegin= yypos, 1)
  38. #endif
  39. #ifndef YY_END
  40. #define YY_END ( yyend= yypos, 1)
  41. #endif
  42. #ifdef YY_DEBUG
  43. # define yyprintf(args) fprintf args
  44. #else
  45. # define yyprintf(args)
  46. #endif
  47. #ifndef YYSTYPE
  48. #define YYSTYPE int
  49. #endif
  50. #ifndef YY_PART
  51. typedef void (*yyaction)(char *yytext, int yyleng);
  52. typedef struct _yythunk { int begin, end; yyaction action; struct _yythunk *next; } yythunk;
  53. YY_VARIABLE(char * ) yybuf= 0;
  54. YY_VARIABLE(int ) yybuflen= 0;
  55. YY_VARIABLE(int ) yypos= 0;
  56. YY_VARIABLE(int ) yylimit= 0;
  57. YY_VARIABLE(char * ) yytext= 0;
  58. YY_VARIABLE(int ) yytextlen= 0;
  59. YY_VARIABLE(int ) yybegin= 0;
  60. YY_VARIABLE(int ) yyend= 0;
  61. YY_VARIABLE(int ) yytextmax= 0;
  62. YY_VARIABLE(yythunk *) yythunks= 0;
  63. YY_VARIABLE(int ) yythunkslen= 0;
  64. YY_VARIABLE(int ) yythunkpos= 0;
  65. YY_VARIABLE(YYSTYPE ) yy;
  66. YY_VARIABLE(YYSTYPE *) yyval= 0;
  67. YY_VARIABLE(YYSTYPE *) yyvals= 0;
  68. YY_VARIABLE(int ) yyvalslen= 0;
  69. YY_LOCAL(int) yyrefill(void)
  70. {
  71. int yyn;
  72. while (yybuflen - yypos < 512)
  73. {
  74. yybuflen *= 2;
  75. yybuf= realloc(yybuf, yybuflen);
  76. }
  77. YY_INPUT((yybuf + yypos), yyn, (yybuflen - yypos));
  78. if (!yyn) return 0;
  79. yylimit += yyn;
  80. return 1;
  81. }
  82. YY_LOCAL(int) yymatchDot(void)
  83. {
  84. if (yypos >= yylimit && !yyrefill()) return 0;
  85. ++yypos;
  86. return 1;
  87. }
  88. YY_LOCAL(int) yymatchChar(int c)
  89. {
  90. if (yypos >= yylimit && !yyrefill()) return 0;
  91. if (yybuf[yypos] == c)
  92. {
  93. ++yypos;
  94. yyprintf((stderr, " ok yymatchChar(%c) @ %s\n", c, yybuf+yypos));
  95. return 1;
  96. }
  97. yyprintf((stderr, " fail yymatchChar(%c) @ %s\n", c, yybuf+yypos));
  98. return 0;
  99. }
  100. YY_LOCAL(int) yymatchString(char *s)
  101. {
  102. int yysav= yypos;
  103. while (*s)
  104. {
  105. if (yypos >= yylimit && !yyrefill()) return 0;
  106. if (yybuf[yypos] != *s)
  107. {
  108. yypos= yysav;
  109. return 0;
  110. }
  111. ++s;
  112. ++yypos;
  113. }
  114. return 1;
  115. }
  116. YY_LOCAL(int) yymatchClass(unsigned char *bits)
  117. {
  118. int c;
  119. if (yypos >= yylimit && !yyrefill()) return 0;
  120. c= yybuf[yypos];
  121. if (bits[c >> 3] & (1 << (c & 7)))
  122. {
  123. ++yypos;
  124. yyprintf((stderr, " ok yymatchClass @ %s\n", yybuf+yypos));
  125. return 1;
  126. }
  127. yyprintf((stderr, " fail yymatchClass @ %s\n", yybuf+yypos));
  128. return 0;
  129. }
  130. YY_LOCAL(void) yyDo(yyaction action, int begin, int end)
  131. {
  132. while (yythunkpos >= yythunkslen)
  133. {
  134. yythunkslen *= 2;
  135. yythunks= realloc(yythunks, sizeof(yythunk) * yythunkslen);
  136. }
  137. yythunks[yythunkpos].begin= begin;
  138. yythunks[yythunkpos].end= end;
  139. yythunks[yythunkpos].action= action;
  140. ++yythunkpos;
  141. }
  142. YY_LOCAL(int) yyText(int begin, int end)
  143. {
  144. int yyleng= end - begin;
  145. if (yyleng <= 0)
  146. yyleng= 0;
  147. else
  148. {
  149. while (yytextlen < (yyleng - 1))
  150. {
  151. yytextlen *= 2;
  152. yytext= realloc(yytext, yytextlen);
  153. }
  154. memcpy(yytext, yybuf + begin, yyleng);
  155. }
  156. yytext[yyleng]= '\0';
  157. return yyleng;
  158. }
  159. YY_LOCAL(void) yyDone(void)
  160. {
  161. int pos;
  162. for (pos= 0; pos < yythunkpos; ++pos)
  163. {
  164. yythunk *thunk= &yythunks[pos];
  165. int yyleng= thunk->end ? yyText(thunk->begin, thunk->end) : thunk->begin;
  166. yyprintf((stderr, "DO [%d] %p %s\n", pos, thunk->action, yytext));
  167. thunk->action(yytext, yyleng);
  168. }
  169. yythunkpos= 0;
  170. }
  171. YY_LOCAL(void) yyCommit()
  172. {
  173. if ((yylimit -= yypos))
  174. {
  175. memmove(yybuf, yybuf + yypos, yylimit);
  176. }
  177. yybegin -= yypos;
  178. yyend -= yypos;
  179. yypos= yythunkpos= 0;
  180. }
  181. YY_LOCAL(int) yyAccept(int tp0)
  182. {
  183. if (tp0)
  184. {
  185. fprintf(stderr, "accept denied at %d\n", tp0);
  186. return 0;
  187. }
  188. else
  189. {
  190. yyDone();
  191. yyCommit();
  192. }
  193. return 1;
  194. }
  195. YY_LOCAL(void) yyPush(char *text, int count) { if (text) { } yyval += count; }
  196. YY_LOCAL(void) yyPop(char *text, int count) { if (text) { } yyval -= count; }
  197. YY_LOCAL(void) yySet(char *text, int count) { if (text) { } yyval[count]= yy; }
  198. #endif /* YY_PART */
  199. #define YYACCEPT yyAccept(yythunkpos0)
  200. YY_RULE(int) yy_start(); /* 1 */
  201. YY_ACTION(void) yy_2_start(char *yytext, int yyleng)
  202. { if(yytext) { } if (yyleng) { }
  203. yyprintf((stderr, "do yy_2_start\n"));
  204. putchar(yytext[0]); ;
  205. }
  206. YY_ACTION(void) yy_1_start(char *yytext, int yyleng)
  207. { if(yytext) { } if (yyleng) { }
  208. yyprintf((stderr, "do yy_1_start\n"));
  209. printf("%s", getlogin()); ;
  210. }
  211. YY_RULE(int) yy_start()
  212. { int yypos0= yypos, yythunkpos0= yythunkpos;
  213. yyprintf((stderr, "%s\n", "start"));
  214. { int yypos2= yypos, yythunkpos2= yythunkpos; if (!yymatchString("username")) goto l3; yyDo(yy_1_start, yybegin, yyend); goto l2;
  215. l3:; yypos= yypos2; yythunkpos= yythunkpos2; yyText(yybegin, yyend); if (!(YY_BEGIN)) goto l1; if (!yymatchDot()) goto l1; yyText(yybegin, yyend); if (!(YY_END)) goto l1; yyDo(yy_2_start, yybegin, yyend);
  216. }
  217. l2:;
  218. yyprintf((stderr, " ok %s @ %s\n", "start", yybuf+yypos));
  219. return 1;
  220. l1:; yypos= yypos0; yythunkpos= yythunkpos0;
  221. yyprintf((stderr, " fail %s @ %s\n", "start", yybuf+yypos));
  222. return 0;
  223. }
  224. #ifndef YY_PART
  225. typedef int (*yyrule)();
  226. YY_PARSE(int) YYPARSEFROM(yyrule yystart)
  227. {
  228. int yyok;
  229. if (!yybuflen)
  230. {
  231. yybuflen= 1024;
  232. yybuf= malloc(yybuflen);
  233. yytextlen= 1024;
  234. yytext= malloc(yytextlen);
  235. yythunkslen= 32;
  236. yythunks= malloc(sizeof(yythunk) * yythunkslen);
  237. yyvalslen= 32;
  238. yyvals= malloc(sizeof(YYSTYPE) * yyvalslen);
  239. yybegin= yyend= yypos= yylimit= yythunkpos= 0;
  240. }
  241. yybegin= yyend= yypos;
  242. yythunkpos= 0;
  243. yyval= yyvals;
  244. yyok= yystart();
  245. if (yyok) yyDone();
  246. yyCommit();
  247. return yyok;
  248. (void)yyrefill;
  249. (void)yymatchDot;
  250. (void)yymatchChar;
  251. (void)yymatchString;
  252. (void)yymatchClass;
  253. (void)yyDo;
  254. (void)yyText;
  255. (void)yyDone;
  256. (void)yyCommit;
  257. (void)yyAccept;
  258. (void)yyPush;
  259. (void)yyPop;
  260. (void)yySet;
  261. (void)yytextmax;
  262. }
  263. YY_PARSE(int) YYPARSE(void)
  264. {
  265. return YYPARSEFROM(yy_start);
  266. }
  267. #endif
  268. int main()
  269. {
  270. while (yyparse());
  271. return 0;
  272. }