~ubuntu-branches/ubuntu/wily/luatex/wily

« back to all changes in this revision

Viewing changes to source/libs/zziplib/zziplib-0.13.58/bins/zziptest.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Preining
  • Date: 2010-04-29 00:47:19 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20100429004719-o42etkqe90n97b9e
Tags: 0.60.1-1
* new upstream release, adapt build-script patch
* disable patch: upstream-epstopdf_cc_no_xpdf_patching, included upstream
* disable patch: libpoppler-0.12, not needed anymore

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Author:
 
3
 *      Guido Draheim <guidod@gmx.de>
 
4
 *      Tomi Ollila <Tomi.Ollila@iki.fi>
 
5
 *
 
6
 *      Copyright (c) 1999,2000,2001,2002,2003 Guido Draheim
 
7
 *          All rights reserved,
 
8
 *          use under the restrictions of the
 
9
 *          Lesser GNU General Public License
 
10
 *          or alternatively the restrictions
 
11
 *          of the Mozilla Public License 1.1
 
12
 */
 
13
 
 
14
#include <stdio.h>
 
15
#include <string.h>
 
16
 
 
17
#include <zzip/lib.h>
 
18
 
 
19
#if defined ZZIP_HAVE_WINDOWS_H
 
20
#define WIN32_LEAN_AND_MEAN
 
21
#include <windows.h>
 
22
#define sleep Sleep
 
23
#endif
 
24
 
 
25
#ifdef ZZIP_HAVE_UNISTD_H
 
26
#include <unistd.h> /* sleep */
 
27
#endif
 
28
 
 
29
#ifndef O_BINARY
 
30
#define O_BINARY 0
 
31
#endif
 
32
 
 
33
#if __GNUC__+0 >= 3 && __GNUC_MINOR__+0 >= 3
 
34
# ifdef DEBUG
 
35
# warning suppress a warning where the compiler should have optimized instead.
 
36
# endif
 
37
#define I_(_T,_L,_R) do { _T _l = (_T) _L; \
 
38
                          _l _R; _L = (typeof(_L)) _l; } while(0)
 
39
#else
 
40
#define I_(_T,_L,_R) _L _R
 
41
#endif
 
42
 
 
43
int main(int argc, char ** argv)
 
44
{
 
45
    ZZIP_DIR * dir;
 
46
    const char * name = "test.zip";
 
47
    zzip_error_t rv;
 
48
    int i;
 
49
 
 
50
    if (argc > 1 && argv[1] != NULL)
 
51
    {
 
52
        if (! strcmp (argv[1], "--help")) {
 
53
            printf ("zziptest [testfile]\n - selftest defaults to 'test.zip'");
 
54
            return 0;
 
55
        }else if (! strcmp (argv[1], "--version")) {
 
56
            printf (__FILE__" version "ZZIP_PACKAGE" "ZZIP_VERSION"\n");
 
57
            return 0;
 
58
        }else{
 
59
            name = argv[1];
 
60
            argv++; argc--;
 
61
        }
 
62
    }
 
63
 
 
64
    printf("Opening zip file `%s'... ", name);
 
65
    {   int fd = open (name, O_RDONLY|O_BINARY);
 
66
        if (fd == -1) { perror ("could not open input file"); return 0; }
 
67
        if (! (dir = zzip_dir_fdopen(fd, &rv)))
 
68
        {
 
69
            printf("error %d.\n", rv);
 
70
            return 0;
 
71
        }
 
72
    } printf("OK.\n");
 
73
 
 
74
#if 1
 
75
    printf("{check...\n");
 
76
    { struct zzip_dir_hdr * hdr = dir->hdr0;
 
77
 
 
78
        if (hdr == NULL)
 
79
          { printf ("could not find first header in dir_hdr"); }
 
80
        else
 
81
        {
 
82
            while (1)
 
83
            {
 
84
                printf("\ncompression method: %d", hdr->d_compr);
 
85
                if (hdr->d_compr == 0) printf(" (stored)");
 
86
                else if (hdr->d_compr == 8) printf(" (deflated)");
 
87
                else printf(" (unknown)");
 
88
                printf("\ncrc32: %x\n", hdr->d_crc32);
 
89
                printf("compressed size: %d\n", hdr->d_csize);
 
90
                printf("uncompressed size: %d\n", hdr->d_usize);
 
91
                printf("offset of file in archive: %d\n", hdr->d_off);
 
92
                printf("filename: %s\n\n", hdr->d_name);
 
93
 
 
94
                if (hdr->d_reclen == 0) break;
 
95
                I_(char *, hdr, += hdr->d_reclen);
 
96
                sleep(1);
 
97
            }
 
98
        }
 
99
    } printf ("\n}\n");
 
100
#endif
 
101
#if 1
 
102
    {   printf("{contents...\n");
 
103
        for (i = 0; i < 2; i++)
 
104
        {
 
105
            ZZIP_DIRENT* d;
 
106
 
 
107
            while((d=zzip_readdir(dir)))
 
108
            {
 
109
                printf(" name \"%s\", compr %d, size %d, ratio %2d\n",
 
110
                    d->d_name, d->d_compr, d->st_size,
 
111
                    100 - (d->d_csize|1)*100/(d->st_size|1));
 
112
            }
 
113
            printf(" %d. time ---------------\n", i + 1);
 
114
            zzip_rewinddir(dir);
 
115
        }
 
116
        printf("}...OK\n");
 
117
    }
 
118
#endif
 
119
 
 
120
    {   ZZIP_FILE * fp;
 
121
        char buf[17];
 
122
        const char * name = argv[1]? argv[1]: "README";
 
123
 
 
124
 
 
125
        printf("Opening file `%s' in zip archive... ", name);
 
126
        fp = zzip_file_open(dir, (char *)name, ZZIP_CASEINSENSITIVE);
 
127
 
 
128
        if (! fp)
 
129
          { printf("error %d: %s\n", zzip_error(dir), zzip_strerror_of(dir)); }
 
130
        else
 
131
        {
 
132
            printf("OK.\n");
 
133
            printf("Contents of the file:\n");
 
134
 
 
135
            while (0 < (i = zzip_file_read(fp, buf, 16)))
 
136
            {
 
137
                buf[i] = '\0';
 
138
                /*printf("\n*** read %d ***\n", i); fflush(stdout); */
 
139
                printf("%s", buf);
 
140
                /*write(1, buf, i);*/ /* Windows does not have write !!! */
 
141
            }
 
142
            if (i < 0) printf("error %d\n", zzip_error(dir));
 
143
        }
 
144
    }
 
145
 
 
146
    return 0;
 
147
}
 
148
 
 
149
/*
 
150
 * Local variables:
 
151
 * c-file-style: "stroustrup"
 
152
 * End:
 
153
 */