chiark / gitweb /
Upgrade licence to GPLv3+.
[userv.git] / lexer.l.m4
index 7b26c1507c6c44981be7a1f89746a2ae29d5cde0..0c6416d7f0266a02f753b2cd45aedd79e47db59b 100644 (file)
@@ -1,21 +1,22 @@
 dnl  userv - lexer.l.m4
 dnl  lexer, passed through m4 with defs from langauge.i4
-/*
- *   Copyright (C)1996-1997,1999 Ian Jackson
- *  
- *   This 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
- *   (at your option) any later version.
- *  
- *   This program is distributed in the hope that it will be useful, but
- *   WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- *   General Public License for more details.
- *  
- *   You should have received a copy of the GNU General Public License
- *   along with userv; if not, write to the Free Software
- *   Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+/* userv is
+ * Copyright 1996-2017 Ian Jackson <ian@davenant.greenend.org.uk>.
+ * Copyright 2000      Ben Harris <bjh21@cam.ac.uk>
+ * Copyright 2016-2017 Peter Benie <pjb1008@cam.ac.uk>
+ *
+ * This 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with userv; if not, see <http://www.gnu.org/licenses/>.
  */
 
 %{
@@ -42,6 +43,7 @@ include(language.i4)
 #include "common.h"
 #include "daemon.h"
 #include "lib.h"
+#include "both.h"
 #include "tokens.h"
 
 #define HYPHEN '-'
@@ -50,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;
@@ -131,12 +133,14 @@ struct error_handling {
 static struct error_handling eh = { tokv_word_errorstostderr, 0,0,0,0,0 };
 
 static int dequote(char *inplace);
+static void countnewlines(void);
 
-#define YY_NO_UNPUT
+#define YY_NO_INPUT
 
 %}
 
 %option noyywrap
+%option nounput
 
 %%
 
@@ -154,40 +158,35 @@ changequote({*,*})
                          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" */
 *}
 changequote(`,')
 %%