diff options
author | Oliver Webb <aquahobbyist@proton.me> | 2024-02-28 17:34:53 -0600 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2024-02-29 12:21:35 -0600 |
commit | e58d53d77a6980cadadf0aebf20be794355b6a2d (patch) | |
tree | 03c5340a3225205fc1662770cf3772b5fc0c2699 /toys | |
parent | 878786c67e9a75177528e4a7e53213bd91a9043f (diff) | |
download | toybox-e58d53d77a6980cadadf0aebf20be794355b6a2d.tar.gz |
getopt.c: Formatting, printf -> xprintf/xputsn/putchar, Referance link
Diffstat (limited to 'toys')
-rw-r--r-- | toys/pending/getopt.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/toys/pending/getopt.c b/toys/pending/getopt.c index 225db579..e6e239a5 100644 --- a/toys/pending/getopt.c +++ b/toys/pending/getopt.c @@ -1,6 +1,9 @@ /* getopt.c - Parse command-line options * * Copyright 2019 The Android Open Source Project + * + * See https://man7.org/linux/man-pages/man1/getopt.1.html + * No standard USE_GETOPT(NEWTOY(getopt, "^a(alternative)n:(name)o:(options)l*(long)(longoptions)Tu", TOYFLAG_USR|TOYFLAG_BIN)) @@ -31,14 +34,14 @@ GLOBALS( static void out(char *s) { - if (FLAG(u)) printf(" %s", s); + if (FLAG(u)) xprintf(" %s", s); else { - printf(" '"); + xputsn(" '"); for (; *s; s++) { - if (*s == '\'') printf("'\\''"); + if (*s == '\'') xputsn("'\\''"); else putchar(*s); } - printf("'"); + putchar('\''); } } @@ -85,21 +88,21 @@ void getopt_main(void) // BSD getopts don't honor argv[0] (for -n), so handle errors ourselves. opterr = 0; optind = 1; - while ((ch = (FLAG(a)?getopt_long_only:getopt_long)(argc, argv, TT.o, + while ((ch = (FLAG(a) ? getopt_long_only : getopt_long)(argc, argv, TT.o, lopts, &i)) != -1) { if (ch == '?') { fprintf(stderr, "%s: invalid option '%c'\n", argv[0], optopt); toys.exitval = 1; } else if (!ch) { - printf(" --%s", lopts[i].name); - if (lopts[i].has_arg) out(optarg ? optarg : ""); + xprintf(" --%s", lopts[i].name); + if (lopts[i].has_arg) out(optarg ? : ""); } else { - printf(" -%c", ch); + xprintf(" -%c", ch); if (optarg) out(optarg); } } - printf(" --"); + xputsn(" --"); for (; optind<argc; optind++) out(argv[optind]); - printf("\n"); + putchar('\n'); } |