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

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

checkpoint - can now connect and get status information from a z39.50 server.
Still need to get queries and data retrieval working.

  • Property svn:keywords set to Author Date Id Revision
File size: 5.1 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 lang
75%type <about> about aboutLang aboutList
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 {if ($2!=NULL) {$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 | error {$$=NULL;}
100 ;
101
102port : ':' DATA {$$=atoi($2);}
103 | {$$=210;} /* default z39.50 server port */
104 ;
105
106icon : ICON STRING {$$=$2;}
107 | ICON DATA {$$=$2;
108 errormsg("Icon must be enclosed in quotes");
109 yylex();yylex();}
110 | {$$=NULL;}
111smallicon : SMALLICON STRING {$$=$2;}
112 | SMALLICON DATA {$$=$2;
113 /* this is because of the ':' */
114 errormsg("Smallicon must be enclosed in quotes.\n");
115 yylex();yylex();
116 }
117 | {$$=NULL;}
118
119about : aboutList {;}
120 | {$$=NULL;}
121
122aboutList : aboutLang {;}
123 /* note this action reverses the order of the list */
124 | aboutList aboutLang {$$=$2;$2->next=$1;}
125
126
127aboutLang : ABOUT lang STRING
128 {
129 if(($$=malloc(sizeof(struct z3950aboutlist)))
130 ==NULL) {
131 fprintf(stderr,"Malloc failed\n");
132 exit(1);
133 }
134 $$->lang=$2;
135 $$->text=$3;
136 $$->next=NULL;
137 }
138 | ABOUT STRING
139 {
140 if (defLanguage)
141 {
142 fprintf(stderr,"warning: (line %d): already have a default language in config file\n",lineno);
143 }
144 else defLanguage=1;
145
146 if(($$=malloc(sizeof(struct z3950aboutlist)))
147 ==NULL) {
148 fprintf(stderr,"Malloc failed\n");
149 exit(1);
150 }
151 $$->lang=NULL; /* default lang... */
152 $$->text=$2;
153 $$->next=NULL;
154 }
155/* this can only happen once (default lang) */
156
157
158/* languages should be done using a lookup, rather than hard-coding
159 them as tokens. Also '_' token for en_BR */
160lang : DATA '_' DATA
161 {
162 $$=malloc(strlen($1)+strlen($3)+1);
163 strncpy($$,$1,strlen($1));
164 $$[strlen($1)]='_';
165 strncpy($$+strlen($1)+1,$3,strlen($3));
166 free($1);free($3);
167 }
168 | DATA {;}
169/*lang '_' DATA {;} */
170/* | EN {;}
171 | FR {;}
172 | MI {;}
173 | ZH {;}
174 | DE {;}
175 | DATA {errormsg("unknown language");}*/
176 | error {errormsg("missing language");}
177
178documentHeader : DOCUMENTHEADER STRING {;}
179 | {;}
180
181documentText : DOCUMENTTEXT STRING {;}
182 | {;}
183
184
185%%
186/*int strncasecmp (const char *, const char *,size_t);*/
187int yyerror(char *string) {
188 fprintf(stderr,"Parse error (line %d) near \n\"%s\"<---:%s\n",lineno,
189 yylval.string,string);
190 return(1);
191}
192
193void errormsg(char *str) {
194 fprintf(stderr,"Err (line %d, near \"%s\"): %s.\n",lineno,
195 yylval.string,str);
196}
197
198/* *
199int main (int argc, char *argv[]) {
200 if (argc==2)
201 if (argv[1][0]=='-'&&argv[1][1]=='d')
202 yydebug=1;
203
204 yyparse();
205 return(0);
206}
207* */
Note: See TracBrowser for help on using the repository browser.