From 966304f09ab32a2b7a135d447b66d348933894ef Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Mon, 15 Apr 2024 08:47:20 -0700 Subject: [PATCH] Halt after a number of rewrites --- src/modal.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/modal.c b/src/modal.c index eb90197..4a5cf6c 100644 --- a/src/modal.c +++ b/src/modal.c @@ -5,7 +5,7 @@ typedef struct { char *a, *b; } Rule; -static int flip; +static int flip, cycles = 0x10000; static Rule rules[0x1000], lambda, *rules_ = rules; static char dict[0x8000], *dict_ = dict; static char bank_a[0x4000], *src_ = bank_a; @@ -197,9 +197,9 @@ main(int argc, char **argv) if(argc < 2) return !printf("usage: modal [-v] source.modal\n"); if(argc < 3 && argv[1][0] == '-' && argv[1][1] == 'v') - return !printf("Modal Interpreter, 14 Apr 2024.\n"); + return !printf("Modal Interpreter, 15 Apr 2024.\n"); if(!(f = fopen(argv[1], "r"))) - return !printf("Invalid Modal file: %s.\n", argv[1]); + return !fprintf(stderr, "Invalid Modal file: %s.\n", argv[1]); while(fread(&c, 1, 1, f)) { c = c <= 0x20 ? 0x20 : c; if(w > bank_a) { @@ -212,6 +212,6 @@ main(int argc, char **argv) while(*(--w) <= ' ') *w = 0; fclose(f); while(rewrite()) - ; + if(cycles--) return !fprintf(stderr, "Cycle limit exceeded.\n"); return 0; } \ No newline at end of file