]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/amd/amd/conf_parse.y
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / amd / amd / conf_parse.y
1 /*
2  * Copyright (c) 1997-2006 Erez Zadok
3  * Copyright (c) 1989 Jan-Simon Pendry
4  * Copyright (c) 1989 Imperial College of Science, Technology & Medicine
5  * Copyright (c) 1989 The Regents of the University of California.
6  * All rights reserved.
7  *
8  * This code is derived from software contributed to Berkeley by
9  * Jan-Simon Pendry at Imperial College, London.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgment:
21  *      This product includes software developed by the University of
22  *      California, Berkeley and its contributors.
23  * 4. Neither the name of the University nor the names of its contributors
24  *    may be used to endorse or promote products derived from this software
25  *    without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37  * SUCH DAMAGE.
38  *
39  *
40  * File: am-utils/amd/conf_parse.y
41  *
42  */
43
44 %{
45 #ifdef HAVE_CONFIG_H
46 # include <config.h>
47 #endif /* HAVE_CONFIG_H */
48 #include <am_defs.h>
49 #include <amd.h>
50
51 extern char *yytext;
52 extern int ayylineno;
53 extern int yylex(void);
54
55 static int yyerror(const char *s);
56 static int retval;
57 static char *header_section = NULL; /* start with no header section */
58
59 #define YYDEBUG 1
60
61 #define PARSE_DEBUG 0
62
63 #if PARSE_DEBUG
64 # define dprintf(f,s) fprintf(stderr, (f), ayylineno, (s))
65 # define amu_return(v)
66 #else /* not PARSE_DEBUG */
67 # define dprintf(f,s)
68 # define amu_return(v) return((v))
69 #endif /* not PARSE_DEBUG */
70
71 %}
72
73 %union {
74 char *strtype;
75 }
76
77 %token LEFT_BRACKET RIGHT_BRACKET EQUAL
78 %token NEWLINE
79 %token <strtype> NONWS_STRING
80 %token <strtype> NONWSEQ_STRING
81 %token <strtype> QUOTED_NONWSEQ_STRING
82
83 %start file
84 %%
85
86 /****************************************************************************/
87 file            : { yydebug = PARSE_DEBUG; } newlines map_sections
88                 | { yydebug = PARSE_DEBUG; } map_sections
89                 ;
90
91 newlines        : NEWLINE
92                 | NEWLINE newlines
93                 ;
94
95 map_sections    : map_section
96                 | map_section map_sections
97                 ;
98
99 map_section     : sec_header kv_pairs
100                 ;
101
102 sec_header      : LEFT_BRACKET NONWS_STRING RIGHT_BRACKET NEWLINE
103                 {
104                   if (yydebug)
105                     fprintf(stderr, "sec_header1 = \"%s\"\n", $2);
106                   header_section = $2;
107                 }
108                 ;
109
110 kv_pairs        : kv_pair
111                 | kv_pair kv_pairs
112                 ;
113
114 kv_pair         : NONWS_STRING EQUAL NONWS_STRING NEWLINE
115                 {
116                   if (yydebug)
117                     fprintf(stderr,"parse1: key=\"%s\", val=\"%s\"\n", $1, $3);
118                   retval = set_conf_kv(header_section, $1, $3);
119                   if (retval != 0) {
120                     yyerror("syntax error");
121                     YYABORT;
122                   }
123                 }
124                 | NONWS_STRING EQUAL NONWSEQ_STRING NEWLINE
125                 {
126                   if (yydebug)
127                     fprintf(stderr,"parse2: key=\"%s\", val=\"%s\"\n", $1, $3);
128                   retval = set_conf_kv(header_section, $1, $3);
129                   if (retval != 0) {
130                     yyerror("syntax error");
131                     YYABORT;
132                   }
133                 }
134                 | NONWS_STRING EQUAL QUOTED_NONWSEQ_STRING NEWLINE
135                 {
136                   if (yydebug)
137                     fprintf(stderr,"parse3: key=\"%s\", val=\"%s\"\n", $1, $3);
138                   retval = set_conf_kv(header_section, $1, $3);
139                   if (retval != 0) {
140                     yyerror("syntax error");
141                     YYABORT;
142                   }
143                 }
144                 | NEWLINE
145                 ;
146
147 /****************************************************************************/
148 %%
149
150 static int
151 yyerror(const char *s)
152 {
153   fprintf(stderr, "AMDCONF: %s on line %d (section %s)\n",
154           s, ayylineno,
155           (header_section ? header_section : "null"));
156   exit(1);
157   return 1;     /* to full compilers that insist on a return statement */
158 }