]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - support/nfs/conffile.c
Added support for line comments parsing which should
[nfs-utils.git] / support / nfs / conffile.c
index 97dc88a06df6762547336959238882ae2f809bc2..6bf423728a5d02cb8e74a20d565fe177d1979f4f 100644 (file)
@@ -119,18 +119,6 @@ conf_hash(char *s)
        return hash;
 }
 
-/*
- * Convert letter from upper case to lower case
- */
-static inline void upper2lower(char *str)
-{
-       char *ptr = str;
-
-       while (*ptr) 
-               *ptr++ = tolower(*ptr);
-}
-
-
 /*
  * Insert a tag-value combination from LINE (the equal sign is at POS)
  */
@@ -231,9 +219,6 @@ conf_parse_line(int trans, char *line, size_t sz)
 
        /* Lines starting with '#' or ';' are comments.  */
        ln++;
-       if (*line == '#' || *line == ';')
-               return;
-
        /* Ignore blank lines */
        if (*line == '\0')
                return;
@@ -242,6 +227,9 @@ conf_parse_line(int trans, char *line, size_t sz)
        while (isblank(*line)) 
                line++;
 
+       if (*line == '#' || *line == ';')
+               return;
+
        /* '[section]' parsing...  */
        if (*line == '[') {
                line++;
@@ -308,9 +296,23 @@ conf_parse_line(int trans, char *line, size_t sz)
                        }
                        line[strcspn (line, " \t=")] = '\0';
                        val = line + i + 1 + strspn (line + i + 1, " \t");
+
+                       /* Skip trailing comments, if any */
+                       for (j = 0; j < sz - (val - line); j++) {
+                               if (val[j] == '#' || val[j] == ';') {
+                                       val[j] = '\0';
+                                       break;
+                               }
+                       }
+
                        /* Skip trailing whitespace, if any */
-                       for (j = sz - (val - line) - 1; j > 0 && isspace(val[j]); j--)
-                               val[j] = '\0';
+                       for (j--; j > 0; j--) {
+                               if (isspace(val[j]))
+                                       val[j] = '\0';
+                               else 
+                                       break;
+                       }
+
                        /* XXX Perhaps should we not ignore errors?  */
                        conf_set(trans, section, arg, line, val, 0, 0);
                        return;