aboutsummaryrefslogtreecommitdiff
path: root/xexamine.c
diff options
context:
space:
mode:
Diffstat (limited to 'xexamine.c')
-rw-r--r--xexamine.c89
1 files changed, 44 insertions, 45 deletions
diff --git a/xexamine.c b/xexamine.c
index d47993e..3c277e5 100644
--- a/xexamine.c
+++ b/xexamine.c
@@ -309,7 +309,7 @@ int main(int argc, char **argv) {
xex_segment seg;
unsigned char buffer[65536];
char *filename;
- int opt, offset, segcount = 0, only_segment = 0, header_printed = 0, decimal = 0;
+ int opt, offset, segcount = 0, only_segment = 0, header_printed = 0, decimal = 0, print_filenames = 0;
uint32_t crc;
while((opt = getopt(argc, argv, "vhs:d")) != -1) {
@@ -337,65 +337,64 @@ int main(int argc, char **argv) {
}
}
- if(argv[optind + 1]) {
- fprintf(stderr, SELF ": don't know what to do with excess argument '%s'.\n", argv[optind + 1]);
- usage(1);
- }
-
if(optind >= argc) {
fprintf(stderr, SELF ": no xex file argument.\n");
usage(1);
}
- filename = argv[optind];
- if( !(f = fopen(filename, "rb")) ) {
- fprintf(stderr, "%s: ", SELF);
- perror(filename);
- exit(1);
- }
+ if(argc > optind + 1) print_filenames = 1;
+ while(optind < argc) {
+ filename = argv[optind++];
+ if( !(f = fopen(filename, "rb")) ) {
+ fprintf(stderr, "%s: ", SELF);
+ perror(filename);
+ exit(1);
+ }
+ if(print_filenames) printf("%s:\n", filename);
- seg.object = buffer;
+ seg.object = buffer;
- offset = 0;
- while(xex_fread_seg(&seg, f)) {
- segcount++;
+ offset = segcount = 0;
+ while(xex_fread_seg(&seg, f)) {
+ segcount++;
- crc = 0;
- crc32(seg.object, seg.len, &crc);
+ crc = 0;
+ crc32(seg.object, seg.len, &crc);
- if(!only_segment || (only_segment == segcount)) {
- if(!header_printed) {
- printf("Seg | Offset | Start | End | Bytes | CRC32 | Type\n");
- header_printed++;
- }
+ if(!only_segment || (only_segment == segcount)) {
+ if(!header_printed) {
+ printf("Seg | Offset | Start | End | Bytes | CRC32 | Type\n");
+ header_printed++;
+ }
- printf((decimal ?
- "%3d | %6d | %5d | %5d | %5d | %08x | " :
- "%3d | %6d | $%04x | $%04x | %5d | %08x | "),
- segcount, offset, seg.start_addr, seg.end_addr, seg.len, crc);
+ printf((decimal ?
+ "%3d | %6d | %5d | %5d | %5d | %08x | " :
+ "%3d | %6d | $%04x | $%04x | %5d | %08x | "),
+ segcount, offset, seg.start_addr, seg.end_addr, seg.len, crc);
- /* TODO: what if there's a >=4 byte segment that loads at RUNAD?
- the next 2 bytes are INITAD, we would silently ignore that fact. */
- if(seg.start_addr == XEX_RUNAD && seg.len > 1)
- printf((decimal ? "Run %5d" : "Run $%04x"), (seg.object[0] | (seg.object[1] << 8)));
- else if(seg.start_addr == XEX_INITAD && seg.len > 1)
- printf((decimal ? "Init %5d" : "Run $%04x"), (seg.object[0] | (seg.object[1] << 8)));
- else printf("%d%% code", classify_seg(seg));
+ /* TODO: what if there's a >=4 byte segment that loads at RUNAD?
+ the next 2 bytes are INITAD, we would silently ignore that fact. */
+ if(seg.start_addr == XEX_RUNAD && seg.len > 1)
+ printf((decimal ? "Run %5d" : "Run $%04x"), (seg.object[0] | (seg.object[1] << 8)));
+ else if(seg.start_addr == XEX_INITAD && seg.len > 1)
+ printf((decimal ? "Init %5d" : "Init $%04x"), (seg.object[0] | (seg.object[1] << 8)));
+ else printf("%d%% code", classify_seg(seg));
- putchar('\n');
- }
+ putchar('\n');
+ }
- offset = ftell(f);
- }
+ offset = ftell(f);
+ }
- if(only_segment && (segcount < only_segment)) {
- fprintf(stderr, SELF ": can't show segment %d, only %d segments in file.\n", only_segment, segcount);
- return 1;
- }
+ if(only_segment && (segcount < only_segment)) {
+ fprintf(stderr, SELF ": can't show segment %d, only %d segments in file.\n", only_segment, segcount);
+ return 1;
+ }
- if(!segcount) {
- fprintf(stderr, SELF ": %s is not an Atari 8-bit executable.\n", filename);
- return 1;
+ if(!segcount) {
+ fprintf(stderr, SELF ": %s is not an Atari 8-bit executable.\n", filename);
+ return 1;
+ }
}
return 0;