beta-0.89.2
[luatex.git] / source / libs / zziplib / zziplib-0.13.62 / bins / zzdir.c
blob5345f0852da1343c83e38d2edcbfc5be2ed2c18d
1 /*
2 * Copyright (c) 2000,2001,2002 Guido Draheim <guidod@gmx.de>
3 * Use freely under the restrictions of the ZLIB license.
4 */
6 #include <zzip/zzip.h>
7 #include <stdio.h>
8 #include <string.h>
10 #ifndef O_BINARY
11 #define O_BINARY 0
12 #endif
14 static const char usage[] =
16 "zzdir <dir>.. \n"
17 " - prints a content table to stdout, but the dir can also be a zip-arch."
18 "\n"
19 " To show the contents of a zip-archive named 'test.zip', you may write \n"
20 " zzdir test \n"
23 int
24 main (int argc, char ** argv)
26 int argn;
27 int exitcode = 0;
29 if (argc <= 1 || ! strcmp (argv[1], "--help"))
31 printf (usage);
32 return 0;
34 if (! strcmp (argv[1], "--version"))
36 printf (__FILE__" version "ZZIP_PACKAGE" "ZZIP_VERSION"\n");
37 return 0;
40 for (argn=1; argn < argc; argn++)
42 ZZIP_DIR * dir;
43 ZZIP_DIRENT * d;
45 dir = zzip_opendir(argv[argn]);
46 if (! dir)
48 fprintf (stderr, "did not open %s: ", argv[argn]);
49 perror(argv[argn]);
50 exitcode++;
51 continue;
54 if (argc > 2) printf ("%s: \n", argv[argn]);
56 /* read each dir entry and show one line of info per file */
57 while ((d = zzip_readdir (dir)))
59 /* orignalsize / compression-type / compression-ratio / filename */
60 if (d->st_size > 999999)
62 printf ("%5dK %-9s %2d%% %s \n",
63 d->st_size>>10,
64 zzip_compr_str(d->d_compr),
65 100 - (d->d_csize|1)/((d->st_size/100)|1),
66 d->d_name);
67 }else{
68 printf ("%6d %-9s %2d%% %s \n",
69 d->st_size,
70 zzip_compr_str(d->d_compr),
71 100 - (d->d_csize|1)*100/(d->st_size|1),
72 d->d_name);
76 zzip_closedir(dir);
79 return exitcode;
82 /*
83 * Local variables:
84 * c-file-style: "stroustrup"
85 * End: