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 zzipfseeko api usage.
8 #include <zzip/fseeko.h>
12 #ifdef ZZIP_HAVE_FNMATCH_H
15 #define fnmatch(x,y,z) strcmp(x,y)
22 static const char usage
[] =
24 "unzzipcat-seeko <zip> [names].. \n"
25 " - unzzip data content of files contained in a zip archive.\n"
28 static void zzip_entry_fprint(ZZIP_ENTRY
* entry
, FILE* out
)
30 ZZIP_ENTRY_FILE
* file
= zzip_entry_fopen (entry
, 0);
33 char buffer
[1024]; int len
;
34 while ((len
= zzip_entry_fread (buffer
, 1024, 1, file
)))
35 fwrite (buffer
, len
, 1, out
);
37 zzip_entry_fclose (file
);
41 static void zzip_cat_file(FILE* disk
, char* name
, FILE* out
)
43 ZZIP_ENTRY_FILE
* file
= zzip_entry_ffile (disk
, name
);
46 char buffer
[1024]; int len
;
47 while ((len
= zzip_entry_fread (buffer
, 1024, 1, file
)))
48 fwrite (buffer
, len
, 1, out
);
50 zzip_entry_fclose (file
);
55 main (int argc
, char ** argv
)
60 if (argc
<= 1 || ! strcmp (argv
[1], "--help"))
65 if (! strcmp (argv
[1], "--version"))
67 printf (__FILE__
" version "ZZIP_PACKAGE
" "ZZIP_VERSION
"\n");
71 disk
= fopen (argv
[1], "r");
78 { /* print directory list */
79 ZZIP_ENTRY
* entry
= zzip_entry_findfirst(disk
);
80 if (! entry
) puts("no first entry!\n");
81 for (; entry
; entry
= zzip_entry_findnext(entry
))
83 char* name
= zzip_entry_strdup_name (entry
);
84 printf ("%s\n", name
);
91 { /* list from one spec */
92 ZZIP_ENTRY
* entry
= 0;
93 while ((entry
= zzip_entry_findmatch(disk
, argv
[2], entry
, 0, 0)))
94 zzip_entry_fprint (entry
, stdout
);
99 for (argn
=1; argn
< argc
; argn
++)
100 { /* list only the matching entries - each in order of commandline */
101 ZZIP_ENTRY
* entry
= zzip_entry_findfirst(disk
);
102 for (; entry
; entry
= zzip_entry_findnext(entry
))
104 char* name
= zzip_entry_strdup_name (entry
);
105 if (! fnmatch (argv
[argn
], name
,
106 FNM_NOESCAPE
|FNM_PATHNAME
|FNM_PERIOD
))
107 zzip_cat_file (disk
, name
, stdout
);
116 * c-file-style: "stroustrup"