summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorTing-Wei Lan <lantw44@gmail.com>2015-11-30 15:51:45 +0800
committerTing-Wei Lan <lantw44@gmail.com>2015-11-30 15:55:07 +0800
commit3914e568ee28efd4e6fb18d6a1070c2c47d69894 (patch)
tree19f244c4278b6433cbb7677953e2d42b5d76c8bd /src/main.c
parent52913df8619a848127e8c300cb8c601e7c153feb (diff)
downloadcompiler2015-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.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/main.c b/src/main.c
index fde8aef..2370f5a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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;