beta-0.89.2
[luatex.git] / source / libs / zziplib / zziplib-0.13.62 / bins / unzzipdir.c
blob3c570c5548f835165e884cf3943cadb3ce1daf77
1 /*
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 zzipmmap api usage.
6 */
8 #include <zzip/mmapped.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
13 #ifdef ZZIP_HAVE_UNISTD_H
14 #include <unistd.h>
15 #endif
16 #ifdef ZZIP_HAVE_IO_H
17 #include <io.h>
18 #endif
20 #ifdef ZZIP_HAVE_FNMATCH_H
21 #include <fnmatch.h>
22 #else
23 #define fnmatch(x,y,z) strcmp(x,y)
24 #endif
26 #ifndef O_BINARY
27 #define O_BINARY 0
28 #endif
30 static const char usage[] =
32 "unzzipdir <zip> [names].. \n"
33 " - unzzip a listing of files contained in a zip archive.\n"
36 int
37 main (int argc, char ** argv)
39 int argn;
40 ZZIP_DISK* disk;
42 if (argc <= 1 || ! strcmp (argv[1], "--help"))
44 printf (usage);
45 return 0;
47 if (! strcmp (argv[1], "--version"))
49 printf (__FILE__" version "ZZIP_PACKAGE" "ZZIP_VERSION"\n");
50 return 0;
53 disk = zzip_disk_open (argv[1]);
54 if (! disk) {
55 perror(argv[1]);
56 return -1;
59 if (argc == 2)
60 { /* list all */
61 ZZIP_DISK_ENTRY* entry = zzip_disk_findfirst(disk);
62 for (; entry ; entry = zzip_disk_findnext(disk, entry))
64 char* name = zzip_disk_entry_strdup_name (disk, entry);
65 printf ("%s\n", name);
66 free (name);
68 return 0;
71 if (argc == 3)
72 { /* list from one spec */
73 ZZIP_DISK_ENTRY* entry = 0;
74 while ((entry = zzip_disk_findmatch(disk, argv[2], entry, 0, 0)))
76 char* name = zzip_disk_entry_strdup_name (disk, entry);
77 printf ("%s\n", name);
78 free (name);
80 return 0;
83 { /* list only the matching entries - in order of zip directory */
84 ZZIP_DISK_ENTRY* entry = zzip_disk_findfirst(disk);
85 for (; entry ; entry = zzip_disk_findnext(disk, entry))
87 char* name = zzip_disk_entry_strdup_name (disk, entry);
88 for (argn=1; argn < argc; argn++)
90 if (! fnmatch (argv[argn], name,
91 FNM_NOESCAPE|FNM_PATHNAME|FNM_PERIOD))
92 printf ("%s\n", name);
94 free (name);
96 return 0;
101 * Local variables:
102 * c-file-style: "stroustrup"
103 * End: