Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libvcodex/vcodex.h
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 2003-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
* Phong Vo <[email protected]> *
18
* *
19
***********************************************************************/
20
#ifndef _VCODEX_H
21
#define _VCODEX_H 1
22
23
/* VCODEX = COmpression + DElta + X (encryption, etc.)
24
**
25
** Written by Kiem-Phong Vo ([email protected])
26
*/
27
28
#define VC_VERSION 20081104L /* ILU-NDV */
29
#define VC_ID "vcodex" /* package identification */
30
#define VC_LIB "vcodex_lib" /* function name */
31
32
#if _PACKAGE_ast
33
#include <ast_std.h>
34
#undef VCSFIO
35
#define VCSFIO 1
36
#undef VCPROPRIETARY
37
#define VCPROPRIETARY 0
38
#else
39
#include <ast_common.h>
40
#define VCSFIO 0
41
#define VCPROPRIETARY 1
42
#endif
43
44
#define VCODEX_PLUGIN_VERSION AST_PLUGIN_VERSION(VC_VERSION)
45
46
#if VCSFIO == 1
47
#include <sfio.h>
48
#else
49
#include <stdio.h>
50
#endif
51
52
#include <cdt.h> /* container data types */
53
54
#if !_SFIO_H /* emulate Sfio features */
55
#define Sfoff_t off_t /* file offset type */
56
#define Sfio_t FILE /* stream structure */
57
#define Sfdisc_t int /* Sfio discipline */
58
59
#define sfstderr stderr /* standard streams */
60
#define sfstdout stdout
61
#define sfstdin stdin
62
63
#define SF_IOCHECK 010
64
65
#define SF_LOCKR 001
66
#define SF_LASTR 002
67
68
#define SF_SYNC 001
69
#define SF_CLOSING 002
70
#define SF_DPOP 004
71
#define SF_ATEXIT 010
72
73
#define sfprintf fprintf
74
#define sfvprintf vfprintf
75
#define sfopen(s,f,m) ((s) ? freopen((f),(m),(s)) : fopen((f), (m)) )
76
#define sfread(s,b,n) fread((b), 1, (n), (s))
77
#define sfwrite(s,b,n) fwrite((b), 1, (n), (s))
78
#define sfrd(s,b,n,d) fread((b), 1, (n), (s))
79
#define sfwr(s,b,n,d) fwrite((b), 1, (n), (s))
80
#define sfseek(s,p,t) (fseek((s),(long)(p),(t)) >= 0 ? (Sfoff_t)ftell(s) : (Sfoff_t)(-1))
81
#define sfdisc(s,d) (d)
82
#define sfset(f,m,t) (0)
83
#define sfsetbuf(f,b,n) (0)
84
#define sffileno(f) fileno(f)
85
#define sftmp(n) tmpfile()
86
87
extern Void_t* sfreserve _ARG_((Sfio_t*, ssize_t, int));
88
extern char* sfgetr _ARG_((Sfio_t*, int, int));
89
extern ssize_t sfvalue _ARG_((Sfio_t*));
90
extern Sfoff_t sfsize _ARG_((Sfio_t*));
91
extern int sfclose _ARG_((Sfio_t*));
92
#endif /*_SFIO_H*/
93
94
/* define 32-bit integer types */
95
#if !defined(Vcint32_t) && _typ_int32_t
96
#define Vcint32_t int32_t
97
#endif
98
#if !defined(Vcint32_t) && defined(_ast_int4_t)
99
#define Vcint32_t _ast_int4_t
100
#endif
101
#if !defined(Vcint32_t)
102
Help needed to define signed 32-bit integer type.
103
#endif
104
105
#if !defined(Vcuint32_t) && _typ_uint32_t
106
#define Vcuint32_t uint32_t
107
#endif
108
#if !defined(Vcuint32_t) && defined(_ast_int4_t)
109
#define Vcuint32_t unsigned _ast_int4_t
110
#endif
111
#if !defined(Vcuint32_t)
112
Help needed to define unsigned 32-bit integer type.
113
#endif
114
115
typedef unsigned char Vcchar_t;
116
typedef struct _vcodex_s Vcodex_t;
117
typedef struct _vcdisc_s Vcdisc_t;
118
typedef struct _vcmethod_s Vcmethod_t;
119
typedef struct _vcmtarg_s Vcmtarg_t;
120
typedef struct _vcmtcode_s Vcmtcode_t;
121
typedef struct _vccontext_s Vccontext_t;
122
typedef int (*Vcevent_f)_ARG_((Vcodex_t*, int, Void_t*, Vcdisc_t*));
123
typedef ssize_t (*Vcapply_f)_ARG_((Vcodex_t*, const Void_t*, size_t, Void_t**));
124
125
typedef int (*Vcwalk_f)_ARG_((Void_t*, char*, char*, Void_t*));
126
127
/* type of buffers allocated for transformed data */
128
typedef struct _vcbuffer_s Vcbuffer_t;
129
130
/* types to encode/decode bits and integers */
131
typedef Vcuint32_t Vcbit_t; /* 32-bit accumulator */
132
#define VC_BITSIZE (sizeof(Vcbit_t)*8 )
133
typedef Vcint32_t Vcint_t; /* 32-bit integers */
134
#define VC_INTSIZE (sizeof(Vcint_t)*8 )
135
136
/* Vcio_t: handle to perform IO functions on strings */
137
typedef struct _vcio_s
138
{ Vcchar_t* data; /* the data buffer */
139
Vcchar_t* next; /* current position in buffer */
140
Vcchar_t* endb; /* end of buffer or data in it */
141
Vcbit_t bits; /* buffer usable for bit-coding */
142
ssize_t nbits; /* # of bits cached in "bits" */
143
} Vcio_t;
144
145
/* Discipline structure: what application supplies */
146
struct _vcdisc_s
147
{ Void_t* data; /* data, key string, etc. */
148
ssize_t size; /* size of data or just an int */
149
Vcevent_f eventf; /* call-back function on events */
150
};
151
152
/* Arguments to a method */
153
struct _vcmtarg_s
154
{ char* name; /* argument name - alphanumeric */
155
char* desc; /* short description of arg */
156
Void_t* data; /* predefined data, if any */
157
};
158
159
/* structure to extract/restore a handle by its private code */
160
struct _vcmtcode_s
161
{ Vcchar_t* data; /* the encoding data for handle */
162
ssize_t size; /* the data size */
163
Vcodex_t* coder; /* the reconstructed coder */
164
};
165
166
/* Method structure: what a tranform looks like */
167
struct _vcmethod_s
168
{ Vcapply_f encodef; /* function to encode */
169
Vcapply_f decodef; /* function to decode */
170
int (*eventf)_ARG_((Vcodex_t*, int, Void_t*));
171
char* name; /* string name, 0-terminated */
172
char* desc; /* description, 0-terminated */
173
char* about; /* [-name?value]...0-terminated */
174
Vcmtarg_t* args; /* list of possible arguments */
175
ssize_t window; /* suggested window size */
176
int type; /* flags telling type of method */
177
};
178
179
/* Method writers: note that this should be first in any context type */
180
struct _vccontext_s
181
{ Vccontext_t *next;
182
};
183
184
/* Vcodex_t handle structure: to keep states */
185
struct _vcodex_s
186
{ Vcapply_f applyf; /* function to process data */
187
Vcdisc_t* disc; /* supplied discipline */
188
Vcmethod_t* meth; /* selected coding method */
189
Vcodex_t* coder; /* continuation coder */
190
size_t undone; /* left-over after vcapply() */
191
unsigned int flags; /* bits to control operations */
192
Vccontext_t* ctxt; /* list of contexts */
193
Void_t* data; /* private method data */
194
ssize_t head; /* required buffer head size */
195
char* file; /* file with allocation request */
196
int line; /* line number in file */
197
#ifdef _VCODEX_PRIVATE
198
_VCODEX_PRIVATE
199
#endif
200
};
201
202
/* flags passable to vcopen() */
203
#define VC_FLAGS 007777 /* all supported flags */
204
#define VC_ENCODE 000001 /* handle for encoding data */
205
#define VC_DECODE 000002 /* handle to decode data */
206
#define VC_CLOSECODER 000010 /* 2nd-ary coders to be closed */
207
208
/* event types passable to discipline event handlers */
209
#define VC_OPENING 1 /* opening event */
210
#define VC_CLOSING 2 /* closing event */
211
#define VC_DISC 3 /* changing discipline */
212
#define VC_DATA 4 /* on getting data for method */
213
214
/* event types to be processed by method event handlers */
215
#define VC_INITCONTEXT 101 /* setting/creating a context */
216
#define VC_FREECONTEXT 102 /* freeing one or all contexts */
217
#define VC_FREEBUFFER 103 /* free all associated buffers */
218
#define VC_SETMTARG 104 /* set argument(s) to a method */
219
#define VC_EXTRACT 105 /* extract code for handle */
220
#define VC_RESTORE 106 /* restoring a handle from code */
221
222
/* flags defining certain method attributes */
223
#define VC_MTSOURCE 000001 /* use source data (Vcdelta) */
224
225
/* separators for arguments */
226
#define VC_ARGSEP '.' /* separator for method args */
227
#define VC_METHSEP ',' /* separator for methods */
228
229
/* function to initialize a discipline structure */
230
#define VCDISC(dc,dt,sz,fn) \
231
((dc)->data = (dt), (dc)->size = (sz), (dc)->eventf = (fn) )
232
233
/* return vcodex discipline event */
234
#define VCSF_DISC ((((int)('V'))<<7)|((int)('C')))
235
236
_BEGIN_EXTERNS_
237
238
#if _BLD_vcodex && defined(__EXPORT__)
239
#define extern extern __EXPORT__
240
#endif
241
#if !_BLD_vcodex && defined(__IMPORT__)
242
#define extern extern __IMPORT__
243
#endif
244
245
/* pointers to the default public -lvcodex methods */
246
#include <vcmethods.h>
247
248
#undef extern
249
250
#if _BLD_vcodex && defined(__EXPORT__)
251
#define extern __EXPORT__
252
#endif
253
254
/* public functions */
255
extern Vcodex_t* vcopen _ARG_((Vcdisc_t*, Vcmethod_t*, Void_t*, Vcodex_t*, int));
256
extern Vcodex_t* vcmake _ARG_((char*, int));
257
extern ssize_t vcextract _ARG_((Vcodex_t*, Void_t**));
258
extern Vcodex_t* vcrestore _ARG_((Void_t*, size_t));
259
extern int vcclose _ARG_((Vcodex_t*));
260
extern ssize_t vcapply _ARG_((Vcodex_t*, Void_t*, size_t, Void_t**));
261
extern size_t vcundone _ARG_((Vcodex_t*));
262
extern Vcdisc_t* vcdisc _ARG_((Vcodex_t*, Vcdisc_t*));
263
264
extern int vcaddmeth _ARG_((Vcmethod_t**, ssize_t));
265
extern Vcmethod_t* vcgetmeth _ARG_((char*, int));
266
extern int vcwalkmeth _ARG_((Vcwalk_f, Void_t*));
267
268
extern void vcaddalias _ARG_((char**));
269
extern char* vcgetalias _ARG_((char*, char*, ssize_t));
270
extern int vcwalkalias _ARG_((Vcwalk_f, Void_t*));
271
extern char* vcgetfname _ARG_((char*, char*, ssize_t));
272
extern int vcwalkfname _ARG_((Vcwalk_f, Void_t*));
273
274
extern char* vcgetident _ARG_((Vcmethod_t*, char*, ssize_t));
275
extern char* vcgetmtarg _ARG_((char*, char*, ssize_t, Vcmtarg_t*, Vcmtarg_t**));
276
extern int vcsetmtarg _ARG_((Vcodex_t*, char*, Void_t*, int));
277
278
extern char* vcsubstring _ARG_((char*, int, char*, ssize_t, int));
279
extern double vclog _ARG_((size_t)); /* fast log2 */
280
extern size_t vclogi _ARG_((size_t)); /* integer part of log2 */
281
extern ssize_t vcbcktsort _ARG_((ssize_t*, ssize_t*, ssize_t, Vcchar_t*, ssize_t*));
282
283
typedef int (*Vccompare_f)_ARG_((Void_t*, Void_t*, Void_t*));
284
extern Void_t vcqsort _ARG_((Void_t*, ssize_t, ssize_t, Vccompare_f, Void_t*));
285
286
#undef extern
287
288
_END_EXTERNS_
289
290
/* macro functions to run the transformation and return amount of data left unprocessed */
291
#define vcapply(vc,s,sz,b) (*(vc)->applyf)((vc), (Void_t*)(s), (size_t)(sz), (Void_t**)(b) )
292
#define vcundone(vc) ((vc)->undone) /* amount left unprocessed by transform */
293
294
295
/**************************************************************************
296
FAST SUBSYSTEM FOR BITS/INTS/STRINGS I/O
297
**************************************************************************/
298
299
_BEGIN_EXTERNS_
300
301
#if _BLD_vcodex && defined(__EXPORT__)
302
#define extern __EXPORT__
303
#endif
304
305
extern Vcint_t vcatoi _ARG_((char*));
306
extern ssize_t vcitoa _ARG_((Vcint_t, char*, ssize_t));
307
extern Vcint_t vcintcode _ARG_((Vcint_t, Vcint_t, Vcint_t, Vcint_t, int));
308
extern char* vcstrcode _ARG_((char*, char*, ssize_t));
309
extern ssize_t vchexcode _ARG_((Vcchar_t*, ssize_t, Vcchar_t*, ssize_t, int));
310
extern ssize_t vcstr2list _ARG_((char*, int, ssize_t**));
311
312
extern ssize_t vcioputc _ARG_((Vcio_t*, int));
313
extern int vciogetc _ARG_((Vcio_t*));
314
extern ssize_t vcioputs _ARG_((Vcio_t*, Void_t*, size_t));
315
extern ssize_t vciogets _ARG_((Vcio_t*, Void_t*, size_t));
316
317
extern ssize_t vcioputu _ARG_((Vcio_t*, Vcint_t));
318
extern Vcint_t vciogetu _ARG_((Vcio_t*));
319
extern ssize_t vcioputm _ARG_((Vcio_t*, Vcint_t, Vcint_t));
320
extern Vcint_t vciogetm _ARG_((Vcio_t*, Vcint_t));
321
extern ssize_t vcioput2 _ARG_((Vcio_t*, Vcchar_t, Vcchar_t, Vcint_t));
322
extern Vcint_t vcioget2 _ARG_((Vcio_t*, Vcchar_t, Vcchar_t));
323
extern ssize_t vcioputg _ARG_((Vcio_t*, Vcint_t));
324
extern Vcint_t vciogetg _ARG_((Vcio_t*));
325
extern ssize_t vcioputlist _ARG_((Vcio_t*, Vcint_t*, ssize_t));
326
extern ssize_t vciogetlist _ARG_((Vcio_t*, Vcint_t*, ssize_t));
327
328
extern ssize_t _vcioputu _ARG_((Vcio_t*, Vcint_t));
329
extern Vcint_t _vciogetu _ARG_((Vcio_t*));
330
extern ssize_t _vcioputm _ARG_((Vcio_t*, Vcint_t, Vcint_t));
331
extern Vcint_t _vciogetm _ARG_((Vcio_t*, Vcint_t));
332
extern ssize_t _vcioput2 _ARG_((Vcio_t*, Vcint_t, Vcchar_t, Vcchar_t));
333
extern Vcint_t _vcioget2 _ARG_((Vcio_t*, Vcchar_t, Vcchar_t));
334
extern ssize_t _vcioputg _ARG_((Vcio_t*, Vcint_t));
335
extern Vcint_t _vciogetg _ARG_((Vcio_t*));
336
337
#undef extern
338
339
_END_EXTERNS_
340
341
#define vcioinit(io,b,n) ((io)->data = (io)->next = (Vcchar_t*)(b), \
342
(io)->endb = (io)->data + (n) )
343
#define vciosize(io) ((io)->next - (io)->data)
344
#define vciomore(io) ((io)->endb - (io)->next)
345
#define vcioextent(io) ((io)->endb - (io)->data)
346
#define vciodata(io) ((io)->data)
347
#define vcionext(io) ((io)->next)
348
#define vcioskip(io, n) ((io)->next += (n))
349
#define vcioputc(io, v) (*(io)->next++ = (Vcchar_t)(v) )
350
#define vciogetc(io) (*(io)->next++)
351
#define vcioputs(io, str, sz) (memcpy((io)->next, (str), (sz)), (io)->next += (sz) )
352
#define vciogets(io, str, sz) (memcpy((str), (io)->next, (sz)), (io)->next += (sz) )
353
#define vciomove(io1, io2, sz) (memcpy((io2)->next, (io1)->next, (sz)), \
354
(io1)->next += (sz), (io2)->next += (sz) )
355
#define vcioputm(io, v, m) _vcioputm((io), (Vcint_t)(v), (Vcint_t)(m))
356
#define vciogetm(io, m) _vciogetm((io), (Vcint_t)(m))
357
#define vcioputu(io, v) \
358
((Vcint_t)(v) < (Vcint_t)(1<<7) ? (*(io)->next++ = (Vcchar_t)(v), 1) : \
359
_vcioputu((io), (Vcint_t)(v)) )
360
#define vciogetu(io) _vciogetu((io))
361
#define vcioput2(io, v, a, z) _vcioput2((io),(Vcint_t)(v),(Vcchar_t)(a),(Vcchar_t)(z))
362
#define vcioget2(io, a, z) _vcioget2((io),(Vcchar_t)(a),(Vcchar_t)(z))
363
#define vcioputg(io, v) _vcioputg((io), (Vcint_t)(v))
364
#define vciogetg(io) _vciogetg((io))
365
366
/* Compute the size of a 32-bit integer coded by vcioputu() and vcputm() */
367
#define vcsizeu(v) ((v)<(1<<7) ? 1 : (v)<(1<<14) ? 2 : \
368
(v)<(1<<21) ? 3 : (v)<(1<<28) ? 4 : 5 )
369
#define vcsizem(v) ((v)<(1<<8) ? 1 : (v)<(1<<16) ? 2 : \
370
(v)<(1<<24) ? 3 : 4 )
371
372
/* The below bit I/O macro functions use (bt,nb) for bit accumulation. These
373
** are (register) variables that will be modified in place to keep states.
374
** The variables must be initialized by vciosetb() before starting bit coding
375
** and finalized by vcioendb() before restarting to byte coding.
376
** For convenience, the Vcio_t structure itself provides two fields (bits,nbits)
377
** usable as (bt,nb). In this way, applications that perform bits ops in function
378
** calls does not need extra (static) variables to keep states.
379
*/
380
#define vciosetb(io, bt, nb, tp) /* (tp) is only for symmetry with vcioendb */ \
381
do { (bt) = 0; (nb) = 0; \
382
} while(0)
383
384
#define vciofilb(io, bt, nb, mb) /* getting bits from stream into (bt) */ \
385
do { if((nb) < (mb)) while((nb) <= (VC_BITSIZE-8) && (io)->next < (io)->endb) \
386
{ (nb) += 8; (bt) |= (*(io)->next++ << (VC_BITSIZE - (nb))); } \
387
} while(0)
388
389
#define vciodelb(io, bt, nb, nd) /* consume bits already read */ \
390
do { (bt) <<= (nd); (nb) -= (nd); \
391
} while(0)
392
393
#define vcioflsb(io, bt, nb) /* putting accumulated bits out to stream */ \
394
do { for(; (nb) >= 8 && (io)->next < (io)->endb; (nb) -= 8) \
395
{ *(io)->next++ = (Vcchar_t)((bt) >> (VC_BITSIZE-8)); (bt) <<= 8; } \
396
} while(0)
397
398
#define vcioaddb(io, bt, nb, ad, na) /* add new bits to accumulator */ \
399
do { if(((nb)+(na)) > VC_BITSIZE ) \
400
vcioflsb((io), (bt), (nb)); \
401
(bt) |= (ad) >> (nb); (nb) += (na); \
402
} while(0)
403
404
#define vcioendb(io, bt, nb, tp) /* finishing bit operations */ \
405
do { if((tp) == VC_ENCODE) \
406
{ vcioflsb(io, bt, nb); \
407
if((nb) > 0) /* finish up the partial last byte */ \
408
{ *(io)->next++ = (Vcchar_t)((bt) >> (VC_BITSIZE-8)); (bt) = 0; } \
409
} else \
410
{ while(((nb) -= 8) >= 0) \
411
(io)->next--;\
412
(bt) = 0; (nb) = 0; \
413
} \
414
} while(0)
415
416
417
/*************************************************************************
418
TYPES AND MACROS/FUNCTIONS USEFUL FOR WRITING TRANSFORMS
419
*************************************************************************/
420
421
typedef Vcuint32_t Vchash_t; /* 32-bit hash value */
422
#define VCHASH(ky) (((ky)>>13)^0x1add2b3^(ky) )
423
#define VCINDEX(ky,msk) (VCHASH(ky) & (msk) )
424
425
/* get/set private method data */
426
#define vcgetmtdata(vc, tp) ((tp)(vc)->data)
427
#define vcsetmtdata(vc, mt) ((vc)->data = (Void_t*)(mt))
428
429
/* get disciplines */
430
#define vcgetdisc(vc) ((vc)->disc)
431
432
/* get context and coerce to the true type */
433
#define vcgetcontext(vc, tp) ((tp)(vc)->ctxt)
434
435
/* allocate/deallocate buffer.
436
** bb: if !NULL, current buffer to resize.
437
** zz: new size, 0 to deallocate.
438
** hh: slack amount at head of buffer for certain header data
439
*/
440
#if defined(__FILE__) && defined(__LINE__)
441
#define vcbuffer(vv,bb,zz,hh) \
442
(!(vv) ? ((Vcchar_t*)0) : \
443
((vv)->file = __FILE__, (vv)->line = __LINE__, \
444
_vcbuffer((vv),(bb),(zz),(hh)) ) )
445
#else
446
#define vcbuffer(vv,bb,zz,hh) _vcbuffer((vv),(bb),(zz),(hh))
447
#endif
448
449
struct _vcbuffer_s /* type of a buffer */
450
{ Vcbuffer_t* next;
451
size_t size; /* total buffer size */
452
char* file; /* file allocating it */
453
int line; /* line number in file */
454
unsigned char buf[1]; /* actual data buffer */
455
};
456
457
_BEGIN_EXTERNS_
458
459
#if _BLD_vcodex && defined(__EXPORT__)
460
#define extern __EXPORT__
461
#endif
462
463
extern Vcchar_t* _vcbuffer _ARG_((Vcodex_t*, Vcchar_t*, ssize_t, ssize_t));
464
extern int vcrecode _ARG_((Vcodex_t*, Vcchar_t**, ssize_t*, ssize_t, int));
465
extern Vccontext_t* vcinitcontext _ARG_((Vcodex_t*, Vccontext_t*));
466
extern int vcfreecontext _ARG_((Vcodex_t*, Vccontext_t*));
467
468
#undef extern
469
470
_END_EXTERNS_
471
472
473
/*************************************************************************
474
TYPES AND FUNCTIONS RELATED TO STRING, SUFFIX SORTING
475
*************************************************************************/
476
477
#if VCSFXINT /* may be desirable when sizeof(int) < sizeof(ssize_t) */
478
#define Vcsfxint_t int
479
#else
480
#define Vcsfxint_t ssize_t
481
#endif
482
typedef struct _vcsfx_s
483
{ Vcsfxint_t* idx; /* the sorted suffix array */
484
Vcsfxint_t* inv; /* the inverted indices/ranks */
485
Vcchar_t* str; /* the source string */
486
Vcsfxint_t nstr;
487
} Vcsfx_t;
488
489
_BEGIN_EXTERNS_
490
491
#if _BLD_vcodex && defined(__EXPORT__)
492
#define extern __EXPORT__
493
#endif
494
495
extern Vcsfx_t* vcsfxsort _ARG_((const Void_t*, ssize_t));
496
extern ssize_t vcperiod _ARG_((const Void_t*, ssize_t));
497
498
#undef extern
499
500
_END_EXTERNS_
501
502
503
/*************************************************************************
504
TYPES AND FUNCTIONS RELATED TO GENERALIZED LZ-PARSING
505
*************************************************************************/
506
507
/* (*parsef)(Vclzparse_t* vcpa, int type, Vcmatch_t* mtch, ssize_t n)
508
Arguments:
509
vcpa: structure describing source&target data and matching requirements.
510
type: type of match, VC_REVERSE, VCP_MAP, etc.
511
mtch: array of matched data.
512
n: number of elements in mtch.
513
Return values:
514
> 0: amount of data used up.
515
= 0: all given data should be considered unmatchable.
516
< 0: processing failed, quit and return immediately.
517
*/
518
519
#define VCLZ_REVERSE 0001 /* use/do reverse matching */
520
#define VCLZ_MAP 0002 /* matching by mapping bytes */
521
522
typedef struct _vclzparse_s Vclzparse_t;
523
typedef struct _vclzmatch_s Vclzmatch_t;
524
typedef ssize_t (*Vclzparse_f)_ARG_((Vclzparse_t*,int,Vclzmatch_t*,ssize_t));
525
526
/* tpos is monotonically increasing in an array of these */
527
struct _vclzmatch_s
528
{ ssize_t tpos; /* position in target to match */
529
ssize_t mpos; /* match pos or <0 for none */
530
ssize_t size; /* length of data involved */
531
};
532
533
struct _vclzparse_s
534
{ Vclzparse_f parsef; /* function to process parsed segments */
535
Vcchar_t* src; /* source string, if any, to learn from */
536
ssize_t nsrc;
537
Vcchar_t* tar; /* target string to be parsed */
538
ssize_t ntar;
539
ssize_t mmin; /* minimum acceptable match length */
540
Vcchar_t* cmap; /* character map for matching */
541
int type; /* VCP_REVERSE, VCP_MAP */
542
};
543
544
_BEGIN_EXTERNS_
545
546
#if _BLD_vcodex && defined(__EXPORT__)
547
#define extern __EXPORT__
548
#endif
549
550
extern int vclzparse _ARG_((Vclzparse_t*, ssize_t));
551
552
#undef extern
553
554
_END_EXTERNS_
555
556
557
/*************************************************************************
558
HEADER DATA FOR PERSISTENT STORAGE.
559
This is based on and extending IETF RFC3284,
560
the Vcdiff delta compression coding format.
561
The 4th byte can be changed for different versions.
562
*************************************************************************/
563
564
#define VC_HEADER0 (0126|0200) /* ASCII 'V' | 0200 */
565
#define VC_HEADER1 (0103|0200) /* ASCII 'C' | 0200 */
566
#define VC_HEADER2 (0104|0200) /* ASCII 'D' | 0200 */
567
#define VC_HEADER3 (0130|0200) /* ASCII 'X' | 0200 */
568
569
/* Bits in the file control byte.
570
** The first two bits are for windowing with respect to IETF RFC3284.
571
** They are no longer needed with VCDX since information about secondary
572
** compression, etc. are now packaged along with method encoding. However,
573
** we keep them for compatibility.
574
*/
575
#define VCD_COMPRESSOR (1<<0) /* using a secondary compressor */
576
#define VCD_CODETABLE (1<<1) /* alternative code table */
577
#define VC_EXTRAHEADER (1<<2) /* application-defined header */
578
#define VC_CHECKSUM (1<<3) /* window has a checksum */
579
#define VC_INITS (0xf)
580
581
/* Bits in the window control byte. Again, the first two bits are for
582
** windowing with respect to IETF RFC3284.
583
*/
584
#define VCD_SOURCEFILE (1<<0) /* match window in source file */
585
#define VCD_TARGETFILE (1<<1) /* match window in target file */
586
#define VC_RAW (1<<2) /* data was left uncoded */
587
#define VC_EOF (1<<7) /* end-of-file */
588
589
590
/*************************************************************************
591
TYPES AND FUNCTIONS FOR VARIOUS SUBPACKAGES AND TRANSFORMS
592
*************************************************************************/
593
#include <vcwindow.h>
594
#if _PACKAGE_ast
595
#include <vcsfio.h>
596
#endif
597
598
599
/*************************************************************************
600
BUILTIN/PLUGIN LIBRARY DEFINITIONS
601
*************************************************************************/
602
603
#ifdef _BLD_vcodex
604
605
#ifdef __STDC__
606
#define VCLIB(m) Vcmethod_t* m = &_##m;
607
#else
608
#define VCLIB(m) Vcmethod_t* m = &_/**/m;
609
#endif
610
611
#else
612
613
#ifdef __STDC__
614
#if defined(__EXPORT__)
615
#define VCLIB(m) Vcmethod_t* m = &_##m; extern __EXPORT__ Vcmethod_t* vcodex_lib(const char* path) { return m; } \
616
unsigned long plugin_version(void) { return VCODEX_PLUGIN_VERSION; }
617
#else
618
#define VCLIB(m) Vcmethod_t* m = &_##m; extern Vcmethod_t* vcodex_lib(const char* path) { return m; } \
619
unsigned long plugin_version(void) { return VCODEX_PLUGIN_VERSION; }
620
#endif
621
#else
622
#define VCLIB(m) Vcmethod_t* m = &_/**/m; extern Vcmethod_t* vcodex_lib(path) char* path; { return m; } \
623
unsigned long plugin_version() { return VCODEX_PLUGIN_VERSION; }
624
#endif
625
626
#endif
627
628
#endif /*_VCODEX_H*/
629
630