+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().
#include <stdlib.h>
#include <string.h>
#include "config.h"
+#include "fileio.h"
#include "ircd.h"
#include "ircd_alloc.h"
#include "ircd_string.h"
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;
+ }
}
%}
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. */
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;