comparison lwar/list.c @ 0:2c24602be78f

Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
author lost@l-w.ca
date Wed, 19 Jan 2011 22:27:17 -0700
parents
children 346966cffeef
comparison
equal deleted inserted replaced
-1:000000000000 0:2c24602be78f
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 <errno.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29
30 #include "lwar.h"
31
32 void do_list(void)
33 {
34 FILE *f;
35 char buf[8];
36 long l;
37 int c;
38
39 f = fopen(archive_file, "r");
40 if (!f)
41 {
42 perror("Opening archive file");
43 exit(1);
44 }
45
46 fread(buf, 1, 6, f);
47 if (memcmp("LWAR1V", buf, 6))
48 {
49 fprintf(stderr, "%s is not a valid archive file.\n", archive_file);
50 exit(1);
51 }
52
53 for (;;)
54 {
55 c = fgetc(f);
56 if (ferror(f))
57 {
58 perror("Reading archive file");
59 exit(1);
60 }
61 if (c == EOF)
62 return;
63
64
65 // find the end of the file name
66 if (!c)
67 return;
68
69 while (c)
70 {
71 putchar(c);
72 c = fgetc(f);
73 if (c == EOF || ferror(f))
74 {
75 fprintf(stderr, "Bad archive file\n");
76 exit(1);
77 }
78 }
79
80 // get length of archive member
81 l = 0;
82 c = fgetc(f);
83 l = c << 24;
84 c = fgetc(f);
85 l |= c << 16;
86 c = fgetc(f);
87 l |= c << 8;
88 c = fgetc(f);
89 l |= c;
90 printf(": %04lx bytes\n", l);
91 fseek(f, l, SEEK_CUR);
92 }
93 }