Merge from vendor branch LIBARCHIVE:
[dragonfly.git] / libexec / dma / aliases_parse.y
1 %{
2 /* $DragonFly: src/libexec/dma/aliases_parse.y,v 1.2 2008/02/03 11:06:17 matthias Exp $ */
3
4 #include <err.h>
5 #include <string.h>
6 #include "dma.h"
7
8 extern int yylineno;
9 static void yyerror(const char *);
10 int yywrap(void);
11 int yylex(void);
12
13 static void
14 yyerror(const char *msg)
15 {
16         warnx("aliases line %d: %s", yylineno, msg);
17 }
18
19 int
20 yywrap(void)
21 {
22         return (1);
23 }
24
25 %}
26
27 %union {
28         char *ident;
29         struct stritem *strit;
30         struct alias *alias;
31 }
32
33 %token <ident> T_IDENT
34 %token T_ERROR
35 %token T_EOF 0
36
37 %type <strit> dests
38 %type <alias> alias aliases
39
40 %%
41
42 start   : aliases T_EOF
43                 {
44                         LIST_FIRST(&aliases) = $1;
45                 }
46
47 aliases : /* EMPTY */
48                 {
49                         $$ = NULL;
50                 }
51         | alias aliases
52                 {
53                         if ($2 != NULL && $1 != NULL)
54                                 LIST_INSERT_AFTER($2, $1, next);
55                         else if ($2 == NULL)
56                                 $2 = $1;
57                         $$ = $2;
58                 }
59         ;
60
61 alias   : T_IDENT ':' dests '\n'
62                 {
63                         struct alias *al;
64
65                         if ($1 == NULL)
66                                 YYABORT;
67                         al = calloc(1, sizeof(*al));
68                         if (al == NULL)
69                                 YYABORT;
70                         al->alias = $1;
71                         SLIST_FIRST(&al->dests) = $3;
72                         $$ = al;
73                 }
74         | error '\n'
75                 {
76                         yyerrok;
77                         $$ = NULL;
78                 }
79         ;
80
81 dests   : T_IDENT
82                 {
83                         struct stritem *it;
84
85                         if ($1 == NULL)
86                                 YYABORT;
87                         it = calloc(1, sizeof(*it));
88                         if (it == NULL)
89                                 YYABORT;
90                         it->str = $1;
91                         $$ = it;
92                 }
93         | T_IDENT ',' dests
94                 {
95                         struct stritem *it;
96
97                         if ($1 == NULL)
98                                 YYABORT;
99                         it = calloc(1, sizeof(*it));
100                         if (it == NULL)
101                                 YYABORT;
102                         it->str = $1;
103                         SLIST_NEXT(it, next) = $3;
104                         $$ = it;
105                 }
106         ;
107
108 %%