chiark / gitweb /
debian/control: Add missing build-dependency on flex. Fixes FTBFS. Report from Aurel...
[userv.git] / parser.c
index a5b5fb5fd66de0b10d504a7238c6883efae7190c..ade124e1f64afd09349533171b7fd0c144aa0016 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -6,11 +6,12 @@
  * about m4 quoting &c., but we have to #include it so that the C
  * objects from the lexer are available.
  *
- * Copyright (C)1996-1999,2001,2006,2012 Ian Jackson
+ * userv is copyright Ian Jackson and other contributors.
+ * See README for full authorship information.
  *
  * 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
+ * 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
@@ -19,8 +20,7 @@
  * 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.
+ * along with userv; if not, see <http://www.gnu.org/licenses/>.
  */
 
 static int parse_file(const char *string, int *didexist);
@@ -591,9 +591,7 @@ int pcf_range(int ctoken, char *const *pv, int *rtrue) {
   char *ep;
   unsigned long v;
 
-  r= pa_mwsp(); if (r) return r;
   mintoken= pa_numberdollar(&min); if (mintoken == tokv_error) return mintoken;
-  r= pa_mwsp(); if (r) return r;
   maxtoken= pa_numberdollar(&max); if (maxtoken == tokv_error) return maxtoken;
   r= pa_mnl(); if (r) return r;
   for (pp= pv; *pp; pp++) {
@@ -997,7 +995,7 @@ int df_includedirectory(int dtoken) {
     return parseerrprint("unable to open directory `%s': %s",cpget,strerror(errno));
   cp= xstrsave(cpget);
   cpl= strlen(cp);
-  while ((de= readdir(d))) {
+  while ((errno=0, de= readdir(d))) {
     tel= strlen(de->d_name);
     if (!tel) continue;
     p= de->d_name;
@@ -1016,6 +1014,12 @@ int df_includedirectory(int dtoken) {
       goto x_err;
     }
   }
+  if (errno) {
+    parseerrprint("error reading directory `%s': %s",cp,strerror(errno));
+    closedir(d);
+    free(cp);
+    return tokv_error;
+  }
   if (closedir(d)) {
     parseerrprint("error closing directory `%s': %s",cp,strerror(errno));
     free(cp);
@@ -1030,6 +1034,15 @@ x_err:
   return r;
 }
 
+static int oldquote = 0;
+
+int dfg_lookupquotemode(int dtoken) {
+  int r;
+  r= pa_mnl(); if (r) return r;
+  oldquote = dtoken == tokv_word_includelookupquoteold;
+  return r;
+}
+
 int df_includelookup(int dtoken) {
   static char *buildbuf=0;
   int buildbuflen=0;
@@ -1081,9 +1094,11 @@ int df_includelookup(int dtoken) {
          if (c=='/') {
            *q++= ':';
            c= '-';
-         } else if (!((c >= '0' && c <= '9') ||
+         } else if (oldquote ?
+                    !((c >= '0' && c <= '9') ||
                       (c >= 'a' && c <= 'z') ||
-                      c == '-' || c == '_')) {
+                      c == '-' || c == '_') :
+                    (c==':')) {
            *q++= ':';
          }
          *q++= c;