Commit: 831675c848e504b5fced2722d503fe76b5f37266 Parent: 00d8fd4d22d3f41c25e0f34cc016a8e641af219c Author: Randy Palamar Date: Sat, 24 Apr 2021 13:37:21 -0600 properly handle arguments Diffstat:
M | status.c | | | 22 | ++++++++++++++++------ |
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/status.c b/status.c @@ -155,14 +155,24 @@ statusloop(void) int main(int argc, char *argv[]) { - if (argc > 2) - die("usage: %s [-d]\n", argv[0]); + int i; + char *argv0 = *argv; - for (;argc && *argv; argc--) { - switch ((argv++)[0][1]) { - case 'd': - dflag = 1; + for (argv++; --argc && *argv && argv[0][0] == '-' && argv[0][1]; argv++) { + if (argv[0][1] == '-' && argv[0][2] == '\0') { + argv++; + argc--; + break; } + + for (i = 1; argv[0][i]; i++) + switch (argv[0][i]) { + case 'd': + dflag = 1; + break; + default: + die("usage: %s [-d]\n", argv0); + } } setupsigs();