diff options
author | PikalaxALT <pikalaxalt@gmail.com> | 2018-06-04 10:16:15 -0400 |
---|---|---|
committer | PikalaxALT <pikalaxalt@gmail.com> | 2018-06-04 10:16:15 -0400 |
commit | ec992a2654c719b758e3f0c21324a7df30417ed6 (patch) | |
tree | 3881e23444496fb1d2828d70ce1d946dcdbf474f | |
parent | 51e7c4a5cb7870d9ee861543245a961bb7c70f6e (diff) |
Even more informative error messages from make_shim
-rw-r--r-- | tools/make_shim.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/tools/make_shim.c b/tools/make_shim.c index c5b684e..70da31d 100644 --- a/tools/make_shim.c +++ b/tools/make_shim.c @@ -54,17 +54,19 @@ size_t strrcspn(const char *s1, const char *s2) { return _s1 - s1; } -#define RIP(errmsg) { \ - if (errno == 0) errno = EIO; \ - perror(errmsg); \ - if (file) fclose(file); \ - return 1; \ +#define RIP(errmsg) { \ + fprintf(stderr, "%s:%d:%s: %s\n", fname, lineno, eline, errmsg); \ + if (file) fclose(file); \ + return 1; \ } int main(int argc, char * argv[]) { int ch; char line[16*1024]; + char eline[16*1024]; char *lineptr = NULL; + char *fname; + int lineno; section_t section_list[] = { {0x4000, false, "ROM0", false}, @@ -93,15 +95,21 @@ int main(int argc, char * argv[]) { } for (int arg_idx = optind; arg_idx < argc; arg_idx++) { - FILE * file = fopen(argv[arg_idx], "r"); + eline[0] = 0; + lineno = 0; + fname = argv[arg_idx]; + FILE * file = fopen(fname, "r"); if (file == NULL) RIP("Unable to open file"); while ((lineptr = fgets(line, sizeof(line), file)) != NULL) { + lineno++; unsigned short bank = 0; unsigned short pointer = 0; char * symbol = NULL; char * end; char * addr_p; + strcpy(eline, line); // Unmodified copy for tracebacks + *strrchr(eline, '\n') = 0; // line = line.split(";")[0].strip() lineptr += strspn(lineptr, " \t\n"); |