diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-05-11 19:39:58 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-05-11 19:39:58 +0900 |
| commit | 6529e5a11e6d1c6f2a3fc3c08d77d22aaeccfef6 (patch) | |
| tree | 3876298654c8c1164b523918f85f26e221a78c5e | |
| parent | b6e59680819b1cea7ec1f081d246bef537b89f47 (diff) | |
| download | ducc-6529e5a11e6d1c6f2a3fc3c08d77d22aaeccfef6.tar.gz ducc-6529e5a11e6d1c6f2a3fc3c08d77d22aaeccfef6.tar.zst ducc-6529e5a11e6d1c6f2a3fc3c08d77d22aaeccfef6.zip | |
refactor
| -rw-r--r-- | main.c | 17 |
1 files changed, 8 insertions, 9 deletions
@@ -10,6 +10,7 @@ extern FILE* stderr; int atoi(const char*); void* calloc(size_t, size_t); void exit(int); +char* fgets(char*, int, FILE*); int getchar(void); int isalnum(int); int isalpha(int); @@ -34,16 +35,14 @@ void unreachable() { fatal_error("unreachable"); } -char* read_all() { +char* read_all(FILE* in) { char* buf = calloc(1024 * 1024, sizeof(char)); char* cur = buf; - while (1) { - int c = getchar(); - if (c == -1) { - break; - } - *cur = c; - ++cur; + char* tmp = calloc(1024, sizeof(char)); + while (fgets(tmp, 1024, in)) { + size_t len = strlen(tmp); + memcpy(cur, tmp, len); + cur += len; } return buf; } @@ -2184,7 +2183,7 @@ void codegen(Program* prog) { } int main() { - char* source = read_all(); + char* source = read_all(stdin); Token* tokens = tokenize(source); Program* prog = parse(tokens); analyze(prog); |
