You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

582 lines
14KB

  1. #line 1 "control_parser.rl"
  2. #include "control_parser.h"
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <sys/socket.h>
  6. typedef control_parser_ctx context;
  7. static void extract(context *ctx, char *fpc) {
  8. gssize curpos = (fpc - ctx->buffer->str);
  9. gssize len = curpos - ctx->mark;
  10. g_string_truncate(ctx->tmp, 0);
  11. g_string_append_len(ctx->tmp, ctx->buffer->str + ctx->mark, len);
  12. ctx->mark = -1;
  13. /* printf("Read chunk '%s'\n", ctx->tmp->str); */
  14. }
  15. static double extract_double(context *ctx, char *fpc) {
  16. extract(ctx, fpc);
  17. return strtod(ctx->tmp->str, NULL);
  18. }
  19. static timestamp extract_ts(context *ctx, char *fpc) {
  20. extract(ctx, fpc);
  21. return atoi(ctx->tmp->str);
  22. }
  23. #line 144 "control_parser.rl"
  24. #line 35 "control_parser.c"
  25. static const char _control_parser_actions[] = {
  26. 0, 1, 0, 1, 1, 1, 2, 1,
  27. 3, 1, 4, 1, 5, 1, 6, 1,
  28. 7, 1, 8, 1, 9, 1, 10, 1,
  29. 11, 1, 12, 1, 13, 1, 14, 1,
  30. 15, 1, 16, 1, 17, 1, 18, 1,
  31. 19, 1, 20, 1, 21, 1, 22, 1,
  32. 23, 1, 24, 1, 25, 1, 26, 1,
  33. 27, 1, 28, 1, 29, 2, 1, 5,
  34. 2, 1, 6, 2, 1, 7, 2, 1,
  35. 8, 2, 1, 9, 2, 1, 10, 2,
  36. 1, 11, 2, 1, 12, 2, 1, 13,
  37. 2, 1, 14, 2, 1, 15, 2, 1,
  38. 16, 2, 1, 25, 2, 1, 26, 2,
  39. 3, 2
  40. };
  41. static const short _control_parser_key_offsets[] = {
  42. 0, 0, 7, 8, 11, 12, 18, 19,
  43. 22, 23, 24, 25, 28, 31, 32, 35,
  44. 38, 41, 42, 45, 48, 53, 54, 59,
  45. 64, 69, 74, 79, 85, 86, 91, 96,
  46. 101, 106, 107, 112, 117, 122, 127, 128,
  47. 133, 138, 143, 148, 149, 154, 159, 164,
  48. 169, 174, 178, 182, 186, 190, 194, 198,
  49. 202, 206, 210, 214, 218, 222, 226, 230,
  50. 234, 238, 242, 245, 248, 249, 254, 259,
  51. 264, 269, 274, 279, 284, 289, 293, 297,
  52. 301, 305, 309, 313, 317, 321
  53. };
  54. static const char _control_parser_trans_keys[] = {
  55. 66, 67, 69, 73, 75, 83, 84, 32,
  56. 32, 48, 57, 59, 66, 67, 69, 75,
  57. 83, 84, 32, 32, 48, 57, 59, 69,
  58. 32, 32, 48, 57, 32, 48, 57, 59,
  59. 32, 48, 57, 32, 48, 57, 32, 48,
  60. 57, 32, 32, 48, 57, 45, 97, 98,
  61. 45, 76, 82, 108, 114, 32, 32, 45,
  62. 46, 48, 57, 32, 45, 46, 48, 57,
  63. 32, 45, 46, 48, 57, 32, 45, 46,
  64. 48, 57, 59, 98, 99, 104, 109, 66,
  65. 67, 69, 75, 83, 84, 32, 32, 45,
  66. 46, 48, 57, 32, 45, 46, 48, 57,
  67. 32, 45, 46, 48, 57, 59, 98, 99,
  68. 104, 109, 32, 32, 45, 46, 48, 57,
  69. 32, 45, 46, 48, 57, 32, 45, 46,
  70. 48, 57, 59, 98, 99, 104, 109, 32,
  71. 32, 45, 46, 48, 57, 32, 45, 46,
  72. 48, 57, 32, 45, 46, 48, 57, 59,
  73. 98, 99, 104, 109, 32, 32, 45, 46,
  74. 48, 57, 32, 45, 46, 48, 57, 32,
  75. 45, 46, 48, 57, 32, 45, 46, 48,
  76. 57, 59, 98, 99, 104, 109, 32, 46,
  77. 48, 57, 32, 46, 48, 57, 32, 46,
  78. 48, 57, 32, 46, 48, 57, 32, 46,
  79. 48, 57, 32, 46, 48, 57, 32, 46,
  80. 48, 57, 32, 46, 48, 57, 32, 46,
  81. 48, 57, 32, 46, 48, 57, 32, 46,
  82. 48, 57, 32, 46, 48, 57, 32, 46,
  83. 48, 57, 32, 46, 48, 57, 32, 46,
  84. 48, 57, 32, 46, 48, 57, 32, 46,
  85. 48, 57, 32, 48, 57, 32, 48, 57,
  86. 32, 32, 45, 46, 48, 57, 32, 45,
  87. 46, 48, 57, 32, 45, 46, 48, 57,
  88. 32, 45, 46, 48, 57, 32, 45, 46,
  89. 48, 57, 32, 45, 46, 48, 57, 32,
  90. 45, 46, 48, 57, 32, 45, 46, 48,
  91. 57, 32, 46, 48, 57, 32, 46, 48,
  92. 57, 32, 46, 48, 57, 32, 46, 48,
  93. 57, 32, 46, 48, 57, 32, 46, 48,
  94. 57, 32, 46, 48, 57, 32, 46, 48,
  95. 57, 0
  96. };
  97. static const char _control_parser_single_lengths[] = {
  98. 0, 7, 1, 1, 1, 6, 1, 1,
  99. 1, 1, 1, 1, 1, 1, 1, 1,
  100. 1, 1, 1, 3, 5, 1, 1, 1,
  101. 1, 1, 5, 6, 1, 1, 1, 1,
  102. 5, 1, 1, 1, 1, 5, 1, 1,
  103. 1, 1, 5, 1, 1, 1, 1, 1,
  104. 5, 2, 2, 2, 2, 2, 2, 2,
  105. 2, 2, 2, 2, 2, 2, 2, 2,
  106. 2, 2, 1, 1, 1, 1, 1, 1,
  107. 1, 1, 1, 1, 1, 2, 2, 2,
  108. 2, 2, 2, 2, 2, 0
  109. };
  110. static const char _control_parser_range_lengths[] = {
  111. 0, 0, 0, 1, 0, 0, 0, 1,
  112. 0, 0, 0, 1, 1, 0, 1, 1,
  113. 1, 0, 1, 0, 0, 0, 2, 2,
  114. 2, 2, 0, 0, 0, 2, 2, 2,
  115. 0, 0, 2, 2, 2, 0, 0, 2,
  116. 2, 2, 0, 0, 2, 2, 2, 2,
  117. 0, 1, 1, 1, 1, 1, 1, 1,
  118. 1, 1, 1, 1, 1, 1, 1, 1,
  119. 1, 1, 1, 1, 0, 2, 2, 2,
  120. 2, 2, 2, 2, 2, 1, 1, 1,
  121. 1, 1, 1, 1, 1, 0
  122. };
  123. static const short _control_parser_index_offsets[] = {
  124. 0, 0, 8, 10, 13, 15, 22, 24,
  125. 27, 29, 31, 33, 36, 39, 41, 44,
  126. 47, 50, 52, 55, 59, 65, 67, 71,
  127. 75, 79, 83, 89, 96, 98, 102, 106,
  128. 110, 116, 118, 122, 126, 130, 136, 138,
  129. 142, 146, 150, 156, 158, 162, 166, 170,
  130. 174, 180, 184, 188, 192, 196, 200, 204,
  131. 208, 212, 216, 220, 224, 228, 232, 236,
  132. 240, 244, 248, 251, 254, 256, 260, 264,
  133. 268, 272, 276, 280, 284, 288, 292, 296,
  134. 300, 304, 308, 312, 316, 320
  135. };
  136. static const char _control_parser_trans_targs[] = {
  137. 2, 6, 10, 68, 6, 6, 17, 0,
  138. 3, 0, 4, 67, 0, 5, 0, 2,
  139. 6, 10, 6, 6, 17, 0, 7, 0,
  140. 8, 16, 0, 9, 0, 10, 0, 11,
  141. 0, 12, 15, 0, 13, 14, 0, 85,
  142. 0, 13, 14, 0, 12, 15, 0, 8,
  143. 16, 0, 18, 0, 19, 66, 0, 20,
  144. 20, 20, 0, 21, 21, 21, 21, 21,
  145. 0, 22, 0, 23, 65, 65, 0, 24,
  146. 64, 64, 0, 25, 63, 63, 0, 26,
  147. 62, 62, 0, 27, 28, 33, 38, 43,
  148. 0, 2, 6, 10, 6, 6, 17, 0,
  149. 29, 0, 30, 61, 61, 0, 31, 60,
  150. 60, 0, 32, 59, 59, 0, 27, 28,
  151. 33, 38, 43, 0, 34, 0, 35, 58,
  152. 58, 0, 36, 57, 57, 0, 37, 56,
  153. 56, 0, 27, 28, 33, 38, 43, 0,
  154. 39, 0, 40, 55, 55, 0, 41, 54,
  155. 54, 0, 42, 53, 53, 0, 27, 28,
  156. 33, 38, 43, 0, 44, 0, 45, 52,
  157. 52, 0, 46, 51, 51, 0, 47, 50,
  158. 50, 0, 48, 49, 49, 0, 27, 28,
  159. 33, 38, 43, 0, 48, 49, 49, 0,
  160. 47, 50, 50, 0, 46, 51, 51, 0,
  161. 45, 52, 52, 0, 42, 53, 53, 0,
  162. 41, 54, 54, 0, 40, 55, 55, 0,
  163. 37, 56, 56, 0, 36, 57, 57, 0,
  164. 35, 58, 58, 0, 32, 59, 59, 0,
  165. 31, 60, 60, 0, 30, 61, 61, 0,
  166. 26, 62, 62, 0, 25, 63, 63, 0,
  167. 24, 64, 64, 0, 23, 65, 65, 0,
  168. 19, 66, 0, 4, 67, 0, 69, 0,
  169. 70, 84, 84, 0, 71, 83, 83, 0,
  170. 72, 82, 82, 0, 73, 81, 81, 0,
  171. 74, 80, 80, 0, 75, 79, 79, 0,
  172. 76, 78, 78, 0, 4, 77, 77, 0,
  173. 4, 77, 77, 0, 76, 78, 78, 0,
  174. 75, 79, 79, 0, 74, 80, 80, 0,
  175. 73, 81, 81, 0, 72, 82, 82, 0,
  176. 71, 83, 83, 0, 70, 84, 84, 0,
  177. 0, 0
  178. };
  179. static const char _control_parser_trans_actions[] = {
  180. 0, 0, 0, 0, 0, 0, 5, 0,
  181. 0, 0, 97, 3, 0, 0, 0, 0,
  182. 0, 0, 0, 0, 5, 0, 0, 0,
  183. 97, 3, 0, 0, 0, 0, 0, 0,
  184. 0, 97, 3, 0, 100, 3, 0, 1,
  185. 0, 53, 0, 0, 51, 0, 0, 51,
  186. 0, 0, 0, 0, 97, 3, 0, 37,
  187. 35, 39, 0, 45, 41, 49, 43, 47,
  188. 0, 0, 0, 82, 3, 3, 0, 85,
  189. 3, 3, 0, 91, 3, 3, 0, 94,
  190. 3, 3, 0, 9, 9, 9, 9, 9,
  191. 0, 7, 7, 7, 7, 7, 103, 0,
  192. 0, 0, 82, 3, 3, 0, 85, 3,
  193. 3, 0, 88, 3, 3, 0, 55, 55,
  194. 55, 55, 55, 0, 0, 0, 82, 3,
  195. 3, 0, 85, 3, 3, 0, 88, 3,
  196. 3, 0, 57, 57, 57, 57, 57, 0,
  197. 0, 0, 82, 3, 3, 0, 85, 3,
  198. 3, 0, 88, 3, 3, 0, 0, 0,
  199. 0, 0, 0, 0, 0, 0, 82, 3,
  200. 3, 0, 85, 3, 3, 0, 91, 3,
  201. 3, 0, 94, 3, 3, 0, 59, 59,
  202. 59, 59, 59, 0, 33, 0, 0, 0,
  203. 31, 0, 0, 0, 27, 0, 0, 0,
  204. 25, 0, 0, 0, 29, 0, 0, 0,
  205. 27, 0, 0, 0, 25, 0, 0, 0,
  206. 29, 0, 0, 0, 27, 0, 0, 0,
  207. 25, 0, 0, 0, 29, 0, 0, 0,
  208. 27, 0, 0, 0, 25, 0, 0, 0,
  209. 33, 0, 0, 0, 31, 0, 0, 0,
  210. 27, 0, 0, 0, 25, 0, 0, 0,
  211. 51, 0, 0, 51, 0, 0, 0, 0,
  212. 61, 3, 3, 0, 64, 3, 3, 0,
  213. 0, 0, 0, 0, 67, 3, 3, 0,
  214. 70, 3, 3, 0, 73, 3, 3, 0,
  215. 76, 3, 3, 0, 79, 3, 3, 0,
  216. 23, 0, 0, 0, 21, 0, 0, 0,
  217. 19, 0, 0, 0, 17, 0, 0, 0,
  218. 15, 0, 0, 0, 0, 0, 0, 0,
  219. 13, 0, 0, 0, 11, 0, 0, 0,
  220. 0, 0
  221. };
  222. static const int control_parser_start = 1;
  223. static const int control_parser_first_final = 85;
  224. static const int control_parser_error = 0;
  225. static const int control_parser_en_main = 1;
  226. #line 147 "control_parser.rl"
  227. static int control_parser_has_error(context *ctx) {
  228. return ctx->cs == control_parser_error;
  229. }
  230. static int control_parser_is_finished(context *ctx) {
  231. return ctx->cs >= control_parser_first_final;
  232. }
  233. void control_parser_new(trial *t) {
  234. context *ctx = t->parse_ctx = g_slice_new(context);
  235. #line 260 "control_parser.c"
  236. {
  237. ( ctx->cs) = control_parser_start;
  238. }
  239. #line 159 "control_parser.rl"
  240. ctx->buffer = g_string_sized_new(0);
  241. ctx->tmp = g_string_sized_new(0);
  242. ctx->mark = -1;
  243. ctx->pos = 0;
  244. }
  245. void control_parser_reset(trial *t) {
  246. context *ctx = t->parse_ctx;
  247. #line 274 "control_parser.c"
  248. {
  249. ( ctx->cs) = control_parser_start;
  250. }
  251. #line 168 "control_parser.rl"
  252. g_string_truncate(ctx->tmp, 0);
  253. ctx->mark = -1;
  254. /* fprintf(stderr, "Parser reset\n"); */
  255. }
  256. void control_parser_free(trial *t) {
  257. g_string_free(t->parse_ctx->buffer, TRUE);
  258. g_string_free(t->parse_ctx->tmp, TRUE);
  259. g_slice_free(context, t->parse_ctx);
  260. }
  261. run_t control_parse(trial *t) {
  262. context *ctx = t->parse_ctx;
  263. gsize wehave;
  264. if (0 < (wehave = ctx->buffer->len - ctx->pos)) {
  265. char *p, *pe;
  266. p = ctx->buffer->str + ctx->pos;
  267. pe = p + wehave;
  268. /* fprintf(stderr, "Parsing '%s' (len=%zu)\n", p, wehave); */
  269. #line 302 "control_parser.c"
  270. {
  271. int _klen;
  272. unsigned int _trans;
  273. const char *_acts;
  274. unsigned int _nacts;
  275. const char *_keys;
  276. if ( p == pe )
  277. goto _test_eof;
  278. if ( ( ctx->cs) == 0 )
  279. goto _out;
  280. _resume:
  281. _keys = _control_parser_trans_keys + _control_parser_key_offsets[( ctx->cs)];
  282. _trans = _control_parser_index_offsets[( ctx->cs)];
  283. _klen = _control_parser_single_lengths[( ctx->cs)];
  284. if ( _klen > 0 ) {
  285. const char *_lower = _keys;
  286. const char *_mid;
  287. const char *_upper = _keys + _klen - 1;
  288. while (1) {
  289. if ( _upper < _lower )
  290. break;
  291. _mid = _lower + ((_upper-_lower) >> 1);
  292. if ( (*p) < *_mid )
  293. _upper = _mid - 1;
  294. else if ( (*p) > *_mid )
  295. _lower = _mid + 1;
  296. else {
  297. _trans += (_mid - _keys);
  298. goto _match;
  299. }
  300. }
  301. _keys += _klen;
  302. _trans += _klen;
  303. }
  304. _klen = _control_parser_range_lengths[( ctx->cs)];
  305. if ( _klen > 0 ) {
  306. const char *_lower = _keys;
  307. const char *_mid;
  308. const char *_upper = _keys + (_klen<<1) - 2;
  309. while (1) {
  310. if ( _upper < _lower )
  311. break;
  312. _mid = _lower + (((_upper-_lower) >> 1) & ~1);
  313. if ( (*p) < _mid[0] )
  314. _upper = _mid - 2;
  315. else if ( (*p) > _mid[1] )
  316. _lower = _mid + 2;
  317. else {
  318. _trans += ((_mid - _keys)>>1);
  319. goto _match;
  320. }
  321. }
  322. _trans += _klen;
  323. }
  324. _match:
  325. ( ctx->cs) = _control_parser_trans_targs[_trans];
  326. if ( _control_parser_trans_actions[_trans] == 0 )
  327. goto _again;
  328. _acts = _control_parser_actions + _control_parser_trans_actions[_trans];
  329. _nacts = (unsigned int) *_acts++;
  330. while ( _nacts-- > 0 )
  331. {
  332. switch ( *_acts++ )
  333. {
  334. case 0:
  335. #line 34 "control_parser.rl"
  336. {
  337. t->alive = 0;
  338. /* fprintf(stderr, "Run finished\n"); */
  339. {p++; goto _out; }
  340. }
  341. break;
  342. case 1:
  343. #line 39 "control_parser.rl"
  344. { ctx->mark = p - ctx->buffer->str; }
  345. break;
  346. case 2:
  347. #line 40 "control_parser.rl"
  348. { ctx->tm = telemetry_new(); }
  349. break;
  350. case 3:
  351. #line 41 "control_parser.rl"
  352. {
  353. g_queue_push_tail(&t->telemetry, ctx->tm);
  354. if (!t->alive) {
  355. t->vehicle.accel = ctx->tm->vehicle.accel;
  356. t->vehicle.turn = ctx->tm->vehicle.turn;
  357. gettimeofday(&t->started, NULL);
  358. /* fprintf(stderr, "New run\n"); */
  359. } else {
  360. /* fprintf(stderr, "time difference [ms]: %i\n", getcurts(t) - ctx->tm->ts); */
  361. fprintf(stderr, "Miss predict: dx=%f, dy=%f, ddir=%f, steps=%u\n",
  362. t->sim.tm.vehicle.x - t->vehicle.x,
  363. t->sim.tm.vehicle.y - t->vehicle.y,
  364. t->sim.tm.vehicle.dir - t->vehicle.dir,
  365. t->sim.steps);
  366. }
  367. /* Reset simulation */
  368. t->sim.tm.ts = ctx->tm->ts;
  369. t->sim.tm.vehicle = ctx->tm->vehicle;
  370. g_array_set_size(t->sim.tm.objects, 0);
  371. g_array_append_vals(t->sim.tm.objects, ctx->tm->objects->data, ctx->tm->objects->len);
  372. t->sim.steps = 0;
  373. t->last_ts = ctx->tm->ts;
  374. ctx->tm = NULL;
  375. t->alive = 1;
  376. }
  377. break;
  378. case 4:
  379. #line 67 "control_parser.rl"
  380. {
  381. ctx->tm->ts = ctx->ts;
  382. ctx->tm->vehicle.x = ctx->x;
  383. ctx->tm->vehicle.y = ctx->y;
  384. ctx->tm->vehicle.dir = ctx->dir;
  385. ctx->tm->vehicle.speed = ctx->speed;
  386. t->vehicle.x = ctx->x;
  387. t->vehicle.y = ctx->y;
  388. t->vehicle.dir = ctx->dir;
  389. t->vehicle.speed = ctx->speed;
  390. /* printf("Vehicle at %f / %f\n", ctx->x, ctx->y); */
  391. }
  392. break;
  393. case 5:
  394. #line 84 "control_parser.rl"
  395. { t->map.dx = extract_double(ctx, p); }
  396. break;
  397. case 6:
  398. #line 85 "control_parser.rl"
  399. { t->map.dy = extract_double(ctx, p); }
  400. break;
  401. case 7:
  402. #line 86 "control_parser.rl"
  403. { t->map.min_sensor = extract_double(ctx, p); }
  404. break;
  405. case 8:
  406. #line 87 "control_parser.rl"
  407. { t->map.max_sensor = extract_double(ctx, p); }
  408. break;
  409. case 9:
  410. #line 88 "control_parser.rl"
  411. { t->map.max_speed = extract_double(ctx, p); }
  412. break;
  413. case 10:
  414. #line 89 "control_parser.rl"
  415. { t->map.max_turn = extract_double(ctx, p); }
  416. break;
  417. case 11:
  418. #line 90 "control_parser.rl"
  419. { t->map.max_hard_turn = extract_double(ctx, p); }
  420. break;
  421. case 12:
  422. #line 94 "control_parser.rl"
  423. { ctx->x = extract_double(ctx, p); }
  424. break;
  425. case 13:
  426. #line 95 "control_parser.rl"
  427. { ctx->y = extract_double(ctx, p); }
  428. break;
  429. case 14:
  430. #line 96 "control_parser.rl"
  431. { ctx->r = extract_double(ctx, p); }
  432. break;
  433. case 15:
  434. #line 97 "control_parser.rl"
  435. { ctx->dir = extract_double(ctx, p); }
  436. break;
  437. case 16:
  438. #line 98 "control_parser.rl"
  439. { ctx->speed = extract_double(ctx, p); }
  440. break;
  441. case 17:
  442. #line 100 "control_parser.rl"
  443. { ctx->tm->vehicle.accel = ACCEL; }
  444. break;
  445. case 18:
  446. #line 101 "control_parser.rl"
  447. { ctx->tm->vehicle.accel = ROLL; }
  448. break;
  449. case 19:
  450. #line 102 "control_parser.rl"
  451. { ctx->tm->vehicle.accel = BRAKE; }
  452. break;
  453. case 20:
  454. #line 104 "control_parser.rl"
  455. { ctx->tm->vehicle.turn = TURN_HARD_LEFT; }
  456. break;
  457. case 21:
  458. #line 105 "control_parser.rl"
  459. { ctx->tm->vehicle.turn = TURN_LEFT; }
  460. break;
  461. case 22:
  462. #line 106 "control_parser.rl"
  463. { ctx->tm->vehicle.turn = TURN_STRAIGHT; }
  464. break;
  465. case 23:
  466. #line 107 "control_parser.rl"
  467. { ctx->tm->vehicle.turn = TURN_RIGHT; }
  468. break;
  469. case 24:
  470. #line 108 "control_parser.rl"
  471. { ctx->tm->vehicle.turn = TURN_HARD_RIGHT; }
  472. break;
  473. case 25:
  474. #line 110 "control_parser.rl"
  475. { ctx->ts = extract_ts(ctx, p); }
  476. break;
  477. case 26:
  478. #line 111 "control_parser.rl"
  479. { printf("Score %u\n", extract_ts(ctx, p)); }
  480. break;
  481. case 27:
  482. #line 113 "control_parser.rl"
  483. {
  484. object *o = object_new(BOLDER, ctx->x, ctx->y, ctx->r, 0, 0);
  485. /* g_array_append_vals(ctx->tm->objects, o, 1); */
  486. g_hash_table_replace(t->map.solid_objects, o, o);
  487. }
  488. break;
  489. case 28:
  490. #line 118 "control_parser.rl"
  491. {
  492. object *o = object_new(CRATER, ctx->x, ctx->y, ctx->r, 0, 0);
  493. /* g_array_append_vals(ctx->tm->objects, o, 1); */
  494. g_hash_table_replace(t->map.solid_objects, o, o);
  495. }
  496. break;
  497. case 29:
  498. #line 124 "control_parser.rl"
  499. {
  500. object o = { MARTIAN, ctx->x, ctx->y, MARTIAN_RADIUS, ctx->dir, ctx->speed };
  501. g_array_append_val(ctx->tm->objects, o);
  502. }
  503. break;
  504. #line 546 "control_parser.c"
  505. }
  506. }
  507. _again:
  508. if ( ( ctx->cs) == 0 )
  509. goto _out;
  510. if ( ++p != pe )
  511. goto _resume;
  512. _test_eof: {}
  513. _out: {}
  514. }
  515. #line 191 "control_parser.rl"
  516. ctx->pos = p - ctx->buffer->str;
  517. if (ctx->mark == -1) {
  518. g_string_erase(ctx->buffer, 0, ctx->pos);
  519. ctx->pos = 0;
  520. } else if (ctx->mark) {
  521. g_string_erase(ctx->buffer, 0, ctx->mark);
  522. ctx->pos -= ctx->mark;
  523. ctx->mark = 0;
  524. }
  525. } else {
  526. fprintf(stderr, "No data to parse\n");
  527. }
  528. if (control_parser_has_error(ctx)) {
  529. fprintf(stderr, "Parse error: '%s'\n", ctx->buffer->str + ctx->pos);
  530. shutdown(t->socket, SHUT_RDWR);
  531. close(t->socket);
  532. exit(126);
  533. return RUN_ERROR;
  534. }
  535. if (control_parser_is_finished(ctx)) return RUN_DONE;
  536. return RUN_GO_ON;
  537. }