- /* '#' is comment markers, like bash style */
- *strchrnul(line, '#') = '\0';
+ /*
+ * '#' is comment markers, like bash style but it is a valid
+ * character in some fields, so only treat it as a comment
+ * marker if it occurs at the beginning of the line, or after
+ * whitespace
+ */
+ hashmarker = strchr(line, '#');
+ if (line == hashmarker)
+ line[0] = '\0';
+ else {
+ while (hashmarker != NULL) {
+ --hashmarker;
+ if (isblank(hashmarker[0])) {
+ hashmarker[0] = '\0';
+ break;
+ } else {
+ /*
+ * false positive; '#' occured
+ * within a string
+ */
+ hashmarker = strchr(hashmarker+2, '#');
+ }
+ }
+ }