source: trunk/gsdl/src/recpt/zparse.y@ 1347

Last change on this file since 1347 was 1347, checked in by jrm21, 24 years ago

merged z39.50 receptionist stuff into main trunk (along with the mgpp stuff)

  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 KB
Line 
1/* RUN-TIME CONFIGURATION FILE PARSER */
2
3%{
4 /* verbatim C code - functions, etc */
5#include <stdlib.h>
6#include <stdio.h>
7#include <string.h>
8#include <ctype.h>
9#include "z3950cfg.h"
10
11#define YYDEBUG 1
12#define YYERROR_VERBOSE 1
13/* can't use default yyparse(), as this name is used elsewhere (eg mg)*/
14#define yyin zconfigin
15#define yyparse zconfigparse
16char defLanguage=0;
17
18/* defined in parse.fl */
19extern int lineno;
20
21#ifndef YYRECOVERING
22int YYRECOVERING=0; /* this is supposed to already be defined as a macro */
23#endif
24
25/* defined in z3950proto.cpp */
26extern struct z3950cfg *zservers_cfg_file;
27
28int yylex(void);
29
30int yyerror(char *string);
31
32void errormsg(char *str);
33
34%}
35
36
37%union {
38 char *string;
39 struct z3950cfg *cfg;
40 struct z3950aboutlist *about;
41 int number;
42}
43
44
45/* keywords */
46/***** NOTE: can explicitly give values for each token, AND
47give a string for the token name eg
48%token GSDLVERSION 257 "Version"
49*******/
50%token GSDLVERSION 257
51%token GENERAL_SECTION 258 SEARCH_SECTION 259
52%token BROWSE_SECTION 260 MACROS_SECTION 261
53%token MAINTAINER 262
54%token PUBLIC 263
55%token TRUE 264 FALSE 265
56%token LANGUAGES 266 EN 267 FR 268 MI 269 ZH 270 DE 271
57%token NAME 272
58%token <string> STRING 273
59%token ICON 274 SMALLICON 275
60%token ABOUT 276
61%token SEARCHTEXT 277
62%token DOCUMENT 278 SECTION 279
63%token BROWSE 280 TYPE 281 FORMAT 282
64/* classifiers */
65%token LIST 283 SORTEDLIST 284 SECTIONLIST 285 SORTEDSECTIONLIST 286
66%token DATELIST 287
67/* formats */
68%token ICONLINK 288 TEXTLINK 289
69/* layouts */
70%token DOCUMENTIMAGES 290 DOCUMENTHEADER 291 DOCUMENTTEXT 292
71%token DOCUMENTBUTTONS 293 DOCUMENTARROWSBOTTOM 294
72
73/* all other text */
74%token <string> DATA 295
75
76%type <cfg> zserver zserverlist
77%type <number> port
78%type <string> icon smallicon lang name
79%type <about> about aboutLang aboutList
80%%
81/* grammar */
82z3950 : version zserverlist {zserver_list=$2;}
83
84
85version : GSDLVERSION {;}
86 | {fprintf(stderr,"No version - not GSDL config file?\n");exit(1);}
87
88zserverlist : zserverlist zserver {if ($2!=NULL) {$2->next=$1;$$=$2;}}
89 | zserver ;
90
91zserver : DATA DATA port DATA name icon smallicon about
92 {
93 if (YYRECOVERING)
94 {$$=NULL;YYRECOVERING=0;}
95 else {
96 if(($$=malloc(sizeof(struct z3950cfg)))==NULL)
97 fprintf(stderr,"malloc failed\n");
98 $$->shortname=$1;
99 $$->hostname=$2;
100 $$->port=$3;
101 $$->dbname=$4;
102 $$->longname=$5;
103 $$->icon=$6;
104 $$->smallicon=$7;
105 $$->about=$8;
106 }
107 }
108 | error {$$=NULL;printf("discarding zserver\n");}
109 ;
110
111name : STRING {;}
112 | {errormsg("Database name needs to be followed by a short "
113 "descriptive name (enclosed in \" marks)");
114 $$=NULL;
115 YYRECOVERING=1;} /* we should scrap this server */
116
117port : ':' DATA {$$=atoi($2);}
118 | {$$=210;} /* default z39.50 server port */
119 ;
120
121icon : ICON STRING {$$=$2;}
122 | ICON DATA {$$=$2;
123 errormsg("Icon must be enclosed in quotes");
124 yylex();yylex();}
125 | {$$=NULL;}
126smallicon : SMALLICON STRING {$$=$2;}
127 | SMALLICON DATA {$$=$2;
128 /* this is because of the ':' */
129 errormsg("Smallicon must be enclosed in quotes.\n");
130 yylex();yylex();
131 }
132 | {$$=NULL;}
133
134about : aboutList {defLanguage=0;}
135 | {$$=NULL;}
136
137aboutList : aboutLang {;}
138 /* note this action reverses the order of the list */
139 | aboutList aboutLang {$$=$2;$2->next=$1;}
140
141
142aboutLang : ABOUT lang STRING
143 {
144 if(($$=malloc(sizeof(struct z3950aboutlist)))
145 ==NULL) {
146 fprintf(stderr,"Malloc failed\n");
147 exit(1);
148 }
149 $$->lang=$2;
150 $$->text=$3;
151 $$->next=NULL;
152 }
153 | ABOUT STRING
154 {
155 if (defLanguage)
156 {
157 fprintf(stderr,"warning: (line %d): already have a default language in config file\n",lineno);
158 }
159 else defLanguage=1;
160
161 if(($$=malloc(sizeof(struct z3950aboutlist)))
162 ==NULL) {
163 fprintf(stderr,"Malloc failed\n");
164 exit(1);
165 }
166 $$->lang=NULL; /* default lang... */
167 $$->text=$2;
168 $$->next=NULL;
169 }
170/* this can only happen once (default lang) */
171
172
173/* languages should be done using a lookup, rather than hard-coding
174 them as tokens. Also '_' token for en_BR */
175lang : DATA '_' DATA
176 {
177 $$=malloc(strlen($1)+strlen($3)+1);
178 strncpy($$,$1,strlen($1));
179 $$[strlen($1)]='_';
180 strncpy($$+strlen($1)+1,$3,strlen($3));
181 free($1);free($3);
182 }
183 | DATA {;}
184/*lang '_' DATA {;} */
185/* | EN {;}
186 | FR {;}
187 | MI {;}
188 | ZH {;}
189 | DE {;}
190 | DATA {errormsg("unknown language");}*/
191 | error {errormsg("missing language");}
192
193documentHeader : DOCUMENTHEADER STRING {;}
194 | {;}
195
196documentText : DOCUMENTTEXT STRING {;}
197 | {;}
198
199
200%%
201/*int strncasecmp (const char *, const char *,size_t);*/
202int yyerror(char *string) {
203 fprintf(stderr,"Parse error (line %d) near \n\"%s\"<---:%s\n",lineno,
204 yylval.string,string);
205 return(1);
206}
207
208void errormsg(char *str) {
209 fprintf(stderr,"Err (line %d, near \"%s\"): %s.\n",lineno,
210 yylval.string,str);
211}
212
213/* *
214int main (int argc, char *argv[]) {
215 if (argc==2)
216 if (argv[1][0]=='-'&&argv[1][1]=='d')
217 yydebug=1;
218
219 yyparse();
220 return(0);
221}
222* */
Note: See TracBrowser for help on using the repository browser.