source: OGRE/trunk/ogre_dependencies/Dependencies/include/zzip/format.h @ 692

Revision 692, 7.4 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

Line 
1/*
2 * Author:
3 *      Guido Draheim <guidod@gmx.de>
4 *
5 *      Copyright (c) 2000,2001,2002,2003 Guido Draheim
6 *          All rights reserved
7 *          use under the restrictions of the
8 *          Lesser GNU General Public License
9 *          or alternatively the restrictions
10 *          of the Mozilla Public License 1.1
11 *
12 *  The information was taken from appnote-981119-iz.zip
13 *  at http://www.freesoftware.com/pub/infozip/doc/
14 *  which in turn is based on PKWARE's appnote.txt
15 *  (newer link: ftp://ftp.info-zip.org/pub/infozip/doc/)
16 */
17#ifndef _ZZIP_FORMAT_H /* zzipformat.h */
18#define _ZZIP_FORMAT_H
19 
20#include <zzip/lib.h>
21/* we have ICO C 9X types defined */
22
23/*
24 * Overall zipfile format
25 *  [local file header + file data stream + checksum descriptor] ...
26 *   ...  [disk central directory] [disk trailer record]
27 */
28 
29# ifdef _MSC_VER
30# pragma pack(push, 1)
31# endif
32
33struct zzip_version
34{
35    char   version[1];
36    char   ostype[1];
37} __zzip_attribute__((packed));
38
39struct zzip_dostime
40{
41    char   time[2];
42    char   date[2];
43} __zzip_attribute__((packed));
44
45#ifdef ZZIP_NEED_PACKED
46/* if your compiler does interesting things about struct packing... */
47typedef char zzip_version_t[2];
48typedef char zzip_dostime_t[4];
49#else
50typedef struct zzip_version zzip_version_t;
51typedef struct zzip_dostime zzip_dostime_t;
52#endif
53
54#define ZZIP_CHECKMAGIC(__p,__A,__B,__C,__D) \
55    ( (((char*)(__p))[0]==(__A)) && \
56      (((char*)(__p))[1]==(__B)) && \
57      (((char*)(__p))[2]==(__C)) && \
58      (((char*)(__p))[3]==(__D)) )
59
60/* A. Local file header */
61struct zzip_file_header
62{
63#   define ZZIP_FILE_HEADER_MAGIC 0x04034b50
64#   define ZZIP_FILE_HEADER_CHECKMAGIC(__p) ZZIP_CHECKMAGIC(__p,'P','K','\3','\4')
65    char   z_magic[4]; /* local file header signature (0x04034b50) */
66    zzip_version_t z_extract; /* version needed to extract */
67    char   z_flags[2]; /* general purpose bit flag */
68    char   z_compr[2]; /* compression method */
69    zzip_dostime_t z_dostime; /* last mod file time (dos format) */
70    char   z_crc32[4]; /* crc-32 */
71    char   z_csize[4]; /* compressed size */
72    char   z_usize[4]; /* uncompressed size */
73    char   z_namlen[2]; /* filename length (null if stdin) */
74    char   z_extras[2]; /* extra field length */
75    /* followed by filename (of variable size) */
76    /* followed by extra field (of variable size) */
77} __zzip_attribute__((packed));
78#define zzip_file_header_headerlength (4+2+2+2+4+4+4+4+2+2)
79
80/* B. data descriptor
81 * the data descriptor exists only if bit 3 of z_flags is set. It is byte aligned
82 * and immediately follows the last byte of compressed data. It is only used if
83 * the output media of the compressor was not seekable, eg. standard output.
84 */
85struct zzip_file_trailer
86{
87#   define ZZIP_FILE_TRAILER_MAGIC 0x08074B50
88#   define ZZIP_FILE_TRAILER_CHECKMAGIC(__p) ZZIP_CHECKMAGIC(__p,'P','K','\7','\8')
89    char   z_magic[4]; /* data descriptor signature (0x08074b50) */
90    char   z_crc32[4]; /* crc-32 */
91    char   z_csize[4]; /* compressed size */
92    char   z_usize[4]; /* uncompressed size */
93} __zzip_attribute__((packed));
94#define zzip_file_trailer_headerlength (4+4+4+4)
95
96/* C. central directory structure:
97    [file header] . . . end of central dir record 
98*/
99
100/* directory file header
101 * - a single entry including filename, extras and comment may not exceed 64k.
102 */
103
104struct zzip_disk_entry
105{
106#   define ZZIP_DISK_ENTRY_MAGIC 0x02014b50
107#   define ZZIP_DISK_ENTRY_CHECKMAGIC(__p) ZZIP_CHECKMAGIC(__p,'P','K','\1','\2')
108    char  z_magic[4];  /* central file header signature (0x02014b50) */
109    zzip_version_t z_encoder;  /* version made by */
110    zzip_version_t z_extract;  /* version need to extract */
111    char  z_flags[2];  /* general purpose bit flag */
112    char  z_compr[2];  /* compression method */
113    zzip_dostime_t z_dostime;  /* last mod file time&date (dos format) */
114    char  z_crc32[4];  /* crc-32 */
115    char  z_csize[4];  /* compressed size */
116    char  z_usize[4];  /* uncompressed size */
117    char  z_namlen[2]; /* filename length (null if stdin) */
118    char  z_extras[2];  /* extra field length */
119    char  z_comment[2]; /* file comment length */
120    char  z_diskstart[2]; /* disk number of start (if spanning zip over multiple disks) */
121    char  z_filetype[2];  /* internal file attributes, bit0 = ascii */
122    char  z_filemode[4];  /* extrnal file attributes, eg. msdos attrib byte */
123    char  z_offset[4];    /* relative offset of local file header, seekval if singledisk */
124    /* followed by filename (of variable size) */
125    /* followed by extra field (of variable size) */
126    /* followed by file comment (of variable size) */
127} __zzip_attribute__((packed));
128#define zzip_disk_entry_headerlength (4+2+2+2+2+4+4+4+4+2+2+2+2+2+4+4)
129
130
131struct zzip_root_dirent
132{   /* the old name of the structure above */
133#   define ZZIP_ROOT_DIRENT_MAGIC 0x02014b50
134#   define ZZIP_ROOT_DIRENT_CHECKMAGIC(__p) ZZIP_DISK_ENTRY_CHECKMAGIC(__p)
135    char  z_magic[4];
136    zzip_version_t z_encoder;                     zzip_version_t z_extract;
137    char  z_flags[2];      char  z_compr[2];      zzip_dostime_t z_dostime;
138    char  z_crc32[4];      char  z_csize[4];      char  z_usize[4];
139    char  z_namlen[2];     char  z_extras[2];     char  z_comment[2];   
140    char  z_diskstart[2];  char  z_filetype[2];   char  z_filemode[4];
141    char  z_off[4];
142} __zzip_attribute__((packed));
143
144
145/* end of central dir record */
146struct zzip_disk_trailer
147{
148#   define ZZIP_DISK_TRAILER_MAGIC 0x06054b50
149#   define ZZIP_DISK_TRAILER_CHECKMAGIC(__p) ZZIP_CHECKMAGIC(__p,'P','K','\5','\6')
150    char  z_magic[4]; /* end of central dir signature (0x06054b50) */
151    char  z_disk[2];  /* number of this disk */
152    char  z_finaldisk[2]; /* number of the disk with the start of the central dir */
153    char  z_entries[2]; /* total number of entries in the central dir on this disk */
154    char  z_finalentries[2]; /* total number of entries in the central dir */
155    char  z_rootsize[4]; /* size of the central directory */
156    char  z_rootseek[4]; /* offset of start of central directory with respect to *
157                          * the starting disk number */
158    char  z_comment[2];  /* zipfile comment length */
159    /* followed by zipfile comment (of variable size) */
160} __zzip_attribute__((packed));
161#define zzip_disk_trailer_headerlength (4+2+2+2+2+4+4+2)
162
163/* extra field should be type + size + data + type + size + data ... */
164struct zzip_extra_block
165{                              /* fetch.h macros do not need this struct */
166    char  z_datatype[2];       /* as input type - a mere <char*> is okay */
167    char  z_datasize[2];       /* being returned by xx_to_extras usually */
168} __zzip_attribute__((packed));
169#define zzip_extra_block_headerlength (2+2)
170
171/* z_flags */
172#define ZZIP_IS_ENCRYPTED(p)    ((*(unsigned char*)p)&1)
173#define ZZIP_IS_COMPRLEVEL(p)  (((*(unsigned char*)p)>>1)&3)
174#define ZZIP_IS_STREAMED(p)    (((*(unsigned char*)p)>>3)&1)
175#define ZZIP_IS_PATCHED(p)     (((*(unsigned char*)p)>>5)&1)
176
177/* z_compr */
178#define ZZIP_IS_STORED          0
179#define ZZIP_IS_SHRUNK          1
180#define ZZIP_IS_REDUCEDx1       2
181#define ZZIP_IS_REDUCEDx2       3
182#define ZZIP_IS_REDUCEDx3       4
183#define ZZIP_IS_REDUCEDx4       5
184#define ZZIP_IS_IMPLODED        6
185#define ZZIP_IS_TOKENIZED       7
186#define ZZIP_IS_DEFLATED        8
187#define ZZIP_IS_DEFLATED_BETTER 9
188#define ZZIP_IS_IMPLODED_BETTER 10
189
190/* deflated comprlevel */
191#define ZZIP_DEFLATED_STD_COMPR 0
192#define ZZIP_DEFLATED_MAX_COMPR 1
193#define ZZIP_DEFLATED_LOW_COMPR 2
194#define ZZIP_DEFLATED_MIN_COMPR 3
195
196# ifdef _MSC_VER
197# pragma pack(pop)
198# endif
199
200#endif /* _ZZIPFORMAT_H */
201
202
203
204
Note: See TracBrowser for help on using the repository browser.