ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hopm/trunk/src/config-lexer.l
(Generate patch)

Comparing hopm/trunk/src/config-lexer.l (file contents):
Revision 7711 by michael, Mon Sep 26 11:45:41 2016 UTC vs.
Revision 8564 by michael, Wed Sep 26 19:23:54 2018 UTC

# Line 1 | Line 1
1   /*
2   *  Copyright (c) 2002 Erik Fears
3 < *  Copyright (c) 2014-2016 ircd-hybrid development team
3 > *  Copyright (c) 2014-2018 ircd-hybrid development team
4   *
5   *  This program is free software; you can redistribute it and/or modify
6   *  it under the terms of the GNU General Public License as published by
# Line 20 | Line 20
20  
21   %option case-insensitive
22   %option noyywrap
23 + %option noinput
24   %option nounput
25   %option never-interactive
26  
27 + %x IN_COMMENT
28 +
29   %{
30   #include <stdio.h>
31   #include <string.h>
# Line 32 | Line 35
35   #include "config-parser.h"  /* autogenerated header file */
36   #include "log.h"
37  
38 + /* libopm includes */
39 + #include "libopm/src/opm_types.h"
40 +
41 + #undef YY_FATAL_ERROR
42 + #define YY_FATAL_ERROR(msg) conf_yy_fatal_error(msg)
43  
44   #undef YY_INPUT
45   #define YY_INPUT(buf,result,max_size) \
# Line 55 | Line 63 | static struct included_file
63   static unsigned int include_stack_ptr;
64  
65  
58 static void ccomment(void);
66   static void conf_include(void);
67   static int conf_eof(void);
68  
69   static int
70   conf_yy_input(char *lbuf, unsigned int max_size)
71   {
72 <  return !fgets(lbuf, max_size, conf_file) ? 0 : strlen(lbuf);
72 >  return fgets(lbuf, max_size, conf_file) == NULL ? 0 : strlen(lbuf);
73   }
74  
75 <
75 > static int
76 > conf_yy_fatal_error(const char *msg)
77 > {
78 >  return 0;
79 > }
80   %}
81  
82 < string                 \"[^\"\n]*[\"\n]
83 < include                \.include{WS}(\<.*\>|\".*\")
84 < comment                ("//"|"#").*
85 < whitespace             [ \t\r]*
82 > WS        [[:blank:]]*
83 > DIGIT     [[:digit:]]+
84 > COMMENT   ("//"|"#").*
85 > qstring   \"[^\"\n]*[\"\n]
86 > include   \.include{WS}(\<.*\>|\".*\")
87  
88   %%
89  
90 < "/*"                    { ccomment(); }
91 <
92 < {comment}               ;
93 <
94 < {string}                {
95 <                           /* QSTRING from Hybrid7. Why re-invent the wheel? */
96 <
97 <                           if(yytext[yyleng-2] == '\\')
98 <                           {
99 <                              yyless(yyleng-1); /* return last quote */
100 <                              yymore();         /* append next string */
101 <                           }
102 <                           else
103 <                           {
104 <                              yylval.string = yytext+1;
105 <                              if(yylval.string[yyleng-2] != '"') ; /* log error */
106 <                              else
107 <                              {
108 <                                 int i,j;
109 <
110 <                                 yylval.string[yyleng-2] = '\0'; /* remove close
111 <                                                                  *  quote
112 <                                                                  */
113 <
114 <                                 for (j=i=0 ;yylval.string[i] != '\0'; i++,j++)
115 <                                 {
116 <                                    if (yylval.string[i] != '\\')
117 <                                    {
118 <                                       yylval.string[j] = yylval.string[i];
119 <                                    }
120 <                                    else
121 <                                    {
122 <                                        i++;
123 <                                        yylval.string[j] = yylval.string[i];
124 <                                    }
125 <                                 }
126 <                                 yylval.string[j] = '\0';
127 <                                 return STRING;
128 <                              }
129 <                           }
130 <                        }
90 > "/*"                { BEGIN IN_COMMENT; }
91 > <IN_COMMENT>"*/"    { BEGIN INITIAL;    }
92 > <IN_COMMENT>.       ;  /* Eat everything but a newline */
93 > <IN_COMMENT>\n      { ++lineno; }
94 > <IN_COMMENT><<EOF>> { BEGIN INITIAL; if (conf_eof()) yyterminate(); }
95 >
96 > {include}       { conf_include(); }
97 > \n.*            { strlcpy(linebuf, yytext + 1, sizeof(linebuf)); ++lineno; yyless(1); }
98 > {WS}            ;
99 > {COMMENT}       ;
100 > {DIGIT}         { yylval.number = atoi(yytext); return NUMBER; }
101 > {qstring}       { if (yytext[yyleng - 2] == '\\')
102 >                  {
103 >                    yyless(yyleng - 1);  /* Return last quote */
104 >                    yymore();  /* Append next string */
105 >                  }
106 >                  else
107 >                  {
108 >                    yylval.string = yytext + 1;
109 >
110 >                    if (yylval.string[yyleng - 2] != '"')
111 >                      log_printf("CONFIG ->Unterminated character string");
112 >                    else
113 >                    {
114 >                      unsigned int i = 0, j = 0;
115 >
116 >                      yylval.string[yyleng - 2] = '\0';  /* Remove close quote */
117 >
118 >                      for (; yylval.string[i] != '\0'; ++i, ++j)
119 >                      {
120 >                        if (yylval.string[i] != '\\')
121 >                          yylval.string[j] = yylval.string[i];
122 >                        else
123 >                        {
124 >                          ++i;
125 >
126 >                          if (yylval.string[i] == '\0')  /* XXX: should not happen */
127 >                          {
128 >                            log_printf("CONFIG -> Unterminated character string");
129 >                            break;
130 >                          }
131 >
132 >                          yylval.string[j] = yylval.string[i];
133 >                        }
134 >                      }
135 >
136 >                      yylval.string[j] = '\0';
137 >                      return STRING;
138 >                    }
139 >                  }
140 >                }
141  
142 + ADDRESS_FAMILY          { return ADDRESS_FAMILY; }
143   AWAY                    { return AWAY;         }
144   BAN_UNKNOWN             { return BAN_UNKNOWN;  }
145   BLACKLIST               { return BLACKLIST;    }
# Line 132 | Line 155 | DNSBL_TO                { return DNSBL_T
155   EXEMPT                  { return EXEMPT;       }
156   FD                      { return FD;           }
157   INVITE                  { return INVITE;       }
158 + IPV4                    { return IPV4;         }
159 + IPV6                    { return IPV6;         }
160   IRC                     { return IRC;          }
161   KLINE                   { return KLINE;        }
162   KEY                     { return KEY;          }
# Line 243 | Line 268 | DREAMBOX                {
268                          }
269  
270  
271 <
272 < [0-9]+                  {
273 <                           yylval.number=atoi(yytext);
249 <                           return NUMBER;
271 > SSH                     {
272 >                          yylval.number = OPM_TYPE_SSH;
273 >                          return PROTOCOLTYPE;
274                          }
275  
252
253
254
255
276   TRUE                     {
277                             yylval.number=1;
278                             return NUMBER;
# Line 283 | Line 303 | OFF                      {
303                             return NUMBER;
304                           }
305  
306 <
287 < \n.*                     {
288 <                           strlcpy(linebuf, yytext + 1, sizeof(linebuf));
289 <                           ++lineno;
290 <                           yyless(1);
291 <                         }
292 <
293 < {whitespace}            /* ignore whitespace */;
294 <
295 < .                       return yytext[0];
306 > .                       { return yytext[0]; }
307   <<EOF>>                 { if (conf_eof()) yyterminate(); }
308  
309   %%
310  
300
301 /* C-comment ignoring routine -kre*/
302 static void
303 ccomment(void)
304 {
305  int c = 0;
306
307  /* log(L_NOTICE, "got comment"); */
308  while (1)
309  {
310    while ((c = input()) != '*' && c != EOF)
311      if (c == '\n')
312        ++lineno;
313
314    if (c == '*')
315    {
316      while ((c = input()) == '*')
317        /* Nothing */ ;
318      if (c == '/')
319        break;
320      else if (c == '\n')
321        ++lineno;
322    }
323
324    if (c == EOF)
325    {
326      YY_FATAL_ERROR("EOF in comment");
327
328      /* XXX hack alert this disables
329       * the stupid unused function warning
330       * gcc generates
331       */
332      if (1 == 0)
333        yy_fatal_error("EOF in comment");
334      break;
335    }
336  }
337 }
338
311   static void
312   conf_include(void)
313   {
# Line 375 | Line 347 | conf_include(void)
347  
348    lineno = 1;
349    conf_file = tmp_fbfile_in;
350 +  strlcpy(conffilebuf, filenamebuf, sizeof(conffilebuf));
351  
352 <  snprintf(conffilebuf, sizeof(conffilebuf), "%s", filenamebuf);
380 <  yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
352 >  yy_switch_to_buffer(yy_create_buffer(NULL, YY_BUF_SIZE));
353   }
354  
355   static int
356   conf_eof(void)
357   {
358    if (include_stack_ptr == 0)
387  {
388    lineno = 1;
359      return 1;
390  }
360  
361    /* switch buffer */
362    struct included_file *file = &include_stack[--include_stack_ptr];

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)