File: zzcat.c

package info (click to toggle)
texlive-bin 2009-8
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 231,976 kB
  • ctags: 165,663
  • sloc: ansic: 1,113,212; cpp: 454,597; sh: 49,189; perl: 43,889; makefile: 15,564; python: 11,825; xml: 7,446; lisp: 6,494; asm: 4,361; lex: 3,571; java: 3,569; pascal: 2,487; yacc: 2,451; exp: 2,031; ruby: 2,012; ada: 1,681; objc: 1,362; cs: 879; sed: 519; csh: 47; tcl: 45; awk: 35
file content (74 lines) | stat: -rw-r--r-- 1,589 bytes parent folder | download | duplicates (13)
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:
 */