mirror of
https://github.com/swaywm/sway.git
synced 2024-12-28 07:56:31 +01:00
Fix option parsing
Using 'flag' results in duplicate code paths for short and long options. This broke the -q short option in swaymsg, because there was: {"quiet", no_argument, &quiet, 'q'} Which will set quiet to 'q' and return 0, not 'q'.
This commit is contained in:
parent
bf97a5ada5
commit
923c3245ac
3 changed files with 8 additions and 11 deletions
|
@ -57,10 +57,10 @@ int main(int argc, char **argv) {
|
||||||
static struct option long_options[] = {
|
static struct option long_options[] = {
|
||||||
{"help", no_argument, NULL, 'h'},
|
{"help", no_argument, NULL, 'h'},
|
||||||
{"config", required_argument, NULL, 'c'},
|
{"config", required_argument, NULL, 'c'},
|
||||||
{"validate", no_argument, &validate, 1},
|
{"validate", no_argument, NULL, 'C'},
|
||||||
{"debug", no_argument, &debug, 1},
|
{"debug", no_argument, NULL, 'd'},
|
||||||
{"version", no_argument, NULL, 'v'},
|
{"version", no_argument, NULL, 'v'},
|
||||||
{"verbose", no_argument, &verbose, 1},
|
{"verbose", no_argument, NULL, 'V'},
|
||||||
{"get-socketpath", no_argument, NULL, 'p'},
|
{"get-socketpath", no_argument, NULL, 'p'},
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
|
@ -87,8 +87,6 @@ int main(int argc, char **argv) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 0: // Flag
|
|
||||||
break;
|
|
||||||
case 'h': // help
|
case 'h': // help
|
||||||
fprintf(stdout, "%s", usage);
|
fprintf(stdout, "%s", usage);
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
|
|
|
@ -128,10 +128,10 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
static struct option long_options[] = {
|
static struct option long_options[] = {
|
||||||
{"help", no_argument, NULL, 'h'},
|
{"help", no_argument, NULL, 'h'},
|
||||||
{"capture", no_argument, &capture, 'c'},
|
{"capture", no_argument, NULL, 'c'},
|
||||||
{"version", no_argument, NULL, 'v'},
|
{"version", no_argument, NULL, 'v'},
|
||||||
{"socket", required_argument, NULL, 's'},
|
{"socket", required_argument, NULL, 's'},
|
||||||
{"raw", no_argument, &raw, 'r'},
|
{"raw", no_argument, NULL, 'r'},
|
||||||
{"rate", required_argument, NULL, 'R'},
|
{"rate", required_argument, NULL, 'R'},
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
|
@ -154,8 +154,6 @@ int main(int argc, char **argv) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 0: // Flag
|
|
||||||
break;
|
|
||||||
case 's': // Socket
|
case 's': // Socket
|
||||||
socket_path = strdup(optarg);
|
socket_path = strdup(optarg);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -24,7 +24,7 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
static struct option long_options[] = {
|
static struct option long_options[] = {
|
||||||
{"help", no_argument, NULL, 'h'},
|
{"help", no_argument, NULL, 'h'},
|
||||||
{"quiet", no_argument, &quiet, 'q'},
|
{"quiet", no_argument, NULL, 'q'},
|
||||||
{"version", no_argument, NULL, 'v'},
|
{"version", no_argument, NULL, 'v'},
|
||||||
{"socket", required_argument, NULL, 's'},
|
{"socket", required_argument, NULL, 's'},
|
||||||
{"type", required_argument, NULL, 't'},
|
{"type", required_argument, NULL, 't'},
|
||||||
|
@ -48,7 +48,8 @@ int main(int argc, char **argv) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 0: // Flag
|
case 'q': // Quiet
|
||||||
|
quiet = 1;
|
||||||
break;
|
break;
|
||||||
case 's': // Socket
|
case 's': // Socket
|
||||||
socket_path = strdup(optarg);
|
socket_path = strdup(optarg);
|
||||||
|
|
Loading…
Reference in a new issue