HAMMER 2.0:01 - MFC HAMMER 2.1:01
[dragonfly.git] / libexec / dma / aliases_parse.y
blob489085728789a16248b0f26003bb2a5d3fc7381f
1 %{
2 /* $DragonFly: src/libexec/dma/aliases_parse.y,v 1.2 2008/02/03 11:06:17 matthias Exp $ */
4 #include <err.h>
5 #include <string.h>
6 #include "dma.h"
8 extern int yylineno;
9 static void yyerror(const char *);
10 int yywrap(void);
11 int yylex(void);
13 static void
14 yyerror(const char *msg)
16 warnx("aliases line %d: %s", yylineno, msg);
19 int
20 yywrap(void)
22 return (1);
27 %union {
28 char *ident;
29 struct stritem *strit;
30 struct alias *alias;
33 %token <ident> T_IDENT
34 %token T_ERROR
35 %token T_EOF 0
37 %type <strit> dests
38 %type <alias> alias aliases
42 start : aliases T_EOF
44 LIST_FIRST(&aliases) = $1;
47 aliases : /* EMPTY */
49 $$ = NULL;
51 | alias aliases
53 if ($2 != NULL && $1 != NULL)
54 LIST_INSERT_AFTER($2, $1, next);
55 else if ($2 == NULL)
56 $2 = $1;
57 $$ = $2;
61 alias : T_IDENT ':' dests '\n'
63 struct alias *al;
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;
74 | error '\n'
76 yyerrok;
77 $$ = NULL;
81 dests : T_IDENT
83 struct stritem *it;
85 if ($1 == NULL)
86 YYABORT;
87 it = calloc(1, sizeof(*it));
88 if (it == NULL)
89 YYABORT;
90 it->str = $1;
91 $$ = it;
93 | T_IDENT ',' dests
95 struct stritem *it;
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;