Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libpz/pzlib.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 private definitions
24
*/
25
26
#ifndef _PZLIB_H
27
#define _PZLIB_H 1
28
29
#include <ast.h>
30
#include <dt.h>
31
#include <ctype.h>
32
#include <error.h>
33
#include <tv.h>
34
35
#define PZ_VERSION_SPLIT 19990811L /* splitf added */
36
37
#define state _pz_info /* library private state */
38
#define pznospace _pz_nospace
39
#define pzsdeflate _pz_sdeflate
40
#define pzsinflate _pz_sinflate
41
#define pzssplit _pz_ssplit
42
43
#define _(s) ERROR_translate(0,0,0,s)
44
45
struct Pz_s;
46
47
typedef struct Pzelt_s /* window row order element */
48
{
49
Dtlink_t link; /* dictionary link */
50
unsigned char buf[1]; /* row data */
51
} Pzelt_t;
52
53
typedef struct Pzrs_s /* read stream state */
54
{
55
size_t hi; /* num hi frequency rows in buf */
56
size_t lo; /* rem lo frequency reps in pat */
57
} Pzrs_t;
58
59
typedef struct Pzws_s /* write stream state */
60
{
61
unsigned char* bp; /* hi freq buf ptr */
62
unsigned char* vp; /* lo freq code val ptr */
63
unsigned char* ve; /* lo freq code val end */
64
unsigned char* pb; /* partial row buffer */
65
66
unsigned char* sp; /* PZ_SORT partial buffer */
67
68
size_t pc; /* partial row count */
69
size_t rep; /* lo freq repeat count */
70
size_t row; /* lo freq row count */
71
size_t sz; /* PZ_SORT partial buffer rem */
72
73
Pzelt_t* se; /* PZ_SORT partial element */
74
75
Sfio_t* io; /* output sync stream */
76
} Pzws_t;
77
78
typedef struct Pzss_s /* split stream state */
79
{
80
char* match; /* strmatch() file pattern */
81
unsigned long flags; /* PZ_SPLIT_* flags */
82
size_t* data; /* split data */
83
size_t size; /* split data size */
84
} Pzss_t;
85
86
#define _PZ_PART_PRIVATE_ \
87
Dtlink_t link; /* dictionary by name link */ \
88
void* discdata; /* discipline specific data */
89
90
#define _PZ_PRIVATE_ \
91
Vmdisc_t vmdisc; /* vmalloc region discipline */ \
92
Dtdisc_t partdisc; /* partition discipline */ \
93
Dt_t* partdict; /* partition dictionary by name */ \
94
Pzpart_t* mainpart; /* the main partition */ \
95
Pzpart_t* freepart; /* free partition */ \
96
char* partname; /* specific part name */ \
97
size_t mrow; /* max row size */ \
98
size_t mwin; /* max window size */ \
99
struct \
100
{ \
101
size_t count; /* prefix record count */ \
102
int skip; /* skip prefix on decompress */ \
103
int terminator; /* prefix record terminator */ \
104
char* data; /* prefix data */ \
105
} prefix; /* header prefix info */ \
106
struct \
107
{ \
108
Dt_t* order; /* order dictionary */ \
109
Dt_t* free; /* free list dictionary */ \
110
Dtdisc_t orderdisc; /* order discipline */ \
111
Dtdisc_t freedisc; /* free list discipline */ \
112
} sort; /* PZ_SORT info */ \
113
Sfio_t* oip; /* original input stream */ \
114
Sfio_t* oop; /* original output stream */ \
115
Sfio_t* tmp; /* temp string stream */ \
116
Sfio_t* str; /* sfstrtmp() string stream */ \
117
Sfio_t* det; /* processed options stream */ \
118
Sfio_t* pin; /* partition input stream */ \
119
char* headoptions; /* header options */ \
120
char* options; /* current options */ \
121
Pzrs_t rs; /* read stream state */ \
122
Pzws_t ws; /* read stream state */ \
123
Pzss_t split; /* split state */ \
124
Tv_t start; /* elapsed start time */ \
125
void* discdata; /* discipline specific data */
126
127
#include <pzip.h>
128
129
typedef struct Pzdllpz_s /* initialized pz list for dll */
130
{
131
struct Pzdllpz_s*next; /* next in list */
132
Pz_t* pz; /* pz initialized for dll */
133
} Pzdllpz_t;
134
135
typedef struct Pzdll_s /* loaded dlls */
136
{
137
struct Pzdll_s* next; /* next in list */
138
char* name; /* name */
139
void* dll; /* handle */
140
const char* usage; /* optget() usage */
141
Pzinit_f initf; /* initialization function */
142
Pzdllpz_t* pzs; /* initialized pz list */
143
} Pzdll_t;
144
145
typedef struct
146
{
147
const char* id; /* library id */
148
Pzdll_t* dll; /* loaded dll list */
149
} Pzstate_t;
150
151
#define PZ_MAJOR 2 /* current format major version */
152
#define PZ_MINOR 1 /* current format minor version */
153
154
#define PZ_SPLIT_DEFLATE 0x0001 /* split deflate enabled */
155
#define PZ_SPLIT_HEADER 0x0002 /* split header already written */
156
#define PZ_SPLIT_INFLATE 0x0004 /* split inflate enabled */
157
#define PZ_SPLIT_PART 0x0008 /* currently splitting a part */
158
159
#define PZ_DELAY 0x01000000 /* delay unknown error */
160
#define PZ_HANDLE 0x02000000 /* sfdcpzip() sp arg is Pz_t */
161
#define PZ_UNKNOWN 0x04000000 /* unknown input row size */
162
#define PZ_MAINONLY 0x08000000 /* mainpart only in header */
163
#define PZ_ROWONLY 0x10000000 /* grab row size from prt file */
164
#define PZ_AGAIN 0x20000000 /* path arg is Pz_t */
165
#define PZ_POP 0x40000000 /* pop pz->io on pzclose() */
166
#define PZ_ERROR 0x80000000 /* make pzclose() return error */
167
168
#define PZ_INTERNAL (PZ_HANDLE|PZ_UNKNOWN|PZ_MAINONLY|PZ_ROWONLY|PZ_AGAIN|PZ_POP|PZ_ERROR)
169
170
#define PZ_MARK_TAIL 1 /* tail marker */
171
#define PZ_MARK_PART 2 /* tail marker */
172
173
#define PZ_HDR_ARR(x) ((x)>=0x41&&(x)<=0x5a) /* header array op */
174
#define PZ_HDR_BUF(x) ((x)>=0x61&&(x)<=0x7a) /* header buffer op */
175
176
#define PZ_HDR_comment 0x63 /* header comment string */
177
#define PZ_HDR_options 0x64 /* header options string */
178
#define PZ_HDR_fix 0x46 /* header fix array */
179
#define PZ_HDR_grp 0x47 /* header grp array */
180
#define PZ_HDR_map 0x4d /* header map array */
181
#define PZ_HDR_part 0x50 /* header partition */
182
#define PZ_HDR_prefix 0x70 /* header prefix data */
183
#define PZ_HDR_split 0x53 /* split { major minor } */
184
185
#define PZGETZ(pz,ip,z,i) \
186
if ((z = sfgetc(ip)) & SF_MORE) \
187
{ \
188
z &= (SF_MORE - 1); \
189
while ((i = sfgetc(ip)) & SF_MORE) \
190
{ \
191
if (i < 0) \
192
{ \
193
if (pz->disc->errorf) \
194
(*pz->disc->errorf)(pz, pz->disc, 2, "%s: input truncated", pz->path); \
195
return -1; \
196
} \
197
z = (z << SF_UBITS) | (i & (SF_MORE - 1)); \
198
} \
199
z = (z << SF_UBITS) | i; \
200
}
201
202
#define PZGETP(pz,ip,z,i,a) \
203
if (!(z = sfgetc(ip))) \
204
a; \
205
if (z & SF_MORE) \
206
{ \
207
z &= (SF_MORE - 1); \
208
while ((i = sfgetc(ip)) & SF_MORE) \
209
{ \
210
if (i < 0) \
211
{ \
212
if (pz->disc->errorf) \
213
(*pz->disc->errorf)(pz, pz->disc, 2, "%s: input truncated", pz->path); \
214
return -1; \
215
} \
216
z = (z << SF_UBITS) | (i & (SF_MORE - 1)); \
217
} \
218
z = (z << SF_UBITS) | i; \
219
}
220
221
extern Pzstate_t state;
222
223
extern int pznospace(Pz_t*);
224
extern int pzsdeflate(Pz_t*, Sfio_t*);
225
extern int pzsinflate(Pz_t*, Sfio_t*);
226
extern int pzssplit(Pz_t*);
227
228
#endif
229
230