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