chiark / gitweb /
more manpage, remove -h option
[innduct.git] / innfeed / configfile.l
1 %{
2 /*  $Id: configfile.l 6145 2003-01-19 19:42:22Z rra $
3 **
4 **  A flex input file for the innfeed config file.
5 **
6 **  Written by James Brister <brister@vix.com>
7 */
8
9 #include "innfeed.h"
10
11 #include <errno.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <syslog.h>
15
16 #include "libinn.h"
17
18 #include "configfile.h"
19 #include "config_y.h"
20 #include "misc.h"
21
22 #if ! defined (FLEX_SCANNER)
23 #error "You must use FLEX to process the lex input file."
24 #endif
25
26 #if defined (FLEX_DEBUG)
27 #define YY_USER_INIT yy_flex_debug = (getenv ("YYDEBUG") == NULL ? 0 : 1)
28 #endif
29
30 /* We never use this function but flex always defines it, so silence the
31    warnings about it. */
32 static void yyunput(int, char *) UNUSED;
33
34 char *strPtr = 0 ;
35 int strPtrLen = 0 ;
36 int strIdx = 0 ;
37 int sawBsl ;
38 int lineCount = 0 ;
39 int current ;
40
41 static void strAppend (int ch);
42 static void strAppend (int ch)
43 {
44   if (strIdx == strPtrLen)
45     {
46       if (strPtr == 0)
47         strPtr = xmalloc (strPtrLen = 50) ;
48       else
49         strPtr = xrealloc (strPtr,strPtrLen += 10) ;
50     }
51   strPtr [strIdx++] = ch ;
52 }
53
54 #define MAX_INCLUDE_DEPTH 11
55 struct includeFile {
56     YY_BUFFER_STATE state;
57     char *name ;
58 } include_stack[MAX_INCLUDE_DEPTH];
59 int include_stack_ptr = 0;
60
61 %}
62
63 %x incl
64
65 ID      [a-zA-Z][-a-zA-Z0-9._/]+
66
67 %%
68
69 \n                      lineCount++ ;
70
71 ":"                     { return (COLON) ; }
72
73 "{"                     { return (LBRACE) ; }
74
75 "}"                     { return (RBRACE) ; }
76
77 [pP][eE][eE][rR]        { return (PEER) ; }
78
79 ^"$INCLUDE"             BEGIN(incl);
80
81 <incl>[ \t]*            /* eat the whitespace before include filename */
82
83 <incl>[^ \t\n]+         {
84   if (include_stack_ptr == MAX_INCLUDE_DEPTH - 1)
85     {
86       int i ;
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) ;
90       
91       syslog (LOG_ERR, "includes nested to deeply") ;
92       exit( 1 );
93     }
94
95   if ((yyin = fopen(yytext,"r")) == NULL)
96     {
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));
101       exit (1) ;
102     }
103   else
104     {
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));
110     }
111
112   BEGIN(INITIAL);
113 }
114
115 <<EOF>> {
116   if ( include_stack_ptr <= 0 )
117     yyterminate();
118   else
119     {
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);
123     }
124 }
125
126 [gG][rR][oO][uU][pP]    { return (GROUP) ; }
127
128 #[^\n]*                 { (void) 0 ; }
129
130 [ \t]+                  { (void) 1 ; }
131
132 '\\[\\abfnrtv]'         {
133         switch (yytext[2]) {
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 ;
142         }
143         return (CHAR) ; }
144
145 '.'                     { yylval.chr = yytext[1] ; return (CHAR) ; }
146
147 '\\[0-9][0-9][0-9]'     { yylval.chr = (char)strtol(&yytext[2], (char **)NULL, 8);
148                           return (CHAR) ;}
149
150 \"[^\"]*        {{
151         int i ;
152
153         for (i = 1, strIdx = 0, sawBsl = 0 ; ; i++)
154           {
155             if (i < yyleng)
156               current = yytext [i] ;
157             else
158               current = input() ;
159             
160             if (current != EOF)
161               {
162                 switch (current)
163                   {
164                     case '\\':  
165                       if (sawBsl)
166                         {
167                           strAppend (current) ;
168                           sawBsl = 0 ;
169                         }
170                       else
171                         sawBsl = 1 ;
172                       break ;
173
174                     case '\n':  
175                       if (!sawBsl)
176                         strAppend(current) ;
177                       sawBsl = 0 ;
178                       lineCount++ ;
179                       break ;
180
181                     case '\"':  
182                       if (sawBsl)
183                         { 
184                           strAppend (current) ;
185                           sawBsl = 0 ;
186                         }
187                       else
188                         {
189                           strAppend ('\0') ;
190                           yylval.string = strPtr ;
191                           strPtr = 0 ;
192                           strPtrLen = strIdx = 0 ;
193                           return (XSTRING) ;
194                         }
195                       break ;
196
197                     case 'a':
198                     case 'b':
199                     case 'f':
200                     case 'n':
201                     case 'r':
202                     case 't':
203                     case 'v':
204                       if (sawBsl)
205                         {
206                           switch (current) 
207                             {
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 ;
215                             }
216                           sawBsl = 0 ;
217                         }
218                       else
219                         strAppend (current) ;
220                       break ;
221
222                     default:    
223                       strAppend (current) ;
224                       sawBsl = 0 ;
225                       break ;
226                   }
227               }
228             else
229               {
230                 return (XSTRING) ;
231               }
232           }
233 }}
234
235 [-0-9][0-9]*            { yylval.integer = atoi (yytext) ; return (IVAL) ; }
236
237 [-0-9][0-9]*\.[0-9]*    { yylval.real = atof (yytext) ; return (RVAL) ; }
238
239 [^#:\'\" \t\n]+ {
240   yylval.name = xstrdup (yytext) ;
241   if (strcasecmp (yylval.name,"false") == 0)
242     return (FALSEBVAL) ;
243   else if (strcasecmp (yylval.name,"true") == 0)
244     return (TRUEBVAL) ;
245   else
246   return (WORD) ;
247 }
248
249 %%
250
251
252