aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGustav HÃ¥llberg <gustav@gmail.com>2009-01-01 02:02:57 (GMT)
committerGustav HÃ¥llberg <gustav@gmail.com>2009-01-16 23:38:32 (GMT)
commit6932d16e08df4447e2532aa2c061959221914c5e (patch)
tree6578b7fb19c06a31da086b88b5806b257a8c00e3
parent1d452fc1cee76b013582ad1921436612d6647ddf (diff)
downloadpowwow-6932d16e08df4447e2532aa2c061959221914c5e.zip
powwow-6932d16e08df4447e2532aa2c061959221914c5e.tar.gz
powwow-6932d16e08df4447e2532aa2c061959221914c5e.tar.bz2
bugfixes for characters read from tty with high bit set
-rw-r--r--ChangeLog.old5
-rw-r--r--cmd2.c46
2 files changed, 29 insertions, 22 deletions
diff --git a/ChangeLog.old b/ChangeLog.old
index e73b4b2..b8abcb4 100644
--- a/ChangeLog.old
+++ b/ChangeLog.old
@@ -1,3 +1,8 @@
+2008-12-31 dain
+
+ * cmd2.c: Fixed some problems related to binding keys with the
+ high bit set.
+
2008-12-29 dain
* tty.c: Manually buffer tty output to fix output problems on some
diff --git a/cmd2.c b/cmd2.c
index ee40ce5..8267058 100644
--- a/cmd2.c
+++ b/cmd2.c
@@ -1042,34 +1042,38 @@ static char *unescape_seq __P3 (char *,buf, char *,seq, int *,seqlen)
*/
static int get_one_char __P1 (int,timeout)
{
- extern int errno;
- int err;
+ struct timeval timeoutbuf;
fd_set fds;
+ int n;
char c;
- struct timeval timeoutbuf;
+ again:
FD_ZERO(&fds);
FD_SET(tty_read_fd, &fds);
timeoutbuf.tv_sec = 0;
timeoutbuf.tv_usec = timeout * uSEC_PER_mSEC;
- err = select(tty_read_fd+1, &fds, NULL, NULL,
- timeout ? &timeoutbuf : NULL);
- if (err == -1 && errno == EINTR)
+ n = select(tty_read_fd + 1, &fds, NULL, NULL,
+ timeout ? &timeoutbuf : NULL);
+ if (n == -1 && errno == EINTR)
return -1;
- if (err == -1) {
+ if (n == -1) {
errmsg("select");
return -1;
}
- while ((err = tty_read(&c, 1)) < 0 && errno == EINTR)
- ;
- if (err != 1 && errno == EAGAIN) {
+ do {
+ n = tty_read(&c, 1);
+ } while (n < 0 && errno == EINTR);
+ if (n == 1)
+ return (unsigned char)c;
+ if (n < 0) {
+ if (errno != EAGAIN)
+ errmsg("read from tty");
return -1;
}
- if (err != 1) {
- errmsg("read from tty");
- return -1;
- }
- return (int)c;
+ /* n == 0 */
+ if (timeout == 0)
+ goto again;
+ return -1;
}
/*
@@ -1077,10 +1081,8 @@ static int get_one_char __P1 (int,timeout)
*/
void print_seq __P2 (char *,seq, int,len)
{
- char ch;
-
while (len--) {
- ch = *(seq++);
+ unsigned char ch = *(seq++);
if (ch == '\033') {
tty_puts("esc ");
continue;
@@ -1108,7 +1110,6 @@ char *seq_name __P2 (char *,seq, int,len)
{
static char buf[CAPLEN*4];
char *p = buf;
- char c;
/*
* rules: control chars are written as ^X, where
* X is char | 64
@@ -1118,7 +1119,7 @@ char *seq_name __P2 (char *,seq, int,len)
* special case: 0x7f is written ^?
*/
while (len--) {
- c = *seq++;
+ unsigned char c = *seq++;
if (c == '^' || (c && strchr(SPECIAL_CHARS, c)))
*(p++) = ESC;
@@ -1283,8 +1284,9 @@ static void parse_bind_noninteractive __P1 (char *,arg)
add_keynode(arg, rawseq, seqlen, key_run_command, p);
if (opt_info) {
- PRINTF("#%s: %s %s=%s\n", (kp && *kp) ?
- "redefined key" : "new key binding", arg, seq, p);
+ PRINTF("#%s: %s %s=%s\n",
+ (kp && *kp) ? "redefined key" : "new key binding",
+ arg, seq, p);
}
}