diff options
Diffstat (limited to 'tools/make_shim.c')
-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"); |