diff options
-rw-r--r-- | pw.c | 22 |
1 files changed, 14 insertions, 8 deletions
@@ -15,6 +15,12 @@ #include <errno.h> #include <regex.h> +#define ctrl(ch) ((ch) & 0x1f) +#define BS 8 +#define CR 13 +#define ESC 27 +#define DEL 127 + enum status_flags { stat_dirty = 1, // display needs refresh stat_eof = 2, // end of data reached @@ -137,7 +143,7 @@ static char *addch(char *line, int ch) static char *addchesc(char *line, int ch) { - if (ch == 127) { + if (ch == DEL) { line = addch(line, '^'); line = addch(line, '?'); } else if (ch < 32) { @@ -636,11 +642,11 @@ int main(int argc, char **argv) if ((stat & stat_eof) == 0) stat |= (stat_dirty | stat_susp); break; - case 13: + case CR: stat &= ~stat_susp; stat |= stat_dirty; break; - case 27: + case ESC: kbd_state = kbd_esc; break; case ':': @@ -693,9 +699,9 @@ int main(int argc, char **argv) // fallthrough case kbd_colon: switch (ch) { - case 27: case 13: case 3: + case ESC: case CR: case ctrl('c'): stat |= stat_dirty; - if (ch == 13) { + if (ch == CR) { if (kbd_state == kbd_colon && cmdbuf[1]) { execute(cmdbuf, &stat); if (cmdbuf[0] != 0) { @@ -722,7 +728,7 @@ int main(int argc, char **argv) kbd_state = kbd_cmd; curcmd = 0; break; - case 8: case 127: + case BS: case DEL: { size_t len = strlen(cmdbuf); if (len == 1) { @@ -734,10 +740,10 @@ int main(int argc, char **argv) } } break; - case 21: + case ctrl('u'): cmdbuf[1] = 0; break; - case 23: + case ctrl('w'): { size_t len = strlen(cmdbuf); while (len > 1 && isspace((unsigned char) cmdbuf[len - 1])) |