#include <stdlib.h>
#include <string.h>
#include <limits.h>
-#include <sys/stat.h>
#include "gmqcc.h"
int usage(const char *name) {
printf("Usage: %s -f infile -o outfile\n", name);
return 0;
}
-
int main(int argc, char **argv) {
- struct stat chk;
const char *ofile = NULL;
const char *ifile = NULL;
int i;
- if (argc <= 2)
+ if (argc <= 2) {
return usage(*argv);
+ }
- for (i=0; i<argc; i++) {
+ for (i=0; i < argc; i++) {
if (argc != i + 1) {
switch(argv[i][0]) {
case '-':
}
}
- if (!ofile || !ifile)
+ if (!ofile || !ifile) {
return usage(*argv);
+ }
printf("ifile: %s\n", ifile);
printf("ofile: %s\n", ofile);
- /* we check here for file existance, not in the lexer */
- if (stat(ifile, &chk) != 0)
- return error(ERROR_COMPILER, "source file `%s` not found\n", ifile);
-
- struct lex_file *lex = lex_open(ifile);
- lex_debug(lex);
- parse (lex);
- lex_close(lex);
+ /* Open file */
+ FILE *fp = fopen(ifile, "r");
+ if (!fp) {
+ fclose(fp);
+ return error(ERROR_COMPILER, "Source file: %s not found\n", ifile);
+ } else {
+ struct lex_file *lex = lex_open(fp);
+ parse (lex);
+ lex_close(lex);
+ }
return 0;
}