--- old.main.c Sat Aug 18 16:55:33 2007 +++ main.c Sat Aug 18 19:22:12 2007 @@ -386,6 +386,29 @@ return (cp); } +static char slashbuf[4]; +static char * +slashify(char c) +{ + + memset(slashbuf, 0, sizeof(slashbuf)); + slashbuf[0] = '\\'; + switch (c) { + case '"': + slashbuf[1] = '"'; + break; + case '?': + slashbuf[1] = '?'; + break; + case '\\': + slashbuf[1] = '\\'; + break; + default: + return (NULL); + } + return (slashbuf); +} + /* * Generate configuration file based on actual settings. With this mode, user * will be able to obtain and build conifguration file with one command. @@ -396,7 +419,7 @@ struct cputype *cput; struct device *d; struct opt *ol; - char *lend; + char *c, *lend; unsigned int i; asprintf(&lend, "\\n\\\n"); @@ -416,9 +439,9 @@ if (ol->op_value != NULL) { sbuf_putc(sb, '='); for (i = 0; i < strlen(ol->op_value); i++) { - if (ol->op_value[i] == '"') - sbuf_printf(sb, "\\%c", - ol->op_value[i]); + c = slashify(ol->op_value[i]); + if (c != NULL) + sbuf_printf(sb, "%s", c); else sbuf_printf(sb, "%c", ol->op_value[i]); @@ -445,7 +468,8 @@ FILE *cff; struct cfgfile *cf; int i; - + char *t; + STAILQ_FOREACH(cf, &cfgfiles, cfg_next) { cff = fopen(cf->cfg_path, "r"); if (cff == NULL) { @@ -453,11 +477,11 @@ continue; } while ((i = getc(cff)) != EOF) { - if (i == '\n') + if (i == '\n') { sbuf_printf(sb, "\\n\\\n"); - else if (i == '"' || i == '\'') - sbuf_printf(sb, "\\%c", i); - else + } else if ((t = slashify(i)) != NULL) { + sbuf_printf(sb, "%s", t); + } else sbuf_putc(sb, i); } fclose(cff);