sbase

suckless unix tools
git clone git://git.suckless.org/sbase
Log | Files | Refs | README | LICENSE

commit f06ada45922a7f58ddc53bfbea14388750930d0a
parent e4e47a617e6c7cca6141aa34c0cdb47b36746b19
Author: sin <sin@2f30.org>
Date:   Tue, 11 Nov 2014 17:28:27 +0000

Simplify logic in kill(1)

Diffstat:
Mkill.c | 50++++++++++++++++++++++++--------------------------
1 file changed, 24 insertions(+), 26 deletions(-)

diff --git a/kill.c b/kill.c @@ -37,7 +37,6 @@ int main(int argc, char *argv[]) { char *end; - const char *name; int ret = 0; int sig = SIGTERM; pid_t pid; @@ -48,20 +47,8 @@ main(int argc, char *argv[]) usage(); argc--, argv++; - if (strcmp(argv[0], "--") == 0) { - argc--, argv++; - } else if (argv[0][0] == '-' && isdigit(argv[0][1])) { - /* handle XSI extension -signum */ - errno = 0; - sig = strtol(&argv[0][1], &end, 10); - if (*end != '\0' || errno != 0) - eprintf("%s: bad signal number\n", &argv[0][1]); - sig2name(sig); + if (strcmp(argv[0], "-l") == 0) { argc--, argv++; - } else if (strcmp(argv[0], "-l") == 0) { - argc--, argv++; - if (argc > 0 && strcmp(argv[0], "--") == 0) - argc--, argv++; if (argc == 0) { for (i = 0; i < LEN(sigs); i++) puts(sigs[i].name); @@ -76,22 +63,33 @@ main(int argc, char *argv[]) sig = WTERMSIG(sig); puts(sig2name(sig)); exit(0); - } else { - if (strcmp(argv[0], "-s") == 0) { + } + + if (strcmp(argv[0], "-s") == 0) { + argc--, argv++; + if (argc == 0) + usage(); + sig = strcmp(argv[0], "0") == 0 ? 0 : name2sig(argv[0]); + argc--, argv++; + } else if (argv[0][0] == '-') { + if (isdigit(argv[0][1])) { + /* handle XSI extension -signum */ + errno = 0; + sig = strtol(&argv[0][1], &end, 10); + if (*end != '\0' || errno != 0) + eprintf("%s: bad signal number\n", &argv[0][1]); + sig2name(sig); + argc--, argv++; + } else if (argv[0][1] != '-') { + /* handle XSI extension -signame */ + sig = strcmp(&argv[0][1], "0") == 0 ? 0 : name2sig(&argv[0][1]); argc--, argv++; - if (argc > 0 && strcmp(argv[0], "--") == 0) - argc--, argv++; - if (argc == 0) - usage(); - name = argv[0]; - } else { - /* assume XSI extension -signame */ - name = &argv[0][1]; } - sig = strcmp(name, "0") == 0 ? 0 : name2sig(name); - argc--, argv++; } + if (argc > 0 && strcmp(argv[0], "--") == 0) + argc--, argv++; + if (argc == 0) usage();