2 /* $Id: configfile.l 6145 2003-01-19 19:42:22Z rra $
4 ** A flex input file for the innfeed config file.
6 ** Written by James Brister <brister@vix.com>
18 #include "configfile.h"
22 #if ! defined (FLEX_SCANNER)
23 #error "You must use FLEX to process the lex input file."
26 #if defined (FLEX_DEBUG)
27 #define YY_USER_INIT yy_flex_debug = (getenv ("YYDEBUG") == NULL ? 0 : 1)
30 /* We never use this function but flex always defines it, so silence the
32 static void yyunput(int, char *) UNUSED;
41 static void strAppend (int ch);
42 static void strAppend (int ch)
44 if (strIdx == strPtrLen)
47 strPtr = xmalloc (strPtrLen = 50) ;
49 strPtr = xrealloc (strPtr,strPtrLen += 10) ;
51 strPtr [strIdx++] = ch ;
54 #define MAX_INCLUDE_DEPTH 11
56 YY_BUFFER_STATE state;
58 } include_stack[MAX_INCLUDE_DEPTH];
59 int include_stack_ptr = 0;
65 ID [a-zA-Z][-a-zA-Z0-9._/]+
71 ":" { return (COLON) ; }
73 "{" { return (LBRACE) ; }
75 "}" { return (RBRACE) ; }
77 [pP][eE][eE][rR] { return (PEER) ; }
79 ^"$INCLUDE" BEGIN(incl);
81 <incl>[ \t]* /* eat the whitespace before include filename */
84 if (include_stack_ptr == MAX_INCLUDE_DEPTH - 1)
87 fprintf( stderr, "Includes nested too deeply:\n" );
88 for (i = 1 ; i <= include_stack_ptr ; i++)
89 fprintf (stderr,"\t%s\n",include_stack[i].name) ;
91 syslog (LOG_ERR, "includes nested to deeply") ;
95 if ((yyin = fopen(yytext,"r")) == NULL)
97 syslog (LOG_CRIT,"include file fopen failed: %s %s",
98 yytext,strerror(errno));
99 fprintf (stderr,"include file fopen failed: %s %s\n",
100 yytext,strerror(errno));
105 d_printf (1,"Including (%d) from %s\n",
106 include_stack_ptr + 1,yytext) ;
107 include_stack[include_stack_ptr].state = YY_CURRENT_BUFFER;
108 include_stack[++include_stack_ptr].name = xstrdup (yytext) ;
109 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
116 if ( include_stack_ptr <= 0 )
120 free (include_stack[include_stack_ptr].name) ;
121 yy_delete_buffer(YY_CURRENT_BUFFER);
122 yy_switch_to_buffer(include_stack[--include_stack_ptr].state);
126 [gG][rR][oO][uU][pP] { return (GROUP) ; }
128 #[^\n]* { (void) 0 ; }
130 [ \t]+ { (void) 1 ; }
134 case '\\': yylval.chr = '\\' ; break ;
135 case 'a': yylval.chr = 007 ; break ;
136 case 'b': yylval.chr = 010 ; break ;
137 case 'f': yylval.chr = 014 ; break ;
138 case 'n': yylval.chr = 012 ; break ;
139 case 'r': yylval.chr = 015 ; break ;
140 case 't': yylval.chr = 011 ; break ;
141 case 'v': yylval.chr = 013 ; break ;
145 '.' { yylval.chr = yytext[1] ; return (CHAR) ; }
147 '\\[0-9][0-9][0-9]' { yylval.chr = (char)strtol(&yytext[2], (char **)NULL, 8);
153 for (i = 1, strIdx = 0, sawBsl = 0 ; ; i++)
156 current = yytext [i] ;
167 strAppend (current) ;
184 strAppend (current) ;
190 yylval.string = strPtr ;
192 strPtrLen = strIdx = 0 ;
208 case 'a': strAppend (007) ; break ;
209 case 'b': strAppend (010) ; break ;
210 case 'f': strAppend (014) ; break ;
211 case 'n': strAppend (012) ; break ;
212 case 'r': strAppend (015) ; break ;
213 case 't': strAppend (011) ; break ;
214 case 'v': strAppend (013) ; break ;
219 strAppend (current) ;
223 strAppend (current) ;
235 [-0-9][0-9]* { yylval.integer = atoi (yytext) ; return (IVAL) ; }
237 [-0-9][0-9]*\.[0-9]* { yylval.real = atof (yytext) ; return (RVAL) ; }
240 yylval.name = xstrdup (yytext) ;
241 if (strcasecmp (yylval.name,"false") == 0)
243 else if (strcasecmp (yylval.name,"true") == 0)