#define _POSIX_C_SOURCE 200809L #include #include #include #include #include #include "check.h" #include "lex.h" #include "parse.h" #include "util.h" int main(int argc, char *argv[]) { int optind = 1; int nsources = argc - optind; struct lexer lexer; struct ast_unit ast; for (int i = 0; i < nsources; ++i) { FILE *in; const char *path = argv[optind + i]; if (strcmp(path, "-") == 0) { in = stdin; } else { in = fopen(path, "r"); struct stat stat; if (in && fstat(fileno(in), &stat) == 0 && S_ISDIR(stat.st_mode) != 0) { fprintf(stderr, "Unable to open %s for reading: Is a directory\n", path); return EXIT_USER; } } if (!in) { fprintf(stderr, "Unable to open %s for reading: %s\n", path, strerror(errno)); return EXIT_ABNORMAL; } lex_init(&lexer, in, path); parse(&lexer, &ast); lex_finish(&lexer); check(&ast); } return EXIT_SUCCESS; }