Debian Codegraph @

libs/zziplib/zziplib-src/bins/unzzipdir-big.c

raw
1 /*
2 * Copyright (c) 2003 Guido Draheim <[email protected]>
3 * Use freely under the restrictions of the ZLIB license.
4 *
5 * This file is used as an example to clarify zzipfseeko api usage.
6 */
7
8 #define _ZZIP_ENTRY_STRUCT 1
9
10 #include <zzip/fseeko.h>
11 #include <zzip/fetch.h>
12 #include <zzip/__fnmatch.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include "unzzipdir-zip.h"
16 #include "unzzip-states.h"
17
18 static const char* comprlevel[] = {
19 "stored", "shrunk", "redu:1", "redu:2", "redu:3", "redu:4",
20 "impl:N", "toknze", "defl:N", "defl:B", "impl:B" };
21
22 static int exitcode(int e)
23 {
24 return EXIT_ERRORS;
25 }
26
27 static int
28 unzzip_list (int argc, char ** argv, int verbose)
29 {
30 int argn;
31 FILE* disk;
32
33 disk = fopen (argv[1], "rb");
34 if (! disk) {
35 perror(argv[1]);
36 return exitcode(errno);
37 }
38
39 if (argc == 2)
40 { /* print directory list */
41 ZZIP_ENTRY* entry = zzip_entry_findfirst(disk);
42 for (; entry ; entry = zzip_entry_findnext(entry))
43 {
44 char* name = zzip_entry_strdup_name (entry);
45 unsigned compr = zzip_entry_compr(entry);
46 const char* defl = (compr < sizeof(comprlevel)) ? comprlevel[compr] : "(redu)";
47 printf (" %s %s\n", defl, name);
48 free (name);
49 }
50 return 0;
51 }
52
53 for (argn=1; argn < argc; argn++)
54 { /* list only the matching entries - each in order of commandline */
55 ZZIP_ENTRY* entry = zzip_entry_findfirst(disk);
56 for (; entry ; entry = zzip_entry_findnext(entry))
57 {
58 char* name = zzip_entry_strdup_name (entry);
59 unsigned compr = zzip_entry_compr(entry);
60 const char* defl = (compr < sizeof(comprlevel)) ? comprlevel[compr] : "(redu)";
61 printf (" %s %s\n", defl, name);
62 free (name);
63 }
64 }
65 return 0;
66 }
67
68 int
69 unzzip_long_list (int argc, char ** argv)
70 {
71 return unzzip_list(argc, argv, 1);
72 }
73
74 int
75 unzzip_show_list (int argc, char ** argv)
76 {
77 return unzzip_list(argc, argv, 0);
78 }
79
80 /*
81 * Local variables:
82 * c-file-style: "stroustrup"
83 * End:
84 */