]> jfr.im git - irc/quakenet/newserv.git/blobdiff - newsearch/newsearch.l
LUA: add function for channel chanop notice
[irc/quakenet/newserv.git] / newsearch / newsearch.l
index 360a5fd8dc9ea9b58bad4655f73666f759cf2d50..043c6e03f8817ba12d2fc1a0534547d94a9903b2 100644 (file)
@@ -1,26 +1,31 @@
 %option noyywrap
 
 %{
+
+#include <stdlib.h>
+#include <string.h>
+#ifndef __POSIX_VISIBLE
+#define fileno(x) 0
+#endif
+
 #include "../lib/sstring.h"
 
 #define YYSTYPE sstring *
 extern YYSTYPE yylval;
 
 #include "y.tab.h"
-
-#include <stdlib.h>
 #include "../lib/stringbuf.h"
 
 #define MAX_STR_CONST 512
 
-/* shuts gcc up */
-static void yyunput (int c,char *buf_ptr);
-void newsearch_parser_dummy(void) {
-  yyunput(0, NULL);
-}
+int lexpos, lexerror;
 
-int fileno(void *arg) {
-  return 0;
+#define addpos(x) lexpos+=x;
+#define incpos() addpos(1);
+
+void lexreset(void) {
+  lexerror = 0;
+  lexpos = -1;
 }
 
 %}
@@ -28,41 +33,85 @@ int fileno(void *arg) {
 digit          [0-9]
 letter         [a-zA-Z]
 
-%x str
+%x str pascalstr
 %%
 
        char bufdata[MAX_STR_CONST];
        StringBuf buf;
 
-\"             {
+\"             { incpos();
                  sbinit(&buf, bufdata, sizeof(bufdata));
                  BEGIN(str);
                }
 
 <str>{
-  \"           {
+  \"           { incpos();
                  BEGIN(INITIAL);
                  sbterminate(&buf);
                  yylval = getsstring(bufdata, 512);
                  return STRING;
                }
-  \\\\         { sbaddchar(&buf, '\\');        }
-  \\\"         { sbaddchar(&buf, '"');         }
-  [^\\]                { sbaddchar(&buf, *yytext);     }
+  \\\\         { addpos(2);
+                 sbaddchar(&buf, '\\');
+               }
+  \\\"         { addpos(2);
+                 sbaddchar(&buf, '"');
+               }
+  [^\\]                { incpos();
+                 sbaddchar(&buf, *yytext);
+               }
 }
 
-"("            { return LPAREN;                }
-")"            { return RPAREN;                }
-[ \t]+         { return WHITESPACE;            }
-{letter}+      {
+\'             { incpos();
+                 sbinit(&buf, bufdata, sizeof(bufdata));
+                 BEGIN(pascalstr);
+               }
+
+<pascalstr>{
+  \'\'         { addpos(2);
+                 sbaddchar(&buf, '\'');
+               }
+  \'           { incpos();
+                 BEGIN(INITIAL);
+                 sbterminate(&buf);
+                 yylval = getsstring(bufdata, 512);
+                 return STRING;
+               }
+  .            { incpos();
+                 sbaddchar(&buf, *yytext);
+               }
+}
+
+"("            { incpos();
+                 return LPAREN;
+               }
+")"            { incpos();
+                 return RPAREN;
+               }
+[ \t]+         { addpos(strlen(yytext));
+                 return WHITESPACE;
+               }
+({letter}|{digit}|[#\-\+\.\*])+        { addpos(strlen(yytext));
                  yylval = getsstring(yytext, 512);
                  return IDENTIFIER;
                }
 
-[\n\r]         /* ignore */;
+[\n\r]         { incpos();
+                 /* ignore */;
+               }
+
+.              {
+                 incpos();
+                 lexerror = 1;
+                 yyterminate();
+               }
 
 <<EOF>>                {
                  BEGIN(INITIAL);
                  yyterminate();
                }
 %%
+
+void ydummyfn(void) {
+  yyunput(0, NULL);
+}