From 51b32bbc0aa9599347e488e3912211a292ca7310 Mon Sep 17 00:00:00 2001 From: Simon Forman Date: Sun, 12 Feb 2023 15:15:01 -0800 Subject: [PATCH] Quiet mode for C. --- implementations/C/definitions.c | 2 +- implementations/C/joy.c | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/implementations/C/definitions.c b/implementations/C/definitions.c index c5dab97..9bfd770 100644 --- a/implementations/C/definitions.c +++ b/implementations/C/definitions.c @@ -218,7 +218,7 @@ init_defs(void) def_popopdd_body = text_to_expression("[popop] dipd"); def_product_body = text_to_expression("1 swap [*] step"); def_quoted_body = text_to_expression("[unit] dip"); - def_range_body = text_to_expression("[0 <=] [1 - dup] anamorphism"); + def_range_body = text_to_expression("[0 <=] [-- dup] anamorphism"); def_range_to_zero_body = text_to_expression("unit [down_to_zero] infra"); def_reco_body = text_to_expression("rest cons"); def_reverse_body = text_to_expression("<{} shunt"); diff --git a/implementations/C/joy.c b/implementations/C/joy.c index eb37401..494b4fc 100644 --- a/implementations/C/joy.c +++ b/implementations/C/joy.c @@ -841,8 +841,17 @@ joy(JoyListPtr stack, JoyListPtr expression) } +/* Set quiet mode by "-q as only command line option. "*/ +int quiet = 0; + +#define SHH(message) \ +if (!quiet) { \ + printf(message); \ +} + + int -main(void) +main(int argc, char *argv[]) { char *line; char *status; @@ -858,10 +867,12 @@ main(void) init_defs(); + quiet = ((2 == argc) && (!strcmp("-q", argv[1]))); + line = (char *)GC_malloc(1025); while (1) { - printf("\njoy? "); + SHH("\njoy? ") status = gets_s(line, 1025); if (NULL == status) { /* @@ -878,7 +889,7 @@ main(void) TODO: "use feof(3) and ferror(3)"... */ - printf("bye\n"); + SHH("bye\n") break; } s = stack;