diff options
author | Ting-Wei Lan <lantw44@gmail.com> | 2015-11-30 15:51:45 +0800 |
---|---|---|
committer | Ting-Wei Lan <lantw44@gmail.com> | 2015-11-30 15:55:07 +0800 |
commit | 3914e568ee28efd4e6fb18d6a1070c2c47d69894 (patch) | |
tree | 19f244c4278b6433cbb7677953e2d42b5d76c8bd /src/main.c | |
parent | 52913df8619a848127e8c300cb8c601e7c153feb (diff) | |
download | compiler2015-3914e568ee28efd4e6fb18d6a1070c2c47d69894.tar compiler2015-3914e568ee28efd4e6fb18d6a1070c2c47d69894.tar.gz compiler2015-3914e568ee28efd4e6fb18d6a1070c2c47d69894.tar.bz2 compiler2015-3914e568ee28efd4e6fb18d6a1070c2c47d69894.tar.lz compiler2015-3914e568ee28efd4e6fb18d6a1070c2c47d69894.tar.xz compiler2015-3914e568ee28efd4e6fb18d6a1070c2c47d69894.tar.zst compiler2015-3914e568ee28efd4e6fb18d6a1070c2c47d69894.zip |
Use strerror_r to make error messages more useful
This commit adds a new file, common.h, which contains private macros
and static functions to make the code cleaner.
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 21 |
1 files changed, 18 insertions, 3 deletions
@@ -3,25 +3,40 @@ #endif #include "ast.h" +#include "common.h" #include "libparser_a-parser.h" +#include <errno.h> +#include <locale.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> + extern FILE *yyin; extern AST_NODE *prog; +const char *ccmmc_main_name; + int main (int argc, char **argv) { + ERR_DECL; + setlocale (LC_ALL, ""); + name = strrchr (argv[0], '/'); + name = name == NULL ? name : name + 1; + if (argc != 2) { - fputs("usage: parser [source file]\n", stderr); + fprintf(stderr, "Usage: %s SOURCE\n", name); exit(1); } - yyin = fopen(argv[1],"r"); + + const char *filename = argv[1]; + yyin = fopen(filename, "r"); if (yyin == NULL) { - fputs("Error opening source file.\n", stderr); + fprintf(stderr, "%s: %s: %s\n", name, filename, ERR_MSG); exit(1); } + yyparse(); printGV(prog, NULL); return 0; |