(uxnasm.c) Support outputting to stdout using `-`

This commit is contained in:
Remko Tronçon 2023-10-27 09:32:27 +02:00 committed by neauoire
parent 187f92d31d
commit cff5746e03
1 changed files with 7 additions and 3 deletions

View File

@ -506,12 +506,16 @@ main(int argc, char *argv[])
return !error("Invalid input", argv[1]); return !error("Invalid input", argv[1]);
if(!assemble(src)) if(!assemble(src))
return !error("Assembly", "Failed to assemble rom."); return !error("Assembly", "Failed to assemble rom.");
if(!(dst = fopen(argv[2], "wb"))) if (scmp(argv[2], "-", 2))
dst = stdout;
else if(!(dst = fopen(argv[2], "wb")))
return !error("Invalid Output", argv[2]); return !error("Invalid Output", argv[2]);
if(p.length <= TRIM) if(p.length <= TRIM)
return !error("Assembly", "Output rom is empty."); return !error("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)) {
review(argv[2]); review(argv[2]);
writesym(argv[2]); writesym(argv[2]);
}
return 0; return 0;
} }