-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreactd_conf.l.m4
109 lines (91 loc) · 2.7 KB
/
reactd_conf.l.m4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
* This is processed through m4 to generate a flex analyzer to parse config files
*
* Change the default characters for m4 quotes and disable comments
* so that they don't interfere with bison:
* changequote(「,」) changecom
*/
%{
#include "reactd_conf.tab.h"
#include "log.h"
#include "debug.h"
void yyerror(const char *s);
;
%}
%option noyywrap noinput nounput yylineno
%%
#.* ; // ignore comments
ifdef(DEBUG,「
[ \t\n]+ { printf("newline\n");
」,「
[ \t\n]+
」)
\. { return DOT; }
[\{\},=] { return yytext[0]; } // return single characters that are used in the config file
[1-9][0-9]* { yylval.ival = atoi(yytext); return POSITIVE_INT; }
version { return VERSION_KEY; }
options { return OPTIONS_KEY; }
pidfile { return PIDFILE_KEY; }
logdst { return LOGDST_KEY; }
logfile { return LOGFILE_KEY; }
logprefix { return LOGPREFIX_KEY; }
loglevel { return LOGLEVEL_KEY; }
(syslog|file|stdout|stderr) {
yylval.ival = logdst_int(yytext);
return LOGDST;
}
(emergency|emerg|alert|critical|crit|error|err|warning|warn|notice|info|debug) {
yylval.ival = loglevel_int(yytext);
return LOGLEVEL;
}
ifdef(「SYSTEMD」,「
journal { return JOURNAL_KEY; }
」)
command { return COMMAND_KEY; }
key { return KEY_KEY; }
trigger { return TRIGGER_KEY; }
reset { return RESET_KEY; }
timeout { return TIMEOUT_KEY; }
" in " { return IN_KEY; }
[1-9][0-9]*[ \t]+(second|minute|hour|day)s? {
int num;
char unit[7];
sscanf(yytext, "%d %s", &num, unit);
if (!strncasecmp(unit, "second", 6)) {
yylval.ival = num;
} else if (!strncasecmp(unit, "minute", 6)) {
yylval.ival = num * 60;
} else if (!strncasecmp(unit, "hour", 4)) {
yylval.ival = num * 60 * 60;
} else {
yylval.ival = num * 60 * 60 * 24;
}
return TIMEPERIOD;
}
\/([^\/]|\\\/)+\/ { // regex
// we have to copy because we can't rely on yytext not changing underneath us:
yylval.sval = strndup(yytext+1, strlen(yytext)-2);
return REGEX;
}
\"([^\"]|\\\")*\" { // quoted string
// we have to copy because we can't rely on yytext not changing underneath us:
yylval.sval = strndup(yytext+1, strlen(yytext)-2);
return STRING;
}
(\\[^\n][^ ="\\=\{\}\n]*|[^ ="\\=\{\}\n]([^ ="\\=\{\}\n]|\\[ ="\\=\{\}])*) { // unquoted string
yylval.sval = strdup(yytext);
return STRING;
}
<<EOF>> {
dprint("EOF of config file");
yy_delete_buffer(YY_CURRENT_BUFFER);
yyterminate();
}
. {
fprintf(stderr, "Unrecognized token in line %u: ->%s<-\n", yylineno, yytext);
yyterminate();
}
%%
void yyerror(const char *s) {
printf("Error parsing line %d: %s\n-->\n%s\n<--", yylineno, s, yytext);
}