version 1.19, 2006/05/25 08:41:52 |
version 1.20, 2006/11/06 19:37:21 |
|
|
cumain(int argc, char *argv[]) |
cumain(int argc, char *argv[]) |
{ |
{ |
int ch, i, parity; |
int ch, i, parity; |
long l; |
const char *errstr; |
char *cp; |
|
static char sbuf[12]; |
static char sbuf[12]; |
|
|
if (argc < 2) |
if (argc < 2) |
|
|
CU = DV = NOSTR; |
CU = DV = NOSTR; |
BR = DEFBR; |
BR = DEFBR; |
parity = 0; /* none */ |
parity = 0; /* none */ |
while ((ch = getopt(argc, argv, "a:l:s:htoe0123456789")) != -1) { |
|
|
/* |
|
* Convert obsolecent -### speed to modern -s### syntax which |
|
* getopt() 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 >= sizeof(sbuf)) { |
|
errx(3, "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; |
|
} |
|
} |
|
} |
|
|
|
getopt: |
|
while ((ch = getopt(argc, argv, "a:l:s:htoe")) != -1) { |
switch (ch) { |
switch (ch) { |
case 'a': |
case 'a': |
CU = optarg; |
CU = optarg; |
|
|
asprintf(&DV, "/dev/%s", optarg); |
asprintf(&DV, "/dev/%s", optarg); |
break; |
break; |
case 's': |
case 's': |
l = strtol(optarg, &cp, 10); |
BR = (int)strtonum(optarg, 0, INT_MAX, &errstr); |
if (*cp != '\0' || l < 0 || l >= INT_MAX) { |
if (errstr) |
fprintf(stderr, "%s: unsupported speed %s\n", |
errx(3, "speed is %s: %s", errstr, optarg); |
__progname, optarg); |
|
exit(3); |
|
} |
|
BR = (int)l; |
|
break; |
break; |
case 'h': |
case 'h': |
setboolean(value(LECHO), TRUE); |
setboolean(value(LECHO), TRUE); |
|
|
parity = 0; /* -o -e */ |
parity = 0; /* -o -e */ |
else |
else |
parity = -1; /* even */ |
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; |
break; |
default: |
default: |
cuusage(); |
cuusage(); |