diff options
| author | peter <peter@pmikkelsen.com> | 2026-08-30 13:05:02 +0000 |
|---|---|---|
| committer | peter <peter@pmikkelsen.com> | 2026-08-30 13:05:02 +0000 |
| commit | d361abaeb8dcf19446a9322737ea600b22568a5b (patch) | |
| tree | 4166cebc87c27f2512028bfaffffa4d6cfddb18d | |
| parent | a01b62d7ace95aef73b9f2d33f01486e0856233f (diff) | |
| parent | 969729d0b0e13314e1cb6266b1304e7606d4563f (diff) | |
Merge branch getting-started into trunk. It turns out there is no need to have the branch.
FossilOrigin-Name: 028cf019fc0daacf38ddceb28afd3dafb305887a5421995fc57d09daa295a34b
| -rw-r--r-- | src/bin/main.c | 56 | ||||
| -rw-r--r-- | src/include/aplwc.h | 2 | ||||
| -rwxr-xr-x | tests/scripts/1.aplwc | 2 |
3 files changed, 51 insertions, 9 deletions
diff --git a/src/bin/main.c b/src/bin/main.c index 93d28c0..572d170 100644 --- a/src/bin/main.c +++ b/src/bin/main.c @@ -11,10 +11,11 @@ main(int argc, char *argv[]) struct aplwc_line *line; struct aplwc_value *value; uint8_t *data; - char *input; + char *input, *src; int ret, exit_code, line_number; - size_t memsize, input_size; + size_t memsize, input_size, src_size, i; int opt, xflag, input_file; + long tmp; FILE *f; input = NULL; @@ -64,6 +65,50 @@ usage: return 1; } + if(input_file){ + if(fseek(f, 0, SEEK_END)){ +file_size: + fprintf(stderr, "Failed to determine file size\n"); + return 1; + } + tmp = ftell(f); + if(tmp < 0) + goto file_size; + input_size = tmp; + rewind(f); + input = malloc(input_size); + if(input == NULL){ + fprintf(stderr, "Failed to allocate space for file contents\n"); + return 1; + } + if(fread(input, 1, input_size, f) < input_size){ + fprintf(stderr, "Failed to read file contents\n"); + return 1; + } + fclose(f); + + src = input; + src_size = input_size; + if((input_size > 2) && (input[0] == '#') && (input[1] == '!')){ + for(i = 0; i < input_size; i++){ + if(input[i] == '\n'){ + src += i; + src_size -= i; + xflag = 1; + break; + } + } + } + + ret = aplwc_load_module(aplwc, "Main", src, src_size); + if(ret){ + fprintf(stderr, "Couldn't load Main module from file %s: %s\n", argv[optind], aplwc_errstr_rc(ret)); + return 1; + } + free(input); + input = NULL; + } + if(xflag) goto exit; @@ -76,16 +121,11 @@ usage: aplwc_free_value(value); input = NULL; - if(getline(&input, &input_size, f) < 0){ + if(getline(&input, &input_size, stdin) < 0){ free(input); break; }else{ line_number++; - if(input_file && (line_number == 1)){ - if((strlen(input) > 2) && (input[0] == '#') && (input[1] == '!')) - continue; - } - line = aplwc_read(aplwc, input); if(line == NULL){ line_error: diff --git a/src/include/aplwc.h b/src/include/aplwc.h index a22bd8d..3061500 100644 --- a/src/include/aplwc.h +++ b/src/include/aplwc.h @@ -30,6 +30,6 @@ void aplwc_free_value(struct aplwc_value *); const char *aplwc_value_string(struct aplwc_value *); enum aplwc_rc aplwc_load_module(struct aplwc *, const char *, const char *, int n); -#define APLWC_MIN_MEM (2048) +#define APLWC_MIN_MEM (64000) #endif /* APLWC_H */ diff --git a/tests/scripts/1.aplwc b/tests/scripts/1.aplwc index 77104b2..e101d02 100755 --- a/tests/scripts/1.aplwc +++ b/tests/scripts/1.aplwc @@ -1,3 +1,5 @@ #!/usr/bin/env aplwc-repl +∇ run ⎕←40 + 2 +∇ |