summaryrefslogtreecommitdiffstats
path: root/support/nfs/conffile.c
diff options
context:
space:
mode:
authorBenny Halevy <bhalevy@panasas.com>2009-08-17 07:12:03 -0400
committerSteve Dickson <steved@redhat.com>2009-08-17 07:12:03 -0400
commit4d0175ad400ec56456765a15829557f1d541866a (patch)
treed383c2b506a0de7571b962954792559e4b8ef862 /support/nfs/conffile.c
parent8414d150cee62ba0554cfd645956a88dba02a7eb (diff)
downloadnfs-utils-4d0175ad400ec56456765a15829557f1d541866a.tar.gz
nfs-utils-4d0175ad400ec56456765a15829557f1d541866a.tar.xz
nfs-utils-4d0175ad400ec56456765a15829557f1d541866a.zip
Added support for line comments parsing which should
help with readability with in the configuration file. Signed-off-by: Steve Dickson <steved@redhat.com>
Diffstat (limited to 'support/nfs/conffile.c')
-rw-r--r--support/nfs/conffile.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/support/nfs/conffile.c b/support/nfs/conffile.c
index b19b739..6bf4237 100644
--- a/support/nfs/conffile.c
+++ b/support/nfs/conffile.c
@@ -219,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;
@@ -230,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++;
@@ -296,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;