diff options
Diffstat (limited to 'src/bootstrap')
-rwxr-xr-x | src/bootstrap/main.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/bootstrap/main.c b/src/bootstrap/main.c index 2847397..b5fd821 100755 --- a/src/bootstrap/main.c +++ b/src/bootstrap/main.c | |||
@@ -50,6 +50,34 @@ run_file(char *file_name) { | |||
50 | fclose(file); | 50 | fclose(file); |
51 | } | 51 | } |
52 | 52 | ||
53 | #define STDIN_BUF_SIZE 16 | ||
54 | |||
55 | void | ||
56 | run_stdin(void) { | ||
57 | size_t buf_size = 0; | ||
58 | size_t buf_cap = STDIN_BUF_SIZE; | ||
59 | char *source = malloc(sizeof(char) * buf_cap); | ||
60 | |||
61 | char c; | ||
62 | while ((c = getchar()) != EOF) { | ||
63 | if (buf_size == buf_cap) { | ||
64 | buf_cap *= 2; | ||
65 | source = realloc(source, buf_cap * sizeof(char)); | ||
66 | } | ||
67 | source[buf_size] = c; | ||
68 | buf_size++; | ||
69 | } | ||
70 | |||
71 | StringView sv = (StringView){ | ||
72 | .start = source, | ||
73 | .n = buf_size, | ||
74 | }; | ||
75 | |||
76 | process_source(&sv); | ||
77 | |||
78 | free(source); | ||
79 | } | ||
80 | |||
53 | #ifndef BIN_NAME | 81 | #ifndef BIN_NAME |
54 | #define BIN_NAME "bdl" | 82 | #define BIN_NAME "bdl" |
55 | #endif | 83 | #endif |
@@ -81,7 +109,7 @@ main(int argc, char *argv[]) { | |||
81 | 109 | ||
82 | // Run from stdin. | 110 | // Run from stdin. |
83 | if (optind == argc) { | 111 | if (optind == argc) { |
84 | // TODO: Run from stdin if no file is given. | 112 | run_stdin(); |
85 | return EXIT_SUCCESS; | 113 | return EXIT_SUCCESS; |
86 | } | 114 | } |
87 | 115 | ||