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