diff options
author | Tiago Cunha <tcunha@gmx.com> | 2011-08-25 21:14:23 +0000 |
---|---|---|
committer | Tiago Cunha <tcunha@gmx.com> | 2011-08-25 21:14:23 +0000 |
commit | 4a01da19df3d3d0c0628856700e32c9e0bb47760 (patch) | |
tree | aa3d40f8277f3ed254c470ee298e04fd23f8c0ac /cfg.c | |
parent | d390a90bf081efc589b4d3e1f8a570e8f12be3d1 (diff) | |
download | rtmux-4a01da19df3d3d0c0628856700e32c9e0bb47760.tar.gz rtmux-4a01da19df3d3d0c0628856700e32c9e0bb47760.tar.bz2 rtmux-4a01da19df3d3d0c0628856700e32c9e0bb47760.zip |
Sync OpenBSD patchset 951:
Support \ for line continuation in the configuration file, from Julius
Plenz.
Diffstat (limited to 'cfg.c')
-rw-r--r-- | cfg.c | 35 |
1 files changed, 27 insertions, 8 deletions
@@ -92,22 +92,37 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes) retval = 0; while ((buf = fgetln(f, &len))) { if (buf[len - 1] == '\n') - buf[len - 1] = '\0'; + len--; + + if (line != NULL) + line = xrealloc(line, 1, strlen(line) + len + 1); else { - line = xrealloc(line, 1, len + 1); - memcpy(line, buf, len); - line[len] = '\0'; - buf = line; + line = xmalloc(len + 1); + *line = '\0'; } + + /* Append buffer to line. strncat will terminate. */ + strncat(line, buf, len); n++; + /* Continuation: get next line? */ + len = strlen(line); + if (len > 0 && line[len - 1] == '\\') { + line[len - 1] = '\0'; + continue; + } + buf = line; + line = NULL; + if (cmd_string_parse(buf, &cmdlist, &cause) != 0) { + xfree(buf); if (cause == NULL) continue; cfg_add_cause(causes, "%s: %u: %s", path, n, cause); xfree(cause); continue; - } + } else + xfree(buf); if (cmdlist == NULL) continue; cfg_cause = NULL; @@ -131,12 +146,16 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes) retval = 1; cmd_list_free(cmdlist); if (cfg_cause != NULL) { - cfg_add_cause(causes, "%s: %d: %s", path, n, cfg_cause); + cfg_add_cause( + causes, "%s: %d: %s", path, n, cfg_cause); xfree(cfg_cause); } } - if (line != NULL) + if (line != NULL) { + cfg_add_cause(causes, + "%s: %d: line continuation at end of file", path, n); xfree(line); + } fclose(f); return (retval); |