#ifndef _CDTLIB_H
#define _CDTLIB_H 1
#if _PACKAGE_ast
#include <ast.h>
#if !_BLD_cdt
#include <dlldefs.h>
#endif
#endif
#include <cdt.h>
#include <unistd.h>
#include <aso.h>
#include "debug.h"
#define NIL(t) ((t)0)
#define reg register
#define DT_HTABLE 10
#if !defined(uint)
#define uint unsigned int
#endif
#if !defined(uchar)
#define uchar unsigned char
#endif
struct _dtdata_s
{ unsigned int lock;
Dtuser_t user;
unsigned int type;
ssize_t size;
Dt_t dict;
};
typedef struct _dtlib_s
{
char* name;
char* description;
char* release;
char* prefix;
Dtmethod_t** methods;
} Dtlib_t;
#if _BLD_cdt
#if defined(__STDC__)
#define CDTLIB(m) __DEFINE__(Dtmethod_t*,m,&_##m);
#else
#define CDTLIB(m) __DEFINE__(Dtmethod_t*,m,&_m);
#endif
#else
#if defined(__STDC__)
#define CDTLIB(m) \
void* cdt_lib(const char* name, Dtdisc_t* disc, const char* type) \
{ \
int i; \
int n; \
if (!type) \
return &cdt_lib_##m; \
n = strlen(cdt_lib_##m.prefix); \
if (!strncmp(type, cdt_lib_##m.prefix, n)) \
type += n; \
for (i = 0; cdt_lib_##m.methods[i]; i++) \
if (!strcmp(type, cdt_lib_##m.methods[i]->name + n)) \
return cdt_lib_##m.methods[i]; \
return 0; \
} \
unsigned long plugin_version(void) { return CDT_PLUGIN_VERSION; }
#else
#define CDTLIB(m) \
void* cdt_lib(name, disc, type) const char* name; Dtdisc_t* disc; const char* type; \
{ \
int i; \
int n; \
if (!type) \
return &cdt_lib_m; \
n = strlen(cdt_lib_m.prefix); \
if (!strncmp(type, cdt_lib_m.prefix, n)) \
type += n; \
for (i = 0; cdt_lib_m.methods[i]; i++) \
if (!strcmp(type, cdt_lib_m.methods[i]->name + n)) \
return cdt_lib_m.methods[i]; \
return 0; \
} \
unsigned long plugin_version() { return CDT_PLUGIN_VERSION; }
#endif
#endif
#define DTSETLOCK(dt) (((dt)->data->type&DT_SHARE) ? asolock(&(dt)->data->lock,1,ASO_SPINLOCK) : 0 )
#define DTCLRLOCK(dt) (((dt)->data->type&DT_SHARE) ? asolock(&(dt)->data->lock,1,ASO_UNLOCK) : 0 )
#define DTRETURN(ob,rv) do { (ob) = (rv); goto dt_return; } while(0)
#define DTERROR(dt, mesg) (!((dt)->disc && (dt)->disc->eventf) ? 0 : \
(*(dt)->disc->eventf)((dt),DT_ERROR,(Void_t*)(mesg),(dt)->disc) )
#define DTANNOUNCE(dt,ob,ty) ( ((ob) && ((ty)&DT_TOANNOUNCE) && ((dt)->data->type&DT_ANNOUNCE) && \
(dt)->disc && (dt)->disc->eventf ) ? \
(*(dt)->disc->eventf)((dt), DT_ANNOUNCE|(ty), (ob), (dt)->disc) : 0 )
#define DTTYPE(dt,ty) ((dt)->typef ? (*(dt)->typef)((dt), (ty)) : (ty) )
#define _left lh.__left
#define _hash lh.__hash
#define _ppos lh.__hash
#define _rght rh.__rght
#define _ptbl rh.__ptbl
#define rrotate(x,y) ((x)->_left = (y)->_rght, (y)->_rght = (x))
#define lrotate(x,y) ((x)->_rght = (y)->_left, (y)->_left = (x))
#define rlink(r,x) ((r) = (r)->_left = (x) )
#define llink(l,x) ((l) = (l)->_rght = (x) )
#define RROTATE(x,y) (rrotate(x,y), (x) = (y))
#define LROTATE(x,y) (lrotate(x,y), (x) = (y))
#define RRSHIFT(x,t) ((t) = (x)->_left->_left, (x)->_left->_left = (t)->_rght, \
(t)->_rght = (x), (x) = (t) )
#define LLSHIFT(x,t) ((t) = (x)->_rght->_rght, (x)->_rght->_rght = (t)->_left, \
(t)->_left = (x), (x) = (t) )
_BEGIN_EXTERNS_
#if _BLD_cdt && defined(__EXPORT__)
#define extern __EXPORT__
#endif
extern Dtlink_t* _dtmake _ARG_((Dt_t*, Void_t*, int));
extern void _dtfree _ARG_((Dt_t*, Dtlink_t*, int));
extern int _dtlock _ARG_((Dt_t*, int));
#undef extern
#if !_PACKAGE_ast
extern Void_t* malloc _ARG_((size_t));
extern Void_t* realloc _ARG_((Void_t*, size_t));
extern void free _ARG_((Void_t*));
#endif
_END_EXTERNS_
#endif