diff options
Diffstat (limited to 'src/bin')
| -rw-r--r-- | src/bin/main.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/bin/main.c b/src/bin/main.c index fb75a9d..99149f6 100644 --- a/src/bin/main.c +++ b/src/bin/main.c @@ -4,15 +4,21 @@ #include <errno.h> #include "aplwc_repl.h" -#define MEMSIZE 20000 +static void *my_alloc(size_t min, size_t max, size_t *actual) +{ + UNUSED_PARAMETER(max); + + *actual = min; + return malloc(min); +} int main(int argc, char *argv[]) { + struct aplwc_fns fns; struct aplwc *aplwc; struct aplwc_line *line; struct aplwc_value *value; - uint8_t *data; char *input, *src; int ret, exit_code, line_number; size_t input_size, src_size, i; @@ -28,6 +34,9 @@ main(int argc, char *argv[]) exit_code = 0; line_number = 0; + memset(&fns, 0, sizeof(fns)); + fns.alloc = my_alloc; + while((opt = getopt(argc, argv, "x")) != -1){ switch(opt){ case 'x': @@ -52,16 +61,9 @@ usage: else goto usage; - data = malloc(MEMSIZE); - if(data == NULL){ - fprintf(stderr, "Couldn't allocate memory\n"); - return 1; - } - - ret = aplwc_new(&aplwc, data, MEMSIZE); + ret = aplwc_new(&aplwc, fns); if(ret){ fprintf(stderr, "Couldn't create new aplwc instance: %s\n", aplwc_errstr_rc(ret)); - free(data); return 1; } @@ -152,6 +154,5 @@ exit: aplwc_free_value(value); aplwc_destroy(aplwc); - free(data); return exit_code; } |