diff options
-rw-r--r-- | blob2xex.1 | 4 | ||||
-rw-r--r-- | blob2xex.c | 16 |
2 files changed, 11 insertions, 9 deletions
@@ -54,7 +54,7 @@ part of the input file. To read from standard input, use \fB\-\fP for the input files are used, the resulting .xex file will have multiple segments. If \fIoutfile\fP already exists, it will be overwritten. If \fIoutfile\fP is a filename that begins with a \fB\-\fP, prefix it with -"./", otherwise it\(aqll be taken as an option. Use \fB\-\fP to write to +"./", otherwise it\(aqll be taken as an option. Use \fB\-\fP to write to standard output. \fBblob2xex\fP will not write output to a terminal; \fB\-\fP must be used with redirection or a pipe. .sp @@ -111,7 +111,7 @@ blob2xex program.xex \-l \(aq$2000\(aq \-r \(aq$2000\(aq program.bin Notice the use of quotes around the addresses? That\(aqs because the $ character must be quoted, or the shell will try to interpret it as a variable reference. You could also have typed \fB$2000\fP or -\fB0x2000\fP\&. +\fB0x2000\fP\&. Or you could have used decimal (\fB4096\fP). .SS More Complex Example .sp Suppose you want to write a program that can run on an Atari 800, @@ -46,12 +46,13 @@ int write_segment( int c; if(size < 1) { - fprintf(stderr, SELF ": invalid size %d (must be >= 1).\n", size); + fprintf(stderr, SELF ": fatal: invalid size %d (must be >= 1).\n", size); return(0); } if(strcmp(infile, "-") == 0) { infh = stdin; + infile = "(standard input)"; } else { infh = fopen(infile, "rb"); if(!infh) { @@ -69,7 +70,7 @@ int write_segment( } else { outfh = fopen(outfile, "wb"); if(!outfh) { - fprintf(stderr, SELF ": %s: %s\n", outfile, strerror(errno)); + fprintf(stderr, SELF ": fatal: %s: %s\n", outfile, strerror(errno)); return(0); } } @@ -77,7 +78,7 @@ int write_segment( if(isatty(fileno(outfh))) { fprintf(stderr, - SELF ": Standard output is a terminal; not writing binary data\n"); + SELF ": fatal: standard output is a terminal; not writing binary data.\n"); return 0; } @@ -85,12 +86,13 @@ int write_segment( seg.len = 0; seg.start_addr = loadaddr; - /* skip <offset> bytes in input. don't seek, input might be stdin */ + /* skip <offset> bytes in input. don't seek, input might be stdin. + not very efficient to read 1 byte at a time, but we're dealing + with very small files, by modern standards. */ while(offset) { - /* TODO: not very efficient to read 1 byte at a time? */ c = getc(infh); if(c < 0) { - fprintf(stderr, SELF ": offset extends past EOF on file %s\n", infile); + fprintf(stderr, SELF ": fatal: offset extends past EOF on file %s\n", infile); return(0); } offset--; @@ -110,7 +112,7 @@ int write_segment( } if(seg.len == 0) { - fprintf(stderr, SELF ": read 0 bytes from %s, xex files cannot contain empty segments.\n", infile); + fprintf(stderr, SELF ": fatal: read 0 bytes from %s, xex files cannot contain empty segments.\n", infile); return(0); } |