source: branches/z3950-branch/gsdl/src/recpt/zparse.y@ 1168

Last change on this file since 1168 was 1168, checked in by johnmcp, 24 years ago

added proper config file parsing for z39.50 servers, and minor changes
to pageaction (minor bug when display collections from >1 proto) and
cgiwrapper (announces which collections are z39.50 servers).

  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 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/* defined in z3950proto.cpp */
22extern struct z3950cfg *zservers_cfg_file;
23
24int yylex(void);
25
26int yyerror(char *string);
27
28void errormsg(char *str);
29
30%}
31
32
33%union {
34 char *string;
35 struct z3950cfg *cfg;
36 struct z3950aboutlist *about;
37 int number;
38}
39
40
41/* keywords */
42/***** NOTE: can explicitly give values for each token, AND
43give a string for the token name eg
44%token GSDLVERSION 257 "Version"
45*******/
46%token GSDLVERSION 257
47%token GENERAL_SECTION 258 SEARCH_SECTION 259
48%token BROWSE_SECTION 260 MACROS_SECTION 261
49%token MAINTAINER 262
50%token PUBLIC 263
51%token TRUE 264 FALSE 265
52%token LANGUAGES 266 EN 267 FR 268 MI 269 ZH 270 DE 271
53%token NAME 272
54%token <string> STRING 273
55%token ICON 274 SMALLICON 275
56%token ABOUT 276
57%token SEARCHTEXT 277
58%token DOCUMENT 278 SECTION 279
59%token BROWSE 280 TYPE 281 FORMAT 282
60/* classifiers */
61%token LIST 283 SORTEDLIST 284 SECTIONLIST 285 SORTEDSECTIONLIST 286
62%token DATELIST 287
63/* formats */
64%token ICONLINK 288 TEXTLINK 289
65/* layouts */
66%token DOCUMENTIMAGES 290 DOCUMENTHEADER 291 DOCUMENTTEXT 292
67%token DOCUMENTBUTTONS 293 DOCUMENTARROWSBOTTOM 294
68
69/* all other text */
70%token <string> DATA 295
71
72%type <cfg> zserver zserverlist
73%type <number> port
74%type <string> icon smallicon
75%type <about> about
76%%
77/* grammar */
78z3950 : version zserverlist {zserver_list=$2;}
79
80
81version : GSDLVERSION {;}
82 | {fprintf(stderr,"No version - not GSDL config file?\n");exit(1);}
83
84zserverlist : zserverlist zserver {$2->next=$1;$$=$2;}
85 | zserver ;
86
87zserver : DATA DATA port DATA STRING icon smallicon about {
88 if(($$=malloc(sizeof(struct z3950cfg)))==NULL)
89 fprintf(stderr,"malloc failed\n");
90 $$->shortname=$1;
91 $$->hostname=$2;
92 $$->port=$3;
93 $$->dbname=$4;
94 $$->longname=$5;
95 $$->icon=$6;
96 $$->smallicon=$7;
97 $$->about=$8;
98 }
99 ;
100
101port : ':' DATA {$$=atoi($2);}
102 | {$$=210;} /* default z39.50 server port */
103 ;
104
105icon : ICON STRING {$$=$2;}
106 | ICON DATA {$$=$2;
107 errormsg("Icon must be enclosed in quotes");
108 yylex();yylex();}
109 | {;}
110smallicon : SMALLICON STRING {$$=$2;}
111 | SMALLICON DATA {$$=$2;
112 /* this is because of the ':' */
113 errormsg("Smallicon must be enclosed in quotes.\n");
114 yylex();yylex();
115 }
116 | {;}
117
118about : aboutList {;}
119 | {;}
120
121aboutList : aboutLang {;}
122 | aboutList aboutLang {;}
123
124aboutLang : ABOUT lang STRING {/*printf("string is <%s>\n",$3)*/;}
125 | ABOUT STRING {
126 if (defLanguage)
127 {
128 fprintf(stderr,"warning: (line %d): already have a default language in config file\n",lineno);
129 }
130 else defLanguage=1;
131 }
132 /* this can only happen once (default lang) */
133
134/* languages should be done using a lookup, rather than hard-coding
135 them as tokens like this. Eg '_' token for en_BR */
136lang : lang '_' DATA {;}
137 | EN {;}
138 | FR {;}
139 | MI {;}
140 | ZH {;}
141 | DE {;}
142 | DATA {errormsg("unknown language");}
143 | error {errormsg("missing language");}
144
145documentHeader : DOCUMENTHEADER STRING {;}
146 | {;}
147
148documentText : DOCUMENTTEXT STRING {;}
149 | {;}
150
151
152%%
153/*int strncasecmp (const char *, const char *,size_t);*/
154int yyerror(char *string) {
155 fprintf(stderr,"Parse error (line %d) near \n\"%s\"<---:%s\n",lineno,
156 yylval.string,string);
157 return(1);
158}
159
160void errormsg(char *str) {
161 fprintf(stderr,"Err (line %d, near \"%s\"): %s.\n",lineno,
162 yylval.string,str);
163}
164
165/* *
166int main (int argc, char *argv[]) {
167 if (argc==2)
168 if (argv[1][0]=='-'&&argv[1][1]=='d')
169 yydebug=1;
170
171 yyparse();
172 return(0);
173}
174* */
Note: See TracBrowser for help on using the repository browser.