Fixes.
h3rald h3rald@h3rald.com
Thu, 05 Dec 2024 21:28:07 +0100
1 files changed,
26 insertions(+),
3 deletions(-)
jump to
M
hex.c
→
hex.c
@@ -3854,19 +3854,41 @@
fclose(file); return content; } +#if defined(__EMSCRIPTEN__) && defined(BROWSER) -static int do_repl(void *v_ctx) +static void do_repl(void *v_ctx) { hex_context_t *ctx = (hex_context_t *)v_ctx; char line[1024]; -#if defined(__EMSCRIPTEN__) && defined(BROWSER) + char *p = line; p = em_fgets(line, 1024); if (!p) { printf("Error reading output"); + return; } + // Normalize line endings (remove trailing \r\n or \n) + line[strcspn(line, "\r\n")] = '\0'; + + // Tokenize and process the input + hex_interpret(ctx, line, "<repl>", 1, 1); + // Print the top item of the stack + if (ctx->stack.top >= 0) + { + hex_print_item(stdout, ctx->stack.entries[ctx->stack.top]); + // hex_print_item(stdout, HEX_STACK[HEX_TOP]); + printf("\n"); + } + return; +} + #else + +static int do_repl(void *v_ctx) +{ + hex_context_t *ctx = (hex_context_t *)v_ctx; + char line[1024]; printf("> "); // Prompt fflush(stdout); if (fgets(line, sizeof(line), stdin) == NULL)@@ -3874,7 +3896,6 @@ {
printf("\n"); // Handle EOF (Ctrl+D) return 1; } -#endif // Normalize line endings (remove trailing \r\n or \n) line[strcspn(line, "\r\n")] = '\0';@@ -3889,6 +3910,8 @@ printf("\n");
} return 0; } + +#endif // REPL implementation void hex_repl(hex_context_t *ctx)