fix: replace direct stdio calls with portable I/O hooks

Co-authored-by: aider (openrouter/moonshotai/kimi-k2.6) <aider@aider.chat>
This commit is contained in:
2026-05-03 22:51:46 +03:00
parent 3c292cfc18
commit 1c0c6daf4f
2 changed files with 12 additions and 6 deletions
+1 -1
View File
@@ -78,7 +78,7 @@ void data_push(int64_t val) {
int64_t data_pop(void) { int64_t data_pop(void) {
if (data_sp < 0) { if (data_sp < 0) {
fprintf(stderr, "Data stack underflow\n"); forth_printf("Data stack underflow\n");
return 0; return 0;
} }
return data_stack[data_sp--]; return data_stack[data_sp--];
+11 -5
View File
@@ -87,15 +87,21 @@ void outer_interpreter(void) {
while (1) { while (1) {
forth_printf("ok "); forth_printf("ok ");
forth_fflush(); forth_fflush();
if (fgets(line_buf, sizeof(line_buf), stdin) == NULL) { size_t i = 0;
int c;
while (i < sizeof(line_buf) - 1) {
c = forth_getchar();
if (c == EOF || c == '\n' || c == '\r') {
break;
}
line_buf[i++] = (char)c;
}
line_buf[i] = '\0';
if (i == 0 && c == EOF) {
break; break;
} }
input_buf = line_buf; input_buf = line_buf;
input_buf_cap = sizeof(line_buf); input_buf_cap = sizeof(line_buf);
size_t n = strlen(input_buf);
if (n > 0 && input_buf[n - 1] == '\n') {
input_buf[n - 1] = '\0';
}
input_ptr = input_buf; input_ptr = input_buf;
char* tok; char* tok;
while ((tok = next_token()) != NULL) { while ((tok = next_token()) != NULL) {