beta-0.89.2
[luatex.git] / source / libs / zziplib / zziplib-0.13.62 / zzipwrap / zzipwrap.c
blob447ce23f5b443f2a9ef83178e9f4c6cf454092e0
1 /*
2 * Copyright (c) 2000,2001 Guido Draheim <guidod@gmx.de>
3 * Use freely under the restrictions of the ZLIB license.
5 * Modified by Andreas Schiffler, 2001, for the zzipwrap feature
6 * Modified by Guido Draheim in 2002 for the plugin_io feature
7 */
9 #include <stdio.h>
10 #include <string.h>
11 #include <stdlib.h> /* exit */
13 #include <zzip/zzip.h>
14 /* #incl <zzip/wrap.h> */
15 #include "wrap.h"
17 #ifndef O_BINARY
18 #define O_BINARY 0
19 #endif
21 static const char usage[] =
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"
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)
34 fprintf (stderr,
35 "demo_block_callback( buffer-pointer=%p"
36 " buffer-size=%i data='%s' )\n",
37 buffer,buffersize,(char*)data);
40 int
41 main (int argc, char ** argv)
43 zzip_plugin_io_t io;
44 int argn;
46 if (argc <= 1)
48 printf (usage);
49 exit(0);
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)
58 fprintf(stderr, "could not initialize memory-io");
59 return 1;
62 for (argn=1; argn < argc; argn++)
64 ZZIP_DIR * dir;
65 ZZIP_DIRENT * d;
67 dir = zzip_opendir_ext_io(argv[argn], 0, 0, io);
68 if (! dir)
70 fprintf (stderr, "did not open %s:", argv[argn]);
71 perror(argv[argn]);
72 continue;
75 if (argc > 2) printf ("%s:\n", argv[argn]);
77 /* read each dir entry and show one line of info per file */
78 while ((d = zzip_readdir (dir)))
80 /* orignalsize / compression-type / compression-ratio / filename */
81 if (d->st_size > 999999)
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);
97 zzip_closedir(dir);
100 return 0;