diff options
author | June McEnroe <june@causal.agency> | 2021-01-10 13:49:57 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2021-01-10 13:49:57 -0500 |
commit | cdff668d8f2523bdff624d5f357ccc5ed6ee21a0 (patch) | |
tree | a7da2fc5699526b69e60eddf365e01a259d62443 /config.c | |
parent | Move -o to a separate SYNOPSIS line (diff) | |
download | catgirl-cdff668d8f2523bdff624d5f357ccc5ed6ee21a0.tar.gz catgirl-cdff668d8f2523bdff624d5f357ccc5ed6ee21a0.zip |
Allow interspersing flags and config files
Don't wait for getopt_long to move all the arguments to the end. This allows overriding options set by config files by placing flags after them on the command line.
Diffstat (limited to 'config.c')
-rw-r--r-- | config.c | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/config.c b/config.c index 121a849..d6eaa45 100644 --- a/config.c +++ b/config.c @@ -56,21 +56,17 @@ int getopt_config( const char *optstring, const struct option *longopts, int *longindex ) { static int opt; - if (opt >= 0) { - opt = getopt_long(argc, argv, optstring, longopts, longindex); - } - if (opt >= 0) return opt; - for (;;) { if (!file) { - if (optind < argc) { - num = 0; - path = argv[optind++]; - file = configOpen(path, "r"); - if (!file) return clean('?'); - } else { - return clean(-1); + if (optind == argc) return clean(-1); + if (opt >= 0 && argv[optind][0] == '-') { + opt = getopt_long(argc, argv, optstring, longopts, longindex); + if (opt >= 0 || optind == argc) return clean(opt); } + num = 0; + path = argv[optind++]; + file = configOpen(path, "r"); + if (!file) return clean('?'); } for (;;) { |