~ubuntu-branches/ubuntu/warty/zziplib/warty

« back to all changes in this revision

Viewing changes to SDL/SDL_rwops_zzcat.c

  • Committer: Bazaar Package Importer
  • Author(s): Aurelien Jarno
  • Date: 2004-03-29 12:41:28 UTC
  • Revision ID: james.westby@ubuntu.com-20040329124128-hf9y5elywpavuh5y
Tags: upstream-0.10.82
ImportĀ upstreamĀ versionĀ 0.10.82

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *      Copyright (c) 2001 Guido Draheim <guidod@gmx.de>
 
3
 *      Use freely under the restrictions of the ZLIB License
 
4
 *
 
5
 *      (this example uses errno which might not be multithreaded everywhere)
 
6
 */
 
7
 
 
8
#include <SDL_rwops_zzip.h>
 
9
#include <stdlib.h> /* exit */
 
10
 
 
11
/* mostly a copy from zzcat.c */
 
12
 
 
13
int main (int argc, char** argv)
 
14
{
 
15
    static const char usage[] = 
 
16
        " zzcat <file>... \n"
 
17
        "  - prints the file to stdout. the file can be a normal file\n"
 
18
        "  or an inflated part of a zip-archive \n"
 
19
        ;
 
20
 
 
21
    int argn;
 
22
    if (argc <= 1)
 
23
    {
 
24
        printf (usage);
 
25
        exit (0);
 
26
    }
 
27
    
 
28
    for (argn=1; argn < argc; argn++)
 
29
    {
 
30
        SDL_RWops* rwops;
 
31
 
 
32
        rwops = SDL_RWFromZZIP (argv[argn], "rb");
 
33
        if (! rwops)
 
34
        {
 
35
            perror (argv[argn]);
 
36
            continue;
 
37
        }else{
 
38
            char buf[17];
 
39
            int n;
 
40
 
 
41
            /* read chunks of 16 bytes into buf and print them to stdout */
 
42
            while (0 < (n = SDL_RWread(rwops, buf, 16, 1)))
 
43
            {
 
44
                buf[n] = '\0';
 
45
#             ifdef STDOUT_FILENO
 
46
                write (STDOUT_FILENO, buf, n);
 
47
#             else
 
48
                fwrite (buf, 1, n, stdout);
 
49
#             endif
 
50
            }
 
51
 
 
52
            if (n == -1) 
 
53
                perror (argv[argn]);
 
54
 
 
55
            SDL_RWclose (rwops);
 
56
        }
 
57
    }
 
58
    
 
59
    return 0;
 
60
}
 
61
 
 
62
 
 
63