#define LF '\n'
#define BS '\b'
#define DEL '\x7f'
+#define ESC '\x1b'
#if defined(CCDTR_IFLOW) && defined(CDSR_OFLOW)
#define CDTRDSR (CDTR_IFLOW | CDSR_OFLOW)
#endif
soft ^= 1; break;
case 'd':;
char* endptr;
- long t = strtol(optarg, &endptr, 10);
+ long t;
+ t = strtol(optarg, &endptr, 10);
if (errno != 0 || *endptr != '\0' || t < 0) {
fprintf(stderr, "invalid character delay\n");
goto ustusage;
if (!isatty(fd))
die(2, "device \"%s\" is not a TTY\n", line);
- int flags = fcntl(fd, F_GETFL, 0);
- flags &= ~(O_NONBLOCK | O_NDELAY); /* opened to check with non-blocking mode, now set to blocking */
+ int flags;
+ flags = fcntl(fd, F_GETFL, 0);
+ /* opened to check with non-blocking mode, now set to blocking */
+ flags &= ~(O_NONBLOCK | O_NDELAY);
if (fcntl(fd, F_SETFL, flags) == -1)
die(1, "failed to set the device to blocking mode\n");
options->lfincr = !options->lfincr; return 0;
} else if (strcmp(str, "lf-to-cr") == 0) {
options->lftocr = !options->lftocr; return 0;
- } else
+ } else {
goto trerr;
+ }
break;
case 'c':
if (strcmp(str, "cr-in-lf") == 0) {
options->crinlf = !options->crinlf; return 0;
} else if (strcmp(str, "cr-to-lf") == 0) {
options->crtolf = !options->crtolf; return 0;
- } else
+ } else {
goto trerr;
+ }
break;
case 'n':
if (strcmp(str, "no-lf") == 0) {
options->nolf = !options->nolf; return 0;
} else if (strcmp(str, "no-cr") == 0) {
options->nocr = !options->nocr; return 0;
- } else
+ } else {
goto trerr;
+ }
break;
default:
trerr:
struct termios *iterm = (struct termios*)term;
#define TERMIOS_STRUCT termios
#endif
- for (size_t i = 0; i < sizeof(struct TERMIOS_STRUCT); i++) {
+ for (size_t i = 0; i < sizeof(struct TERMIOS_STRUCT); i++)
if (((char*)iterm)[i] != 0)
return 1;
- }
+
return 0;
}
write(fd, &writebuff[i], 1);
nanosleep(&wts, NULL);
}
- }
- else {
+ } else {
write(fd, writebuff, 1);
}
}
inline void __attribute__((hot))
replacechar(char *str, ssize_t size, const char find, const char repl)
{
- for (int i = 0; i < size; i++) {
+ for (int i = 0; i < size; i++)
if (str[i] == find)
str[i] = repl;
- }
}
+
/* TODO: optimize the function and allow for offsets greater than 1 */
inline ssize_t __attribute__((hot))
addchar(char *str, int *scratch, ssize_t size, const size_t bsize,const char find, const char inp, const int offset)
}
if (!c)
return(size);
- for (int i = c; i > 0; i--) {
+
+ for (int i = c; i > 0; i--)
for (int s = size; s >= scratch[i]; s--)
str[s] = str[s + 1];
- }
+
return(size - c);
}
die(1, "failed to set terminal attributes\n");
break;
case 'w':
- if (!half || !canonical) {
- newterm.c_lflag |= ECHO;
- newterm.c_lflag |= ICANON;
- settermattr(STDIN_FILENO, &newterm);
- }
+ cechck();
if (fgets(ttr, sizeof(ttr), stdin) != NULL) {
replacechar(ttr, 63, LF, '\0');
ssize_t frln;
st ^= TIOCM_DTR;
if (ioctl(fd, TIOCMSET, &st) != 0) {
fprintf(stderr, "failed to set DTR [assertion]\n");
+ break;
}
nanosleep(&ts, NULL);
st ^= TIOCM_DTR;
- if (ioctl(fd, TIOCMSET, &st) != 0) {
+ if (ioctl(fd, TIOCMSET, &st) != 0)
fprintf(stderr, "failed to set DTR [negation]\n");
- }
break;
case BS:
- break;
case DEL:
+ case ESC:
break;
default:
fprintf(stderr, "not a valid command [%c]\n", cmdchar);