2023-01-25 01:15:04 -05:00
|
|
|
/** @license 2022 Neil Edelman, distributed under the terms of the
|
|
|
|
[MIT License](https://opensource.org/licenses/MIT).
|
|
|
|
|
|
|
|
Scan journal entries for kjv references. */
|
|
|
|
|
|
|
|
#include "../src/journal.h"
|
2023-02-01 03:58:51 -05:00
|
|
|
#include "../src/scan_flight.h"
|
2023-01-25 01:15:04 -05:00
|
|
|
#include <inttypes.h> /* C99 */
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
/*!conditions:re2c*/
|
|
|
|
|
2023-02-01 03:58:51 -05:00
|
|
|
int scan(union date32 date, const char *const buffer,
|
2023-01-25 01:15:04 -05:00
|
|
|
struct flights *const f) {
|
|
|
|
const char *YYCURSOR, *YYMARKER, *yyt1, *yyt2, *yyt3, *s0, *s1, *t0, *t1;
|
|
|
|
enum flight_type type = Glider;
|
|
|
|
enum YYCONDTYPE condition = yycline;
|
|
|
|
size_t line = 1;
|
|
|
|
char datestr[12] = {0};
|
|
|
|
const char *why = "unexpected";
|
2023-02-01 03:58:51 -05:00
|
|
|
assert(buffer && f);
|
2023-01-25 01:15:04 -05:00
|
|
|
YYCURSOR = YYMARKER = yyt1 = buffer;
|
|
|
|
/*!re2c /**/
|
|
|
|
re2c:define:YYCTYPE = char;
|
|
|
|
re2c:yyfill:enable = 0;
|
|
|
|
re2c:define:YYGETCONDITION = "condition";
|
|
|
|
re2c:define:YYSETCONDITION = "condition = @@;";
|
|
|
|
re2c:define:YYGETCONDITION:naked = 1;
|
|
|
|
re2c:define:YYSETCONDITION:naked = 1;
|
|
|
|
|
|
|
|
unix_control = [\x01-\x08\x0b-\x1f\x7f];
|
|
|
|
ws = [ \t];
|
|
|
|
glyph = [^] \ ("\x00" | "\n" | unix_control | ws);
|
|
|
|
natural = [1-9][0-9]*;
|
|
|
|
*/
|
|
|
|
for( ; ; ) { /*!re2c /**/
|
2023-02-01 03:58:51 -05:00
|
|
|
/* Default ignore. */
|
2023-01-25 01:15:04 -05:00
|
|
|
<skip> [^\n\x00] { continue; }
|
|
|
|
<skip> "\x00" { why = "no newline at end of file"; goto catch; }
|
|
|
|
<line> "\x00" { return 1; }
|
2023-02-01 03:58:51 -05:00
|
|
|
<line, skip> "\n" => line { line++; continue; }
|
|
|
|
<line> * :=> skip
|
|
|
|
|
|
|
|
/* Except these two. */
|
2023-01-25 01:15:04 -05:00
|
|
|
<line> "[glider]" :=> glider
|
|
|
|
<line> "[flight]" :=> flight
|
2023-02-01 03:58:51 -05:00
|
|
|
|
2023-01-25 01:15:04 -05:00
|
|
|
/* "M" - Motor Car Tow
|
|
|
|
"W" - Winch
|
|
|
|
"A" - Aero Tow */
|
|
|
|
/* type; registration; launch -- landing; pic; sic;
|
|
|
|
single engine day dual; pilot; instrument simulated; actual; remarks */
|
2023-02-01 03:58:51 -05:00
|
|
|
<glider, flight> * { why = "default unrecognized"; goto catch; }
|
2023-01-25 01:15:04 -05:00
|
|
|
*/ }
|
|
|
|
assert(0); /* Never gets here. */
|
|
|
|
catch:
|
|
|
|
if(!errno) errno = EILSEQ;
|
|
|
|
date32_to_string(date, &datestr);
|
|
|
|
fprintf(stderr, "%s\n"
|
|
|
|
"%s line %zu: %s.\n", buffer, datestr, line, why);
|
|
|
|
return 0;
|
|
|
|
}
|