Make "dump" print numbers as ASCII characters if they are printable

This commit is contained in:
bʰedoh₂ swé 2024-06-20 01:38:25 +05:00
parent 3d12a78090
commit 5ac9f3e5da

View File

@ -3,6 +3,7 @@
#else #else
#include <windows.h> #include <windows.h>
#endif #endif
#include <ctype.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -619,7 +620,13 @@ void execute(Stack *stack, Stack *originstack, char *modname)
if (!strcmp(NAME, "dump")) if (!strcmp(NAME, "dump"))
{ {
for (int i = 0; i < stack->pointer; i++) for (int i = 0; i < stack->pointer; i++)
{
// Almost all printable ASCII symbols are bigger than 32 and smaller than 126
if (stack->memory[i] >= 32 && stack->memory[i] <= 126)
printf("%d: (%c) %d\n", i, stack->memory[i], stack->memory[i]);
else
printf("%d: %d\n", i, stack->memory[i]); printf("%d: %d\n", i, stack->memory[i]);
}
continue; continue;
} }