source: trunk/zoo-project/zoo-kernel/main_conf_read.y @ 686

Last change on this file since 686 was 621, checked in by djay, 10 years ago

Major update. Creation of a basic parsing api. Call validateRequest after fork if any.

File size: 3.9 KB
RevLine 
[607]1/*
2 * Zoo main configuration file parser
[621]3 *
4 * Author : Gérald FENOY
5 *
6 * Copyright (c) 209-2015 GeoLabs SARL
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
[607]25 */
[621]26%{
[1]27#include <service.h>
28
29static maps* my_maps=NULL;
30static maps* current_maps=NULL;
31static map* current_content=NULL;
32static char* curr_key;
33static int debug=0;
34
[114]35extern void crerror(const char *s);
[1]36
37void usage(void) ;
38
39extern int crdebug;
40
41extern char crtext[];
42
43extern int crlineno;
44
45extern FILE* crin;
46
47extern int crlex(void);
[9]48extern int crlex_destroy(void);
[1]49
50%}
51
[225]52%union { char* s;char* chaine; char* key;char* val;}
[1]53
54%token <s> ID
55%token <s> CHAINE
[621]56
57%token PAIR SPAIR EPAIR EPAIRS ANID
[1]58%type <chaine> PAIR
59%type <chaine> EPAIRS
60%type <chaine> EPAIR
61%type <chaine> SPAIR
62
[621]63%token WHITESPACE NEWLINE
64
[1]65%type <s> ANID
66
67%%
[621]68
[1]69document
[621]70 : miscetoile miscetoile {}
[1]71 | contentetoile processid contentetoile document {}
72 ;
73
74miscetoile
[621]75 : {}
[1]76 ;
77
78Attributeetoile
[621]79 : Attributeetoile  {}
[1]80 |                                {/* Epsilon */}
81 ;
[621]82
[1]83contentetoile
[621]84: contentetoile NEWLINE {}
[1]85 | contentetoile pair {}
86 | {/* Epsilon */}
87 ;
88
[621]89pair: PAIR {curr_key=zStrdup($1);}
[1]90| EPAIR {
91  if(current_content==NULL)
92    current_content=createMap(curr_key,$1);
[9]93  else{
[1]94    addToMap(current_content,curr_key,$1);
[9]95  }
[1]96  if(debug){
97    printf("EPAIR FOUND !! \n");
98    printf("[%s=>%s]\n",curr_key,$1);
99  }
100  free(curr_key);
101  }
[453]102| SPAIR  {curr_key=zStrdup($1);if(debug) printf("SPAIR FOUND !!\n"); }
[1]103 ;
104
105
106processid
[9]107: ANID  {
[1]108   if(current_maps->name!=NULL){
[9]109     addMapToMap(&current_maps->content,current_content);
110     freeMap(&current_content);
111     free(current_content);
112     current_maps->next=NULL;
113     current_maps->next=(maps*)malloc(MAPS_SIZE);
[453]114     current_maps->next->name=zStrdup($1);
[9]115     current_maps->next->content=NULL;
116     current_maps->next->next=NULL;
[1]117     current_maps=current_maps->next;
[9]118     current_content=current_maps->content;
[1]119   }
120   else{
[9]121     current_maps->name=(char*)malloc((strlen($1)+1)*sizeof(char));
122     snprintf(current_maps->name,(strlen($1)+1),"%s",$1);
123     current_maps->content=NULL;
124     current_maps->next=NULL;
125     current_content=NULL;
[1]126   }
127 }
128 ;
129
130%%
131
[607]132/**
133 * Print on stderr the message and the line number of the error which occured.
134 *
135 * @param s the error message
136 */
[114]137void crerror(const char *s)
[1]138{
139  if(debug)
140    printf("\nligne %d : %s\n",crlineno,s);
141}
142
[607]143/**
144 * Parse the main.cfg file and fill the maps structure.
145 *
146 * @param file the filename to parse
147 * @param my_map the maps structure to fill
148 */
[114]149int conf_read(const char* file,maps* my_map){
[1]150 
151  crin = fopen(file,"r");
152  if (crin==NULL){
153    return 2 ;
154  }
155
156  my_maps=my_map;
157  my_maps->name=NULL;
158  current_maps=my_maps;
159 
160  int resultatYYParse = crparse() ;
[9]161  if(current_content!=NULL){
162    addMapToMap(&current_maps->content,current_content);
163    current_maps->next=NULL;
164    freeMap(&current_content);
165    free(current_content);
166  }
[1]167
[9]168  fclose(crin);
[216]169#ifndef WIN32
[9]170  crlex_destroy();
[216]171#endif
[1]172
173  return resultatYYParse;
174}
175
Note: See TracBrowser for help on using the repository browser.

Search

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png