(uxnasm) Only display location in internal errors

This commit is contained in:
Devine Lu Linvega 2024-03-01 17:26:49 -08:00
parent 80e2f9cc0c
commit a5ff070dd0
1 changed files with 12 additions and 5 deletions

View File

@ -69,6 +69,13 @@ static char *scat(char *dst, const char *src) { char *ptr = dst + slen(dst); whi
static int parse(char *w, FILE *f); static int parse(char *w, FILE *f);
static int
error_top(const char *name, const char *msg)
{
fprintf(stderr, "%s: %s\n", name, msg);
return 0;
}
static int static int
error(const char *name, const char *msg) error(const char *name, const char *msg)
{ {
@ -520,17 +527,17 @@ main(int argc, char *argv[])
{ {
FILE *src, *dst; FILE *src, *dst;
if(argc == 1) if(argc == 1)
return error("usage", "uxnasm [-v] input.tal output.rom"); return error_top("usage", "uxnasm [-v] input.tal output.rom");
if(argv[1][0] == '-' && argv[1][1] == 'v') if(argv[1][0] == '-' && argv[1][1] == 'v')
return !fprintf(stdout, "Uxnasm - Uxntal Assembler, 1 Mar 2024.\n"); return !fprintf(stdout, "Uxnasm - Uxntal Assembler, 1 Mar 2024.\n");
if(!(src = fopen(setlocation(argv[1]), "r"))) if(!(src = fopen(setlocation(argv[1]), "r")))
return !error("Invalid input", argv[1]); return !error_top("Invalid input", argv[1]);
if(!assemble(src)) if(!assemble(src))
return !error("Assembly", "Failed to assemble rom."); return !error_top("Assembly", "Failed to assemble rom.");
if(!(dst = fopen(argv[2], "wb"))) if(!(dst = fopen(argv[2], "wb")))
return !error("Invalid Output", argv[2]); return !error_top("Invalid Output", argv[2]);
if(p.length <= TRIM) if(p.length <= TRIM)
return !error("Assembly", "Output rom is empty."); return !error_top("Assembly", "Output rom is empty.");
fwrite(p.data + TRIM, p.length - TRIM, 1, dst); fwrite(p.data + TRIM, p.length - TRIM, 1, dst);
if(!scmp(argv[2], "-", 2)) { if(!scmp(argv[2], "-", 2)) {
review(argv[2]); review(argv[2]);