diff options
| author | Simon Tatham <anakin@pobox.com> | 2004-03-31 19:19:34 +0000 |
|---|---|---|
| committer | Simon Tatham <anakin@pobox.com> | 2004-03-31 19:19:34 +0000 |
| commit | 386dbf0fbc4abfd14adf854e920ab6cb213ab63d (patch) | |
| tree | 7c80fa61aa647e1b538612e4912721deafbb3c8c | |
| parent | 03ac8db2fb8e23dbe050d156ec7a6958cbcd704a (diff) | |
| download | halibut-386dbf0fbc4abfd14adf854e920ab6cb213ab63d.zip halibut-386dbf0fbc4abfd14adf854e920ab6cb213ab63d.tar.gz halibut-386dbf0fbc4abfd14adf854e920ab6cb213ab63d.tar.bz2 halibut-386dbf0fbc4abfd14adf854e920ab6cb213ab63d.tar.xz | |
Add the -C command-line option, which allows arbitrary \cfg
directives to be supplied on the Halibut command line.
[originally from svn r4013]
| -rw-r--r-- | error.c | 4 | ||||
| -rw-r--r-- | main.c | 67 |
2 files changed, 65 insertions, 6 deletions
@@ -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); @@ -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 = "<command line>"; + 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); |