Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libpz/pzip.h
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1998-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#pragma prototyped
21
22
/*
23
* partitioned fixed record zip library interface
24
*/
25
26
#ifndef _PZIP_H
27
#define _PZIP_H 1
28
29
#include <ast.h>
30
#include <cdt.h>
31
#include <option.h>
32
#include <sfdcgzip.h>
33
#include <vmalloc.h>
34
35
#define PZ_PLUGIN_VERSION AST_PLUGIN_VERSION(PZ_VERSION)
36
37
#define PZ_VERSION 19990811L /* interface version */
38
39
#if __STDC__
40
#define PZLIB(m) unsigned long plugin_version(void) { return PZ_PLUGIN_VERSION; }
41
#else
42
#define PZLIB(m) unsigned long plugin_version() { return PZ_PLUGIN_VERSION; }
43
#endif
44
45
#define PZ_DATA_SUF "pz" /* data file suffix */
46
#define PZ_PART_SUF "prt" /* partition file suffix */
47
48
#define PZ_WINDOW (4*1024*1024) /* default window size */
49
50
#define PZ_MAGIC_1 0x1f /* first magic char */
51
#define PZ_MAGIC_2 0x10 /* second magic char */
52
53
#define PZ_OPEN 0 /* open event */
54
#define PZ_REOPEN 1 /* reopen event */
55
#define PZ_CLOSE 2 /* close event */
56
#define PZ_OPTION 3 /* run time option event */
57
#define PZ_PARTITION 4 /* new partition event */
58
#define PZ_TAILREAD 5 /* data tail read event */
59
#define PZ_TAILWRITE 6 /* data tail write event */
60
61
#define PZ_READ 0x00000001 /* open for read */
62
#define PZ_WRITE 0x00000002 /* open for write */
63
#define PZ_FORCE 0x00000004 /* open even if not pzip format */
64
#define PZ_STAT 0x00000008 /* open to stat header only */
65
#define PZ_STREAM 0x00000010 /* path arg is Sfio_t* stream */
66
#define PZ_CRC 0x00000020 /* (redundant) inflate crc */
67
#define PZ_DUMP 0x00000040 /* detailed trace */
68
#define PZ_VERBOSE 0x00000080 /* intermediate trace */
69
#define PZ_REGRESS 0x00000100 /* regression test output */
70
#define PZ_DIO 0x00000200 /* push sfdcdio() */
71
#define PZ_NOGZIP 0x00000400 /* no gzip */
72
#define PZ_SECTION 0x00000800 /* process one pzip section */
73
#define PZ_UPDATE 0x00001000 /* header update needed */
74
#define PZ_OVERSIZE 0x00002000 /* row elts for Pzpart_t vectors*/
75
#define PZ_HEAD 0x00004000 /* header already processed */
76
#define PZ_NOPZIP 0x00008000 /* no pzip */
77
#define PZ_ACCEPT 0x00010000 /* accept input (manual id) */
78
#define PZ_DISC 0x00020000 /* discipline push -- any ok */
79
#define PZ_APPEND 0x00040000 /* discipline append op */
80
#define PZ_SUMMARY 0x00080000 /* summary trace */
81
#define PZ_PUSHED 0x00100000 /* internal sfdcpzip() stream */
82
#define PZ_SPLIT 0x00200000 /* open for split */
83
#define PZ_SORT 0x00400000 /* sort window before deflate */
84
#define PZ_VARIABLE 0x00800000 /* variable row size */
85
86
#define PZ_VAR_OFF(r) ((r)&0x3fff) /* row => offset */
87
#define PZ_VAR_LEN(r) (1<<(((r)>>14)&0x3)) /* row => size len */
88
89
#define PZ_VERIFY PZ_STAT /* verify but don't push */
90
91
#define SFPZ_HANDLE SFDCEVENT('P','Z',1)
92
93
struct Pz_s; typedef struct Pz_s Pz_t;
94
struct Pzconvert_s; typedef struct Pzconvert_s Pzconvert_t;
95
struct Pzcount_s; typedef struct Pzcount_s Pzcount_t;
96
struct Pzdisc_s; typedef struct Pzdisc_s Pzdisc_t;
97
struct Pzformat_s; typedef struct Pzformat_s Pzformat_t;
98
struct Pzindex_s; typedef struct Pzindex_s Pzindex_t;
99
struct Pzpart_s; typedef struct Pzpart_s Pzpart_t;
100
struct Pzsplit_s; typedef struct Pzsplit_s Pzsplit_t;
101
102
typedef ssize_t (*Pzconvert_f)(Pz_t*, Pzconvert_t*, const unsigned char*, unsigned char*, Pzdisc_t*);
103
typedef int (*Pzevent_f)(Pz_t*, int, void*, size_t, Pzdisc_t*);
104
typedef int (*Pzindex_f)(Pz_t*, Pzindex_t*, void*, Pzdisc_t*);
105
typedef const char* (*Pzinit_f)(Pz_t*, Pzdisc_t*);
106
typedef char* (*Pzname_f)(Pz_t*, unsigned long, Pzdisc_t*);
107
typedef Pzsplit_t* (*Pzsplit_f)(Pz_t*, Sfio_t*, Pzdisc_t*);
108
typedef ssize_t (*Pzread_f)(Pz_t*, Sfio_t*, void*, Pzdisc_t*);
109
typedef ssize_t (*Pzwrite_f)(Pz_t*, Sfio_t*, const void*, Pzdisc_t*);
110
111
struct Pzcount_s /* caller/library counters */
112
{
113
Sfulong_t uncompressed; /* uncompressed size */
114
Sfulong_t compressed; /* compressed size */
115
Sfulong_t windows; /* # windows */
116
Sfulong_t sections; /* # split sections */
117
Sfulong_t records; /* # records */
118
Sfulong_t modules; /* # split records */
119
Sfulong_t converted; /* # converted records */
120
Sfulong_t repaired; /* # repaired records */
121
Sfulong_t truncated; /* # truncated records */
122
Sfulong_t dropped; /* # dropped records */
123
};
124
125
struct Pzformat_s /* pzdcconvert() format info */
126
{
127
const char* name; /* format (partition) name */
128
size_t row; /* PZ_FORCE row size match */
129
const char* description; /* format description */
130
};
131
132
struct Pzconvert_s /* pzdcconvert() table element */
133
{
134
Pzformat_t* from; /* from format */
135
Pzformat_t* to; /* to format */
136
Pzconvert_f convertf; /* row conversion function */
137
Pzevent_f eventf; /* conversion event function */
138
void* userdata; /* caller defined, 0 by default */
139
};
140
141
struct Pzdisc_s /* user discipline */
142
{
143
unsigned long version; /* PZ_VERSION */
144
const char* comment; /* zipped data comment */
145
const char* options; /* run time options */
146
const char* partition; /* data partition file */
147
const char* lib; /* pathfind() lib */
148
size_t window; /* max window size */
149
Error_f errorf; /* error function */
150
Pzevent_f eventf; /* event function */
151
Pzinit_f initf; /* library init function */
152
Pzread_f readf; /* partition row read function */
153
Pzwrite_f writef; /* partition row write function */
154
Pzindex_f indexf; /* index generation function */
155
Pzsplit_f splitf; /* record split function */
156
Pzname_f namef; /* record id name function */
157
void* local; /* discipline local data */
158
};
159
160
struct Pzindex_s /* record index */
161
{
162
Sfulong_t block; /* compressed block */
163
Sfulong_t offset; /* offset in block */
164
};
165
166
struct Pzpart_s /* partition context */
167
{
168
char* name; /* partition name */
169
unsigned long flags; /* PZ_* flags */
170
size_t row; /* # chars per row */
171
size_t col; /* # chars per col per win */
172
size_t loq; /* lo frequency window size */
173
174
/* hi frequency info */
175
176
size_t* map; /* external to internal map */
177
size_t* grp; /* column groupings */
178
unsigned char** mix; /* column mix */
179
size_t* lab; /* column mix group label */
180
size_t* inc; /* column mix increment */
181
size_t nmap; /* # elements in map */
182
size_t ngrp; /* # elements in grp */
183
184
/* lo frequency info */
185
186
unsigned char* low; /* 1 if lo frequency, 0 if hi */
187
int* value; /* fixed value if >= 0 */
188
size_t* fix; /* fixed columns */
189
size_t nfix; /* # fixed values */
190
191
/* caller defined info */
192
193
void* userdata; /* caller defined, 0 by default */
194
195
#ifdef _PZ_PART_PRIVATE_
196
_PZ_PART_PRIVATE_
197
#endif
198
199
};
200
201
struct Pzsplit_s /* splitf record info */
202
{
203
unsigned long id; /* id: 0 == sized */
204
void* data; /* data */
205
size_t size; /* module size */
206
size_t record; /* record size (guess) if header*/
207
};
208
209
struct Pz_s /* pzip context */
210
{
211
const char* id; /* library id */
212
Pzdisc_t* disc; /* user discipline */
213
unsigned long flags; /* PZ_* flags */
214
unsigned long test; /* implementation test mask */
215
int major; /* data major version number */
216
int minor; /* data minor version number */
217
size_t row; /* default input row size */
218
size_t win; /* window size */
219
const char* path; /* io path */
220
Sfio_t* io; /* io stream */
221
Vmalloc_t* vm; /* local malloc region */
222
Pzpart_t* part; /* current partition */
223
Pzcount_t count; /* caller/library counts */
224
225
/* workspace info */
226
227
unsigned char* buf; /* window buffer */
228
unsigned char* wrk; /* window buffer */
229
unsigned char* pat; /* row buffer */
230
unsigned char* nxt; /* next val pointer */
231
unsigned char* val; /* lo frequency window buffer */
232
233
/* caller defined info */
234
235
void* userdata; /* caller defined, 0 by default */
236
237
#ifdef _PZ_PRIVATE_
238
_PZ_PRIVATE_
239
#endif
240
241
};
242
243
#if defined(__EXPORT__)
244
#define extern __EXPORT__
245
#endif
246
247
extern const char* pz_init(Pz_t*, Pzdisc_t*);
248
249
#undef extern
250
251
#if _BLD_pz && defined(__EXPORT__)
252
#define extern __EXPORT__
253
#endif
254
255
extern Pz_t* pzopen(Pzdisc_t*, const char*, unsigned long);
256
extern int pzclose(Pz_t*);
257
258
extern ssize_t pzread(Pz_t*, void*, size_t);
259
extern ssize_t pzwrite(Pz_t*, Sfio_t*, const void*, size_t);
260
extern int pzsync(Pz_t*);
261
extern int pzfile(Pz_t*);
262
263
extern int pzdeflate(Pz_t*, Sfio_t*);
264
extern int pzinflate(Pz_t*, Sfio_t*);
265
266
extern Sfio_t* pzfind(Pz_t*, const char*, const char*, const char*);
267
extern int pzlib(Pz_t*, const char*, int);
268
extern const char* pzinit(Pz_t*, const char*, Pzinit_f);
269
270
extern int pzoptions(Pz_t*, Pzpart_t*, char*, int);
271
extern int pzpartinit(Pz_t*, Pzpart_t*, const char*);
272
extern int pzpartmap(Pz_t*, Pzpart_t*);
273
extern int pzpartition(Pz_t*, const char*);
274
extern int pzpartprint(Pz_t*, Pzpart_t*, Sfio_t*);
275
extern int pzpartread(Pz_t*);
276
extern int pzpartwrite(Pz_t*, Sfio_t*);
277
extern Pzpart_t* pzpartget(Pz_t*, const char*);
278
extern Pzpart_t* pzpartnext(Pz_t*, Pzpart_t*);
279
extern Pzpart_t* pzpartset(Pz_t*, Pzpart_t*);
280
281
extern int pzheadread(Pz_t*);
282
extern int pzheadwrite(Pz_t*, Sfio_t*);
283
extern int pzheadprint(Pz_t*, Sfio_t*, int);
284
285
extern int pzdcconvert(Pz_t*, const Pzconvert_t*);
286
287
extern ssize_t pzfixed(Pz_t*, Sfio_t*, void*, size_t);
288
289
extern int sfdcpzip(Sfio_t*, const char*, unsigned long, Pzdisc_t*);
290
extern int sfdczip(Sfio_t*, const char*, const char*, Error_f);
291
292
#undef extern
293
294
#endif
295
296