From: Michael Poole Date: Tue, 30 Oct 2007 02:13:09 +0000 (+0000) Subject: Convert lexer to read using fileio.[ch] functions (thanks, Solaris!). X-Git-Url: http://git.pk910.de/?p=ircu2.10.12-pk.git;a=commitdiff_plain;h=0a80be91508519a6bc4d777abb02206a4adb504b Convert lexer to read using fileio.[ch] functions (thanks, Solaris!). git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/branches/u2_10_12_branch@1839 c9e4aea6-c8fd-4c43-8297-357d70d61c8c --- diff --git a/ChangeLog b/ChangeLog index 79d3f41..e1f630c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2007-10-29 Michael Poole + + * ircd/ircd_lexer.l (YY_INPUT): Redefine to use fbgets(). + (init_lexer): Return a value to indicate failure. Use fbopen(). + (deinit_lexer): New function. + + * ircd/s_conf.c (read_configuration_file): Update extern + declarations. Bail if init_lexer() fails. Call deinit_lexer() + rather than directly munging yyin. + 2007-10-29 Michael Poole * include/gline.h: Delete declaration of gline_propagate(). diff --git a/ircd/ircd_lexer.l b/ircd/ircd_lexer.l index d44f106..925f1ac 100644 --- a/ircd/ircd_lexer.l +++ b/ircd/ircd_lexer.l @@ -26,6 +26,7 @@ #include #include #include "config.h" +#include "fileio.h" #include "ircd.h" #include "ircd_alloc.h" #include "ircd_string.h" @@ -185,22 +186,38 @@ find_token(char *token) return tok ? tok->value : 0; } -void +static FBFILE *lexer_input; + +#undef YY_INPUT +#define YY_INPUT(buf, res, size) res = (fbgets(buf, size, lexer_input) ? strlen(buf) : 0) + +int init_lexer(void) { - yyin = fopen(configfile, "r"); - if (yyin == NULL) + lexer_input = fbopen(configfile, "r"); + if (lexer_input == NULL) { #ifdef YY_FATAL_ERROR YY_FATAL_ERROR("Could not open the configuration file."); #else fprintf(stderr, "Could not open the configuration file."); #endif + return 0; } #ifdef YY_NEW_FILE YY_NEW_FILE; #endif lineno = 1; + return 1; +} + +void deinit_lexer(void) +{ + if (lexer_input != NULL) + { + fbclose(lexer_input); + lexer_input = NULL; + } } %} diff --git a/ircd/s_conf.c b/ircd/s_conf.c index 1dc438b..96f2b99 100644 --- a/ircd/s_conf.c +++ b/ircd/s_conf.c @@ -816,9 +816,9 @@ void clear_quarantines(void) static int conf_error; /** When non-zero, indicates that the configuration file was loaded at least once. */ static int conf_already_read; -extern FILE *yyin; extern void yyparse(void); -extern void init_lexer(void); +extern int init_lexer(void); +extern void deinit_lexer(void); /** Read configuration file. * @return Zero on failure, non-zero on success. */ @@ -827,11 +827,10 @@ int read_configuration_file(void) conf_error = 0; feature_unmark(); /* unmark all features for resetting later */ clear_nameservers(); /* clear previous list of DNS servers */ - /* Now just open an fd. The buffering isn't really needed... */ - init_lexer(); + if (!init_lexer()) + return 0; yyparse(); - fclose(yyin); - yyin = NULL; + deinit_lexer(); feature_mark(); /* reset unmarked features */ conf_already_read = 1; return 1;