summaryrefslogtreecommitdiff
path: root/Build/source/libs/zziplib/zziplib-src/bins/unzzip.c
blob: f91c5ebad8634f1ed7a941502c9d390d95d20b07 (plain)
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
75
76
77
78
79
80
81
/*
 *	Copyright (c) 2003 Guido Draheim <guidod@gmx.de>
 *      Use freely under the restrictions of the ZLIB license.
 *
 *      This file is used as an example to clarify zzip api usage.
 */

#include <zzip/zzip.h>
#include <stdio.h>
#include <string.h>
#include "unzzipcat-zip.h"
#include "unzzipdir-zip.h"
#include "unzzip-states.h"

static const char usage[] = 
{
    "unzzip <dir>.. \n"
    "  - unzzip the files contained in a zip archive.\n"
    "  -p            print content of files to pipe\n"
    "  -l            list names in archive (short format)\n"
};

static int unzzip_version(void)
{
    printf (__FILE__" version "ZZIP_PACKAGE" "ZZIP_VERSION"\n");
    return 0;
}

static int unzzip_help(void)
{
    printf (usage);
    return 0;
}

int 
main (int argc, char ** argv)
{
    int argn;
    int exitcode = 0;
    zzip_error_t error;

    if (argc <= 1 || ! strcmp (argv[1], "--help"))
    {
        return unzzip_help();
    }
    if (! strcmp (argv[1], "--version"))
    {
        return unzzip_version();
    }
    if (! strcmp (argv[1], "-l") || ! strcmp(argv[1], "--list"))
    {
        argc -= 1; argv += 1;
        return unzzip_show_list(argc, argv);
    }
    if (! strcmp (argv[1], "-v") || ! strcmp(argv[1], "--versions"))
    {
        if (argc == 2)
            return unzzip_version(); /* compatible with info-zip */
        argc -= 1; argv += 1;
        return unzzip_long_list(argc, argv);
    }
    if (! strcmp (argv[1], "-p") || ! strcmp(argv[1], "--pipe"))
    {
        argc -= 1; argv += 1;
        return unzzip_print(argc, argv);
    }

    if (! strcmp (argv[1], "-"))
    {
        fprintf(stderr, "unknown option %s", argv[1]);
        return EXIT_INVALID_OPTION;
    }
 
    return unzzip_extract(argc, argv);
} 

/* 
 * Local variables:
 * c-file-style: "stroustrup"
 * End:
 */