Convert lexer to read using fileio.[ch] functions (thanks, Solaris!).
authorMichael Poole <mdpoole@troilus.org>
Tue, 30 Oct 2007 02:13:09 +0000 (02:13 +0000)
committerMichael Poole <mdpoole@troilus.org>
Tue, 30 Oct 2007 02:13:09 +0000 (02:13 +0000)
git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/branches/u2_10_12_branch@1839 c9e4aea6-c8fd-4c43-8297-357d70d61c8c

ChangeLog
ircd/ircd_lexer.l
ircd/s_conf.c

index 79d3f4122c5f0b23cb046f0008a5dd03c376f907..e1f630c6f4da2e30940ad01dccbf7298e9e1d9c8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2007-10-29  Michael Poole <mdpoole@troilus.org>
+
+       * 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 <mdpoole@troilus.org>
 
        * include/gline.h: Delete declaration of gline_propagate().
index d44f106fe38d4cd79ab857a44701271d003e571b..925f1ac06fee71f4852b67bf769a6577c0c0a667 100644 (file)
@@ -26,6 +26,7 @@
 #include <stdlib.h>
 #include <string.h>
 #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;
+  }
 }
 
 %}
index 1dc438b14591253982b44c46370664ae07fc4c83..96f2b99efed09ce18333be6e4218e5e1bcb1b2cd 100644 (file)
@@ -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;