/[svn]/ircd-hybrid/src/conf/lexer.l
ViewVC logotype

Diff of /ircd-hybrid/src/conf/lexer.l

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 711 by adx, Sat Jun 24 16:21:12 2006 UTC revision 712 by michael, Sat Jul 8 12:13:14 2006 UTC
# Line 36  Line 36 
36  #include "conf/conf.h"  #include "conf/conf.h"
37  #include "y.tab.h"  #include "y.tab.h"
38    
 int conf_include_sptr = 0;  
   
39  #undef  YY_INPUT  #undef  YY_INPUT
40  #define YY_INPUT(buf, res, siz) res = conf_yy_input(buf, siz)  #define YY_INPUT(buf, res, siz) res = conf_yy_input(buf, siz)
41  /* flex's default is to print a message and exit(0) */  /* flex's default is to print a message and exit(0) */
# Line 45  int conf_include_sptr = 0; Line 43  int conf_include_sptr = 0;
43    
44  #define MAX_INCLUDE_DEPTH 10  #define MAX_INCLUDE_DEPTH 10
45    
46    static int conf_include_sptr = 0;
47  static YY_BUFFER_STATE conf_include_yystack[MAX_INCLUDE_DEPTH];  static YY_BUFFER_STATE conf_include_yystack[MAX_INCLUDE_DEPTH];
48  struct ConfParserContext conf_include_ctxstack[MAX_INCLUDE_DEPTH];  struct ConfParserContext conf_include_ctxstack[MAX_INCLUDE_DEPTH];
49    
# Line 173  yes         { yylval.number = 1; return Line 172  yes         { yylval.number = 1; return
172  static void  static void
173  conf_include(void)  conf_include(void)
174  {  {
175    char *fname, *buf;    char filenamebuf[IRCD_BUFSIZE];
176    FBFILE *f;    char *fname = NULL;
177      FBFILE *f = NULL;
   if (conf_include_sptr == MAX_INCLUDE_DEPTH)  
   {  
     yyerror("includes nested too deep");  
     return;  
   }  
178    
179    if ((fname = strchr(yytext, '"')) == NULL)    if ((fname = strchr(yytext, '"')) == NULL)
180      *strchr(fname = strchr(yytext, '<') + 1, '>') = '\0';      *strchr(fname = strchr(yytext, '<') + 1, '>') = '\0';
181    else    else
182      *strchr(++fname, '"') = '\0';      *strchr(++fname, '"') = '\0';
183    
184    if (fname[0] == '/')    if (conf_include_sptr == MAX_INCLUDE_DEPTH)
     f = fbopen(fname, "r");  
   else  
185    {    {
186      buf = MyMalloc(strlen(ETCPATH) + 1 + strlen(fname) + 1);      ilog(L_ERROR, "Includes nested too deep", fname);
187      sprintf(buf, "%s/%s", ETCPATH, fname);      return;
     f = fbopen(buf, "r");  
     MyFree(buf);  
188    }    }
189    
190    if (f == NULL)    if (*fname == '/')  /* if it is an absolute path */
191        snprintf(filenamebuf, sizeof(filenamebuf), "%s", fname);
192      else
193        snprintf(filenamebuf, sizeof(filenamebuf), "%s/%s", ETCPATH, fname);
194    
195      if ((f = fbopen(filenamebuf, "r")))
196    {    {
197      yyerror("cannot open file to include");      ilog(L_ERROR, "Unable to read configuration file '%s': %s",
198             filenamebuf, strerror(errno));
199      return;      return;
200    }    }
201    
# Line 210  conf_include(void) Line 206  conf_include(void)
206    
207    /* switch lexer context */    /* switch lexer context */
208    conf_linebuf[0] = '\0';    conf_linebuf[0] = '\0';
209    conf_curctx.f = f;  
   DupString(conf_curctx.filename, fname);  
210    conf_curctx.lineno = 1;    conf_curctx.lineno = 1;
211      conf_curctx.f = f;
212      DupString(conf_curctx.filename, filenamebuf);
213    
214    yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));    yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
215  }  }
216    

Legend:
Removed from v.711  
changed lines
  Added in v.712

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28