annotate lwar/list.c @ 448:5cccf90bf838 3.0 tip

Fixed bug with complex external references generating invalid relocations in the object file
author lost@l-w.ca
date Fri, 05 Nov 2010 22:27:00 -0600
parents 1c31e9005ff7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1 /*
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
2 list.c
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
3 Copyright © 2009 William Astle
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
4
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
5 This file is part of LWAR.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
6
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
7 LWAR is free software: you can redistribute it and/or modify it under the
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
8 terms of the GNU General Public License as published by the Free Software
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
9 Foundation, either version 3 of the License, or (at your option) any later
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
10 version.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
11
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
12 This program is distributed in the hope that it will be useful, but WITHOUT
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
15 more details.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
16
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
17 You should have received a copy of the GNU General Public License along with
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
18 this program. If not, see <http://www.gnu.org/licenses/>.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
19
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
20
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
21 Implements the program startup code
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
22
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
23 */
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
24
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
25 #include <config.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
26
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
27 #include <errno.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
28 #include <stdio.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
29 #include <stdlib.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
30 #include <string.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
31
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
32 #include "lwar.h"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
33
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
34 void do_list(void)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
35 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
36 FILE *f;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
37 char buf[8];
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
38 long l;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
39 int c;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
40
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
41 f = fopen(archive_file, "r");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
42 if (!f)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
43 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
44 perror("Opening archive file");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
45 exit(1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
46 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
47
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
48 fread(buf, 1, 6, f);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
49 if (memcmp("LWAR1V", buf, 6))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
50 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
51 fprintf(stderr, "%s is not a valid archive file.\n", archive_file);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
52 exit(1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
53 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
54
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
55 for (;;)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
56 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
57 c = fgetc(f);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
58 if (ferror(f))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
59 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
60 perror("Reading archive file");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
61 exit(1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
62 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
63 if (c == EOF)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
64 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
65
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
66
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
67 // find the end of the file name
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
68 if (!c)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
69 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
70
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
71 while (c)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
72 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
73 putchar(c);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
74 c = fgetc(f);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
75 if (c == EOF || ferror(f))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
76 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
77 fprintf(stderr, "Bad archive file\n");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
78 exit(1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
79 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
80 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
81
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
82 // get length of archive member
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
83 l = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
84 c = fgetc(f);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
85 l = c << 24;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
86 c = fgetc(f);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
87 l |= c << 16;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
88 c = fgetc(f);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
89 l |= c << 8;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
90 c = fgetc(f);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
91 l |= c;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
92 printf(": %04lx bytes\n", l);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
93 fseek(f, l, SEEK_CUR);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
94 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
95 }