| 1 |
/* |
| 2 |
* Copyright (c) 2000,2001 Guido Draheim <[email protected]> |
| 3 |
* Use freely under the restrictions of the ZLIB license. |
| 4 |
* |
| 5 |
* Modified by Andreas Schiffler, 2001, for the zzipwrap feature |
| 6 |
* Modified by Guido Draheim in 2002 for the plugin_io feature |
| 7 |
*/ |
| 8 |
|
| 9 |
#include <stdio.h> |
| 10 |
#include <string.h> |
| 11 |
#include <stdlib.h> /* exit */ |
| 12 |
|
| 13 |
#include <zzip/zzip.h> |
| 14 |
/* #incl <zzip/wrap.h> */ |
| 15 |
#include "wrap.h" |
| 16 |
|
| 17 |
#ifndef O_BINARY |
| 18 |
#define O_BINARY 0 |
| 19 |
#endif |
| 20 |
|
| 21 |
static const char usage[] = |
| 22 |
{ |
| 23 |
"zzipwrap <dir>.. \n" |
| 24 |
" - prints a content table to stdout, but the dir can also be a zip-arch." |
| 25 |
"\n" |
| 26 |
" To show the contents of a zip-archive named 'test.zip', you may write \n" |
| 27 |
" zzipwrap test \n" |
| 28 |
}; |
| 29 |
|
| 30 |
/* This is a demo block callback routine that has access to the buffer */ |
| 31 |
/* that was just read BEFORE it is used by zziplib. */ |
| 32 |
static void demo_block_callback (void *buffer, int buffersize, void *data) |
| 33 |
{ |
| 34 |
fprintf (stderr, |
| 35 |
"demo_block_callback( buffer-pointer=%p" |
| 36 |
" buffer-size=%i data='%s' )\n", |
| 37 |
buffer,buffersize,(char*)data); |
| 38 |
} |
| 39 |
|
| 40 |
int |
| 41 |
main (int argc, char ** argv) |
| 42 |
{ |
| 43 |
zzip_plugin_io_t io; |
| 44 |
int argn; |
| 45 |
|
| 46 |
if (argc <= 1) |
| 47 |
{ |
| 48 |
printf (usage); |
| 49 |
exit(0); |
| 50 |
} |
| 51 |
|
| 52 |
/* Enable blocked (32 bytes) memory buffered IO routines with a */ |
| 53 |
/* demo callback routine. */ |
| 54 |
io = zzipwrap_use_memory_io(32, demo_block_callback, |
| 55 |
(void*) "Some callback data"); |
| 56 |
if (! io) |
| 57 |
{ |
| 58 |
fprintf(stderr, "could not initialize memory-io"); |
| 59 |
return 1; |
| 60 |
} |
| 61 |
|
| 62 |
for (argn=1; argn < argc; argn++) |
| 63 |
{ |
| 64 |
ZZIP_DIR * dir; |
| 65 |
ZZIP_DIRENT * d; |
| 66 |
|
| 67 |
dir = zzip_opendir_ext_io(argv[argn], 0, 0, io); |
| 68 |
if (! dir) |
| 69 |
{ |
| 70 |
fprintf (stderr, "did not open %s:", argv[argn]); |
| 71 |
perror(argv[argn]); |
| 72 |
continue; |
| 73 |
} |
| 74 |
|
| 75 |
if (argc > 2) printf ("%s:\n", argv[argn]); |
| 76 |
|
| 77 |
/* read each dir entry and show one line of info per file */ |
| 78 |
while ((d = zzip_readdir (dir))) |
| 79 |
{ |
| 80 |
/* orignalsize / compression-type / compression-ratio / filename */ |
| 81 |
if (d->st_size > 999999) |
| 82 |
{ |
| 83 |
printf ("%5dK %-9s %2d%% %s\n", |
| 84 |
d->st_size>>10, |
| 85 |
zzip_compr_str(d->d_compr), |
| 86 |
100 - (d->d_csize|1)/((d->st_size/100)|1), |
| 87 |
d->d_name); |
| 88 |
}else{ |
| 89 |
printf ("%6d %-9s %2d%% %s\n", |
| 90 |
d->st_size, |
| 91 |
zzip_compr_str(d->d_compr), |
| 92 |
100 - (d->d_csize|1)*100/(d->st_size|1), |
| 93 |
d->d_name); |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
zzip_closedir(dir); |
| 98 |
} |
| 99 |
|
| 100 |
return 0; |
| 101 |
} |
| 102 |
|