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.
9 #include <zzip/__fnmatch.h>
13 #include "unzzipdir-zip.h"
14 #include "unzzip-states.h"
16 #ifdef ZZIP_HAVE_UNISTD_H
23 static const char* comprlevel[] = {
24 "stored", "shrunk", "redu:1", "redu:2", "redu:3", "redu:4",
25 "impl:N", "toknze", "defl:N", "defl:B", "impl:B" };
27 static int exitcode(int e)
33 case ZZIP_OUTOFMEM: /* out of memory */
35 case ZZIP_DIR_OPEN: /* failed to open zipfile, see errno for details */
36 return EXIT_ZIP_NOT_FOUND;
37 case ZZIP_DIR_STAT: /* failed to fstat zipfile, see errno for details */
38 case ZZIP_DIR_SEEK: /* failed to lseek zipfile, see errno for details */
39 case ZZIP_DIR_READ: /* failed to read zipfile, see errno for details */
40 case ZZIP_DIR_TOO_SHORT:
41 case ZZIP_DIR_EDH_MISSING:
42 return EXIT_FILEFORMAT;
44 return EXIT_EARLY_END_OF_FILE;
46 return EXIT_FILE_NOT_FOUND;
47 case ZZIP_UNSUPP_COMPR:
48 return EXIT_UNSUPPORTED_COMPRESSION;
51 case ZZIP_DIR_LARGEFILE:
52 return EXIT_FILEFORMAT;
58 unzzip_list (int argc, char ** argv, int verbose)
66 printf (__FILE__ " version " ZZIP_PACKAGE_NAME " " ZZIP_PACKAGE_VERSION "\n");
67 return EXIT_OK; /* better provide an archive argument */
70 disk = zzip_dir_open (argv[1], &error);
73 return exitcode(error);
79 while(zzip_dir_read(disk, &entry))
81 char* name = entry.d_name;
82 long long usize = entry.st_size;
85 printf ("%22lli %s\n", usize, name);
88 long long csize = entry.d_csize;
89 unsigned compr = entry.d_compr;
90 const char* defl = (compr < sizeof(comprlevel)) ? comprlevel[compr] : "(redu)";
91 printf ("%lli/%lli %s %s\n", usize, csize, defl, name);
96 { /* list only the matching entries - in order of zip directory */
98 while(zzip_dir_read(disk, &entry))
100 char* name = entry.d_name;
101 for (argn=1; argn < argc; argn++)
103 if (! _zzip_fnmatch (argv[argn], name,
104 _zzip_FNM_NOESCAPE|_zzip_FNM_PATHNAME|_zzip_FNM_PERIOD))
106 long long usize = entry.st_size;
109 printf ("%22lli %s\n", usize, name);
112 long long csize = entry.d_csize;
113 unsigned compr = entry.d_compr;
114 const char* defl = (compr < sizeof(comprlevel)) ? comprlevel[compr] : "(redu)";
115 printf ("%lli/%lli %s %s\n", usize, csize, defl, name);
117 break; /* match loop */
122 zzip_dir_close(disk);
127 unzzip_long_list (int argc, char ** argv)
129 return unzzip_list(argc, argv, 1);
133 unzzip_show_list (int argc, char ** argv)
135 return unzzip_list(argc, argv, 0);
140 * c-file-style: "stroustrup"