From 6a0b9d08e202b6cedbc6fa8f99175ff5e2f5fbc3 Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 31 Mar 2004 19:19:34 +0000 Subject: [PATCH] Add the -C command-line option, which allows arbitrary \cfg directives to be supplied on the Halibut command line. git-svn-id: svn://svn.tartarus.org/sgt/halibut@4013 cda61777-01e9-0310-a592-d414129be87e --- error.c | 4 +++- main.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 65 insertions(+), 6 deletions(-) diff --git a/error.c b/error.c index bf16504..5819e00 100644 --- a/error.c +++ b/error.c @@ -211,7 +211,9 @@ static void do_error(int code, va_list ap) { if (flags & PREFIX) fputs("halibut: ", stderr); if (flags & FILEPOS) { - fprintf(stderr, "%s:%d:", fpos.filename, fpos.line); + fprintf(stderr, "%s:", fpos.filename); + if (fpos.line > 0) + fprintf(stderr, "%d:", fpos.line); if (fpos.col > 0) fprintf(stderr, "%d:", fpos.col); fputc(' ', stderr); diff --git a/main.c b/main.c index a528453..3d72d05 100644 --- a/main.c +++ b/main.c @@ -34,6 +34,7 @@ int main(int argc, char **argv) { int debug; int backendbits; int k, b; + paragraph *cfg, *cfg_tail; /* * Set up initial (default) parameters. @@ -44,6 +45,7 @@ int main(int argc, char **argv) { reportcols = 0; debug = 0; backendbits = 0; + cfg = cfg_tail = NULL; if (argc == 1) { usage(); @@ -132,8 +134,7 @@ int main(int argc, char **argv) { break; } break; -#if 0 - case 'o': + case 'C': /* * Option requiring parameter. */ @@ -150,13 +151,54 @@ int main(int argc, char **argv) { * Now c is the option and p is the parameter. */ switch (c) { - case 'o': - outfile = p; + case 'C': + /* + * -C means we split our argument up into + * colon-separated chunks and assemble them + * into a config paragraph. + */ + { + wchar_t *keywords; + char *q; + wchar_t *u; + paragraph *para; + + keywords = mknewa(wchar_t, 2+strlen(p)); + + u = keywords; + q = p; + + while (*q) { + if (*q == ':') { + *u++ = L'\0'; + } else { + if (*q == '\\' && q[1]) + q++; + /* FIXME: lacks charset flexibility */ + *u++ = *q; + } + q++; + } + *u = L'\0'; + + para = mknew(paragraph); + memset(para, 0, sizeof(*para)); + para->type = para_Config; + para->keyword = keywords; + para->next = NULL; + para->fpos.filename = ""; + para->fpos.line = para->fpos.col = -1; + + if (cfg_tail) + cfg_tail->next = para; + else + cfg = para; + cfg_tail = para; + } break; } p = NULL; /* prevent continued processing */ break; -#endif default: /* * Unrecognised option. @@ -212,6 +254,21 @@ int main(int argc, char **argv) { if (!sourceform) exit(EXIT_FAILURE); + /* + * Append the config directives acquired from the command + * line. + */ + { + paragraph *end; + + end = sourceform; + while (end && end->next) + end = end->next; + assert(end); + + end->next = cfg; + } + sfree(in.pushback); mark_attr_ends(sourceform); -- 2.11.0