static int settermattr(int dv, const struct TERMIOS_STRUCT *optst);
static void settermspd(unsigned int lispeed, unsigned int lospeed, struct TERMIOS_STRUCT *optst);
static int openport(void);
-static unsigned int strtoui(const char *str, const char *msg, unsigned int min);
+static unsigned int strtoui(const char *str, unsigned int min);
static int troptions(CRLFOpt *options, const char *str);
static int setroptions(void);
static inline unsigned int lsbmask(unsigned int n);
}
unsigned int
-strtoui(const char *str, const char *msg, unsigned int min)
+strtoui(const char *str, unsigned int min)
{
long t;
char *endptr;
t = strtol(str, &endptr, 10);
if (errno != 0 || *endptr != '\0' || t < min || t > uintmax) {
- fprintf(stderr, msg, str);
return uintmax;
}
/*
} else if (!strcmp(str, "lf-to-cr")) {
options->lftocr ^= 1; return 0;
} else {
- goto trerr;
+ return 1;
}
- break;
case 'c':
if (!strcmp(str, "cr-in-lf")) {
options->crinlf ^= 1; return 0;
} else if (!strcmp(str, "cr-to-lf")) {
options->crtolf ^= 1; return 0;
} else {
- goto trerr;
+ return 1;
}
- break;
case 'n':
if (!strcmp(str, "no-lf")) {
options->nolf ^= 1; return 0;
} else if (!strcmp(str, "no-cr")) {
options->nocr ^= 1; return 0;
} else {
- goto trerr;
+ return 1;
}
- break;
default:
- trerr:
- fprintf(stderr, "invalid translation option: %s\n", str);
return 1;
}
}
}
void *
-writeport(void *)
+writeport(void *unused)
{
Sizes msizes;
struct timespec ts;
rwc -= write(fd, &writebuff[i], 1);
nanosleep(&wts, NULL);
}
+
} else {
rwc -= write(fd, writebuff, 1);
}
+
} else if (inln == 0 && !interactive) {
break;
}
memmove(&buff[t] + 1, &buff[t], (size + c) - t);
buff[t + (to ^ 1)] = args->input;
}
- printf("%s\n", buff);
return (size + c);
}
cechck();
if (fgets(ttr, sizeof(ttr), stdin) != NULL) {
replacechar(ttr, 63, &nolfargs);
- tspd = strtoui(ttr, "invalid speed\n", 0);
+ tspd = strtoui(ttr, 0);
if (tspd != uintmax) {
ospeed = ispeed = tspd;
settermspd(ispeed, ospeed, &cntrl);
if (settermattr(fd, &cntrl) != 0)
fprintf(stderr, "failed to set baudrate "
"[RX:%u | TX:%u]\n", ispeed, ospeed);
+ } else {
+ fprintf(stderr, "invalid speed: %s\n", ttr);
}
}
goto finish;
cechck();
if (fgets(ttr, sizeof(ttr), stdin) != NULL) {
replacechar(ttr, 63, &nolfargs);
- chardelay = strtoui(ttr, "invalid delay\n", 0);
+ chardelay = strtoui(ttr, 0);
if (chardelay != uintmax) {
wts.tv_sec = 0;
wts.tv_nsec = chardelay;
+ } else {
+ fprintf(stderr, "invalid delay: %s\n", ttr);
}
}
goto finish;
fprintf(stderr, "additional output translation option: ");
if (fgets(ttr, sizeof(ttr), stdin) != NULL) {
replacechar(ttr, 63, &nolfargs);
- if(troptions(&tropts, ttr))
+ if(troptions(&tropts, ttr)) {
+ fprintf(stderr, "invalid output translation option: %s\n", optarg);
goto finish;
+ }
if (setroptions())
fprintf(stderr, "could not set new options\n");
}
printf("additional input translation option: ");
if (fgets(ttr, sizeof(ttr), stdin) != NULL) {
replacechar(ttr, 63, &nolfargs);
- if (troptions(&itropts, ttr))
- goto finish;
+ if (troptions(&itropts, ttr)) {
+ fprintf(stderr, "invalid input translation option: %s\n", optarg);
+ goto finish;
+ }
if (setroptions())
fprintf(stderr, "could not set new options\n");
}
die(int code, const char *msg, ...)
{
va_list fpa;
+
while (rwc > 0) {
int t = rwc;
nanosleep(&wts, NULL);
if (t == rwc) break;
}
+
if (fd != -1)
close(fd);
int oind, rxspdset, devset, c;
oind = rxspdset = devset = 0;
- for (int i = 1; i < argc; i++ ) {
+ for (int i = 1; i < argc; i++) {
if (argv[i][0] == '-' && argv[i][1] >= '0' && argv[i][1] <= '9') {
if (asprintf(&t, "-s%s", argv[i] + 1) == -1) {
fprintf(stderr, "%s: cannot convert -# to -s#\n", argv[0]);
break;
+ } else {
+ argv[i] = t;
}
- argv[i] = t;
}
}
case 'd':
tl = strtol(optarg, &endptr, 10);
if (errno != 0 || *endptr != '\0' || t < 0) {
- fprintf(stderr, "invalid character delay: %s\n", optarg);
+ fprintf(stderr, "%s: invalid character delay: %s\n", argv[0],optarg);
goto ustusage;
} else {
chardelay = tl;
break;
case 'D':
if (optarg[1] != '\0' || !(optarg[0] >= '5' && optarg[0] <= '8')) {
- fprintf(stderr, "invalid number of data bits: %s\n", optarg);
+ fprintf(stderr, "%s: invalid number of data bits: %s\n", argv[0], optarg);
goto ustusage;
} else {
datab = optarg[0];
half ^= 1; break;
case 'i': /* FALLTHROUGH */
case 's':
- tui = strtoui(optarg, "invalid speed: %s\n", 1);
- if (tui == uintmax)
+ tui = strtoui(optarg, 1);
+ if (tui == uintmax) {
+ fprintf(stderr, "%s: invalid speed: %s\n", argv[0], optarg);
goto ustusage;
+ }
if (c == 'i') {
ispeed = tui; rxspdset = 1;
} else {
stopb ^= 1; break;
case 'l':
if (devset) {
- fprintf(stderr, "cannot specify multiple devices\n");
+ fprintf(stderr, "%s: cannot specify multiple devices\n", argv[0]);
goto ustusage;
}
if (strlen(optarg) > 58) {
- fprintf(stderr, "device name too long\n");
+ fprintf(stderr, "%s: device name too long\n", argv[0]);
goto ustusage;
}
if (strchr(optarg, '/')) {
}
break;
case 'm':
- tui = strtoui(optarg, "invalid number of characters: %s\n", 1);
- if (tui == uintmax)
+ tui = strtoui(optarg, 1);
+ if (tui == uintmax) {
+ fprintf(stderr, "%s: invalid number of characters: %s\n", argv[0], optarg);
goto ustusage;
+ }
minchars = tui;
break;
case 't':
- if (troptions(&tropts, optarg))
+ if (troptions(&tropts, optarg)) {
+ fprintf(stderr, "%s: invalid output translation option: %s\n", argv[0], optarg);
goto ustusage;
+ }
break;
case 'T':
- if (troptions(&itropts, optarg))
+ if (troptions(&itropts, optarg)) {
+ fprintf(stderr, "%s: invalid input translation option: %s\n", argv[0], optarg);
goto ustusage;
+ }
break;
case 'v':
verbose ^= 1; break;