1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
/*
* Copyright (c) 2000,2001,2002 Guido Draheim <guidod@gmx.de>
* Use freely under the restrictions of the ZLIB License
*/
#include <zzip/zzip.h>
#include <stdio.h>
#include <string.h>
#ifndef O_BINARY
#define O_BINARY 0
#endif
static const char usage[] =
{
" zzcat <file>... \n"
" - prints the file to stdout, so you may want to redirect the output; \n"
" the file can be a normal file or an inflated part of a zip-archive, \n"
" to get 'README' from dist.zip you may write \n"
" zzcat dist/README \n"
};
int
main (int argc, char ** argv)
{
int argn;
if (argc <= 1 || ! strcmp (argv[1], "--help"))
{
printf (usage);
return 0;
}
if (! strcmp (argv[1], "--version"))
{
printf (__FILE__" version "ZZIP_PACKAGE" "ZZIP_VERSION"\n");
return 0;
}
for (argn=1; argn < argc; argn++)
{
ZZIP_FILE* fp = zzip_open (argv[argn], O_RDONLY|O_BINARY);
if (! fp)
{
perror (argv[argn]);
continue;
}else{
char buf[17];
int n;
/* read chunks of 16 bytes into buf and print them to stdout */
while (0 < (n = zzip_read(fp, buf, 16)))
{
buf[n] = '\0';
# ifdef STDOUT_FILENO
write (STDOUT_FILENO, buf, n);
# else
fwrite (buf, 1, n, stdout);
# endif
}
if (n == -1)
perror (argv[argn]);
}
}
return 0;
}
/*
* Local variables:
* c-file-style: "stroustrup"
* End:
*/
|