4
* isdn4linux options file format parser
6
* This file is part of ANT (Ant is Not a Telephone)
8
* Copyright 2002, 2003 Roland Stigge
10
* ANT is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* (at your option) any later version.
15
* ANT is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
20
* You should have received a copy of the GNU General Public License
21
* along with ANT; if not, write to the Free Software
22
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
/* regular GNU system includes */
30
/* own header files */
36
typedef struct isdn_list_store_t isdn_list_store_t;
37
struct isdn_list_store_t {
38
isdn_tree_node_t* list; /* list itself (start) */
39
isdn_tree_node_t** last; /* pointer to pointer to last element */
40
/* (which in turn should always be NULL) */
44
void isdn_error(const char *message);
47
/* types of semantic values */
50
isdn_list_store_t list;
51
isdn_tree_node_t* element;
54
/* terminal symbols */
55
%token <s> ISDN_TOKEN_NAME
56
%token <s> ISDN_TOKEN_VALUE
58
/* non terminal symbols */
60
%type <list> sections;
61
%type <element> section;
63
%type <element> entry;
68
config : entries sections
70
if ($1.list == NULL) {
81
sections : { $$.list = NULL; $$.last = NULL; }
84
if ($1.list == NULL) {
95
section : '[' ISDN_TOKEN_NAME ']' entries
98
(isdn_tree_node_t*) malloc(sizeof(isdn_tree_node_t))))
100
fprintf(stderr, "Error: Out of memory.\n");
103
$$->type = ISDN_NODE_TYPE_SECTION;
105
$$->content.section = $4.list;
106
/* finally: only list needed */
111
entries : { $$.list = NULL; $$.last = NULL; }
114
if ($1.list == NULL) {
125
fprintf(stderr, "Error region from %d:%d up to %d:%d.\n",
126
@2.first_line, @2.first_column,
127
@2.last_line, @2.last_column);
132
entry : ISDN_TOKEN_NAME '=' value
135
(isdn_tree_node_t*) malloc(sizeof(isdn_tree_node_t))))
137
fprintf(stderr, "Error: Out of memory.\n");
140
$$->type = ISDN_NODE_TYPE_ENTRY;
142
$$->content.value = $3;
145
| ISDN_TOKEN_NAME '=' '{' config '}'
148
(isdn_tree_node_t*) malloc(sizeof(isdn_tree_node_t))))
150
fprintf(stderr, "Error: Out of memory.\n");
153
$$->type = ISDN_NODE_TYPE_SUBSECTION;
155
$$->content.subsection = $4.list;
156
/* finally: only list needed */
161
value : ISDN_TOKEN_VALUE
168
* callback for yyparse(), (also) called on errors (hopefully) handled
169
* by error token actions in grammar, but not if errors occur to
170
* often (bison needs 3 "correct" tokens to recover)
172
void isdn_error(const char *message) {
175
"Warning: Parsing isdn options file: %d:%d: %s.\n",
176
isdn_lloc.first_line, isdn_lloc.first_column, message);