00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef CORE_H
00023
00024 #include <string.h>
00025
00026
00027
00028
00029
00030
00031 #define CORE_VERSION "1.0.3"
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #ifndef __STDC__
00042 #error "need ANSI/ISO C compiler"
00043 #endif
00044
00045
00046
00047 #ifdef __GNUC__
00048 # define OPT_INLINE __inline__
00049 #else
00050 # define OPT_INLINE
00051 #endif
00052 #if defined( __i386__ ) && defined( __GNUC__ )
00053
00054
00055 # define OPT_STDCALL __attribute__((stdcall))
00056 #else
00057 # define OPT_STDCALL
00058 #endif
00059 #if defined( __i386__ ) && defined( __GNUC__ ) && defined(NDEBUG)
00060
00061
00062
00063 # define OPT_REGPARM __attribute__((regparm(3)))
00064 #else
00065 # define OPT_REGPARM OPT_STDCALL
00066 #endif
00067
00068
00069 #if defined( __sparc__ ) || defined( __ppc__ )
00070 # define CPU_BIG_ENDIAN
00071 #endif
00072 #if defined( __sparc__ )
00073 # define CPU_NEED_ALIGN
00074 #endif
00075
00076
00077 #if defined( __ia64__ )
00078 # define CPU_PAGE_SHIFT 16
00079 #elif defined( __arm__ )
00080 # define CPU_PAGE_SHIFT 15
00081 #elif defined( __i386__ ) || defined( __ppc__ )
00082 # define CPU_PAGE_SHIFT 12
00083 #else
00084 # define CPU_PAGE_SHIFT 13
00085 #endif
00086
00087
00088 #ifdef __GNUC__
00089 # define LOLO_BUILTIN long long
00090 # define LOLO( v ) v##LL
00091 # define LULU( v ) v##ULL
00092 #elif defined( _MSC_VER ) || defined( __BORLANDC__ )
00093 # define LOLO_BUILTIN __int64
00094 # define LOLO( v ) v
00095 # define LULU( v ) v
00096 #elif 0xFFFFFFFFL != ~0L
00097 # define LOLO_BUILTIN long
00098 # define LOLO( v ) v##L
00099 # define LULU( v ) v##UL
00100 #else
00101 # error "please use a compiler providing a 64 bit integer type. thanks."
00102 #endif
00103 typedef LOLO_BUILTIN lolo;
00104 typedef unsigned LOLO_BUILTIN lulu;
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 #if defined(BUILD_SHMODE)
00116 # undef BUILD_SHMODE
00117 #endif
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 #define TAB 9
00129 #define LF 10
00130 #define VT 11
00131 #define CR 13
00132
00137 extern int a2i ( const char *p, int l );
00142 extern int a2il ( const char *p, int l, int *res );
00146 extern int a2id ( const char *p, int l, int dflt );
00151 extern int i2a ( char *p, int i );
00152 extern int u2a ( char *p, unsigned u );
00153
00154 extern void u2a0 ( char *p, unsigned u, unsigned n );
00155
00156 extern const char b36dig[36];
00157
00158 extern const char b36val[256];
00159
00160 extern const unsigned char lat1up[256];
00161 extern const unsigned char lat1ct[256];
00162 enum {
00163 CT_WHITE = 0x01,
00164 CT_DIGIT = 0x02,
00165 CT_ALPHA = 0x04,
00166 CT_IDENT = 0x08,
00167 CT_SPECL = 0x10,
00168 CT_LATIN = 0x20
00169 };
00170 enum {
00171 CT_W = CT_WHITE,
00172 CT_D = CT_DIGIT|CT_IDENT|CT_LATIN,
00173 CT_A = CT_ALPHA|CT_IDENT|CT_LATIN,
00174 CT_I = CT_IDENT|CT_LATIN,
00175 CT_S = CT_SPECL,
00176 CT_L = CT_LATIN,
00177 CT_N = 0
00178 };
00179 #define CT_IS(type, c) (CT_##type == lat1ct[(unsigned char)(c)])
00180 #define CT_HAS(flg, c) (CT_##flg & lat1ct[(unsigned char)(c)])
00181
00182
00184 extern void mTr ( char *bytes, char from, char to, int len );
00185
00186
00187 typedef struct Fld {
00188 int tag;
00189 unsigned len;
00190 char *val;
00191 } Fld;
00192
00193
00194
00195
00196 #define V2I( f ) a2i( (f)->val, (f)->len )
00197
00198
00199 #define VKEY( f, k, l ) ( \
00200 (f)->len >= (l) && !memcmp( (f)->val, k, l ) \
00201 && ((f)->len == (l) || TAB == (f)->val[(l)]) \
00202 )
00203
00204
00205 #define VDUPZ( f ) ((char*)mDupz((f)->val, (f)->len))
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215 extern int vGet ( Fld *dst, const Fld *src, const char *opt );
00216
00217
00218
00219 #define VPRI( dst, src ) ((dst)->val = 0, vGet(dst, src, 0), (dst)->len)
00220 #define VEQZ( f, str ) (!strncmp((f)->val,str,(f)->len) && !str[(f)->len])
00221
00228
00229 extern int vCmp ( const Fld *a, const Fld *b );
00230
00231 extern int vGt ( const Fld *a, const Fld *b );
00232
00233
00234 typedef int VGt ( const Fld *a, const Fld *b );
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250 typedef const Fld *Rec;
00251
00252 #define RLEN( r ) (-(r)->tag)
00253 #define REND( r ) ((r)-(r)->tag)
00254 #define RLAST( r ) (REND(r)-1)
00255
00256 extern unsigned rSiz ( const Fld *r );
00257
00265 extern const Fld *rGet ( const Fld *r, int tag, int *pos );
00266
00267
00268
00269
00270 extern const Fld *rKey ( const Fld *r, int tag, const char *key );
00271
00272
00273
00274
00275
00276 extern const Fld *rDup ( const Fld *src, unsigned siz );
00277
00278
00286 extern int rSer ( char *buf, const Fld *rec );
00287
00293 extern void rSort ( Fld *rec, VGt *gt );
00294 extern void rSortTag ( Fld *rec );
00295 extern void rSortVal ( Fld *rec );
00296
00297
00298 #define DEFBLKLEN 8000
00299 #define DEFFIELDS 40
00300
00301 typedef struct LBlk {
00302 struct LBlk *nxt;
00303 unsigned siz;
00304 char byt[DEFBLKLEN];
00305 } LBlk;
00306
00307
00308
00309
00310
00311 typedef struct List {
00312 Fld *fld;
00313 unsigned fav;
00314 int siz;
00315 char *buf;
00316 char *end;
00317 LBlk *blk;
00318 char *bok;
00319 Fld fl0[DEFFIELDS];
00320 LBlk bl0;
00321 } List;
00322
00323
00324 #define LLEN( l ) RLEN((l)->fld)
00325 #define LEND( l ) REND((l)->fld)
00326 #define LLAST( l ) RLAST((l)->fld)
00327
00328
00329
00330
00331
00332
00333
00334
00335 extern List *lInit ( List *l, const char *fmt, ... );
00336
00337
00338
00339 extern List *lClr ( List *l );
00340
00341
00342
00343 extern List *lReset ( List *l );
00344
00345
00346
00347 extern void OPT_STDCALL lFini ( List *l );
00348
00349
00350
00351
00352
00353
00354
00355 extern int OPT_REGPARM lExtend ( List *l, unsigned need, int fields );
00356
00357
00358
00359
00360 #define LAVL( l ) ((unsigned)((l)->end - (l)->buf))
00361 #define LSIZ( l ) ((unsigned)((l)->buf - (l)->blk->byt + (l)->siz))
00362
00363
00364
00365
00366
00367
00368 #define LDEFNEWF( l, t ) \
00369 int __i = (l)->fld->tag; \
00370 Fld *__f = (l)->fld - __i--; \
00371 __f->tag = t; \
00372 (l)->fld->tag = __i;
00373
00374
00375 #define LNEWF( l, t, n ) do { \
00376 if ( ((l)->fav && LAVL(l) >= n) || lExtend( l, n, 1 ) ) { \
00377 LDEFNEWF( l, t ) \
00378 __f->val = (l)->buf; \
00379 __f->len = 0; \
00380 (l)->fav --; \
00381 } } while(0)
00382
00383
00384
00385
00386 #define LPREF( l, t, n ) do { \
00387 if ( (l)->fav ) { \
00388 LDEFNEWF( l, t ) \
00389 __f->val = (l)->buf; \
00390 __f->len = n; \
00391 (l)->fav --; \
00392 (l)->buf += n; \
00393 } } while(0)
00394
00395
00396
00397 #define LADD( l, t, v, n ) do { \
00398 if ( ((l)->fav && LAVL(l) >= n) || lExtend( l, n, 1 ) ) { \
00399 LDEFNEWF( l, t ) \
00400 memcpy( __f->val = (l)->buf, v, __f->len = n ); \
00401 (l)->fav --; \
00402 (l)->buf += n; \
00403 } } while(0)
00404
00405
00406 #define LAPP( l, v, n ) do { \
00407 if ( LAVL(l) >= n || lExtend( l, n, -1 ) ) { \
00408 Fld *__f = LLAST(l); \
00409 memcpy( (l)->buf, v, n ); \
00410 __f->len += n; \
00411 (l)->buf += n; \
00412 } } while(0)
00413
00414
00415 #define LADDI( l, t, i ) do { \
00416 if ( ((l)->fav && LAVL(l) >= 12) || lExtend( l, 12, 1 ) ) { \
00417 LDEFNEWF( l, t ) \
00418 (l)->buf += __f->len = i2a( __f->val = (l)->buf, i ); \
00419 (l)->fav --; \
00420 } } while(0)
00421
00422 #define LADDS( l, t, s ) LADD( l, t, s, strlen(s) )
00423 #define LAPPS( l, s ) LAPP( l, s, strlen(s) )
00424 #define LADDF( l, f ) LADD( l, f->tag, f->val, f->len )
00425
00426
00436
00437
00438
00439
00440
00441
00442
00443
00444 extern int lArgv ( List *l, int tag, int argc, const char **argv );
00445
00446
00447
00448
00454 extern List *lVar ( List *l, int argc, const char **argv );
00455
00456
00457 extern int lCpy ( List *l, const Fld *src, unsigned siz );
00458 #define LCPY( l, src ) lCpy( l, (src)->fld, LSIZ(src) )
00459
00460
00461 #define LCAN( l ) rDup( (l)->fld, LSIZ(l) )
00462
00463
00464
00465
00466
00467
00468 extern int lOut ( List *to, int tag, const char *fmt, ... );
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479 enum {
00480 LPS_SOR,
00481 LPS_SOL = 0x1000000,
00482 LPS_TAG = 0x2000000,
00483 LPS_VAL = 0x3000000,
00484 LPS_NEG = 0x4000000,
00485 LPS_CR = 0x8000000,
00486 LPS_LEN = 0x0ffffff
00487 };
00494 extern int lParse (List *l, const char *txt, int lps);
00495
00496
00507 typedef struct Sink Sink;
00508 typedef void sink (Sink *that, int eor);
00509
00510 struct Sink {
00511 List lst;
00512 sink *snk;
00513 void *dst;
00514 int off;
00515 };
00516
00517 #define SINK(s) (s)->snk(s, 0)
00518 #define SEOR(s) (s)->snk(s, 1)
00519 #define SCPY(s, l) do { LCPY(&(s)->lst, l); SEOR(s); } while (0)
00520 #define SCPYR(s, r) do { lCpy(&(s)->lst, r, 0); SEOR(s); } while (0)
00521
00522
00523
00524
00525
00526
00527
00528 #ifndef WIN32
00529 typedef int file;
00530 #define FIL_NONE -1
00531 #else
00532 typedef void *file;
00533 #define FIL_NONE 0
00534 #endif
00535
00536
00537
00538 typedef struct Env {
00539 List *opt;
00540 file in;
00541 Sink *out;
00542 Sink *err;
00543 int log;
00544 int flg;
00545 int wri;
00546 int sig;
00547 unsigned psz;
00548 int psh;
00549 unsigned rml;
00550 unsigned qml;
00551
00552 } Env;
00553
00554 enum {
00555 ENV_BUFFER = 1,
00556 ENV_MSYNC = 2
00557 };
00558 enum {
00559 ENV_RO,
00560 ENV_EXCL
00561 #ifdef BUILD_SHMODE
00562 , ENV_SHARED
00563 #endif
00564 };
00565 enum {
00566 ENV_CANCEL = 1,
00567 ENV_TERM
00568 };
00569
00570 extern Env env;
00571
00575 enum {
00576 ERR_OK = 0,
00577 ERR_NO = -1,
00578
00579 ERR_IDIOT = -2,
00580 ERR_TRASH = -3,
00581 LOG_FATAL = ERR_TRASH,
00582
00583 ERR_NOMEM = -4,
00584 ERR_IO = -5,
00585 ERR_BUSY = -6,
00586 LOG_SYSERR = ERR_BUSY,
00587 ERR_BADF = -7,
00588 ERR_FAULT = -8,
00589 ERR_INVAL = -9,
00590 LOG_ERROR = ERR_INVAL,
00591 ERR_AGAIN = -10,
00592 LOG_IOERR = ERR_AGAIN,
00593 LOG_WARN = -11,
00594
00595 LOG_INFO = -12,
00596 LOG_VERBOSE = -13,
00597 LOG_DEBUG = -14,
00598 LOG_TRACE = -15,
00599 LOG_ALL = LOG_TRACE
00600 };
00601
00602
00603 #define EADD(t, v, n) LADD(&env.out->lst, t, v, n)
00604 #define EAPP(v, n) LAPP(&env.out->lst, v, n)
00605 #define EADDS(t, s) LADDS(&env.out->lst, t, s)
00606 #define EAPPS(s) LAPPS(&env.out->lst, s)
00607 #define EADDI(t, i) LADDI(&env.out->lst, t, i)
00608 #define EADDF(f) LADDF(&env.out->lst, f)
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620 extern int eOut ( int tag, const char *fmt, ... );
00621 extern int eRr ( int tag, const char *fmt, ... );
00622 #ifndef NDEBUG
00623 # define LOG_DBG eRr
00624 #elif defined( __GNUC__ )
00625 # define LOG_DBG( args... )
00626 #else
00627 # define LOG_DBG (void)
00628 #endif
00629
00636 extern void cInit ( List *args, Sink *out, Sink *err );
00637
00638 #define CINIT(argl) cInit(lVar(lInit(argl,0), argc-1, argv+1), 0, 0)
00639
00640
00647 extern void *mAlloc ( int size );
00648 extern void *mDup ( const void *str, int size );
00649
00650 extern char *mDupz ( const char *str, int size );
00651 extern void *mTryAlloc ( int size );
00652 extern void mFree ( void *mem );
00653 extern Fld *mFldAlloc ( int nfields );
00654 extern void mFldFree ( Fld *fld );
00655 extern LBlk *mBlkAlloc ( int size );
00656 extern void mBlkFree ( LBlk *blk );
00657 extern List *mListAlloc ( const char *name );
00658 extern void mListFree ( List *l );
00659 #define mFldAlloc(n) ((Fld*)mAlloc((n)*sizeof(Fld)))
00660 #define mFldFree mFree
00661 #define mBlkFree mFree
00662 #define MFREE(p) do { mFree(p); (p)=0; } while(0)
00663
00664
00668 extern int tUpd ( lolo *tm );
00676 extern int tGtf ( char *buf, lolo *tm );
00682 extern char *tGtfm ( char *buf, lolo *tm );
00686 extern void tSleep ( lolo tm );
00687
00688
00689
00690
00691
00692
00693
00694 enum {
00695
00696 FIL_RD = 0x001,
00697 FIL_WR = 0x002,
00698 FIL_RDWR = 0x003,
00699 FIL_TRY = 0x004,
00700
00701 FIL_CREAT = 0x010,
00702 FIL_TRUNC = 0x020,
00703 FIL_SYNC = 0x040,
00704
00705 FIL_TLOCK = 0x100,
00706 FIL_BLOCK = 0x200,
00707 FIL_FLOCK = 0x300
00708 };
00709
00715 extern int fOpen ( file *f, const char *name, int flags );
00716 extern int fClose ( file *f );
00717 extern int fSize ( file f );
00718 extern unsigned fTime ( file f );
00719
00720
00721
00722
00723
00724
00725
00726 extern int fRead ( file *f, void *buf, unsigned len );
00727 extern int fWrite ( file *f, const void *buf, unsigned len );
00728 extern int fPread ( file *f, void *buf, unsigned len, unsigned off );
00729 extern int fPwrite ( file *f, const void *buf, unsigned len, unsigned off );
00730 extern int fSeek ( file *f, unsigned off );
00731 extern int fTrunc ( file *f, unsigned length );
00732 #ifdef BUILD_SHMODE
00733
00734 extern void fUnlock ( file f );
00735
00736
00737
00738
00739 extern int fLock ( file f, unsigned n, int flg );
00740 #define FLOCK(f,n,flg) (ENV_SHARED==env.wri && fLock(f,n,flg))
00741 #else
00742 #define FLOCK(f,n,flg) 0
00743 #endif
00744 #define FLOCKSH(f,n) FLOCK(f,n,FIL_BLOCK)
00745 #define FLOCKEX(f,n) FLOCK(f,n,FIL_BLOCK|FIL_WR)
00746 #define FLOCKUN(f,n) FLOCK(f,n,0)
00747
00756 extern int fSlurp ( char **buf, int sz, const char *name, int opt );
00757
00758
00759
00760
00761
00762
00763 extern void fSinkr (Sink *that, int eor);
00764
00765
00766
00767
00768 extern void fSinkl (Sink *that, int eor);
00769
00771 typedef struct {
00772 file fil;
00773 int flg;
00774 char *map;
00775 unsigned npg;
00776 unsigned lim;
00777 #ifdef WIN32
00778 char *nam;
00779 void *hdl;
00780 #endif
00781 } FMap;
00782
00787 extern int fMOpen ( FMap *fm, const char *name, int flags );
00788 extern int fMClose ( FMap *fm );
00798 extern int fMap ( FMap *fm, unsigned npg );
00800 extern int fMSync ( FMap *fm, unsigned page );
00801
00802
00803
00804
00805
00806
00807 typedef struct {
00808 file f;
00809 unsigned n;
00810 unsigned o;
00811 char *b;
00812 unsigned s;
00813 char *p;
00814 unsigned l;
00815 unsigned m;
00816 } FBuf;
00817
00818 #define FIL_BUF( fb, fil, buf ) do { \
00819 fb.f = fil; fb.b = fb.p = buf; fb.s = sizeof(buf); \
00820 fb.n = 1; fb.o = fb.l = fb.m = 0; \
00821 } while (0)
00822
00823 #define FIL_DEFBUF( f ) \
00824 char buf[0x2000]; \
00825 FBuf fb; \
00826 FIL_BUF(fb, f, buf);
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839 extern int fGets ( FBuf *fb );
00840 extern int fGetr ( List *l, FBuf *fb );
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850 enum {
00851 DX_OPEN = 0x1,
00852 DX_WRITE = 0x2,
00853 DX_ASYNC = 0x4,
00854 DX_MODIF = 0x8
00855 };
00861 typedef struct Rdx {
00862 file mrd;
00863 FMap mrx;
00864 int flg;
00865 int mid;
00866 int rdl;
00867 int ptl;
00868 int typ;
00869 } Rdx;
00870
00872 extern int rInit ( Rdx *rdx );
00874 extern void rFini ( Rdx *rdx );
00875
00876
00877
00878
00879
00880
00881 extern int rRead ( List *l, Rdx *rdx, int rid, unsigned mpos );
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891 extern int rWrite ( Rdx *rdx, const Fld *r, int rid, int opos, unsigned siz );
00892
00893
00902 typedef struct Cdx Cdx;
00903
00904 typedef struct Qdx {
00905 file mqd;
00906 FMap mqx;
00907 const Cdx *cdx;
00908 int flg;
00909 unsigned char typ;
00910 unsigned char ksz;
00911 unsigned char ptr;
00912 unsigned char let;
00913
00914 unsigned char vsz;
00915 unsigned char uni;
00916 unsigned char ftp;
00917 unsigned char dpt;
00918 unsigned lsz;
00919 unsigned lln;
00920 unsigned fln;
00921
00922 struct QLoad *qld;
00923 } Qdx;
00924
00925 enum {
00926 QDX_TYPMSK = 0xC0,
00927 QDX_LEAF = 0x00,
00928 QDX_FORKLE = 0x40,
00929 QDX_FORKBE = 0x80,
00930 QDX_LEAFPV = 0xC0,
00931
00932 QDX_COMPRS = 0x08,
00933 QDX_SIZMSK = 0x07,
00934 QDX_LEAF0K = 0x00,
00935 QDX_LEAF1K = 0x01,
00936 QDX_LEAF2K = 0x02,
00937 QDX_LEAF4K = 0x03,
00938 QDX_LEAF8K = 0x04
00939 };
00940 enum {
00941 QDX_MAXVALPERLEAF = 0x800,
00942 QDX_LEAFSH = 9,
00943 QDX_FORKSH = 12
00944 };
00945
00946 typedef struct {
00947 unsigned char len;
00948 unsigned char byt[255];
00949 } Val;
00950
00951 typedef struct {
00952 Val val;
00953 unsigned char len;
00954 unsigned char byt[255];
00955 } Key;
00956
00957
00958 typedef struct QLoop QLoop;
00965 typedef int QCb ( QLoop *self );
00966
00967 struct QLoop {
00968 QCb *qcb;
00969 Qdx *qdx;
00970 int flg;
00971 Key key;
00972 Key to;
00973
00974 Key cur;
00975 unsigned nvals;
00976 const unsigned char *vals;
00977 };
00978
00979 enum {
00980 QLOOP = 0,
00981
00982 QEQ = 1,
00983 QPF = 2,
00984
00985 QUPTO = 4,
00986 QINCL = 5,
00987 QSTOP = 7,
00988 QSKIP = 8,
00989 QSAME = 0x10
00990 };
00991
00992
00994 extern int qInit ( Qdx *bt );
00996 extern void qFini ( Qdx *bt );
00997
00998
00999
01000
01001
01002 extern int qLoad ( Qdx *bt, Key *key );
01003 extern int qLoadf ( Qdx *bt, file *f );
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016 extern int qSet ( Qdx *bt, Key *key );
01017 enum {
01018 QST_OK,
01019 QST_FOUND,
01020 QST_STPWRD,
01021 QST_UNIKEY
01022 };
01023
01024
01025
01026 extern int qDel ( Qdx *bt, Key *key );
01027
01028 extern int qLoop ( QLoop *self );
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038
01039
01040 typedef struct {
01041 unsigned short tag;
01042 unsigned short ext;
01043 unsigned rid;
01044 unsigned pos;
01045 } Ptr;
01046
01047 enum {
01048 QDX_TAGMSK = 0xC0,
01049 QDX_TAG1 = 0x40,
01050 QDX_TAG2 = 0x80,
01051 QDX_TAGSH = 6,
01052 QDX_RIDMSK = 0x30,
01053 QDX_RIDMIN = 3,
01054 QDX_RIDSH = 4,
01055 QDX_RID3 = 0x00,
01056 QDX_RID4 = 0x10,
01057 QDX_RID5 = 0x20,
01058 QDX_RID6 = 0x30,
01059 QDX_FULTXT = 0x08,
01060 QDX_POSMSK = 0x07,
01061
01062 QDX_ISIS = QDX_RID3|QDX_TAG2|QDX_FULTXT|3,
01063
01064 QDX_STDDB = QDX_TAG1|QDX_RID3
01065
01066 };
01067
01068
01069 extern void qRdVal ( Ptr *ptr, const unsigned char *val, unsigned char typ );
01070
01071 extern void qMkVal ( Val *val, Ptr *ptr, unsigned char typ );
01072
01073 extern int qRdKey ( Qdx *qdx, char *plain, int l, Key *key );
01074
01075 extern void qMkKey ( Qdx *qdx, Key *key, char *b, int l );
01076
01077 extern int qMkKeyVal ( Qdx *qdx, Key *key, char *b, int l );
01078
01079
01080 typedef struct {
01081 Qdx *qdx;
01082 int del;
01083 Key pfx;
01084 Ptr ptr;
01085 } QSet;
01086
01087
01088
01089
01090
01091
01092 extern int qSetKeyVal (QSet *qst, char *val, int len);
01093
01094
01095
01096
01097 extern int qSetKeyVals (QSet *qst, char *val, int len);
01098
01099
01103 #define CDX_MAXSEQ 15
01104
01105
01106 extern const Cdx *cOpen ( const Fld *src );
01107 extern int cEnc ( const Cdx *cdx, Key *key, unsigned char *b, int l, int w );
01108 extern int cDec ( const Cdx *cdx, unsigned char *b, int l, Key *key );
01109
01110
01111 enum {
01112 MET_OPT = 001,
01113 MET_UNU = 002,
01114 MET_CTP = 003,
01115 MET_COL = 004,
01116 MET_VER = 005,
01117 MET_FLD = 006
01118 };
01119
01123 typedef struct Db {
01124 char *nam;
01125 char *pat;
01126 int flg;
01127 int mnt;
01128 struct Db *nxt;
01129 const Fld *opt;
01130 Rdx rdx;
01131 Qdx qdx;
01132 } Db;
01133
01134 extern Db *dOpen (const char *dbname);
01135 extern void dClose (Db *db);
01136 extern void dCloseAll ();
01137
01143 #define dRead(l,db,rid) ((rid)?rRead(l,&(db)->rdx,rid,0):lCpy(l,(db)->opt,0))
01144 #define dWrite(db,r,rid) rWrite(&(db)->rdx,r,rid,-1,0)
01145
01146 #define dSet(db,key) qSet(&(db)->qdx,key)
01147 #define dDel(db,key) qDel(&(db)->qdx,key)
01148 #define dLoop(db,ql) ((ql)->qdx=&(db)->qdx, qLoop(ql))
01149
01150 #define CORE_H
01151 #endif