aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/orgaasm.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/orgaasm.c b/src/orgaasm.c
index c35aa4e..785a1ab 100644
--- a/src/orgaasm.c
+++ b/src/orgaasm.c
@@ -36,7 +36,7 @@ fail(void)
free(label_root);
label_root = next;
}
- if (outfile != NULL)
+ if (outfile != NULL && outfile != stdout)
fclose(outfile);
return 1;
}
@@ -59,7 +59,7 @@ static void
write_short(uint_least16_t v)
{
static unsigned int write_n = 0;
- if (verbose) printf("write %04x: %04x\n", write_n, v);
+ if (verbose) fprintf(stderr, "write %04x: %04x\n", write_n, v);
write_n += 1;
if (fputc(v & 0x00ff, outfile) == EOF ||
fputc(v / 0x0100, outfile) == EOF) {
@@ -81,7 +81,7 @@ register_label(const char *s, size_t pc)
label->addr = pc;
label->next = label_root;
label_root = label;
- if (verbose) printf("label: '%s' at pc %zu\n", s, pc);
+ if (verbose) fprintf(stderr, "label: '%s' at pc %zu\n", s, pc);
}
static void
@@ -194,7 +194,7 @@ second_pass(char *s)
const size_t tok_len = strlen(tok);
switch (tok_len) {
case 3: /* opcode */
- if (verbose) printf("opcode: %s\n", tok);
+ if (verbose) fprintf(stderr, "opcode: %s\n", tok);
write_opcode(tok);
break;
case 5: /* LIT literal */
@@ -204,7 +204,7 @@ second_pass(char *s)
tok += 1;
/* fallthrough */
case 4: /* literal */
- if (verbose) printf("literal: %s\n", tok);
+ if (verbose) fprintf(stderr, "literal: %s\n", tok);
write_literal(tok);
break;
default: /* wtf */
@@ -253,11 +253,15 @@ main(int argc, char **argv)
/* First pass, find labels. */
first_pass(data);
- /* Open out file. */
- outfile = fopen(argv[2], "wb");
- if (outfile == NULL) {
- perror(argv[2]);
- return fail();
+ if (strcmp(argv[2], "-") == 0)
+ outfile = stdout;
+ else {
+ /* Open out file. */
+ outfile = fopen(argv[2], "wb");
+ if (outfile == NULL) {
+ perror(argv[2]);
+ return fail();
+ }
}
/* Second pass, generate bytecode. */