| 1 |
/* |
| 2 |
* Copyright (c) 2000,2001,2002 Guido Draheim <[email protected]> |
| 3 |
* Use freely under the restrictions of the ZLIB license. |
| 4 |
*/ |
| 5 |
|
| 6 |
#include <zzip/zzip.h> |
| 7 |
#include <stdio.h> |
| 8 |
#include <string.h> |
| 9 |
|
| 10 |
static const char usage[] = |
| 11 |
{ |
| 12 |
"zzdir <dir>.. \n" |
| 13 |
" - prints a content table to stdout, but the dir can also be a zip-arch." |
| 14 |
"\n" |
| 15 |
" To show the contents of a zip-archive named 'test.zip', you may write \n" |
| 16 |
" zzdir test \n" |
| 17 |
}; |
| 18 |
|
| 19 |
int |
| 20 |
main (int argc, char ** argv) |
| 21 |
{ |
| 22 |
int argn; |
| 23 |
int exitcode = 0; |
| 24 |
|
| 25 |
if (argc <= 1 || ! strcmp (argv[1], "--help")) |
| 26 |
{ |
| 27 |
printf (usage); |
| 28 |
return 0; |
| 29 |
} |
| 30 |
if (! strcmp (argv[1], "--version")) |
| 31 |
{ |
| 32 |
printf (__FILE__ " version " ZZIP_PACKAGE_NAME " " ZZIP_PACKAGE_VERSION "\n"); |
| 33 |
return 0; |
| 34 |
} |
| 35 |
|
| 36 |
for (argn=1; argn < argc; argn++) |
| 37 |
{ |
| 38 |
ZZIP_DIR * dir; |
| 39 |
ZZIP_DIRENT * d; |
| 40 |
|
| 41 |
dir = zzip_opendir(argv[argn]); |
| 42 |
if (! dir) |
| 43 |
{ |
| 44 |
fprintf (stderr, "did not open %s: ", argv[argn]); |
| 45 |
perror(argv[argn]); |
| 46 |
exitcode++; |
| 47 |
continue; |
| 48 |
} |
| 49 |
|
| 50 |
if (argc > 2) printf ("%s: \n", argv[argn]); |
| 51 |
|
| 52 |
/* read each dir entry and show one line of info per file */ |
| 53 |
while ((d = zzip_readdir (dir))) |
| 54 |
{ |
| 55 |
/* orignalsize / compression-type / compression-ratio / filename */ |
| 56 |
if (d->st_size > 999999) |
| 57 |
{ |
| 58 |
printf ("%5dK %-9s %2d%% %s\n", |
| 59 |
d->st_size>>10, |
| 60 |
zzip_compr_str(d->d_compr), |
| 61 |
100 - (d->d_csize|1)/((d->st_size/100)|1), |
| 62 |
d->d_name); |
| 63 |
}else{ |
| 64 |
printf ("%6d %-9s %2d%% %s\n", |
| 65 |
d->st_size, |
| 66 |
zzip_compr_str(d->d_compr), |
| 67 |
100 - (d->d_csize|1)*100/(d->st_size|1), |
| 68 |
d->d_name); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
zzip_closedir(dir); |
| 73 |
} |
| 74 |
|
| 75 |
return exitcode; |
| 76 |
} |
| 77 |
|
| 78 |
/* |
| 79 |
* Local variables: |
| 80 |
* c-file-style: "stroustrup" |
| 81 |
* End: |
| 82 |
*/ |