Skip to content

Commit

Permalink
[libc,cmds] Fix isprint and kilo for CP 437 display
Browse files Browse the repository at this point in the history
  • Loading branch information
ghaerr committed Oct 8, 2023
1 parent cecca16 commit 7eed859
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 4 additions & 4 deletions elkscmd/misc_utils/kilo.c
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ void editorQueryString(char* prompt, char *buffer){
} else if(c == ENTER) {
editorSetStatusMessage("");
return;
} else if(isprint(c)) {
} else if(isprint(c & 255)) {
buffer[len++] = c;
buffer[len] = '\0';
}
Expand Down Expand Up @@ -870,7 +870,7 @@ int editorUpdateSyntax(erow *row) {
}

/* Handle non printable chars. */
if (!isprint(*p)) {
if (!isprint(*p & 255)) {
row->hl[i] = HL_NONPRINT;
p++; i++;
prev_sep = 0;
Expand Down Expand Up @@ -987,7 +987,7 @@ int editorUpdateRow(erow *row) {
if (row->chars[j] == TAB) {
row->render[idx++] = ' ';
while((idx+1) % TABSPACE != 0) row->render[idx++] = ' ';
} else if (!isprint(row->chars[j])) {
} else if (!isprint(row->chars[j] & 255)) {
row->render[idx++] = '?';
} else {
row->render[idx++] = row->chars[j];
Expand Down Expand Up @@ -1715,7 +1715,7 @@ void editorFind(int fd, int mode) {
find_next = 1;
}

} else if (isprint(c)) {
} else if (isprint(c & 255)) {
if (qlen < KILO_QUERY_LEN) {
query[qlen++] = c;
query[qlen] = '\0';
Expand Down
4 changes: 3 additions & 1 deletion libc/ctype/isprint.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <ctype.h>
#include <stdio.h>

int isprint(int c)
{
return (c & 0x7f) >= 32 && c < 127;
if (c == EOF) return 0;
return (c & 0xff) >= 32; /* display ASCII and upper half of CP 437 */
}

0 comments on commit 7eed859

Please sign in to comment.