logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git
commit: 195537341000ff43573d7722d18cd2eea55c892a
parent 8749a3c6ddc198df4b332f35be033ef80336b2ab
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri, 20 Sep 2024 17:05:22 +0200

cmd/tr: handle unknown option

Diffstat:

Mcmd/tr.c14++++++++++++++
1 file changed, 14 insertions(+), 0 deletions(-)

diff --git a/cmd/tr.c b/cmd/tr.c @@ -66,6 +66,8 @@ int translate[NCHARS] = { STR s1 = {STRING1, NORMAL, 0, OOBCH, {0, OOBCH}, NULL, NULL}; STR s2 = {STRING2, NORMAL, 0, OOBCH, {0, OOBCH}, NULL, NULL}; +const char *argv0 = "tr"; + static void setup(int *, char *, STR *, int); static void usage(void); @@ -77,6 +79,7 @@ main(int argc, char *argv[]) cflag = dflag = sflag = 0; while((ch = getopt(argc, argv, "Ccds")) != -1) + { switch(ch) { case 'C': @@ -89,9 +92,20 @@ main(int argc, char *argv[]) case 's': sflag = 1; break; + case ':': + fprintf(stderr, "%s: error: Option '-%c' requires an operand\n", argv0, optopt); + usage(); + return 1; + case '?': + fprintf(stderr, "%s: error: Unhandled option '-%c'\n", argv0, optopt); + usage(); + return 1; default: + fprintf(stderr, "%s: error: Unhandled getopt case '%c'\n", argv0, ch); usage(); + abort(); } + } argc -= optind; argv += optind;