Committer  : entrope
CVSROOT    : /cvsroot/undernet-ircu
Module     : ircu2.10
Commit time: 2006-06-29 00:41:38 UTC

Modified files:
     ircd/s_conf.c ircd/ircd_lexer.l include/s_conf.h ChangeLog

Log message:

Prepare for config include rework.

---------------------- diff included ----------------------
Index: ircu2.10/ChangeLog
diff -u ircu2.10/ChangeLog:1.782 ircu2.10/ChangeLog:1.783
--- ircu2.10/ChangeLog:1.782    Wed Jun 28 17:36:35 2006
+++ ircu2.10/ChangeLog  Wed Jun 28 17:41:28 2006
@@ -1,5 +1,19 @@
 2006-06-28  Michael Poole <[EMAIL PROTECTED]>
 
+       * include/s_conf.h (yyserror): Declare new function.
+       (yywarning): Declare new function.
+
+       * ircd/ircd_lexer.l (init_lexer): Ensure lexer initializes its
+       state on rehash.
+       (lexer_include): Support NULL filename to mean empty string.  If
+       unable to open a file, warn with yyserror() but do the same.
+
+       * ircd/s_conf.c (yyin): Remove declaration and do not touch.
+       (yyserror): New function.
+       (yywarning): New function.
+
+2006-06-28  Michael Poole <[EMAIL PROTECTED]>
+
        * include/ircd_alloc.h (MyFree): Fix "if" nesting.
 
 2006-06-27  Michael Poole <[EMAIL PROTECTED]>
Index: ircu2.10/include/s_conf.h
diff -u ircu2.10/include/s_conf.h:1.34 ircu2.10/include/s_conf.h:1.35
--- ircu2.10/include/s_conf.h:1.34      Sun Aug 21 06:46:07 2005
+++ ircu2.10/include/s_conf.h   Wed Jun 28 17:41:28 2006
@@ -1,6 +1,6 @@
 /** @file s_conf.h
  * @brief ircd configuration file API.
- * @version $Id: s_conf.h,v 1.34 2005/08/21 13:46:07 entrope Exp $
+ * @version $Id: s_conf.h,v 1.35 2006/06/29 00:41:28 entrope Exp $
  */
 #ifndef INCLUDED_s_conf_h
 #define INCLUDED_s_conf_h
@@ -189,5 +189,7 @@
 extern void free_mapping(struct s_map *smap);
 
 extern void yyerror(const char *msg);
+extern void yyserror(const char *fmt, ...);
+extern void yywarning(const char *fmt, ...);
 
 #endif /* INCLUDED_s_conf_h */
Index: ircu2.10/ircd/ircd_lexer.l
diff -u ircu2.10/ircd/ircd_lexer.l:1.26 ircu2.10/ircd/ircd_lexer.l:1.27
--- ircu2.10/ircd/ircd_lexer.l:1.26     Tue Jun 27 04:29:06 2006
+++ ircu2.10/ircd/ircd_lexer.l  Wed Jun 28 17:41:28 2006
@@ -17,7 +17,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  *  USA.
- * $Id: ircd_lexer.l,v 1.26 2006/06/27 11:29:06 entrope Exp $
+ * $Id: ircd_lexer.l,v 1.27 2006/06/29 00:41:28 entrope Exp $
  */
 
 %option never-interactive case-insensitive warn nodefault nounput yylineno
@@ -29,7 +29,7 @@
 #include "ircd_string.h"
 #include "ircd_parser.h"
 
-extern void yyerror(const char *pattern);
+extern void yyserror(const char *pattern, ...);
 
 int
 init_lexer(const char *configfile)
@@ -40,17 +40,25 @@
     fprintf(stderr, "Could not open the configuration file.");
     return 0;
   }
+  yy_init = 1;
   return 1;
 }
 
 void
 lexer_include(const char *filename)
 {
+  if (filename == NULL)
+  {
+    yypush_buffer_state(yy_scan_string(""));
+    return;
+  }
+
   yyin = fopen(filename, "r");
   if (yyin == NULL)
   {
-    yyerror("Unable to open included configuration file.");
-    return TEOF;
+    yyserror("Unable to open included file '%s'.", filename);
+    yypush_buffer_state(yy_scan_string(""));
+    return;
   }
   yypush_buffer_state(yy_create_buffer(yyin, YY_BUF_SIZE));
 }
Index: ircu2.10/ircd/s_conf.c
diff -u ircu2.10/ircd/s_conf.c:1.89 ircu2.10/ircd/s_conf.c:1.90
--- ircu2.10/ircd/s_conf.c:1.89 Tue Jun 27 04:29:05 2006
+++ ircu2.10/ircd/s_conf.c      Wed Jun 28 17:41:28 2006
@@ -19,7 +19,7 @@
  */
 /** @file
  * @brief ircd configuration file driver
- * @version $Id: s_conf.c,v 1.89 2006/06/27 11:29:05 entrope Exp $
+ * @version $Id: s_conf.c,v 1.90 2006/06/29 00:41:28 entrope Exp $
  */
 #include "config.h"
 
@@ -823,7 +823,6 @@
 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 int init_lexer(const char *configfile);
 
@@ -836,8 +835,6 @@
   if (!init_lexer(configfile))
     return 0;
   yyparse();
-  fclose(yyin);
-  yyin = NULL;
   feature_mark(); /* reset unmarked features */
   conf_already_read = 1;
   return 1;
@@ -858,6 +855,41 @@
  conf_error = 1;
 }
 
+/** Report an error message about the configuration file.
+ * @param fmt The error to report.
+ */
+void
+yyserror(const char *fmt, ...)
+{
+  static char error_buffer[1024];
+  va_list vl;
+
+  va_start(vl, fmt);
+  ircd_vsnprintf(NULL, error_buffer, sizeof(error_buffer), fmt, vl);
+  va_end(vl);
+  yyerror(error_buffer);
+}
+
+/** Report a recoverable warning about the configuration file.
+ * @param fmt The error to report.
+ */
+void
+yywarning(const char *fmt, ...)
+{
+  static char warn_buffer[1024];
+  va_list vl;
+
+  va_start(vl, fmt);
+  ircd_vsnprintf(NULL, warn_buffer, sizeof(warn_buffer), fmt, vl);
+  va_end(vl);
+  sendto_opmask_butone(0, SNO_ALL, "Config warning on line %d: %s",
+                       yylineno, warn_buffer);
+  log_write(LS_CONFIG, L_WARNING, 0, "Config warning on line %d: %s",
+                       yylineno, warn_buffer);
+  if (!conf_already_read)
+    fprintf(stderr, "Config warning on line %d: %s\n", yylineno, warn_buffer);
+}
+
 /** Attach CONF_UWORLD items to a server and everything attached to it. */
 static void
 attach_conf_uworld(struct Client *cptr)
----------------------- End of diff -----------------------
_______________________________________________
Patches mailing list
[email protected]
http://undernet.sbg.org/mailman/listinfo/patches

Reply via email to