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.weechat-hashes
parent
a437761267
commit
cdff668d8f
20
config.c
20
config.c
|
@ -56,21 +56,17 @@ int getopt_config(
|
||||||
const char *optstring, const struct option *longopts, int *longindex
|
const char *optstring, const struct option *longopts, int *longindex
|
||||||
) {
|
) {
|
||||||
static int opt;
|
static int opt;
|
||||||
if (opt >= 0) {
|
|
||||||
opt = getopt_long(argc, argv, optstring, longopts, longindex);
|
|
||||||
}
|
|
||||||
if (opt >= 0) return opt;
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (!file) {
|
if (!file) {
|
||||||
if (optind < argc) {
|
if (optind == argc) return clean(-1);
|
||||||
num = 0;
|
if (opt >= 0 && argv[optind][0] == '-') {
|
||||||
path = argv[optind++];
|
opt = getopt_long(argc, argv, optstring, longopts, longindex);
|
||||||
file = configOpen(path, "r");
|
if (opt >= 0 || optind == argc) return clean(opt);
|
||||||
if (!file) return clean('?');
|
|
||||||
} else {
|
|
||||||
return clean(-1);
|
|
||||||
}
|
}
|
||||||
|
num = 0;
|
||||||
|
path = argv[optind++];
|
||||||
|
file = configOpen(path, "r");
|
||||||
|
if (!file) return clean('?');
|
||||||
}
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|
Loading…
Reference in New Issue