]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - support/nfs/conffile.c
nfs-utils: Fix source code character encoding
[nfs-utils.git] / support / nfs / conffile.c
index 97dc88a06df6762547336959238882ae2f809bc2..24640f4a2c3923759ff3818acefb24a5dbaeb600 100644 (file)
@@ -49,7 +49,7 @@
 #include "conffile.h"
 #include "xlog.h"
 
-static void conf_load_defaults (int);
+static void conf_load_defaults(void);
 static int conf_set(int , char *, char *, char *, 
        char *, int , int );
 
@@ -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)
  */
@@ -224,16 +212,13 @@ conf_parse_line(int trans, char *line, size_t sz)
 {
        char *val, *ptr;
        size_t i;
-       int j;
+       size_t j;
        static char *section = 0;
        static char *arg = 0;
        static int ln = 0;
 
        /* 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++;
@@ -256,7 +244,7 @@ conf_parse_line(int trans, char *line, size_t sz)
                if (section)
                        free(section);
                if (i == sz) {
-                       xlog_warn("conf_parse_line: %d:"
+                       xlog_warn("config file error: line %d: "
                                "non-matched ']', ignoring until next section", ln);
                        section = 0;
                        return;
@@ -286,7 +274,7 @@ conf_parse_line(int trans, char *line, size_t sz)
                while (*ptr && *ptr != '"')
                        ptr++;
                if (*ptr == '\0') {
-                       xlog_warn("conf_parse_line: line %d:"
+                       xlog_warn("config file error: line %d: "
                                "non-matched '\"', ignoring until next section", ln);
                }  else {
                        *ptr = '\0';
@@ -302,15 +290,29 @@ conf_parse_line(int trans, char *line, size_t sz)
                if (line[i] == '=') {
                        /* If no section, we are ignoring the lines.  */
                        if (!section) {
-                               xlog_warn("conf_parse_line: %d: ignoring line due to no section", 
-                                       ln);
+                       xlog_warn("config file error: line %d: "
+                               "ignoring line due to no section", ln);
                                return;
                        }
                        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;
@@ -319,7 +321,7 @@ conf_parse_line(int trans, char *line, size_t sz)
        /* Other non-empty lines are weird.  */
        i = strspn(line, " \t");
        if (line[i])
-               xlog_warn("conf_parse_line: %d: syntax error", ln);
+               xlog_warn("config file error: line %d:", ln);
 
        return;
 }
@@ -351,7 +353,7 @@ conf_parse(int trans, char *buf, size_t sz)
 }
 
 static void
-conf_load_defaults(int tr)
+conf_load_defaults(void)
 {
        /* No defaults */
        return;
@@ -410,7 +412,7 @@ conf_reinit(void)
                trans = conf_begin();
 
        /* Load default configuration values.  */
-       conf_load_defaults(trans);
+       conf_load_defaults();
 
        /* Free potential existing configuration.  */
        if (conf_addr) {