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