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