ctype: portability, sign extension and cleanup fixes

This commit is contained in:
Andrey A. Chernov 1997-06-27 11:50:56 +00:00
parent f76efb86fb
commit edfa832c6a
5 changed files with 16 additions and 17 deletions

View File

@ -575,8 +575,8 @@ c_gets(el, buf)
if (el_getc(el, &ch) != 1) if (el_getc(el, &ch) != 1)
return ed_end_of_file(el, 0); return ed_end_of_file(el, 0);
switch (ch) { switch (ch) {
case 0010: /* Delete and backspace */ case '\010': /* Delete and backspace */
case 0177: case '\177':
if (len > 1) { if (len > 1) {
*el->el_line.cursor-- = '\0'; *el->el_line.cursor-- = '\0';
el->el_line.lastchar = el->el_line.cursor; el->el_line.lastchar = el->el_line.cursor;
@ -592,7 +592,7 @@ c_gets(el, buf)
ch = 0; ch = 0;
break; break;
case 0033: /* ESC */ case '\033': /* ESC */
case '\r': /* Newline */ case '\r': /* Newline */
case '\n': case '\n':
break; break;

View File

@ -640,7 +640,7 @@ key__decode_char(buf, cnt, ch)
char *buf; char *buf;
int cnt, ch; int cnt, ch;
{ {
ch &= 0xFF; ch = (unsigned char)ch;
if (ch == 0) { if (ch == 0) {
buf[cnt++] = '^'; buf[cnt++] = '^';
@ -650,10 +650,10 @@ key__decode_char(buf, cnt, ch)
if (iscntrl(ch)) { if (iscntrl(ch)) {
buf[cnt++] = '^'; buf[cnt++] = '^';
if (ch == '\177') if (ch == 0177)
buf[cnt] = '?'; buf[cnt] = '?';
else else
buf[cnt] = ch | 0100; buf[cnt] = toascii(ch) | 0100;
} }
else if (ch == '^') { else if (ch == '^') {
buf[cnt++] = '\\'; buf[cnt++] = '\\';
@ -704,7 +704,7 @@ key__decode_str(str, buf, sep)
if (*p == '\177') if (*p == '\177')
*b++ = '?'; *b++ = '?';
else else
*b++ = *p | 0100; *b++ = toascii(*p) | 0100;
} }
else if (*p == '^' || *p == '\\') { else if (*p == '^' || *p == '\\') {
*b++ = '\\'; *b++ = '\\';

View File

@ -193,14 +193,14 @@ parse__escape(ptr)
break; break;
} }
} }
else if (*p == '^' && isalpha((unsigned char) p[1])) { else if (*p == '^' && isascii(p[1]) && (p[1] == '?' || isalpha(p[1]))) {
p++; p++;
c = (*p == '?') ? '\177' : (*p & 0237); c = (*p == '?') ? '\177' : (*p & 0237);
} }
else else
c = *p; c = *p;
*ptr = ++p; *ptr = ++p;
return c; return (unsigned char)c;
} }
/* parse__string(): /* parse__string():

View File

@ -43,7 +43,6 @@ static char sccsid[] = "@(#)refresh.c 8.1 (Berkeley) 6/4/93";
*/ */
#include "sys.h" #include "sys.h"
#include <stdio.h> #include <stdio.h>
#include <ctype.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
@ -97,7 +96,7 @@ re_addc(el, c)
EditLine *el; EditLine *el;
int c; int c;
{ {
c &= 0xFF; c = (unsigned char)c;
if (isprint(c)) { if (isprint(c)) {
re_putc(el, c); re_putc(el, c);
@ -118,11 +117,11 @@ re_addc(el, c)
} }
else if (iscntrl(c)) { else if (iscntrl(c)) {
re_putc(el, '^'); re_putc(el, '^');
if (c == '\177') if (c == 0177)
re_putc(el, '?'); re_putc(el, '?');
else else
/* uncontrolify it; works only for iso8859-1 like sets */ /* uncontrolify it; works only for iso8859-1 like sets */
re_putc(el, (c | 0100)); re_putc(el, (toascii(c) | 0100));
} }
else { else {
re_putc(el, '\\'); re_putc(el, '\\');
@ -876,7 +875,7 @@ re_refresh_cursor(el)
/* do input buffer to el->el_line.cursor */ /* do input buffer to el->el_line.cursor */
for (cp = el->el_line.buffer; cp < el->el_line.cursor; cp++) { for (cp = el->el_line.buffer; cp < el->el_line.cursor; cp++) {
c = *cp & 0xFF; c = (unsigned char)*cp;
h++; /* all chars at least this long */ h++; /* all chars at least this long */
if (c == '\n') { /* handle newline in data part too */ if (c == '\n') { /* handle newline in data part too */
@ -949,7 +948,7 @@ re_fastaddc(el)
{ {
int c; int c;
c = el->el_line.cursor[-1] & 0xFF; c = (unsigned char)el->el_line.cursor[-1];
if (c == '\t' || el->el_line.cursor != el->el_line.lastchar) { if (c == '\t' || el->el_line.cursor != el->el_line.lastchar) {
re_refresh(el); /* too hard to handle */ re_refresh(el); /* too hard to handle */
@ -957,7 +956,7 @@ re_fastaddc(el)
} /* else (only do at end of line, no TAB) */ } /* else (only do at end of line, no TAB) */
if (iscntrl(c)) { /* if control char, do caret */ if (iscntrl(c)) { /* if control char, do caret */
char mc = (c == '\177') ? '?' : (c | 0100); char mc = (c == 0177) ? '?' : (toascii(c) | 0100);
re_fastputc(el, '^'); re_fastputc(el, '^');
re_fastputc(el, mc); re_fastputc(el, mc);
} }

View File

@ -277,7 +277,7 @@ vi_change_case(el, c)
int c; int c;
{ {
if (el->el_line.cursor < el->el_line.lastchar) { if (el->el_line.cursor < el->el_line.lastchar) {
c = *el->el_line.cursor & 0xFF; c = (unsigned char)*el->el_line.cursor;
if (isupper(c)) if (isupper(c))
*el->el_line.cursor++ = tolower(c); *el->el_line.cursor++ = tolower(c);
else if (islower(c)) else if (islower(c))