339
|
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 #include <config.h>
|
|
26
|
|
27 #include <errno.h>
|
|
28 #include <stdio.h>
|
|
29 #include <stdlib.h>
|
|
30 #include <string.h>
|
|
31
|
|
32 #include "lwar.h"
|
|
33
|
|
34 void do_list(void)
|
|
35 {
|
|
36 FILE *f;
|
|
37 char buf[8];
|
|
38 long l;
|
|
39 int c;
|
|
40
|
|
41 f = fopen(archive_file, "r");
|
|
42 if (!f)
|
|
43 {
|
|
44 perror("Opening archive file");
|
|
45 exit(1);
|
|
46 }
|
|
47
|
|
48 fread(buf, 1, 6, f);
|
|
49 if (memcmp("LWAR1V", buf, 6))
|
|
50 {
|
|
51 fprintf(stderr, "%s is not a valid archive file.\n", archive_file);
|
|
52 exit(1);
|
|
53 }
|
|
54
|
|
55 for (;;)
|
|
56 {
|
|
57 c = fgetc(f);
|
|
58 if (ferror(f))
|
|
59 {
|
|
60 perror("Reading archive file");
|
|
61 exit(1);
|
|
62 }
|
|
63 if (c == EOF)
|
|
64 return;
|
|
65
|
|
66
|
|
67 // find the end of the file name
|
|
68 if (!c)
|
|
69 return;
|
|
70
|
|
71 while (c)
|
|
72 {
|
|
73 putchar(c);
|
|
74 c = fgetc(f);
|
|
75 if (c == EOF || ferror(f))
|
|
76 {
|
|
77 fprintf(stderr, "Bad archive file\n");
|
|
78 exit(1);
|
|
79 }
|
|
80 }
|
|
81
|
|
82 // get length of archive member
|
|
83 l = 0;
|
|
84 c = fgetc(f);
|
|
85 l = c << 24;
|
|
86 c = fgetc(f);
|
|
87 l |= c << 16;
|
|
88 c = fgetc(f);
|
|
89 l |= c << 8;
|
|
90 c = fgetc(f);
|
|
91 l |= c;
|
|
92 printf(": %04lx bytes\n", l);
|
|
93 fseek(f, l, SEEK_CUR);
|
|
94 }
|
|
95 }
|