From 2aebb8bcb4e9552e723739ce37a912dd8cffceeb Mon Sep 17 00:00:00 2001 From: Ruslan Ermilov Date: Thu, 7 Sep 2006 19:48:52 +0000 Subject: [PATCH] Fixed the -# option to work as documented in a manpage. --- usr.bin/tip/tip/cu.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/usr.bin/tip/tip/cu.c b/usr.bin/tip/tip/cu.c index f34bba2e029..d8d104d482e 100644 --- a/usr.bin/tip/tip/cu.c +++ b/usr.bin/tip/tip/cu.c @@ -60,7 +60,26 @@ cumain(int argc, char *argv[]) CU = DV = NOSTR; BR = DEFBR; parity = 0; /* none */ - while ((ch = getopt(argc, argv, "a:l:s:htoe0123456789")) != -1) { + + /* + * We want to accept -# as a speed. It's easiest to look through + * the arguments, replace -# with -s#, and let getopt() handle it. + */ + for (i = 1; i < argc; i++) { + if (argv[i][0] == '-' && + argv[i][1] >= '0' && argv[i][1] <= '9') { + asprintf(&cp, "-s%s", argv[i] + 1); + if (cp == NULL) { + fprintf(stderr, + "%s: cannot convert -# to -s#\n", + __progname); + exit(3); + } + argv[i] = cp; + } + } + + while ((ch = getopt(argc, argv, "a:l:s:htoe")) != -1) { switch (ch) { case 'a': CU = optarg; @@ -105,13 +124,6 @@ cumain(int argc, char *argv[]) else parity = -1; /* even */ break; - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - if (CU) - CU[strlen(CU)-1] = ch; - if (DV) - DV[strlen(DV)-1] = ch; - break; default: cuusage(); break;