~ubuntu-branches/ubuntu/jaunty/luatex/jaunty

« back to all changes in this revision

Viewing changes to src/libs/zziplib/bins/unzzipdir.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Preining
  • Date: 2007-09-24 12:56:11 UTC
  • Revision ID: james.westby@ubuntu.com-20070924125611-a8ge689azbptxvla
Tags: upstream-0.11.2
ImportĀ upstreamĀ versionĀ 0.11.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *      Copyright (c) 2003 Guido Draheim <guidod@gmx.de>
 
3
 *      Use freely under the restrictions of the ZLIB license.
 
4
 *
 
5
 *      This file is used as an example to clarify zzipmmap api usage.
 
6
 */
 
7
 
 
8
#include <zzip/mmapped.h>
 
9
#include <stdio.h>
 
10
#include <stdlib.h>
 
11
#include <string.h>
 
12
 
 
13
#ifdef ZZIP_HAVE_UNISTD_H
 
14
#include <unistd.h>
 
15
#endif
 
16
#ifdef ZZIP_HAVE_IO_H
 
17
#include <io.h>
 
18
#endif
 
19
 
 
20
#ifdef ZZIP_HAVE_FNMATCH_H
 
21
#include <fnmatch.h>
 
22
#else
 
23
#define fnmatch(x,y,z) strcmp(x,y)
 
24
#endif
 
25
 
 
26
#ifndef O_BINARY
 
27
#define O_BINARY 0
 
28
#endif
 
29
 
 
30
static const char usage[] = 
 
31
{
 
32
    "unzzipdir <zip> [names].. \n"
 
33
    "  - unzzip a listing of files contained in a zip archive.\n"
 
34
};
 
35
 
 
36
int 
 
37
main (int argc, char ** argv)
 
38
{
 
39
    int argn;
 
40
    ZZIP_DISK* disk;
 
41
 
 
42
    if (argc <= 1 || ! strcmp (argv[1], "--help"))
 
43
    {
 
44
        printf (usage);
 
45
        return 0;
 
46
    }
 
47
    if (! strcmp (argv[1], "--version"))
 
48
    {
 
49
        printf (__FILE__" version "ZZIP_PACKAGE" "ZZIP_VERSION"\n");
 
50
        return 0;
 
51
    }
 
52
 
 
53
    disk = zzip_disk_open (argv[1]);
 
54
    if (! disk) {
 
55
        perror(argv[1]);
 
56
        return -1;
 
57
    }
 
58
 
 
59
    if (argc == 2)
 
60
    {  /* list all */
 
61
        ZZIP_DISK_ENTRY* entry = zzip_disk_findfirst(disk);
 
62
        for (; entry ; entry = zzip_disk_findnext(disk, entry))
 
63
        {
 
64
            char* name = zzip_disk_entry_strdup_name (disk, entry);
 
65
            printf ("%s\n", name);
 
66
            free (name);
 
67
        }
 
68
        return 0;
 
69
    }
 
70
 
 
71
    if (argc == 3)
 
72
    {  /* list from one spec */
 
73
        ZZIP_DISK_ENTRY* entry = 0;
 
74
        while ((entry = zzip_disk_findmatch(disk, argv[2], entry, 0, 0)))
 
75
        {
 
76
            char* name = zzip_disk_entry_strdup_name (disk, entry);
 
77
            printf ("%s\n", name);
 
78
            free (name);
 
79
        }
 
80
        return 0;
 
81
    }
 
82
 
 
83
    {   /* list only the matching entries - in order of zip directory */
 
84
        ZZIP_DISK_ENTRY* entry = zzip_disk_findfirst(disk);
 
85
        for (; entry ; entry = zzip_disk_findnext(disk, entry))
 
86
        {
 
87
            char* name = zzip_disk_entry_strdup_name (disk, entry);
 
88
            for (argn=1; argn < argc; argn++)
 
89
            {
 
90
                if (! fnmatch (argv[argn], name, 
 
91
                               FNM_NOESCAPE|FNM_PATHNAME|FNM_PERIOD))
 
92
                    printf ("%s\n", name);
 
93
            }
 
94
            free (name);
 
95
        }
 
96
        return 0;
 
97
    }
 
98
 
99
 
 
100
/* 
 
101
 * Local variables:
 
102
 * c-file-style: "stroustrup"
 
103
 * End:
 
104
 */