2 * Copyright (c) 2003 Guido Draheim <guidod@gmx.de>
3 * Use freely under the restrictions of the ZLIB license.
5 * This file is used as an example to clarify zzip api usage.
12 #include "unzzipdir-zip.h"
14 #ifdef ZZIP_HAVE_UNISTD_H
21 #ifdef ZZIP_HAVE_FNMATCH_H
24 #define fnmatch(x,y,z) strcmp(x,y)
27 static const char* comprlevel[] = {
28 "stored", "shrunk", "redu:1", "redu:2", "redu:3", "redu:4",
29 "impl:N", "toknze", "defl:N", "defl:B", "impl:B" };
33 unzzip_list (int argc, char ** argv, int verbose)
41 printf (__FILE__" version "ZZIP_PACKAGE" "ZZIP_VERSION"\n");
42 return -1; /* better provide an archive argument */
45 disk = zzip_dir_open (argv[1], &error);
54 while(zzip_dir_read(disk, &entry))
56 char* name = entry.d_name;
57 long long usize = entry.st_size;
60 printf ("%22lli %s\n", usize, name);
63 long long csize = entry.d_csize;
64 unsigned compr = entry.d_compr;
65 const char* defl = (compr < sizeof(comprlevel)) ? comprlevel[compr] : "(redu)";
66 printf ("%lli/%lli %s %s\n", usize, csize, defl, name);
71 { /* list only the matching entries - in order of zip directory */
73 while(zzip_dir_read(disk, &entry))
75 char* name = entry.d_name;
76 for (argn=1; argn < argc; argn++)
78 if (! fnmatch (argv[argn], name,
79 FNM_NOESCAPE|FNM_PATHNAME|FNM_PERIOD))
81 long long usize = entry.st_size;
84 printf ("%22lli %s\n", usize, name);
87 long long csize = entry.d_csize;
88 unsigned compr = entry.d_compr;
89 const char* defl = (compr < sizeof(comprlevel)) ? comprlevel[compr] : "(redu)";
90 printf ("%lli/%lli %s %s\n", usize, csize, defl, name);
92 break; /* match loop */
102 unzzip_long_list (int argc, char ** argv)
104 return unzzip_list(argc, argv, 1);
108 unzzip_show_list (int argc, char ** argv)
110 return unzzip_list(argc, argv, 0);
115 * c-file-style: "stroustrup"