diff options
| author | Root THC | 2026-02-24 12:42:47 +0000 |
|---|---|---|
| committer | Root THC | 2026-02-24 12:42:47 +0000 |
| commit | c9cbeced5b3f2bdd7407e29c0811e65954132540 (patch) | |
| tree | aefc355416b561111819de159ccbd86c3004cf88 /other/gramble/input-test.c | |
| parent | 073fe4bf9fca6bf40cef2886d75df832ef4b6fca (diff) | |
initial
Diffstat (limited to 'other/gramble/input-test.c')
| -rw-r--r-- | other/gramble/input-test.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/other/gramble/input-test.c b/other/gramble/input-test.c new file mode 100644 index 0000000..6c3fb01 --- /dev/null +++ b/other/gramble/input-test.c | |||
| @@ -0,0 +1,76 @@ | |||
| 1 | /* gramble - grammar ramble | ||
| 2 | * | ||
| 3 | * team teso | ||
| 4 | * | ||
| 5 | * input functions test program | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include <stdio.h> | ||
| 9 | #include <stdlib.h> | ||
| 10 | #include <string.h> | ||
| 11 | #include "common.h" | ||
| 12 | #include "input.h" | ||
| 13 | |||
| 14 | |||
| 15 | char * file_read (char *filename); | ||
| 16 | |||
| 17 | |||
| 18 | char * | ||
| 19 | file_read (char *filename) | ||
| 20 | { | ||
| 21 | FILE * fp; | ||
| 22 | char * array = NULL; | ||
| 23 | unsigned long int readbytes = 0; | ||
| 24 | size_t rb; | ||
| 25 | |||
| 26 | |||
| 27 | fp = fopen (filename, "r"); | ||
| 28 | if (fp == NULL) | ||
| 29 | return (NULL); | ||
| 30 | |||
| 31 | do { | ||
| 32 | array = xrealloc (array, readbytes + 1024); | ||
| 33 | rb = fread (array + readbytes, 1, 1024, fp); | ||
| 34 | readbytes += rb; | ||
| 35 | } while (rb > 0); | ||
| 36 | |||
| 37 | fclose (fp); | ||
| 38 | |||
| 39 | return (array); | ||
| 40 | } | ||
| 41 | |||
| 42 | |||
| 43 | int | ||
| 44 | main (int argc, char **argv) | ||
| 45 | { | ||
| 46 | void * inp; | ||
| 47 | char * grammar; | ||
| 48 | |||
| 49 | |||
| 50 | if (argc != 2) { | ||
| 51 | printf ("usage: %s <inputfile>\n\n", argv[0]); | ||
| 52 | |||
| 53 | exit (EXIT_FAILURE); | ||
| 54 | } | ||
| 55 | |||
| 56 | grammar = file_read (argv[1]); | ||
| 57 | if (grammar == NULL) { | ||
| 58 | fprintf (stderr, "couldn't open or read \"%s\", " | ||
| 59 | "aborting\n", argv[1]); | ||
| 60 | |||
| 61 | exit (EXIT_FAILURE); | ||
| 62 | } | ||
| 63 | |||
| 64 | inp = in_parse (grammar, strlen (grammar)); | ||
| 65 | printf ("---------------------------------------------------------" | ||
| 66 | "----------------------\n"); | ||
| 67 | printf ("parsing of grammar %s %s.\n\n", argv[1], | ||
| 68 | (inp == NULL) ? "failed" : "successful"); | ||
| 69 | |||
| 70 | /* TODO: sanity checking, free'ing etc. | ||
| 71 | */ | ||
| 72 | |||
| 73 | exit (EXIT_SUCCESS); | ||
| 74 | } | ||
| 75 | |||
| 76 | |||
