4 * The olsr.org Optimized Link-State Routing daemon(olsrd)
5 * Copyright (c) 2004, Andreas T�nnesen(andreto@olsr.org)
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
18 * * Neither the name of olsr.org, olsrd nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
35 * Visit http://www.olsr.org for more information.
37 * If you find this software useful feel free to make a donation
38 * to the project. For more information see the website or contact
39 * the copyright holders.
44 #define YYSTYPE struct conf_token *
49 #include <sys/types.h>
50 #include <sys/socket.h>
51 #include <netinet/in.h>
52 #include <arpa/inet.h>
54 #include "olsrd_conf.h"
59 int yyget_lineno(void);
60 FILE * yyget_in(void);
61 FILE* yyget_out(void);
63 char *yyget_text(void);
64 void yyset_lineno(int);
65 void yyset_in(FILE *);
66 void yyset_out(FILE *);
67 int yyget_debug(void);
68 void yyset_debug(int);
69 int yylex_destroy(void);
72 static struct conf_token *get_conf_token(void);
73 static struct conf_token *get_string_token(const char * const s, const size_t n);
74 static struct conf_token *get_integer_token(const char * const s);
75 static struct conf_token *get_floating_token(const char * const s);
76 static struct conf_token *get_boolean_token(const olsr_bool b);
78 static struct conf_token *get_conf_token(void)
80 struct conf_token *t = calloc(1, sizeof(struct conf_token));
82 fprintf(stderr, "Cannot allocate %d bytes for an configuration token.\n", (int)sizeof(struct conf_token));
87 static struct conf_token *get_string_token(const char * const s, const size_t n)
89 struct conf_token *rv = get_conf_token();
91 rv->string = malloc(n+1);
92 if (rv->string == NULL) {
93 fprintf(stderr, "Cannot allocate %lu bytes for string token data.\n", (unsigned long)(n+1)); /* size_t on 64bit */
97 strncpy(rv->string, s, n);
103 static struct conf_token *get_integer_token(const char * const s)
105 struct conf_token *rv = get_conf_token();
107 rv->integer = strtol(s, NULL, 0);
112 static struct conf_token *get_floating_token(const char * const s)
114 struct conf_token *rv = get_conf_token();
117 sscanf(s, "%f", &rv->floating);
122 static struct conf_token *get_boolean_token(const olsr_bool b)
124 struct conf_token *rv = get_conf_token();
133 %option never-interactive
134 %option noalways-interactive
140 FLOAT {DECDIGIT}+\.{DECDIGIT}+
144 IPV4ADDR {QUAD}\.{QUAD}\.{QUAD}\.{QUAD}
148 IP6PAT2 ({HEX16}:){1}:({HEX16}:){0,5}{HEX16}
149 IP6PAT3 ({HEX16}:){2}:({HEX16}:){0,4}{HEX16}
150 IP6PAT4 ({HEX16}:){3}:({HEX16}:){0,3}{HEX16}
151 IP6PAT5 ({HEX16}:){4}:({HEX16}:){0,2}{HEX16}
152 IP6PAT6 ({HEX16}:){5}:({HEX16}:){0,1}{HEX16}
153 IP6PAT7 ({HEX16}:){6}:({HEX16})
154 IP6PAT1 ({HEX16}:){7}{HEX16}
155 IP6PAT8 ({HEX16}:){1,7}:
158 IPV6ADDR {IP6PAT1}|{IP6PAT2}|{IP6PAT3}|{IP6PAT4}|{IP6PAT5}|{IP6PAT6}|{IP6PAT7}|{IP6PAT8}|{IP6PAT9}
183 yylval = get_string_token(yytext + 1, yyleng - 2);
184 if (yylval == NULL) {
191 yylval = get_integer_token(yytext);
196 yylval = get_floating_token(yytext);
201 yylval = get_string_token(yytext, yyleng + 1);
202 if (yylval == NULL) {
208 yylval = get_string_token(yytext, yyleng + 1);
209 if (yylval == NULL) {
221 yylval = get_integer_token(yytext);
227 yylval = get_boolean_token(OLSR_TRUE);
232 yylval = get_boolean_token(OLSR_FALSE);
237 yylval = get_boolean_token(OLSR_TRUE);
242 yylval = get_boolean_token(OLSR_FALSE);
248 return TOK_HOSTLABEL;
263 return TOK_DEBUGLEVEL;
268 return TOK_IPVERSION;
273 return TOK_NICCHGSPOLLRT;
298 return TOK_INTERFACE;
318 return TOK_RTTABLE_DEFAULT;
323 return TOK_WILLINGNESS;
333 return TOK_FIBMETRIC;
343 return TOK_HYSTSCALE;
348 return TOK_HYSTUPPER;
353 return TOK_HYSTLOWER;
364 return TOK_TCREDUNDANCY;
369 return TOK_MPRCOVERAGE;
377 "LinkQualityFishEye" {
382 "LinkQualityDijkstraLimit" {
384 return TOK_LQ_DLIMIT;
392 "LinkQualityAlgorithm" {
394 return TOK_LQ_PLUGIN;
397 "LinkQualityWinSize" {
404 return TOK_LQ_NAT_THRESH;
414 return TOK_CLEAR_SCREEN;
424 return TOK_IP4BROADCAST;
428 return TOK_IP6ADDRTYPE;
432 return TOK_IP6MULTISITE;
434 "Ip6MulticastGlobal" {
436 return TOK_IP6MULTIGLOBAL;
442 "HelloValidityTime" {
470 "AutoDetectChanges" {
472 return TOK_AUTODETCHG;
484 //fprintf(stderr, "Failed to parse line %d of configuration file.\n",
487 //yy_fatal_error("Parsing failed.\n");
489 /* To avoid compiler warning (stupid...) */