]>
Commit | Line | Data |
---|---|---|
86e4d161 | 1 | %{ |
86e4d161 MS |
2 | |
3 | #include <err.h> | |
4 | #include <string.h> | |
b73b879e | 5 | #include <syslog.h> |
86e4d161 MS |
6 | #include "dma.h" |
7 | ||
8 | extern int yylineno; | |
65bec70e | 9 | static void yyerror(const char *); |
86e4d161 | 10 | int yywrap(void); |
65bec70e | 11 | int yylex(void); |
86e4d161 | 12 | |
65bec70e | 13 | static void |
86e4d161 MS |
14 | yyerror(const char *msg) |
15 | { | |
b73b879e SS |
16 | /** |
17 | * Because we do error '\n' below, we need to report the error | |
18 | * one line above of what yylineno points to. | |
19 | */ | |
20 | syslog(LOG_CRIT, "aliases line %d: %s", yylineno - 1, msg); | |
21 | fprintf(stderr, "aliases line %d: %s\n", yylineno - 1, msg); | |
86e4d161 MS |
22 | } |
23 | ||
24 | int | |
25 | yywrap(void) | |
26 | { | |
27 | return (1); | |
28 | } | |
29 | ||
30 | %} | |
31 | ||
32 | %union { | |
33 | char *ident; | |
34 | struct stritem *strit; | |
35 | struct alias *alias; | |
36 | } | |
37 | ||
38 | %token <ident> T_IDENT | |
39 | %token T_ERROR | |
40 | %token T_EOF 0 | |
41 | ||
42 | %type <strit> dests | |
43 | %type <alias> alias aliases | |
44 | ||
45 | %% | |
46 | ||
47 | start : aliases T_EOF | |
48 | { | |
49 | LIST_FIRST(&aliases) = $1; | |
50 | } | |
51 | ||
52 | aliases : /* EMPTY */ | |
53 | { | |
54 | $$ = NULL; | |
55 | } | |
56 | | alias aliases | |
57 | { | |
58 | if ($2 != NULL && $1 != NULL) | |
59 | LIST_INSERT_AFTER($2, $1, next); | |
60 | else if ($2 == NULL) | |
61 | $2 = $1; | |
62 | $$ = $2; | |
63 | } | |
64 | ; | |
65 | ||
66 | alias : T_IDENT ':' dests '\n' | |
67 | { | |
68 | struct alias *al; | |
69 | ||
70 | if ($1 == NULL) | |
71 | YYABORT; | |
72 | al = calloc(1, sizeof(*al)); | |
73 | if (al == NULL) | |
74 | YYABORT; | |
75 | al->alias = $1; | |
76 | SLIST_FIRST(&al->dests) = $3; | |
77 | $$ = al; | |
78 | } | |
79 | | error '\n' | |
80 | { | |
b73b879e | 81 | YYABORT; |
86e4d161 MS |
82 | } |
83 | ; | |
84 | ||
85 | dests : T_IDENT | |
86 | { | |
87 | struct stritem *it; | |
88 | ||
89 | if ($1 == NULL) | |
90 | YYABORT; | |
91 | it = calloc(1, sizeof(*it)); | |
92 | if (it == NULL) | |
93 | YYABORT; | |
94 | it->str = $1; | |
95 | $$ = it; | |
96 | } | |
97 | | T_IDENT ',' dests | |
98 | { | |
99 | struct stritem *it; | |
100 | ||
101 | if ($1 == NULL) | |
102 | YYABORT; | |
103 | it = calloc(1, sizeof(*it)); | |
104 | if (it == NULL) | |
105 | YYABORT; | |
106 | it->str = $1; | |
107 | SLIST_NEXT(it, next) = $3; | |
108 | $$ = it; | |
109 | } | |
110 | ; | |
111 | ||
112 | %% |