diff options
author | Aleksey Veresov <aleksey@veresov.pro> | 2021-01-03 01:19:12 +0300 |
---|---|---|
committer | Aleksey Veresov <aleksey@veresov.pro> | 2021-01-03 01:19:12 +0300 |
commit | abfe132b83219efa30220ecfdaf6e26e31b9d13d (patch) | |
tree | 70d33ac10f4e3e24b0e3ac496017f465dcdec1ae /src | |
parent | faab24e5a6766880c7e4a33433cb4146e3f8a302 (diff) | |
download | csx-abfe132b83219efa30220ecfdaf6e26e31b9d13d.tar csx-abfe132b83219efa30220ecfdaf6e26e31b9d13d.tar.xz csx-abfe132b83219efa30220ecfdaf6e26e31b9d13d.zip |
Input-output added.
Diffstat (limited to 'src')
-rw-r--r-- | src/csx.c | 33 |
1 files changed, 32 insertions, 1 deletions
@@ -3,6 +3,7 @@ #include <stdlib.h> #include <stdarg.h> #include <string.h> +#include <stdio.h> typedef enum csx_type { @@ -380,7 +381,33 @@ static void *base_context(void *arg) static void *base_quote(void *arg) { - return arg; + return head(arg); +} + +static void *base_input(void *arg) +{ + int res = getchar(); + return res != EOF ? new_num(res) : null; +} + +static void *base_output(void *arg) +{ + arg = eval_each(arg); + return putchar(*(int *)head(arg)) != EOF ? one : null; +} + +static void *base_outname(void *arg) +{ + arg = eval_each(arg); + return fputs(head(arg), stdout) != EOF ? one : null; +} + +static void *base_outnum(void *arg) +{ + arg = eval_each(arg); + int num = *(int *)head(arg); + printf("%d", num); + return one; } static void *base_fn(void *arg) @@ -500,6 +527,10 @@ static void new_context() base_define(csx_list(new_name("if"), new_base(base_if), 0)); base_define(csx_list(new_name("and"), new_base(base_and), 0)); base_define(csx_list(new_name("or"), new_base(base_or), 0)); + base_define(csx_list(new_name("input"), new_base(base_input), 0)); + base_define(csx_list(new_name("output"), new_base(base_output), 0)); + base_define(csx_list(new_name("outname"), new_base(base_outname), 0)); + base_define(csx_list(new_name("outnum"), new_base(base_outnum), 0)); } |