annotate lwar/list.c @ 232:1009f302ac11

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