From f35eb2c8ec74dea9a641fb44463e87393a7de5e2 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Thu, 18 Apr 2024 11:33:23 -0700 Subject: [PATCH] Added quiet/infinite flags --- src/modal.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/modal.c b/src/modal.c index 6b1cb0a..5f3206b 100644 --- a/src/modal.c +++ b/src/modal.c @@ -216,13 +216,19 @@ int main(int argc, char **argv) { FILE *f; + int i; char c, *w = bank_a; 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, 17 Apr 2024.\n"); - if(!(f = fopen(argv[1], "r"))) - return !fprintf(stderr, "Invalid Modal file: %s.\n", argv[1]); + return !printf("usage: modal [-vqn] source.modal\n"); + for(i = 1; i < argc && *argv[i] == '-'; i++) { + switch(argv[i][1]) { + case 'v': /* version */ return !printf("Modal Interpreter, 18 Apr 2024.\n"); + case 'q': /* quiet */ fclose(stderr); break; + case 'n': /* infinite */ cycles = 0xffffffff; break; + } + } + if(!(f = fopen(argv[i], "r"))) + return !fprintf(stdout, "Invalid Modal file: %s.\n", argv[i]); while(fread(&c, 1, 1, f)) { c = c <= 0x20 ? 0x20 : c; if(w > bank_a) { @@ -235,6 +241,6 @@ main(int argc, char **argv) while(*(--w) <= ' ') *w = 0; fclose(f); while(rewrite()) - if(!cycles--) return !fprintf(stderr, "Cycle limit exceeded.\n"); + if(!cycles--) return !fprintf(stdout, "Modal rewrites exceeded.\n"); return 0; } \ No newline at end of file