diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-02-09 16:34:52 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-02-09 16:34:52 +0200 |
commit | 62f22e19e0953022d68f220463104117a1a5b7e2 (patch) | |
tree | 1c0ca58723492296f84b25b8f1e195573263188a /src | |
parent | daae7b2e4fbcecbb11f85949358c189fc25291b6 (diff) | |
download | eclat-62f22e19e0953022d68f220463104117a1a5b7e2.tar.gz eclat-62f22e19e0953022d68f220463104117a1a5b7e2.tar.bz2 |
Read default options from the environment variable ECLAT_OPTIONS.
* src/cmdline.opt (process_options): Process the value
of the environment variable ECLAT_OPTIONS prior to the
actual command line options.
* src/eclat.c (main): Update invocation of process_options.
* doc/eclat.1: Update.
Diffstat (limited to 'src')
-rw-r--r-- | src/cmdline.opt | 33 | ||||
-rw-r--r-- | src/eclat.c | 7 |
2 files changed, 33 insertions, 7 deletions
diff --git a/src/cmdline.opt b/src/cmdline.opt index 9ca41ee..23a0858 100644 --- a/src/cmdline.opt +++ b/src/cmdline.opt @@ -276,9 +276,35 @@ END OPTIONS_END static void -parse_options(int argc, char *argv[], int *index) +parse_options(int *pargc, char **pargv[]) { - GETOPT(argc, argv, *index, exit(EX_USAGE)) + int index; + int argc; + char **argv; + char *p; + + argc = *pargc; + argv = *pargv; + + p = getenv("ECLAT_OPTIONS"); + if (p) { + struct wordsplit ws; + int i, j; + + ws.ws_offs = argc; + if (wordsplit(p, &ws, WRDSF_DEFFLAGS|WRDSF_DOOFFS)) + die(EX_SOFTWARE, "wordsplit failed at \"%s\": %s", + p, wordsplit_strerror(&ws)); + memmove(ws.ws_wordv + 1, ws.ws_wordv + ws.ws_offs, + sizeof(ws.ws_wordv[0])*ws.ws_wordc); + ws.ws_wordv[0] = argv[0]; + for (i = 1, j = ws.ws_wordc + 1; i < argc; i++, j++) + ws.ws_wordv[j] = argv[i]; + argc += ws.ws_wordc; + argv = ws.ws_wordv; + } + + GETOPT(argc, argv, index, exit(EX_USAGE)) if (pp_cmd_buffer && grecs_preprocessor) { char *cmd = grecs_malloc(strlen(grecs_preprocessor) + @@ -288,5 +314,8 @@ parse_options(int argc, char *argv[], int *index) grecs_preprocessor = cmd; free(pp_cmd_buffer); } + + *pargc = argc - index; + *pargv = argv + index; } diff --git a/src/eclat.c b/src/eclat.c index 49691e7..eca1b71 100644 --- a/src/eclat.c +++ b/src/eclat.c @@ -632,7 +632,7 @@ read_format(struct command *cmd) int main(int argc, char **argv) { - int index, rc; + int rc; struct grecs_node *tree; CURL *curl; XML_Parser parser; @@ -659,10 +659,7 @@ main(int argc, char **argv) #endif sortcmds(); config_init(); - parse_options(argc, argv, &index); - - argc -= index; - argv += index; + parse_options(&argc, &argv); if (match_command_mode) { if (argc > 1) |