chiark / gitweb /
Correct quoting of include-lookup directory. Closes:#837391. (With new directives...
[userv.git] / lexer.l
diff --git a/lexer.l b/lexer.l
index ac21f695e6c8265e787859a153f3b4ec525a6dc1..27f51814ac3a44371ae52e1dd2737b3362bd39dc 100644 (file)
--- a/lexer.l
+++ b/lexer.l
@@ -43,6 +43,7 @@
 #include "common.h"
 #include "daemon.h"
 #include "lib.h"
+#include "both.h"
 #include "tokens.h"
 
 #define HYPHEN '-'
@@ -51,7 +52,7 @@ typedef int directive_fnt(int dtoken);
 static directive_fnt df_reject, df_execute, df_executefrompath;
 static directive_fnt df_executefromdirectory, df_executebuiltin;
 static directive_fnt df_errorstostderr, df_errorstosyslog, df_errorstofile;
-static directive_fnt dfg_fdwant, dfg_setflag;
+static directive_fnt dfg_fdwant, dfg_setflag, dfg_lookupquotemode;
 static directive_fnt df_reset, df_cd, df_userrcfile, df_include;
 static directive_fnt df_includelookup, df_includedirectory;
 static directive_fnt df_message, df_error, df_quit, df_eof;
@@ -132,12 +133,12 @@ struct error_handling {
 static struct error_handling eh = { tokv_word_errorstostderr, 0,0,0,0,0 };
 
 static int dequote(char *inplace);
-
-#define YY_NO_UNPUT
+static void countnewlines(void);
 
 %}
 
 %option noyywrap
+%option nounput
 
 %%
 
@@ -148,6 +149,8 @@ execute-builtin { lr_dir= df_executebuiltin; return tokv_word_executebuiltin; }
 errors-to-stderr { lr_dir= df_errorstostderr; return tokv_word_errorstostderr; }
 errors-to-syslog { lr_dir= df_errorstosyslog; return tokv_word_errorstosyslog; }
 errors-to-file { lr_dir= df_errorstofile; return tokv_word_errorstofile; }
+include-lookup-quote-old { lr_dir= dfg_lookupquotemode; return tokv_word_includelookupquoteold; }
+include-lookup-quote-new { lr_dir= dfg_lookupquotemode; return tokv_word_includelookupquotenew; }
 require-fd { lr_dir= dfg_fdwant; lr_fdwant_readwrite=1; return tokv_word_requirefd; }
 allow-fd { lr_dir= dfg_fdwant; lr_fdwant_readwrite=0; return tokv_word_allowfd; }
 null-fd { lr_dir= dfg_fdwant; lr_fdwant_readwrite=0; return tokv_word_nullfd; }
@@ -228,6 +231,9 @@ local7 { lr_logfacility= LOG_LOCAL7; return tokv_syslog_local7; }
 read { return tokv_word_read; }
 write { return tokv_word_write; }
 \$ { return tokv_dollar; }
+stdin {  lr_max= lr_min= 0; return tokv_word_stdin; }
+stdout {  lr_max= lr_min= 1; return tokv_word_stdout; }
+stderr {  lr_max= lr_min= 2; return tokv_word_stderr; }
 \( { return tokv_openparen; }
 \) { return tokv_closeparen; }
 \! { return tokv_not; }
@@ -247,40 +253,35 @@ error { lr_dir= df_error; lr_loglevel= LOG_ERR; return tokv_word_error; }
                          char *ep;
                          lr_min= (int)strtoul(yytext,&ep,10);
                          assert(*ep == HYPHEN);
-                         assert(*++ep);
+                         ep++;  assert(*ep);
                          lr_max= (int)strtoul(ep,&ep,10);
                          assert(!*ep);
-                         if (lr_max < lr_min) {
-                           parseerrprint("fd range has min > max");
-                           return tokv_error;
-                         }
+                         if (lr_max < lr_min)
+                           return parseerrprint("fd range has min > max");
                          return tokv_fdrange;
                        }
 [0-9]{1,8}-            {
                          char *ep;
                          lr_min= (int)strtoul(yytext,&ep,10);
                          assert(*ep == HYPHEN);
-                         assert(!*++ep);
+                         ep++;  assert(!*ep);
                          lr_max=-1;
                          return tokv_fdstoend;
                        }
-([\ \t]*\\[\ \t]*\n[\ \t]*)+   return tokv_lwsp;
+([\ \t]*\\[\ \t]*\n[\ \t]*)+   countnewlines(); return tokv_lwsp;
 [\ \t]+                                return tokv_lwsp;
 [\ \t]*\n              cstate->lineno++; return tokv_newline;
 [\ \t]*\#[^\n]*\n      cstate->lineno++; return tokv_newline;
-[\ \t]*\#[^\n]*                {
-                         parseerrprint("missing newline at eof after comment");
-                         return tokv_error;
-                       }
+[\ \t]*\#[^\n]*                return parseerrprint("missing newline at eof after comment");
 \"([^\\\"\n]|\\[a-z]|\\[0-9]{3}|\\x[0-9A-Fa-f]{2}|\\[[:punct:]]|\\[ \t]*\n)*\" {
+                         countnewlines();
                          return dequote(yytext);
                        }
-\".*                   {
-                         parseerrprint("misquoted or unterminated string");
-                         return tokv_error;
-                       }
-[^\ \t\n\\]+           return tokv_barestring;
-<<EOF>>                        return tokv_eof;
+[^\ \t\n\\\"]+         return tokv_barestring;
+<<EOF>>                        return tokv_eof;
+\"                     return parseerrprint("misquoted or unterminated string");
+\\                     return parseerrprint("unexpected backslash");
+.                      abort(); /* expect lex warning "rule cannot be matched" */
 
 
 %%