beta-0.89.2
[luatex.git] / source / libs / zziplib / zziplib-0.13.62 / bins / unzzipdir-mem.c
blobdc0207723097185ac6e27e34ae13ca5325a19fa7
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/memdisk.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_MEM_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_mem_disk_open (argv[1]);
54 if (! disk) {
55 perror(argv[1]);
56 return -1;
59 if (argc == 2)
60 { /* list all */
61 ZZIP_MEM_ENTRY* entry = zzip_mem_disk_findfirst(disk);
62 for (; entry ; entry = zzip_mem_disk_findnext(disk, entry))
64 char* name = zzip_mem_entry_to_name (entry);
65 printf ("%s\n", name);
67 return 0;
70 if (argc == 3)
71 { /* list from one spec */
72 ZZIP_MEM_ENTRY* entry = 0;
73 while ((entry = zzip_mem_disk_findmatch(disk, argv[2], entry, 0, 0)))
75 char* name = zzip_mem_entry_to_name (entry);
76 printf ("%s\n", name);
78 return 0;
81 { /* list only the matching entries - in order of zip directory */
82 ZZIP_MEM_ENTRY* entry = zzip_mem_disk_findfirst(disk);
83 for (; entry ; entry = zzip_mem_disk_findnext(disk, entry))
85 char* name = zzip_mem_entry_to_name (entry);
86 for (argn=1; argn < argc; argn++)
88 if (! fnmatch (argv[argn], name,
89 FNM_NOESCAPE|FNM_PATHNAME|FNM_PERIOD))
90 printf ("%s\n", name);
93 return 0;
97 /*
98 * Local variables:
99 * c-file-style: "stroustrup"
100 * End: