Committer  : entrope
CVSROOT    : /cvsroot/undernet-ircu
Module     : ircu2.10
Commit time: 2006-06-27 04:46:20 UTC

Modified files:
     ChangeLog configure configure.ac ircd/ircd_lexer.l ircd/s_conf.c

Added files:
     test.l

Log message:

Convert lexer to flex format, in preparation for config includes.

---------------------- diff included ----------------------
Index: ircu2.10/ChangeLog
diff -u ircu2.10/ChangeLog:1.779 ircu2.10/ChangeLog:1.780
--- ircu2.10/ChangeLog:1.779    Mon Jun 26 19:39:59 2006
+++ ircu2.10/ChangeLog  Mon Jun 26 21:46:10 2006
@@ -1,3 +1,14 @@
+2006-06-27  Michael Poole <[EMAIL PROTECTED]>
+
+       * configure.ac: Make sure that $LEX is flex-compatible.
+
+       * test.l: Helper file for this test.
+
+       * ircd/ircd_lexer.l: Rewrite to use flex features.
+
+       * ircd/s_conf.c (read_configuration_file): Pass configfile as a
+       parameter to init_lexer().
+
 2006-06-26  Michael Poole <[EMAIL PROTECTED]>
 
        * include/channel.h (CHFL_DEOPPED): Delete, along with its
Index: ircu2.10/configure
diff -u ircu2.10/configure:1.40 ircu2.10/configure:1.41
--- ircu2.10/configure:1.40     Fri Dec 30 17:47:09 2005
+++ ircu2.10/configure  Mon Jun 26 21:46:10 2006
@@ -3282,6 +3282,21 @@
 test -n "$YACC" || YACC="yacc"
 
 
+echo $ECHO_N "checking $LEX compatibility... " >&6
+if ! $LEX ${srcdir}/test.l >&5 ; then
+  { { echo "$as_me:$LINENO: error: Unable to run $LEX on ${srcdir}/test.l, try 
using flex 2.5 or newer." >&5
+echo "$as_me: error: Unable to run $LEX on ${srcdir}/test.l, try using flex 
2.5 or newer." >&2;}
+   { (exit 1); exit 1; }; }
+elif ! $CC -c $CFLAGS $CPPFLAGS lex.yy.c >&5 ; then
+  rm -f lex.yy.c
+  { { echo "$as_me:$LINENO: error: Unable to compile lex.yy.c, check 
config.log for $LEX errors." >&5
+echo "$as_me: error: Unable to compile lex.yy.c, check config.log for $LEX 
errors." >&2;}
+   { (exit 1); exit 1; }; }
+else
+  rm -f lex.yy.c lex.yy.o
+  echo "${ECHO_T}okay" >&6
+fi
+
 echo "$as_me:$LINENO: checking for library containing crypt" >&5
 echo $ECHO_N "checking for library containing crypt... $ECHO_C" >&6
 if test "${ac_cv_search_crypt+set}" = set; then
Index: ircu2.10/configure.ac
diff -u ircu2.10/configure.ac:1.2 ircu2.10/configure.ac:1.3
--- ircu2.10/configure.ac:1.2   Thu Dec 29 14:13:10 2005
+++ ircu2.10/configure.ac       Mon Jun 26 21:46:10 2006
@@ -14,7 +14,7 @@
 dnl along with this program; if not, write to the Free Software
 dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 dnl
-dnl @(#)$Id: configure.ac,v 1.2 2005/12/29 22:13:10 entrope Exp $
+dnl @(#)$Id: configure.ac,v 1.3 2006/06/27 04:46:10 entrope Exp $
 
 AC_INIT([Undernet IRC Daemon], 10.13.alpha.0, [EMAIL PROTECTED], [ircu2])
 AC_PREREQ(2.59)
@@ -34,7 +34,7 @@
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA])
 
-AC_REVISION($Revision: 1.2 $)
+AC_REVISION($Revision: 1.3 $)
 
 AC_CONFIG_SRCDIR([ircd/ircd.c])
 AM_INIT_AUTOMAKE([foreign])
@@ -56,6 +56,18 @@
 AM_PROG_LEX
 AC_PROG_YACC
 
+dnl Make sure that lex is flex (or something sufficiently close)
+echo $ECHO_N "checking $LEX compatibility... " >&6
+if ! $LEX ${srcdir}/test.l >&5 ; then
+  AC_MSG_ERROR([Unable to run $LEX on ${srcdir}/test.l, try using flex 2.5 or 
newer.])
+elif ! $CC -c $CFLAGS $CPPFLAGS lex.yy.c >&5 ; then
+  rm -f lex.yy.c
+  AC_MSG_ERROR([Unable to compile lex.yy.c, check config.log for $LEX errors.])
+else
+  rm -f lex.yy.c lex.yy.o
+  echo "${ECHO_T}okay" >&6
+fi
+
 dnl Let's find the library containing crypt...
 AC_SEARCH_LIBS(crypt, [descrypt crypt], ,
 [AC_MSG_ERROR([Unable to find library containing crypt()])])
Index: ircu2.10/ircd/ircd_lexer.l
diff -u ircu2.10/ircd/ircd_lexer.l:1.24 ircu2.10/ircd/ircd_lexer.l:1.25
--- ircu2.10/ircd/ircd_lexer.l:1.24     Mon Jun 26 17:11:17 2006
+++ ircu2.10/ircd/ircd_lexer.l  Mon Jun 26 21:46:10 2006
@@ -1,8 +1,8 @@
 /*
  * ircd_lexer.l: A lexical scanner for ircd config files.
  * This is part of ircu, an Internet Relay Chat server.
- * The contents of this file are Copyright(C) 2001 by Andrew Miller, the
- * ircd-hybrid team and the ircu team.
+ * Copyright 2006 Michael Poole
+ *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
  *  the Free Software Foundation; either version 2 of the License, or
@@ -17,202 +17,152 @@
  *  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.24 2006/06/27 00:11:17 entrope Exp $
+ * $Id: ircd_lexer.l,v 1.25 2006/06/27 04:46:10 entrope Exp $
  */
 
+%option never-interactive case-insensitive warn nodefault nounput yylineno
+
 %{
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+
+#ifndef YY_FATAL_ERROR
+# define YY_FATAL_ERROR(MSG) fprintf(stderr, MSG)
+#endif
+
+#ifndef YY_NEW_FILE
+# define YY_NEW_FILE
+#endif
+
 #include "config.h"
-#include "ircd.h"
 #include "ircd_alloc.h"
 #include "ircd_string.h"
-#include "s_debug.h"
 #include "ircd_parser.h"
 
-extern int lineno;
-
-static struct lexer_token {
-  const char *string;
-  int value;
-} tokens[] = {
-#define TOKEN(NAME) { #NAME, NAME }
-  TOKEN(ADMIN),
-  TOKEN(GENERAL),
-  TOKEN(LOCATION),
-  TOKEN(CONTACT),
-  TOKEN(CLASS),
-  TOKEN(PINGFREQ),
-  TOKEN(CONNECT),
-  TOKEN(CONNECTFREQ),
-  TOKEN(MAXLINKS),
-  TOKEN(MAXHOPS),
-  TOKEN(SENDQ),
-  TOKEN(NAME),
-  TOKEN(HOST),
-  TOKEN(IP),
-  TOKEN(USERNAME),
-  TOKEN(PASS),
-  TOKEN(SECONDS),
-  TOKEN(MINUTES),
-  TOKEN(HOURS),
-  TOKEN(DAYS),
-  TOKEN(WEEKS),
-  TOKEN(MONTHS),
-  TOKEN(YEARS),
-  TOKEN(DECADES),
-  TOKEN(BYTES),
-  TOKEN(KBYTES),
-  TOKEN(MBYTES),
-  TOKEN(GBYTES),
-  TOKEN(TBYTES),
-  TOKEN(PORT),
-  TOKEN(SERVER),
-  TOKEN(YES),
-  TOKEN(NO),
-  TOKEN(HUB),
-  TOKEN(LEAF),
-  TOKEN(UWORLD),
-  TOKEN(OPER),
-  TOKEN(LOCAL),
-  TOKEN(VHOST),
-  TOKEN(MASK),
-  TOKEN(HIDDEN),
-  TOKEN(MOTD),
-  TOKEN(NUMERIC),
-  TOKEN(NICK),
-  TOKEN(JUPE),
-  TOKEN(DESCRIPTION),
-  TOKEN(CLIENT),
-  TOKEN(REAL),
-  TOKEN(REASON),
-  TOKEN(RULE),
-  TOKEN(ALL),
-  TOKEN(CRULE),
-  TOKEN(KILL),
-  TOKEN(QUARANTINE),
-  TOKEN(IAUTH),
-  TOKEN(TIMEOUT),
-  TOKEN(FEATURES),
-  TOKEN(CHANNEL),
-  TOKEN(PSEUDO),
-  TOKEN(PREPEND),
-  TOKEN(USERMODE),
-  TOKEN(FAST),
-  TOKEN(AUTOCONNECT),
-  TOKEN(PROGRAM),
-#undef TOKEN
-  { "administrator", ADMIN },
-  { "apass_opmode", TPRIV_APASS_OPMODE },
-  { "auto", AUTOCONNECT },
-  { "b", BYTES },
-  { "badchan", TPRIV_BADCHAN },
-  { "chan_limit", TPRIV_CHAN_LIMIT },
-  { "deop_lchan", TPRIV_DEOP_LCHAN },
-  { "die", TPRIV_DIE },
-  { "display", TPRIV_DISPLAY },
-  { "file", TFILE },
-  { "force_local_opmode", TPRIV_FORCE_LOCAL_OPMODE },
-  { "force_opmode", TPRIV_FORCE_OPMODE },
-  { "gline", TPRIV_GLINE },
-  { "kb", KBYTES },
-  { "kilobytes", KBYTES },
-  { "list_chan", TPRIV_LIST_CHAN },
-  { "local_badchan", TPRIV_LOCAL_BADCHAN },
-  { "local_gline", TPRIV_LOCAL_GLINE },
-  { "local_jupe", TPRIV_LOCAL_JUPE },
-  { "local_kill", TPRIV_LOCAL_KILL },
-  { "local_opmode", TPRIV_LOCAL_OPMODE },
-  { "mb", MBYTES },
-  { "megabytes", MBYTES },
-  { "mode_lchan", TPRIV_MODE_LCHAN },
-  { "gb", GBYTES },
-  { "gigabytes", GBYTES },
-  { "operator", OPER },
-  { "opmode", TPRIV_OPMODE },
-  { "password", PASS },
-  { "propagate", TPRIV_PROPAGATE },
-  { "realname", REAL },
-  { "rehash", TPRIV_REHASH },
-  { "restart", TPRIV_RESTART },
-  { "see_chan", TPRIV_SEE_CHAN },
-  { "see_opers", TPRIV_SEE_OPERS },
-  { "set", TPRIV_SET },
-  { "show_all_invis", TPRIV_SHOW_ALL_INVIS },
-  { "show_invis", TPRIV_SHOW_INVIS },
-  { "tb", TBYTES },
-  { "terabytes", TBYTES },
-  { "unlimit_query", TPRIV_UNLIMIT_QUERY },
-  { "walk_lchan", TPRIV_WALK_LCHAN },
-  { "wide_gline", TPRIV_WIDE_GLINE },
-  { "whox", TPRIV_WHOX },
-  { NULL, 0 }
-};
-static int ntokens;
-
-static int
-token_compare(const void *pa, const void *pb)
-{
-  const struct lexer_token *ta = pa;
-  const struct lexer_token *tb = pb;
-  unsigned int ii = 0;
-  int res;
-  while (ta->string[ii] && (ToLower(ta->string[ii]) == 
ToLower(tb->string[ii])))
-    ii++;
-  res = ToLower(tb->string[ii]) - ToLower(ta->string[ii]);
-  return res;
-}
-
-static void
-init_ntokens(void)
-{
-  for (ntokens = 0; tokens[ntokens].string; ++ntokens) ;
-  qsort(tokens, ntokens, sizeof(tokens[0]), token_compare);
-}
-
-static int
-find_token(char *token)
-{
-  struct lexer_token *tok;
-  if (!ntokens)
-    init_ntokens();
-  tok = bsearch(&token, tokens, ntokens, sizeof(tokens[0]), token_compare);
-  return tok ? tok->value : 0;
-}
-
 void
-init_lexer(void)
+init_lexer(const char *configfile)
 {
   yyin = fopen(configfile, "r");
   if (yyin == NULL)
   {
-#ifdef YY_FATAL_ERROR
     YY_FATAL_ERROR("Could not open the configuration file.");
-#else
-    fprintf(stderr, "Could not open the configuration file.");
-#endif
   }
-#ifdef YY_NEW_FILE
   YY_NEW_FILE;
-#endif
-  lineno = 1;
 }
 
 %}
 
-WHITE [ \t\r]+
-SHCOMMENT #[^\n]*
-NUMBER [0-9]+
-QSTRING \"[^"\n]+[\"\n]
 %%
 
-{QSTRING} {yytext[yyleng-1] = 0; DupString(yylval.text, yytext+1); return 
QSTRING;}
-{NUMBER} {yylval.num = strtoul(yytext, NULL, 10); return NUMBER;}
-{WHITE} ;
-{SHCOMMENT} ;
+\"[^"\n]+[\"\n] {yytext[yyleng-1] = 0; DupString(yylval.text, yytext+1); 
return QSTRING;}
+[0-9]+         {yylval.num = strtoul(yytext, NULL, 10); return NUMBER;}
+[ \t\r\n]+     ;
+#.*            ;
+
+ADMIN          return ADMIN;
+ADMINISTRATOR  return ADMIN;
+APASS_OPMODE   return TPRIV_APASS_OPMODE;
+ALL            return ALL;
+AUTO           return AUTOCONNECT;
+AUTOCONNECT    return AUTOCONNECT;
+B              return BYTES;
+BADCHAN                return TPRIV_BADCHAN;
+BYTES          return BYTES;
+CHANNEL                return CHANNEL;
+CHAN_LIMIT     return TPRIV_CHAN_LIMIT;
+CLASS          return CLASS;
+CLIENT         return CLIENT;
+CONNECT                return CONNECT;
+CONNECTFREQ    return CONNECTFREQ;
+CONTACT                return CONTACT;
+CRULE          return CRULE;
+DAYS           return DAYS;
+DECADES                return DECADES;
+DEOP_LCHAN     return TPRIV_DEOP_LCHAN;
+DESCRIPTION    return DESCRIPTION;
+DIE            return TPRIV_DIE;
+DISPLAY                return TPRIV_DISPLAY;
+FAST           return FAST;
+FEATURES       return FEATURES;
+FILE           return TFILE;
+FORCE_LOCAL_OPMODE     return TPRIV_FORCE_LOCAL_OPMODE;
+FORCE_OPMODE   return TPRIV_FORCE_OPMODE;
+GB             return GBYTES;
+GBYTES         return GBYTES;
+GENERAL                return GENERAL;
+GIGABYTES      return GBYTES;
+GLINE          return TPRIV_GLINE;
+HIDDEN         return HIDDEN;
+HOST           return HOST;
+HOURS          return HOURS;
+HUB            return HUB;
+IAUTH          return IAUTH;
+IP             return IP;
+JUPE           return JUPE;
+KB             return KBYTES;
+KBYTES         return KBYTES;
+KILOBYTES      return KBYTES;
+KILL           return KILL;
+LEAF           return LEAF;
+LIST_CHAN      return TPRIV_LIST_CHAN;
+LOCAL          return LOCAL;
+LOCAL_BADCHAN  return TPRIV_LOCAL_BADCHAN;
+LOCAL_GLINE    return TPRIV_LOCAL_GLINE;
+LOCAL_JUPE     return TPRIV_LOCAL_JUPE;
+LOCAL_OPMODE   return TPRIV_LOCAL_OPMODE;
+LOCATION       return LOCATION;
+MASK           return MASK;
+MAXHOPS                return MAXHOPS;
+MAXLINKS       return MAXLINKS;
+MB             return MBYTES;
+MBYTES         return MBYTES;
+MEGABYTES      return MBYTES;
+MINUTES                return MINUTES;
+MODE_LCHAN     return TPRIV_MODE_LCHAN;
+MONTHS         return MONTHS;
+MOTD           return MOTD;
+NAME           return NAME;
+NICK           return NICK;
+NO             return NO;
+NUMERIC                return NUMERIC;
+OPER           return OPER;
+OPERATOR       return OPER;
+OPMODE         return TPRIV_OPMODE;
+PASS           return PASS;
+PASSWORD       return PASS;
+PINGFREQ       return PINGFREQ;
+PORT           return PORT;
+PREPEND                return PREPEND;
+PROGRAM                return PROGRAM;
+PROPAGATE      return TPRIV_PROPAGATE;
+PSEUDO         return PSEUDO;
+QUARANTINE     return QUARANTINE;
+REAL           return REAL;
+REALNAME       return REAL;
+REASON         return REASON;
+REHASH         return TPRIV_REHASH;
+RESTART                return TPRIV_RESTART;
+RULE           return RULE;
+SECONDS                return SECONDS;
+SEE_CHAN       return TPRIV_SEE_CHAN;
+SEE_OPERS      return TPRIV_SEE_OPERS;
+SENDQ          return SENDQ;
+SERVER         return SERVER;
+SET            return TPRIV_SET;
+SHOW_ALL_INVIS return TPRIV_SHOW_ALL_INVIS;
+SHOW_INVIS     return TPRIV_SHOW_INVIS;
+TIMEOUT                return TIMEOUT;
+TB             return TBYTES;
+TBYTES         return TBYTES;
+TERABYTES      return TBYTES;
+UNLIMIT_QUERY  return TPRIV_UNLIMIT_QUERY;
+USERMODE       return USERMODE;
+USERNAME       return USERNAME;
+UWORLD         return UWORLD;
+VHOST          return VHOST;
+WALK_LCHAN     return TPRIV_WALK_LCHAN;
+WEEKS          return WEEKS;
+WIDE_GLINE     return TPRIV_WIDE_GLINE;
+WHOX           return TPRIV_WHOX;
+YEARS          return YEARS;
+YES            return YES;
 
-[a-zA-Z_]+ { int res = find_token(yytext); if (res) return res; else REJECT; }
-\n lineno++;
 . return yytext[0];
Index: ircu2.10/ircd/s_conf.c
diff -u ircu2.10/ircd/s_conf.c:1.87 ircu2.10/ircd/s_conf.c:1.88
--- ircu2.10/ircd/s_conf.c:1.87 Thu Apr  6 20:27:50 2006
+++ ircu2.10/ircd/s_conf.c      Mon Jun 26 21:46:10 2006
@@ -19,7 +19,7 @@
  */
 /** @file
  * @brief ircd configuration file driver
- * @version $Id: s_conf.c,v 1.87 2006/04/07 03:27:50 entrope Exp $
+ * @version $Id: s_conf.c,v 1.88 2006/06/27 04:46:10 entrope Exp $
  */
 #include "config.h"
 
@@ -825,7 +825,7 @@
 static int conf_already_read;
 extern FILE *yyin;
 extern void yyparse(void);
-extern void init_lexer(void);
+extern void init_lexer(const char *configfile);
 
 /** Read configuration file.
  * @return Zero on failure, non-zero on success. */
@@ -833,8 +833,7 @@
 {
   conf_error = 0;
   feature_unmark(); /* unmark all features for resetting later */
-  /* Now just open an fd. The buffering isn't really needed... */
-  init_lexer();
+  init_lexer(configfile);
   yyparse();
   fclose(yyin);
   yyin = NULL;
Index: ircu2.10/test.l
diff -u /dev/null ircu2.10/test.l:1.1
--- /dev/null   Mon Jun 26 21:46:20 2006
+++ ircu2.10/test.l     Mon Jun 26 21:46:10 2006
@@ -0,0 +1,32 @@
+%option never-interactive case-insensitive warn nodefault nounput
+%x incl
+
+%%
+
+#[^\n]*        ;
+\"[^"\n]+[\"\n] ECHO;
+[ \t\r]+       ;
+\n             ;
+[0-9]+                 ECHO;
+INCLUDE                BEGIN(incl);
+.              return yytext[0];
+
+<incl>[ \t]*   /* consume whitespace */
+<incl>[^ \t\n]+ {
+    yyin = fopen(yytext, "r");
+    if (!yyin)
+    {
+      fprintf(stderr, "Unable to open %s: %s\n", yytext, strerror(errno));
+      exit(1);
+    }
+    yypush_buffer_state(yy_create_buffer(yyin, YY_BUF_SIZE));
+    BEGIN(INITIAL);
+    }
+<incl>\n       return yytext[0];
+<<EOF>> {
+    yypop_buffer_state();
+    if (!YY_CURRENT_BUFFER)
+      yyterminate();
+}
+
+%%
----------------------- End of diff -----------------------
_______________________________________________
Patches mailing list
[email protected]
http://undernet.sbg.org/mailman/listinfo/patches

Reply via email to