Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc,cmds] Fix isprint and kilo for CP 437 display #1752

Merged
merged 1 commit into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 */
}
Loading