From 2c4ef41aacbb1cc6acb6998ece87809b8ce5e1ea Mon Sep 17 00:00:00 2001 From: David Gwynne Date: Fri, 13 Jul 2012 05:29:02 +0000 Subject: make the compat for -XXX to -s XXX simpler. sometimes you dont need to use goto. ok nicm@ --- usr.bin/cu/cu.c | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) (limited to 'usr.bin/cu/cu.c') diff --git a/usr.bin/cu/cu.c b/usr.bin/cu/cu.c index b4db4c60002..0ed18005404 100644 --- a/usr.bin/cu/cu.c +++ b/usr.bin/cu/cu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cu.c,v 1.9 2012/07/12 14:00:05 nicm Exp $ */ +/* $OpenBSD: cu.c,v 1.10 2012/07/13 05:29:01 dlg Exp $ */ /* * Copyright (c) 2012 Nicholas Marriott @@ -81,28 +81,15 @@ main(int argc, char **argv) * can handle. */ for (i = 1; i < argc; i++) { - if (argv[i][0] == '-') { - switch (argv[i][1]) { - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - ch = snprintf(sbuf, sizeof(sbuf), "-s%s", - &argv[i][1]); - if (ch <= 0 || ch >= (int)sizeof(sbuf)) { - errx(1, "invalid speed: %s", - &argv[i][1]); - } - argv[i] = sbuf; - break; - case '-': - /* if we get "--" stop processing args */ - if (argv[i][2] == '\0') - goto getopt; - break; - } - } + if (strcmp("--", argv[i]) == 0) + break; + if (argv[i][0] != '-' || !isdigit(argv[i][1])) + continue; + + if (asprintf(&argv[i], "-s%s", &argv[i][1]) == -1) + errx(1, "speed asprintf"); } -getopt: while ((opt = getopt(argc, argv, "l:s:")) != -1) { switch (opt) { case 'l': -- cgit v1.2.3