Substantial cleanup. Performance optimizations.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@460 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
0d453e74ce
commit
2750f23385
10 changed files with 944 additions and 1093 deletions
|
|
@ -14,26 +14,16 @@ static char cvsroot[] = "$Header$";
|
||||||
|
|
||||||
#include "dohint.h"
|
#include "dohint.h"
|
||||||
|
|
||||||
static DohObjInfo DohBaseType = {
|
static DohObjInfo *dohtypes[MAX_DOHTYPE];
|
||||||
"Base", /* objname */
|
|
||||||
sizeof(DohBase), /* objsize */
|
/* -----------------------------------------------------------------------------
|
||||||
0, /* doh_del */
|
* DohRegisterType()
|
||||||
0, /* doh_copy */
|
* ----------------------------------------------------------------------------- */
|
||||||
0, /* doh_clear */
|
|
||||||
0, /* doh_str */
|
void
|
||||||
0, /* doh_data */
|
DohRegisterType(int type, DohObjInfo *objinfo) {
|
||||||
0, /* doh_dump */
|
dohtypes[type] = objinfo;
|
||||||
0, /* doh_load */
|
}
|
||||||
0, /* doh_len */
|
|
||||||
0, /* doh_hash */
|
|
||||||
0, /* doh_cmp */
|
|
||||||
0, /* doh_mapping */
|
|
||||||
0, /* doh_list */
|
|
||||||
0, /* doh_file */
|
|
||||||
0, /* doh_string */
|
|
||||||
0, /* reserved1 */
|
|
||||||
0, /* reserved2 */
|
|
||||||
};
|
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* DohDelete()
|
* DohDelete()
|
||||||
|
|
@ -42,24 +32,22 @@ static DohObjInfo DohBaseType = {
|
||||||
void
|
void
|
||||||
DohDelete(DOH *obj) {
|
DohDelete(DOH *obj) {
|
||||||
DohBase *b = (DohBase *) obj;
|
DohBase *b = (DohBase *) obj;
|
||||||
|
DohObjInfo *objinfo;
|
||||||
|
|
||||||
if (!DohCheck(b)) return;
|
if (!DohCheck(b)) return;
|
||||||
if (b->flags & DOH_FLAG_INTERN) return;
|
if (b->flag_intern) return;
|
||||||
b->refcount--;
|
b->refcount--;
|
||||||
if (b->refcount <= 0) {
|
if (b->refcount <= 0) {
|
||||||
if (b->objinfo->doh_del) (b->objinfo->doh_del)(obj);
|
objinfo = dohtypes[b->type];
|
||||||
|
if (objinfo->doh_del) {
|
||||||
|
(objinfo->doh_del)(b);
|
||||||
|
} else {
|
||||||
|
if (b->data) DohFree(b->data);
|
||||||
|
}
|
||||||
|
DohObjFree(b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
|
||||||
* DohIntern()
|
|
||||||
* ----------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
void
|
|
||||||
DohIntern(DOH *obj) {
|
|
||||||
DohBase *b = (DohBase *) obj;
|
|
||||||
b->flags = b->flags | DOH_FLAG_INTERN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* DohCopy()
|
* DohCopy()
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
@ -67,8 +55,10 @@ DohIntern(DOH *obj) {
|
||||||
DOH *
|
DOH *
|
||||||
DohCopy(const DOH *obj) {
|
DohCopy(const DOH *obj) {
|
||||||
DohBase *b = (DohBase *) obj;
|
DohBase *b = (DohBase *) obj;
|
||||||
if (b->objinfo->doh_copy)
|
DohObjInfo *objinfo = dohtypes[b->type];
|
||||||
return (b->objinfo->doh_copy)(b);
|
objinfo = dohtypes[b->type];
|
||||||
|
if (objinfo->doh_copy)
|
||||||
|
return (objinfo->doh_copy)(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
|
|
@ -78,8 +68,9 @@ DohCopy(const DOH *obj) {
|
||||||
void
|
void
|
||||||
DohClear(DOH *obj) {
|
DohClear(DOH *obj) {
|
||||||
DohBase *b = (DohBase *) obj;
|
DohBase *b = (DohBase *) obj;
|
||||||
if (b->objinfo->doh_clear)
|
DohObjInfo *objinfo = dohtypes[b->type];
|
||||||
(b->objinfo->doh_clear)(obj);
|
if (objinfo->doh_clear)
|
||||||
|
(objinfo->doh_clear)(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
|
|
@ -90,11 +81,13 @@ DOH *
|
||||||
DohStr(const DOH *obj) {
|
DohStr(const DOH *obj) {
|
||||||
char buffer[512];
|
char buffer[512];
|
||||||
DohBase *b = (DohBase *) obj;
|
DohBase *b = (DohBase *) obj;
|
||||||
|
DohObjInfo *objinfo;
|
||||||
if (DohCheck(b)) {
|
if (DohCheck(b)) {
|
||||||
if (b->objinfo->doh_str) {
|
objinfo = dohtypes[b->type];
|
||||||
return (b->objinfo->doh_str)(b);
|
if (objinfo->doh_str) {
|
||||||
|
return (objinfo->doh_str)(b);
|
||||||
}
|
}
|
||||||
sprintf(buffer,"<Object '%s' at %x>", b->objinfo->objname, b);
|
sprintf(buffer,"<Object '%s' at %x>", objinfo->objname, b);
|
||||||
return NewString(buffer);
|
return NewString(buffer);
|
||||||
} else {
|
} else {
|
||||||
return NewString(obj);
|
return NewString(obj);
|
||||||
|
|
@ -108,22 +101,25 @@ DohStr(const DOH *obj) {
|
||||||
int
|
int
|
||||||
DohDump(const DOH *obj, DOH *out) {
|
DohDump(const DOH *obj, DOH *out) {
|
||||||
DohBase *b = (DohBase *) obj;
|
DohBase *b = (DohBase *) obj;
|
||||||
if (b->objinfo->doh_dump) {
|
DohObjInfo *objinfo = dohtypes[b->type];
|
||||||
return (b->objinfo->doh_dump)(b,out);
|
if (objinfo->doh_dump) {
|
||||||
|
return (objinfo->doh_dump)(b,out);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* DohLen()
|
* DohLen() - Defaults to strlen() if not a DOH object
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
int
|
int
|
||||||
DohLen(const DOH *obj) {
|
DohLen(const DOH *obj) {
|
||||||
DohBase *b = (DohBase *) obj;
|
DohBase *b = (DohBase *) obj;
|
||||||
|
DohObjInfo *objinfo;
|
||||||
if (!b) return 0;
|
if (!b) return 0;
|
||||||
if (DohCheck(b)) {
|
if (DohCheck(b)) {
|
||||||
if (b->objinfo->doh_len) {
|
objinfo = dohtypes[b->type];
|
||||||
return (b->objinfo->doh_len)(b);
|
if (objinfo->doh_len) {
|
||||||
|
return (objinfo->doh_len)(b);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -138,9 +134,11 @@ DohLen(const DOH *obj) {
|
||||||
int
|
int
|
||||||
DohHashval(const DOH *obj) {
|
DohHashval(const DOH *obj) {
|
||||||
DohBase *b = (DohBase *) obj;
|
DohBase *b = (DohBase *) obj;
|
||||||
|
DohObjInfo *objinfo;
|
||||||
if (DohCheck(b)) {
|
if (DohCheck(b)) {
|
||||||
if (b->objinfo->doh_hash) {
|
objinfo = dohtypes[b->type];
|
||||||
return (b->objinfo->doh_hashval)(b);
|
if (objinfo->doh_hashval) {
|
||||||
|
return (objinfo->doh_hashval)(b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -153,11 +151,11 @@ DohHashval(const DOH *obj) {
|
||||||
void *
|
void *
|
||||||
DohData(const DOH *obj) {
|
DohData(const DOH *obj) {
|
||||||
DohBase *b = (DohBase *) obj;
|
DohBase *b = (DohBase *) obj;
|
||||||
|
DohObjInfo *objinfo;
|
||||||
if (DohCheck(obj)) {
|
if (DohCheck(obj)) {
|
||||||
if (b->objinfo) {
|
objinfo = dohtypes[b->type];
|
||||||
if (b->objinfo->doh_data) {
|
if (objinfo->doh_data) {
|
||||||
return (b->objinfo->doh_data)(b);
|
return (objinfo->doh_data)(b);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -171,26 +169,29 @@ DohData(const DOH *obj) {
|
||||||
int
|
int
|
||||||
DohCmp(const DOH *obj1, const DOH *obj2) {
|
DohCmp(const DOH *obj1, const DOH *obj2) {
|
||||||
DohBase *b1, *b2;
|
DohBase *b1, *b2;
|
||||||
|
DohObjInfo *b1info, *b2info;
|
||||||
b1 = (DohBase *) obj1;
|
b1 = (DohBase *) obj1;
|
||||||
b2 = (DohBase *) obj2;
|
b2 = (DohBase *) obj2;
|
||||||
if ((!DohCheck(b1)) || (!DohCheck(b2))) {
|
if ((!DohCheck(b1)) || (!DohCheck(b2))) {
|
||||||
return strcmp((char *) DohData(b1),(char *) DohData(b2));
|
return strcmp((char *) DohData(b1),(char *) DohData(b2));
|
||||||
}
|
}
|
||||||
if (b1->objinfo->doh_cmp) {
|
b1info = dohtypes[b1->type];
|
||||||
return (b1->objinfo->doh_cmp)(b1,b2);
|
b2info = dohtypes[b2->type];
|
||||||
}
|
if ((b1info == b2info) && (b1info->doh_cmp))
|
||||||
|
return (b1info->doh_cmp)(b1,b2);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* DohIsMapping()
|
* DohIsMapping()
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
int
|
int
|
||||||
DohIsMapping(const DOH *obj) {
|
DohIsMapping(const DOH *obj) {
|
||||||
DohBase *b = (DohBase *) obj;
|
DohBase *b = (DohBase *) obj;
|
||||||
|
DohObjInfo *objinfo;
|
||||||
if (!DohCheck(b)) return 0;
|
if (!DohCheck(b)) return 0;
|
||||||
if (b->objinfo->doh_hash) return 1;
|
objinfo = dohtypes[b->type];
|
||||||
|
if (objinfo->doh_hash) return 1;
|
||||||
else return 0;
|
else return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -201,8 +202,9 @@ DohIsMapping(const DOH *obj) {
|
||||||
DOH *
|
DOH *
|
||||||
DohGetattr(DOH *obj, const DOH *name) {
|
DohGetattr(DOH *obj, const DOH *name) {
|
||||||
DohBase *b = (DohBase *) obj;
|
DohBase *b = (DohBase *) obj;
|
||||||
if (b->objinfo->doh_hash->doh_getattr) {
|
DohObjInfo *objinfo = dohtypes[b->type];
|
||||||
return (b->objinfo->doh_hash->doh_getattr)(b,(DOH *) name);
|
if (objinfo->doh_hash && objinfo->doh_hash->doh_getattr) {
|
||||||
|
return (objinfo->doh_hash->doh_getattr)(b,(DOH *) name);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -214,8 +216,9 @@ DohGetattr(DOH *obj, const DOH *name) {
|
||||||
int
|
int
|
||||||
DohSetattr(DOH *obj, const DOH *name, const DOH *value) {
|
DohSetattr(DOH *obj, const DOH *name, const DOH *value) {
|
||||||
DohBase *b = (DohBase *) obj;
|
DohBase *b = (DohBase *) obj;
|
||||||
if (b->objinfo->doh_hash->doh_setattr) {
|
DohObjInfo *objinfo = dohtypes[b->type];
|
||||||
return (b->objinfo->doh_hash->doh_setattr)(b,(DOH *) name,(DOH *) value);
|
if (objinfo->doh_hash && objinfo->doh_hash->doh_setattr) {
|
||||||
|
return (objinfo->doh_hash->doh_setattr)(b,(DOH *) name,(DOH *) value);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -227,8 +230,9 @@ DohSetattr(DOH *obj, const DOH *name, const DOH *value) {
|
||||||
void
|
void
|
||||||
DohDelattr(DOH *obj, const DOH *name) {
|
DohDelattr(DOH *obj, const DOH *name) {
|
||||||
DohBase *b = (DohBase *) obj;
|
DohBase *b = (DohBase *) obj;
|
||||||
if (b->objinfo->doh_hash->doh_delattr) {
|
DohObjInfo *objinfo = dohtypes[b->type];
|
||||||
(b->objinfo->doh_hash->doh_delattr)(b,(DOH *) name);
|
if (objinfo->doh_hash && objinfo->doh_hash->doh_delattr) {
|
||||||
|
(objinfo->doh_hash->doh_delattr)(b,(DOH *) name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -239,8 +243,9 @@ DohDelattr(DOH *obj, const DOH *name) {
|
||||||
DOH *
|
DOH *
|
||||||
DohFirstkey(DOH *obj) {
|
DohFirstkey(DOH *obj) {
|
||||||
DohBase *b = (DohBase *) obj;
|
DohBase *b = (DohBase *) obj;
|
||||||
if (b->objinfo->doh_hash->doh_firstkey) {
|
DohObjInfo *objinfo = dohtypes[b->type];
|
||||||
return (b->objinfo->doh_hash->doh_firstkey)(obj);
|
if (objinfo->doh_hash && objinfo->doh_hash->doh_firstkey) {
|
||||||
|
return (objinfo->doh_hash->doh_firstkey)(b);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -252,8 +257,9 @@ DohFirstkey(DOH *obj) {
|
||||||
DOH *
|
DOH *
|
||||||
DohNextkey(DOH *obj) {
|
DohNextkey(DOH *obj) {
|
||||||
DohBase *b = (DohBase *) obj;
|
DohBase *b = (DohBase *) obj;
|
||||||
if (b->objinfo->doh_hash->doh_nextkey) {
|
DohObjInfo *objinfo = dohtypes[b->type];
|
||||||
return (b->objinfo->doh_hash->doh_nextkey)(obj);
|
if (objinfo && objinfo->doh_hash->doh_nextkey) {
|
||||||
|
return (objinfo->doh_hash->doh_nextkey)(b);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -345,9 +351,7 @@ DohSetDouble(DOH *obj, const DOH *name, double value) {
|
||||||
|
|
||||||
void
|
void
|
||||||
DohSetChar(DOH *obj, const DOH *name, char *value) {
|
DohSetChar(DOH *obj, const DOH *name, char *value) {
|
||||||
DOH *temp;
|
Setattr(obj,(DOH *) name,NewString(value));
|
||||||
temp = NewString(value);
|
|
||||||
Setattr(obj,(DOH *) name,temp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
|
|
@ -356,9 +360,7 @@ DohSetChar(DOH *obj, const DOH *name, char *value) {
|
||||||
|
|
||||||
void
|
void
|
||||||
DohSetVoid(DOH *obj, const DOH *name, void *value) {
|
DohSetVoid(DOH *obj, const DOH *name, void *value) {
|
||||||
DOH *temp;
|
Setattr(obj,(DOH *) name,NewVoid(value,0));
|
||||||
temp = NewVoid(value,0);
|
|
||||||
Setattr(obj,(DOH *) name,temp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
|
|
@ -368,8 +370,10 @@ DohSetVoid(DOH *obj, const DOH *name, void *value) {
|
||||||
int
|
int
|
||||||
DohIsSequence(const DOH *obj) {
|
DohIsSequence(const DOH *obj) {
|
||||||
DohBase *b = (DohBase *) obj;
|
DohBase *b = (DohBase *) obj;
|
||||||
|
DohObjInfo *objinfo;
|
||||||
if (!DohCheck(b)) return 0;
|
if (!DohCheck(b)) return 0;
|
||||||
if (b->objinfo->doh_list) return 1;
|
objinfo = dohtypes[b->type];
|
||||||
|
if (objinfo->doh_list) return 1;
|
||||||
else return 0;
|
else return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -380,8 +384,9 @@ DohIsSequence(const DOH *obj) {
|
||||||
DOH *
|
DOH *
|
||||||
DohGetitem(DOH *obj, int index) {
|
DohGetitem(DOH *obj, int index) {
|
||||||
DohBase *b = (DohBase *) obj;
|
DohBase *b = (DohBase *) obj;
|
||||||
if (b->objinfo->doh_list->doh_getitem) {
|
DohObjInfo *objinfo = dohtypes[b->type];
|
||||||
return (b->objinfo->doh_list->doh_getitem)(obj,index);
|
if (objinfo->doh_list && objinfo->doh_list->doh_getitem) {
|
||||||
|
return (objinfo->doh_list->doh_getitem)(b,index);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -393,10 +398,11 @@ DohGetitem(DOH *obj, int index) {
|
||||||
int
|
int
|
||||||
DohSetitem(DOH *obj, int index, const DOH *value) {
|
DohSetitem(DOH *obj, int index, const DOH *value) {
|
||||||
DohBase *b = (DohBase *) obj;
|
DohBase *b = (DohBase *) obj;
|
||||||
if (b->objinfo->doh_list->doh_setitem) {
|
DohObjInfo *objinfo = dohtypes[b->type];
|
||||||
return (b->objinfo->doh_list->doh_setitem)(obj,index,(DOH *) value);
|
if (objinfo->doh_list && objinfo->doh_list->doh_setitem) {
|
||||||
|
return (objinfo->doh_list->doh_setitem)(b,index,(DOH *) value);
|
||||||
}
|
}
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
|
|
@ -406,9 +412,11 @@ DohSetitem(DOH *obj, int index, const DOH *value) {
|
||||||
int
|
int
|
||||||
DohDelitem(DOH *obj, int index) {
|
DohDelitem(DOH *obj, int index) {
|
||||||
DohBase *b = (DohBase *) obj;
|
DohBase *b = (DohBase *) obj;
|
||||||
if (b->objinfo->doh_list->doh_delitem) {
|
DohObjInfo *objinfo = dohtypes[b->type];
|
||||||
return (b->objinfo->doh_list->doh_delitem)(obj,index);
|
if (objinfo->doh_list && objinfo->doh_list->doh_delitem) {
|
||||||
|
return (objinfo->doh_list->doh_delitem)(b,index);
|
||||||
}
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
|
|
@ -417,11 +425,12 @@ DohDelitem(DOH *obj, int index) {
|
||||||
|
|
||||||
int
|
int
|
||||||
DohInsertitem(DOH *obj, int index, const DOH *value) {
|
DohInsertitem(DOH *obj, int index, const DOH *value) {
|
||||||
int no = 0;
|
|
||||||
DohBase *b = (DohBase *) obj;
|
DohBase *b = (DohBase *) obj;
|
||||||
if (b->objinfo->doh_list->doh_insitem) {
|
DohObjInfo *objinfo = dohtypes[b->type];
|
||||||
return (b->objinfo->doh_list->doh_insitem)(obj,index,(DOH *) value);
|
if (objinfo->doh_list && objinfo->doh_list->doh_insitem) {
|
||||||
|
return (objinfo->doh_list->doh_insitem)(b,index,(DOH *) value);
|
||||||
}
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
|
|
@ -431,8 +440,9 @@ DohInsertitem(DOH *obj, int index, const DOH *value) {
|
||||||
DOH *
|
DOH *
|
||||||
DohFirstitem(DOH *obj) {
|
DohFirstitem(DOH *obj) {
|
||||||
DohBase *b = (DohBase *) obj;
|
DohBase *b = (DohBase *) obj;
|
||||||
if (b->objinfo->doh_list->doh_firstitem) {
|
DohObjInfo *objinfo = dohtypes[b->type];
|
||||||
return (b->objinfo->doh_list->doh_firstitem)(obj);
|
if (objinfo->doh_list && objinfo->doh_list->doh_firstitem) {
|
||||||
|
return (objinfo->doh_list->doh_firstitem)(b);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -444,8 +454,9 @@ DohFirstitem(DOH *obj) {
|
||||||
DOH *
|
DOH *
|
||||||
DohNextitem(DOH *obj) {
|
DohNextitem(DOH *obj) {
|
||||||
DohBase *b = (DohBase *) obj;
|
DohBase *b = (DohBase *) obj;
|
||||||
if (b->objinfo->doh_list->doh_nextitem) {
|
DohObjInfo *objinfo = dohtypes[b->type];
|
||||||
return (b->objinfo->doh_list->doh_nextitem)(obj);
|
if (objinfo->doh_list && objinfo->doh_list->doh_nextitem) {
|
||||||
|
return (objinfo->doh_list->doh_nextitem)(b);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -457,8 +468,10 @@ DohNextitem(DOH *obj) {
|
||||||
int
|
int
|
||||||
DohIsFile(const DOH *obj) {
|
DohIsFile(const DOH *obj) {
|
||||||
DohBase *b = (DohBase *) obj;
|
DohBase *b = (DohBase *) obj;
|
||||||
|
DohObjInfo *objinfo;
|
||||||
if (!DohCheck(b)) return 0;
|
if (!DohCheck(b)) return 0;
|
||||||
if (b->objinfo->doh_file) return 1;
|
objinfo = dohtypes[b->type];
|
||||||
|
if (objinfo->doh_file) return 1;
|
||||||
else return 0;
|
else return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -469,9 +482,11 @@ DohIsFile(const DOH *obj) {
|
||||||
int
|
int
|
||||||
DohRead(DOH *obj, void *buffer, int length) {
|
DohRead(DOH *obj, void *buffer, int length) {
|
||||||
DohBase *b = (DohBase *) obj;
|
DohBase *b = (DohBase *) obj;
|
||||||
|
DohObjInfo *objinfo;
|
||||||
if (DohCheck(obj)) {
|
if (DohCheck(obj)) {
|
||||||
if ((b->objinfo->doh_file) && (b->objinfo->doh_file->doh_read)) {
|
objinfo = dohtypes[b->type];
|
||||||
return (b->objinfo->doh_file->doh_read)(obj,buffer,length);
|
if ((objinfo->doh_file) && (objinfo->doh_file->doh_read)) {
|
||||||
|
return (objinfo->doh_file->doh_read)(b,buffer,length);
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
@ -486,9 +501,11 @@ DohRead(DOH *obj, void *buffer, int length) {
|
||||||
int
|
int
|
||||||
DohWrite(DOH *obj, void *buffer, int length) {
|
DohWrite(DOH *obj, void *buffer, int length) {
|
||||||
DohBase *b = (DohBase *) obj;
|
DohBase *b = (DohBase *) obj;
|
||||||
|
DohObjInfo *objinfo;
|
||||||
if (DohCheck(obj)) {
|
if (DohCheck(obj)) {
|
||||||
if ((b->objinfo->doh_file) && (b->objinfo->doh_file->doh_write)) {
|
objinfo = dohtypes[b->type];
|
||||||
return (b->objinfo->doh_file->doh_write)(obj,buffer,length);
|
if ((objinfo->doh_file) && (objinfo->doh_file->doh_write)) {
|
||||||
|
return (objinfo->doh_file->doh_write)(b,buffer,length);
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
@ -503,9 +520,11 @@ DohWrite(DOH *obj, void *buffer, int length) {
|
||||||
int
|
int
|
||||||
DohSeek(DOH *obj, long offset, int whence) {
|
DohSeek(DOH *obj, long offset, int whence) {
|
||||||
DohBase *b = (DohBase *) obj;
|
DohBase *b = (DohBase *) obj;
|
||||||
|
DohObjInfo *objinfo;
|
||||||
if (DohCheck(obj)) {
|
if (DohCheck(obj)) {
|
||||||
if ((b->objinfo->doh_file) && (b->objinfo->doh_file->doh_seek)) {
|
objinfo = dohtypes[b->type];
|
||||||
return (b->objinfo->doh_file->doh_seek)(obj,offset,whence);
|
if ((objinfo->doh_file) && (objinfo->doh_file->doh_seek)) {
|
||||||
|
return (objinfo->doh_file->doh_seek)(b,offset,whence);
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
@ -519,9 +538,11 @@ DohSeek(DOH *obj, long offset, int whence) {
|
||||||
long
|
long
|
||||||
DohTell(DOH *obj) {
|
DohTell(DOH *obj) {
|
||||||
DohBase *b = (DohBase *) obj;
|
DohBase *b = (DohBase *) obj;
|
||||||
|
DohObjInfo *objinfo;
|
||||||
if (DohCheck(obj)) {
|
if (DohCheck(obj)) {
|
||||||
if ((b->objinfo->doh_file) && (b->objinfo->doh_file->doh_tell)) {
|
objinfo = dohtypes[b->type];
|
||||||
return (b->objinfo->doh_file->doh_tell)(obj);
|
if ((objinfo->doh_file) && (objinfo->doh_file->doh_tell)) {
|
||||||
|
return (objinfo->doh_file->doh_tell)(b);
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
@ -535,9 +556,11 @@ DohTell(DOH *obj) {
|
||||||
int
|
int
|
||||||
DohGetc(DOH *obj) {
|
DohGetc(DOH *obj) {
|
||||||
DohBase *b = (DohBase *) obj;
|
DohBase *b = (DohBase *) obj;
|
||||||
|
DohObjInfo *objinfo;
|
||||||
if (DohCheck(obj)) {
|
if (DohCheck(obj)) {
|
||||||
if (b->objinfo->doh_file->doh_getc) {
|
objinfo = dohtypes[b->type];
|
||||||
return (b->objinfo->doh_file->doh_getc)(obj);
|
if (objinfo->doh_file->doh_getc) {
|
||||||
|
return (objinfo->doh_file->doh_getc)(b);
|
||||||
}
|
}
|
||||||
return EOF;
|
return EOF;
|
||||||
}
|
}
|
||||||
|
|
@ -551,9 +574,11 @@ DohGetc(DOH *obj) {
|
||||||
int
|
int
|
||||||
DohPutc(int ch, DOH *obj) {
|
DohPutc(int ch, DOH *obj) {
|
||||||
DohBase *b = (DohBase *) obj;
|
DohBase *b = (DohBase *) obj;
|
||||||
|
DohObjInfo *objinfo;
|
||||||
if (DohCheck(obj)) {
|
if (DohCheck(obj)) {
|
||||||
if (b->objinfo->doh_file->doh_putc) {
|
objinfo = dohtypes[b->type];
|
||||||
return (b->objinfo->doh_file->doh_putc)(obj,ch);
|
if (objinfo->doh_file->doh_putc) {
|
||||||
|
return (objinfo->doh_file->doh_putc)(b,ch);
|
||||||
}
|
}
|
||||||
return EOF;
|
return EOF;
|
||||||
}
|
}
|
||||||
|
|
@ -567,9 +592,11 @@ DohPutc(int ch, DOH *obj) {
|
||||||
int
|
int
|
||||||
DohUngetc(int ch, DOH *obj) {
|
DohUngetc(int ch, DOH *obj) {
|
||||||
DohBase *b = (DohBase *) obj;
|
DohBase *b = (DohBase *) obj;
|
||||||
|
DohObjInfo *objinfo;
|
||||||
if (DohCheck(obj)) {
|
if (DohCheck(obj)) {
|
||||||
if (b->objinfo->doh_file->doh_ungetc) {
|
objinfo = dohtypes[b->type];
|
||||||
return (b->objinfo->doh_file->doh_ungetc)(obj,ch);
|
if (objinfo->doh_file->doh_ungetc) {
|
||||||
|
return (objinfo->doh_file->doh_ungetc)(b,ch);
|
||||||
}
|
}
|
||||||
return EOF;
|
return EOF;
|
||||||
}
|
}
|
||||||
|
|
@ -583,9 +610,11 @@ DohUngetc(int ch, DOH *obj) {
|
||||||
int
|
int
|
||||||
DohClose(DOH *obj) {
|
DohClose(DOH *obj) {
|
||||||
DohBase *b = (DohBase *) obj;
|
DohBase *b = (DohBase *) obj;
|
||||||
|
DohObjInfo *objinfo;
|
||||||
if (DohCheck(obj)) {
|
if (DohCheck(obj)) {
|
||||||
if (b->objinfo->doh_file->doh_close) {
|
objinfo = dohtypes[b->type];
|
||||||
return (b->objinfo->doh_file->doh_close)(obj);
|
if (objinfo->doh_file->doh_close) {
|
||||||
|
return (objinfo->doh_file->doh_close)(b);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -599,8 +628,10 @@ DohClose(DOH *obj) {
|
||||||
int
|
int
|
||||||
DohIsString(const DOH *obj) {
|
DohIsString(const DOH *obj) {
|
||||||
DohBase *b = (DohBase *) obj;
|
DohBase *b = (DohBase *) obj;
|
||||||
|
DohObjInfo *objinfo;
|
||||||
if (!DohCheck(b)) return 0;
|
if (!DohCheck(b)) return 0;
|
||||||
if (b->objinfo->doh_string) return 1;
|
objinfo = dohtypes[b->type];
|
||||||
|
if (objinfo->doh_string) return 1;
|
||||||
else return 0;
|
else return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -611,9 +642,11 @@ DohIsString(const DOH *obj) {
|
||||||
int
|
int
|
||||||
DohReplace(DOH *src, const DOH *token, const DOH *rep, int flags) {
|
DohReplace(DOH *src, const DOH *token, const DOH *rep, int flags) {
|
||||||
DohBase *b = (DohBase *) src;
|
DohBase *b = (DohBase *) src;
|
||||||
|
DohObjInfo *objinfo;
|
||||||
if (DohIsString(src)) {
|
if (DohIsString(src)) {
|
||||||
if (b->objinfo->doh_string->doh_replace) {
|
objinfo = dohtypes[b->type];
|
||||||
return (b->objinfo->doh_string->doh_replace)(src,(DOH *) token, (DOH *) rep,flags);
|
if (objinfo->doh_string->doh_replace) {
|
||||||
|
return (objinfo->doh_string->doh_replace)(b,(DOH *) token, (DOH *) rep,flags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -626,37 +659,26 @@ DohReplace(DOH *src, const DOH *token, const DOH *rep, int flags) {
|
||||||
void
|
void
|
||||||
DohChop(DOH *src) {
|
DohChop(DOH *src) {
|
||||||
DohBase *b = (DohBase *) src;
|
DohBase *b = (DohBase *) src;
|
||||||
|
DohObjInfo *objinfo;
|
||||||
if (DohIsString(src)) {
|
if (DohIsString(src)) {
|
||||||
if (b->objinfo->doh_string->doh_chop) {
|
objinfo = dohtypes[b->type];
|
||||||
(b->objinfo->doh_string->doh_chop)(src);
|
if (objinfo->doh_string->doh_chop) {
|
||||||
|
(objinfo->doh_string->doh_chop)(b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
|
||||||
* DohInit()
|
|
||||||
* ----------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
void
|
|
||||||
DohInit(DOH *b) {
|
|
||||||
DohBase *bs = (DohBase *) b;
|
|
||||||
bs->refcount = 1;
|
|
||||||
bs->objinfo = &DohBaseType;
|
|
||||||
bs->flags = 0;
|
|
||||||
bs->file = 0;
|
|
||||||
bs->line = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* DohSetFile()
|
* DohSetFile()
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
void
|
void
|
||||||
DohSetfile(DOH *ho, DOH *file) {
|
DohSetfile(DOH *ho, DOH *file) {
|
||||||
DohBase *h = (DohBase *) ho;
|
DohBase *h = (DohBase *) ho;
|
||||||
|
DohObjInfo *objinfo;
|
||||||
if (!h) return;
|
if (!h) return;
|
||||||
if (!DohCheck(file)) file = NewString(file);
|
objinfo = dohtypes[h->type];
|
||||||
h->file = file;
|
if (objinfo->doh_setfile)
|
||||||
Incref(h->file);
|
(objinfo->doh_setfile)(h,file);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
|
|
@ -664,8 +686,13 @@ DohSetfile(DOH *ho, DOH *file) {
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
DOH *
|
DOH *
|
||||||
DohGetfile(DOH *ho) {
|
DohGetfile(DOH *ho) {
|
||||||
if (!ho) return 0;
|
DohBase *h = (DohBase *) ho;
|
||||||
return ((DohBase *)ho)->file;
|
DohObjInfo *objinfo;
|
||||||
|
if (!h) return;
|
||||||
|
objinfo = dohtypes[h->type];
|
||||||
|
if (objinfo->doh_getfile)
|
||||||
|
return (objinfo->doh_getfile)(h);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
|
|
@ -673,8 +700,12 @@ DohGetfile(DOH *ho) {
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
void
|
void
|
||||||
DohSetline(DOH *ho, int l) {
|
DohSetline(DOH *ho, int l) {
|
||||||
if (!ho) return;
|
DohBase *h = (DohBase *) ho;
|
||||||
((DohBase *) ho)->line = l;
|
DohObjInfo *objinfo;
|
||||||
|
if (!h) return;
|
||||||
|
objinfo = dohtypes[h->type];
|
||||||
|
if (objinfo->doh_setline)
|
||||||
|
(objinfo->doh_setline)(h,l);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
|
|
@ -682,8 +713,13 @@ DohSetline(DOH *ho, int l) {
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
int
|
int
|
||||||
DohGetline(DOH *ho) {
|
DohGetline(DOH *ho) {
|
||||||
if (!ho) return 0;
|
DohBase *h = (DohBase *) ho;
|
||||||
return ((DohBase *)ho)->line;
|
DohObjInfo *objinfo;
|
||||||
|
if (!h) return;
|
||||||
|
objinfo = dohtypes[h->type];
|
||||||
|
if (objinfo->doh_getline)
|
||||||
|
return (objinfo->doh_getline)(h);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,116 +13,81 @@
|
||||||
static char cvsroot[] = "$Header$";
|
static char cvsroot[] = "$Header$";
|
||||||
|
|
||||||
#include "dohint.h"
|
#include "dohint.h"
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
DOHCOMMON;
|
|
||||||
FILE *filep;
|
FILE *filep;
|
||||||
int fd;
|
int closeondel;
|
||||||
int closeondel;
|
|
||||||
} DohFile;
|
} DohFile;
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* DelFile()
|
* DelFile()
|
||||||
*
|
|
||||||
* Delete a file. Closes the file if the closeondel flag is set.
|
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
DelFile(DOH *so) {
|
DelFile(DOH *fo) {
|
||||||
DohFile *f = (DohFile *) so;
|
DohFile *f = (DohFile *) ObjData(fo);
|
||||||
assert(f->refcount <= 0);
|
|
||||||
if (f->closeondel)
|
if (f->closeondel)
|
||||||
fclose(f->filep);
|
fclose(f->filep);
|
||||||
DohObjFree(f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* File_read()
|
* File_read()
|
||||||
*
|
|
||||||
* Reads data from a file into a buffer.
|
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
File_read(DOH *so, void *buffer, int len) {
|
File_read(DOH *fo, void *buffer, int len) {
|
||||||
DohFile *s = (DohFile *) so;
|
DohFile *f = (DohFile *) ObjData(fo);
|
||||||
if (s->filep)
|
return fread(buffer,1,len,f->filep);
|
||||||
return fread(buffer,1,len,s->filep);
|
|
||||||
else
|
|
||||||
return read(s->fd,buffer,len);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* File_write()
|
* File_write()
|
||||||
*
|
|
||||||
* Write data from a buffer to a file.
|
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
File_write(DOH *so, void *buffer, int len) {
|
File_write(DOH *fo, void *buffer, int len) {
|
||||||
DohFile *s = (DohFile *) so;
|
DohFile *f = (DohFile *) ObjData(fo);
|
||||||
if (s->filep)
|
return fwrite(buffer,1,len,f->filep);
|
||||||
return fwrite(buffer,1,len,s->filep);
|
|
||||||
else
|
|
||||||
return write(s->fd, buffer, len);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* File_seek()
|
* File_seek()
|
||||||
*
|
|
||||||
* Seek to a new file position.
|
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
File_seek(DOH *so, long offset, int whence) {
|
File_seek(DOH *fo, long offset, int whence) {
|
||||||
DohFile *s = (DohFile *) so;
|
DohFile *f = (DohFile *) ObjData(fo);
|
||||||
if (s->filep)
|
return fseek(f->filep,offset,whence);
|
||||||
return fseek(s->filep,offset,whence);
|
|
||||||
else
|
|
||||||
return lseek(s->fd,offset,whence);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* File_tell()
|
* File_tell()
|
||||||
*
|
|
||||||
* Return current file pointer.
|
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static long
|
static long
|
||||||
File_tell(DOH *so) {
|
File_tell(DOH *fo) {
|
||||||
DohFile *s = (DohFile *) so;
|
DohFile *f = (DohFile *) ObjData(fo);
|
||||||
if (s->filep)
|
return ftell(f->filep);
|
||||||
return ftell(s->filep);
|
|
||||||
else
|
|
||||||
return lseek(s->fd,0,SEEK_CUR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* File_putc()
|
* File_putc()
|
||||||
*
|
|
||||||
* Put a character on the output
|
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
File_putc(DOH *obj, int ch) {
|
File_putc(DOH *fo, int ch) {
|
||||||
DohFile *s = (DohFile *) obj;
|
DohFile *f = (DohFile *) ObjData(fo);
|
||||||
if (s->filep)
|
return fputc(ch,f->filep);
|
||||||
return fputc(ch,s->filep);
|
|
||||||
return EOF;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* File_getc()
|
* File_getc()
|
||||||
*
|
|
||||||
* Get a character
|
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
File_getc(DOH *obj) {
|
File_getc(DOH *fo) {
|
||||||
DohFile *s = (DohFile *) obj;
|
DohFile *f = (DohFile *) ObjData(fo);
|
||||||
if (s->filep)
|
return fgetc(f->filep);
|
||||||
return fgetc(s->filep);
|
|
||||||
return EOF;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
|
|
@ -132,11 +97,9 @@ File_getc(DOH *obj) {
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
File_ungetc(DOH *obj, int ch) {
|
File_ungetc(DOH *fo, int ch) {
|
||||||
DohFile *s = (DohFile *) obj;
|
DohFile *f = (DohFile *) ObjData(fo);
|
||||||
if (s->filep)
|
return ungetc(ch, f->filep);
|
||||||
return ungetc(ch, s->filep);
|
|
||||||
return EOF;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static DohFileMethods FileFileMethods = {
|
static DohFileMethods FileFileMethods = {
|
||||||
|
|
@ -152,17 +115,19 @@ static DohFileMethods FileFileMethods = {
|
||||||
|
|
||||||
static DohObjInfo DohFileType = {
|
static DohObjInfo DohFileType = {
|
||||||
"DohFile", /* objname */
|
"DohFile", /* objname */
|
||||||
sizeof(DohFile), /* objsize */
|
|
||||||
DelFile, /* doh_del */
|
DelFile, /* doh_del */
|
||||||
0, /* doh_copy */
|
0, /* doh_copy */
|
||||||
0, /* doh_clear */
|
0, /* doh_clear */
|
||||||
0, /* doh_str */
|
0, /* doh_str */
|
||||||
0, /* doh_data */
|
0, /* doh_data */
|
||||||
0, /* doh_dump */
|
0, /* doh_dump */
|
||||||
0, /* doh_load */
|
|
||||||
0, /* doh_len */
|
0, /* doh_len */
|
||||||
0, /* doh_hash */
|
0, /* doh_hash */
|
||||||
0, /* doh_cmp */
|
0, /* doh_cmp */
|
||||||
|
0, /* doh_setfile */
|
||||||
|
0, /* doh_getfile */
|
||||||
|
0, /* doh_setline */
|
||||||
|
0, /* doh_getline */
|
||||||
0, /* doh_mapping */
|
0, /* doh_mapping */
|
||||||
0, /* doh_sequence */
|
0, /* doh_sequence */
|
||||||
&FileFileMethods,/* doh_file */
|
&FileFileMethods,/* doh_file */
|
||||||
|
|
@ -183,21 +148,25 @@ NewFile(DOH *fn, char *mode)
|
||||||
DohFile *f;
|
DohFile *f;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char *filename;
|
char *filename;
|
||||||
|
static int init = 0;
|
||||||
|
|
||||||
|
if (!init) {
|
||||||
|
DohRegisterType(DOHTYPE_FILE, &DohFileType);
|
||||||
|
init = 1;
|
||||||
|
}
|
||||||
|
|
||||||
filename = Char(fn);
|
filename = Char(fn);
|
||||||
file = fopen(filename,mode);
|
file = fopen(filename,mode);
|
||||||
if (!file) return 0;
|
if (!file) return 0;
|
||||||
|
|
||||||
f = (DohFile *) DohObjMalloc(sizeof(DohFile));
|
f = (DohFile *) DohMalloc(sizeof(DohFile));
|
||||||
if (!f) {
|
if (!f) {
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
f->objinfo = &DohFileType;
|
|
||||||
f->filep = file;
|
f->filep = file;
|
||||||
f->fd = fileno(file);
|
|
||||||
f->closeondel = 1;
|
f->closeondel = 1;
|
||||||
return (DOH *) f;
|
return DohObjMalloc(DOHTYPE_FILE,f);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
|
|
@ -210,52 +179,14 @@ DOH *
|
||||||
NewFileFromFile(FILE *file)
|
NewFileFromFile(FILE *file)
|
||||||
{
|
{
|
||||||
DohFile *f;
|
DohFile *f;
|
||||||
f = (DohFile *) DohObjMalloc(sizeof(DohFile));
|
static int init = 0;
|
||||||
|
if (!init) {
|
||||||
|
DohRegisterType(DOHTYPE_FILE, &DohFileType);
|
||||||
|
init = 1;
|
||||||
|
}
|
||||||
|
f = (DohFile *) DohMalloc(sizeof(DohFile));
|
||||||
if (!f) return 0;
|
if (!f) return 0;
|
||||||
f->objinfo = &DohFileType;
|
|
||||||
f->filep = file;
|
f->filep = file;
|
||||||
f->fd = fileno(file);
|
|
||||||
f->closeondel = 0;
|
f->closeondel = 0;
|
||||||
return (DOH *) f;
|
return DohObjMalloc(DOHTYPE_FILE,f);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
|
||||||
* NewFileFromFd()
|
|
||||||
*
|
|
||||||
* Create a file object from an already existing integer file descriptor.
|
|
||||||
* ----------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
DOH *
|
|
||||||
NewFileFromFd(int fd)
|
|
||||||
{
|
|
||||||
DohFile *f;
|
|
||||||
f = (DohFile *) DohObjMalloc(sizeof(DohFile));
|
|
||||||
if (!f) return 0;
|
|
||||||
f->objinfo = &DohFileType;
|
|
||||||
f->filep = 0;
|
|
||||||
f->fd = fd;
|
|
||||||
f->closeondel = 0;
|
|
||||||
return (DOH *) f;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
|
||||||
* File_check()
|
|
||||||
*
|
|
||||||
* Check if an object is a file.
|
|
||||||
* ----------------------------------------------------------------------------- */
|
|
||||||
int
|
|
||||||
File_check(DOH *f)
|
|
||||||
{
|
|
||||||
DohFile *df;
|
|
||||||
if (!DohCheck(f)) return 0;
|
|
||||||
df = (DohFile *) f;
|
|
||||||
if (df->objinfo == &DohFileType) return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -265,7 +265,7 @@ DohvPrintf(DOH *so, const char *format, va_list ap)
|
||||||
doh = va_arg(ap, DOH *);
|
doh = va_arg(ap, DOH *);
|
||||||
if (DohCheck(doh)) {
|
if (DohCheck(doh)) {
|
||||||
/* Is a DOH object. */
|
/* Is a DOH object. */
|
||||||
if (String_check(doh)) {
|
if (DohIsString(doh)) {
|
||||||
Sval = doh;
|
Sval = doh;
|
||||||
} else {
|
} else {
|
||||||
Sval = Str(doh);
|
Sval = Str(doh);
|
||||||
|
|
@ -435,9 +435,11 @@ DohSplit(DOH *in, char *chs, int nsplits) {
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
list = NewList();
|
list = NewList();
|
||||||
if (String_check(in)) {
|
/* if (String_check(in)) {
|
||||||
Seek(in,0,SEEK_SET);
|
Seek(in,0,SEEK_SET);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
str = NewString("");
|
str = NewString("");
|
||||||
do {
|
do {
|
||||||
|
|
|
||||||
|
|
@ -22,12 +22,13 @@ typedef struct HashNode {
|
||||||
|
|
||||||
/* Hash object */
|
/* Hash object */
|
||||||
typedef struct Hash {
|
typedef struct Hash {
|
||||||
DOHCOMMON;
|
DOH *file;
|
||||||
HashNode **hashtable;
|
int line;
|
||||||
int hashsize;
|
HashNode **hashtable;
|
||||||
int currentindex;
|
int hashsize;
|
||||||
int nitems;
|
int currentindex;
|
||||||
HashNode *current;
|
int nitems;
|
||||||
|
HashNode *current;
|
||||||
} Hash;
|
} Hash;
|
||||||
|
|
||||||
/* Key interning structure */
|
/* Key interning structure */
|
||||||
|
|
@ -98,11 +99,10 @@ static void DelNode(HashNode *hn) {
|
||||||
|
|
||||||
static void
|
static void
|
||||||
DelHash(DOH *ho) {
|
DelHash(DOH *ho) {
|
||||||
Hash *h;
|
Hash *h = (Hash *) ObjData(ho);
|
||||||
HashNode *n,*next;
|
HashNode *n,*next;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
h = (Hash *) ho;
|
|
||||||
for (i = 0; i < h->hashsize; i++) {
|
for (i = 0; i < h->hashsize; i++) {
|
||||||
if ((n = h->hashtable[i])) {
|
if ((n = h->hashtable[i])) {
|
||||||
while (n) {
|
while (n) {
|
||||||
|
|
@ -115,7 +115,7 @@ DelHash(DOH *ho) {
|
||||||
DohFree(h->hashtable);
|
DohFree(h->hashtable);
|
||||||
h->hashtable = 0;
|
h->hashtable = 0;
|
||||||
h->hashsize = 0;
|
h->hashsize = 0;
|
||||||
DohObjFree(h);
|
DohFree(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
|
|
@ -126,11 +126,10 @@ DelHash(DOH *ho) {
|
||||||
|
|
||||||
static void
|
static void
|
||||||
Hash_clear(DOH *ho) {
|
Hash_clear(DOH *ho) {
|
||||||
Hash *h;
|
Hash *h = (Hash *) ObjData(ho);
|
||||||
HashNode *n,*next;
|
HashNode *n,*next;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
h = (Hash *) ho;
|
|
||||||
for (i = 0; i < h->hashsize; i++) {
|
for (i = 0; i < h->hashsize; i++) {
|
||||||
if ((n = h->hashtable[i])) {
|
if ((n = h->hashtable[i])) {
|
||||||
while (n) {
|
while (n) {
|
||||||
|
|
@ -199,7 +198,7 @@ static int
|
||||||
Hash_setattr(DOH *ho, DOH *k, DOH *obj) {
|
Hash_setattr(DOH *ho, DOH *k, DOH *obj) {
|
||||||
int hv;
|
int hv;
|
||||||
HashNode *n, *prev;
|
HashNode *n, *prev;
|
||||||
Hash *h;
|
Hash *h = (Hash *) ObjData(ho);
|
||||||
|
|
||||||
if (!obj) return 0;
|
if (!obj) return 0;
|
||||||
if (!DohCheck(k)) k = find_key(k);
|
if (!DohCheck(k)) k = find_key(k);
|
||||||
|
|
@ -207,7 +206,6 @@ Hash_setattr(DOH *ho, DOH *k, DOH *obj) {
|
||||||
obj = NewString((char *) obj);
|
obj = NewString((char *) obj);
|
||||||
Decref(obj);
|
Decref(obj);
|
||||||
}
|
}
|
||||||
h = (Hash *) ho;
|
|
||||||
hv = (Hashval(k)) % h->hashsize;
|
hv = (Hashval(k)) % h->hashsize;
|
||||||
n = h->hashtable[hv];
|
n = h->hashtable[hv];
|
||||||
prev = 0;
|
prev = 0;
|
||||||
|
|
@ -247,10 +245,9 @@ static DOH *
|
||||||
Hash_getattr(DOH *ho, DOH *k) {
|
Hash_getattr(DOH *ho, DOH *k) {
|
||||||
int hv;
|
int hv;
|
||||||
HashNode *n;
|
HashNode *n;
|
||||||
Hash *h;
|
Hash *h = (Hash *) ObjData(ho);
|
||||||
|
|
||||||
if (!DohCheck(k)) k = find_key(k);
|
if (!DohCheck(k)) k = find_key(k);
|
||||||
h = (Hash *) ho;
|
|
||||||
hv = Hashval(k) % h->hashsize;
|
hv = Hashval(k) % h->hashsize;
|
||||||
n = h->hashtable[hv];
|
n = h->hashtable[hv];
|
||||||
while (n) {
|
while (n) {
|
||||||
|
|
@ -270,10 +267,9 @@ static int
|
||||||
Hash_delattr(DOH *ho, DOH *k) {
|
Hash_delattr(DOH *ho, DOH *k) {
|
||||||
HashNode *n, *prev;
|
HashNode *n, *prev;
|
||||||
int hv;
|
int hv;
|
||||||
Hash *h;
|
Hash *h = (Hash *) ObjData(ho);
|
||||||
|
|
||||||
if (!DohCheck(k)) k = find_key(k);
|
if (!DohCheck(k)) k = find_key(k);
|
||||||
h = (Hash *) ho;
|
|
||||||
hv = Hashval(k) % h->hashsize;
|
hv = Hashval(k) % h->hashsize;
|
||||||
n = h->hashtable[hv];
|
n = h->hashtable[hv];
|
||||||
prev = 0;
|
prev = 0;
|
||||||
|
|
@ -298,7 +294,7 @@ Hash_delattr(DOH *ho, DOH *k) {
|
||||||
/* General purpose iterators */
|
/* General purpose iterators */
|
||||||
static HashNode *
|
static HashNode *
|
||||||
hash_first(DOH *ho) {
|
hash_first(DOH *ho) {
|
||||||
Hash *h = (Hash *) ho;
|
Hash *h = (Hash *) ObjData(ho);
|
||||||
h->currentindex = 0;
|
h->currentindex = 0;
|
||||||
h->current = 0;
|
h->current = 0;
|
||||||
while (!h->hashtable[h->currentindex] && (h->currentindex < h->hashsize))
|
while (!h->hashtable[h->currentindex] && (h->currentindex < h->hashsize))
|
||||||
|
|
@ -310,7 +306,7 @@ hash_first(DOH *ho) {
|
||||||
|
|
||||||
static HashNode *
|
static HashNode *
|
||||||
hash_next(DOH *ho) {
|
hash_next(DOH *ho) {
|
||||||
Hash *h = (Hash *) ho;
|
Hash *h = (Hash *) ObjData(ho);
|
||||||
if (h->currentindex < 0) return hash_first(h);
|
if (h->currentindex < 0) return hash_first(h);
|
||||||
|
|
||||||
/* Try to move to the next entry */
|
/* Try to move to the next entry */
|
||||||
|
|
@ -363,15 +359,14 @@ Hash_str(DOH *ho) {
|
||||||
int i;
|
int i;
|
||||||
HashNode *n;
|
HashNode *n;
|
||||||
DOH *s;
|
DOH *s;
|
||||||
Hash *h;
|
Hash *h = (Hash *) ObjData(ho);
|
||||||
|
|
||||||
h = (Hash *) ho;
|
|
||||||
s = NewString("");
|
s = NewString("");
|
||||||
if (h->flags & DOH_FLAG_PRINT) {
|
if (ObjGetMark(ho)) {
|
||||||
Printf(s,"Hash(0x%x)",h);
|
Printf(s,"Hash(0x%x)",ho);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
h->flags = h->flags | DOH_FLAG_PRINT;
|
ObjSetMark(ho,1);
|
||||||
Printf(s,"Hash {\n");
|
Printf(s,"Hash {\n");
|
||||||
for (i = 0; i < h->hashsize; i++) {
|
for (i = 0; i < h->hashsize; i++) {
|
||||||
n = h->hashtable[i];
|
n = h->hashtable[i];
|
||||||
|
|
@ -381,7 +376,7 @@ Hash_str(DOH *ho) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Printf(s,"}\n");
|
Printf(s,"}\n");
|
||||||
h->flags = h->flags & ~DOH_FLAG_PRINT;
|
ObjSetMark(ho,0);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -393,7 +388,7 @@ Hash_str(DOH *ho) {
|
||||||
|
|
||||||
static int
|
static int
|
||||||
Hash_len(DOH *ho) {
|
Hash_len(DOH *ho) {
|
||||||
Hash *h = (Hash *) ho;
|
Hash *h = (Hash *) ObjData(ho);
|
||||||
return h->nitems;
|
return h->nitems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -428,9 +423,8 @@ CopyHash(DOH *ho) {
|
||||||
Hash *h, *nh;
|
Hash *h, *nh;
|
||||||
HashNode *n;
|
HashNode *n;
|
||||||
int i;
|
int i;
|
||||||
h = (Hash *) ho;
|
h = (Hash *) ObjData(ho);
|
||||||
nh = (Hash *) DohObjMalloc(sizeof(Hash));
|
nh = (Hash *) DohMalloc(sizeof(Hash));
|
||||||
nh->objinfo = h->objinfo;
|
|
||||||
nh->hashsize = h->hashsize;
|
nh->hashsize = h->hashsize;
|
||||||
nh->hashtable = (HashNode **) DohMalloc(nh->hashsize*sizeof(HashNode *));
|
nh->hashtable = (HashNode **) DohMalloc(nh->hashsize*sizeof(HashNode *));
|
||||||
for (i = 0; i < nh->hashsize; i++) {
|
for (i = 0; i < nh->hashsize; i++) {
|
||||||
|
|
@ -451,7 +445,7 @@ CopyHash(DOH *ho) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (DOH *) nh;
|
return DohObjMalloc(DOHTYPE_HASH, nh);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
|
|
@ -468,40 +462,27 @@ static DohHashMethods HashHashMethods = {
|
||||||
|
|
||||||
static DohObjInfo HashType = {
|
static DohObjInfo HashType = {
|
||||||
"Hash", /* objname */
|
"Hash", /* objname */
|
||||||
sizeof(Hash), /* size */
|
|
||||||
DelHash, /* doh_del */
|
DelHash, /* doh_del */
|
||||||
CopyHash, /* doh_copy */
|
CopyHash, /* doh_copy */
|
||||||
Hash_clear, /* doh_clear */
|
Hash_clear, /* doh_clear */
|
||||||
Hash_str, /* doh_str */
|
Hash_str, /* doh_str */
|
||||||
0, /* doh_data */
|
0, /* doh_data */
|
||||||
0, /* doh_dump */
|
0, /* doh_dump */
|
||||||
0, /* doh_load */
|
|
||||||
Hash_len, /* doh_len */
|
Hash_len, /* doh_len */
|
||||||
0, /* doh_hash */
|
0, /* doh_hash */
|
||||||
0, /* doh_cmp */
|
0, /* doh_cmp */
|
||||||
|
0, /* doh_setfile */
|
||||||
|
0, /* doh_getfile */
|
||||||
|
0, /* doh_setline */
|
||||||
|
0, /* doh_getline */
|
||||||
&HashHashMethods, /* doh_mapping */
|
&HashHashMethods, /* doh_mapping */
|
||||||
0, /* doh_sequence */
|
0, /* doh_sequence */
|
||||||
0, /* doh_file */
|
0, /* doh_file */
|
||||||
0, /* doh_string */
|
0, /* doh_string */
|
||||||
0, /* doh_callable */
|
|
||||||
0, /* doh_positional */
|
0, /* doh_positional */
|
||||||
|
0,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
|
||||||
* Hash_check()
|
|
||||||
*
|
|
||||||
* Return 1 if an object is a hash table object.
|
|
||||||
* ----------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
int
|
|
||||||
Hash_check(const DOH *so) {
|
|
||||||
Hash *h = (Hash *) so;
|
|
||||||
if (!h) return 0;
|
|
||||||
if (!DohCheck(so)) return 0;
|
|
||||||
if (h->objinfo != &HashType) return 0;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* NewHash()
|
* NewHash()
|
||||||
*
|
*
|
||||||
|
|
@ -512,8 +493,12 @@ DOH *
|
||||||
NewHash() {
|
NewHash() {
|
||||||
Hash *h;
|
Hash *h;
|
||||||
int i;
|
int i;
|
||||||
h = (Hash *) DohObjMalloc(sizeof(Hash));
|
static int init = 0;
|
||||||
h->objinfo = &HashType;
|
if (!init) {
|
||||||
|
DohRegisterType(DOHTYPE_HASH, &HashType);
|
||||||
|
init = 1;
|
||||||
|
}
|
||||||
|
h = (Hash *) DohMalloc(sizeof(Hash));
|
||||||
h->hashsize = HASH_INIT_SIZE;
|
h->hashsize = HASH_INIT_SIZE;
|
||||||
h->hashtable = (HashNode **) DohMalloc(h->hashsize*sizeof(HashNode *));
|
h->hashtable = (HashNode **) DohMalloc(h->hashsize*sizeof(HashNode *));
|
||||||
for (i = 0; i < h->hashsize; i++) {
|
for (i = 0; i < h->hashsize; i++) {
|
||||||
|
|
@ -522,5 +507,7 @@ NewHash() {
|
||||||
h->currentindex = -1;
|
h->currentindex = -1;
|
||||||
h->current = 0;
|
h->current = 0;
|
||||||
h->nitems = 0;
|
h->nitems = 0;
|
||||||
return (DOH *) h;
|
h->file = 0;
|
||||||
|
h->line = 0;
|
||||||
|
return DohObjMalloc(DOHTYPE_HASH,h);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,10 +14,11 @@ static char cvsroot[] = "$Header$";
|
||||||
#include "dohint.h"
|
#include "dohint.h"
|
||||||
|
|
||||||
typedef struct List {
|
typedef struct List {
|
||||||
DOHCOMMON;
|
|
||||||
int maxitems; /* Max size */
|
int maxitems; /* Max size */
|
||||||
int nitems; /* Num items */
|
int nitems; /* Num items */
|
||||||
int iter; /* Iterator */
|
int iter; /* Iterator */
|
||||||
|
DOH *file;
|
||||||
|
int line;
|
||||||
DOH **items;
|
DOH **items;
|
||||||
} List;
|
} List;
|
||||||
|
|
||||||
|
|
@ -38,9 +39,8 @@ static DOH *
|
||||||
CopyList(DOH *lo) {
|
CopyList(DOH *lo) {
|
||||||
List *l,*nl;
|
List *l,*nl;
|
||||||
int i;
|
int i;
|
||||||
l = (List *) lo;
|
l = (List *) ObjData(lo);
|
||||||
nl = (List *) DohObjMalloc(sizeof(List));
|
nl = (List *) DohMalloc(sizeof(List));
|
||||||
nl->objinfo = l->objinfo;
|
|
||||||
nl->nitems = l->nitems;
|
nl->nitems = l->nitems;
|
||||||
nl->maxitems = l->maxitems;
|
nl->maxitems = l->maxitems;
|
||||||
nl->items = (void **) DohMalloc(l->maxitems*sizeof(void *));
|
nl->items = (void **) DohMalloc(l->maxitems*sizeof(void *));
|
||||||
|
|
@ -52,7 +52,7 @@ CopyList(DOH *lo) {
|
||||||
nl->file = l->file;
|
nl->file = l->file;
|
||||||
if (nl->file) Incref(nl->file);
|
if (nl->file) Incref(nl->file);
|
||||||
nl->line = l->line;
|
nl->line = l->line;
|
||||||
return (DOH *) nl;
|
return DohObjMalloc(DOHTYPE_LIST, nl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
|
|
@ -63,13 +63,12 @@ CopyList(DOH *lo) {
|
||||||
|
|
||||||
static void
|
static void
|
||||||
DelList(DOH *lo) {
|
DelList(DOH *lo) {
|
||||||
List *l;
|
List *l = (List *) ObjData(lo);
|
||||||
int i;
|
int i;
|
||||||
l = (List *) lo;
|
|
||||||
for (i = 0; i < l->nitems; i++)
|
for (i = 0; i < l->nitems; i++)
|
||||||
Delete(l->items[i]);
|
Delete(l->items[i]);
|
||||||
DohFree(l->items);
|
DohFree(l->items);
|
||||||
DohObjFree(l);
|
DohFree(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
|
|
@ -80,9 +79,8 @@ DelList(DOH *lo) {
|
||||||
|
|
||||||
static void
|
static void
|
||||||
List_clear(DOH *lo) {
|
List_clear(DOH *lo) {
|
||||||
List *l;
|
List *l = (List *) lo;
|
||||||
int i;
|
int i;
|
||||||
l = (List *) lo;
|
|
||||||
for (i = 0; i < l->nitems; i++) {
|
for (i = 0; i < l->nitems; i++) {
|
||||||
Delete(l->items[i]);
|
Delete(l->items[i]);
|
||||||
}
|
}
|
||||||
|
|
@ -98,18 +96,14 @@ List_clear(DOH *lo) {
|
||||||
|
|
||||||
static int
|
static int
|
||||||
List_insert(DOH *lo, int pos, DOH *item) {
|
List_insert(DOH *lo, int pos, DOH *item) {
|
||||||
List *l;
|
List *l = (List *) ObjData(lo);
|
||||||
DohBase *b;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!item) return -1;
|
if (!item) return -1;
|
||||||
l = (List *) lo;
|
|
||||||
|
|
||||||
if (!DohCheck(item)) {
|
if (!DohCheck(item)) {
|
||||||
item = NewString(item);
|
item = NewString(item);
|
||||||
Decref(item);
|
Decref(item);
|
||||||
}
|
}
|
||||||
b = (DohBase *) item;
|
|
||||||
if (pos == DOH_END) pos = l->nitems;
|
if (pos == DOH_END) pos = l->nitems;
|
||||||
if (pos < 0) pos = 0;
|
if (pos < 0) pos = 0;
|
||||||
if (pos > l->nitems) pos = l->nitems;
|
if (pos > l->nitems) pos = l->nitems;
|
||||||
|
|
@ -118,7 +112,7 @@ List_insert(DOH *lo, int pos, DOH *item) {
|
||||||
l->items[i] = l->items[i-1];
|
l->items[i] = l->items[i-1];
|
||||||
}
|
}
|
||||||
l->items[pos] = item;
|
l->items[pos] = item;
|
||||||
b->refcount++;
|
Incref(item);
|
||||||
l->nitems++;
|
l->nitems++;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -131,9 +125,8 @@ List_insert(DOH *lo, int pos, DOH *item) {
|
||||||
|
|
||||||
static int
|
static int
|
||||||
List_remove(DOH *lo, int pos) {
|
List_remove(DOH *lo, int pos) {
|
||||||
List *l;
|
List *l = (List *) ObjData(lo);
|
||||||
int i;
|
int i;
|
||||||
l = (List *) lo;
|
|
||||||
if (pos == DOH_END) pos = l->nitems-1;
|
if (pos == DOH_END) pos = l->nitems-1;
|
||||||
if (pos == DOH_BEGIN) pos = 0;
|
if (pos == DOH_BEGIN) pos = 0;
|
||||||
assert((pos < 0) || (pos >= l->nitems));
|
assert((pos < 0) || (pos >= l->nitems));
|
||||||
|
|
@ -153,7 +146,8 @@ List_remove(DOH *lo, int pos) {
|
||||||
|
|
||||||
static int
|
static int
|
||||||
List_len(DOH *lo) {
|
List_len(DOH *lo) {
|
||||||
return ((List *) lo)->nitems;
|
List *l = (List *) ObjData(lo);
|
||||||
|
return l->nitems;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
|
|
@ -164,8 +158,7 @@ List_len(DOH *lo) {
|
||||||
|
|
||||||
static DOH *
|
static DOH *
|
||||||
List_get(DOH *lo, int n) {
|
List_get(DOH *lo, int n) {
|
||||||
List *l;
|
List *l = (List *) ObjData(lo);
|
||||||
l = (List *) lo;
|
|
||||||
if (n == DOH_END) n = l->nitems-1;
|
if (n == DOH_END) n = l->nitems-1;
|
||||||
if (n == DOH_BEGIN) n = 0;
|
if (n == DOH_BEGIN) n = 0;
|
||||||
assert((n < 0) || (n >= l->nitems));
|
assert((n < 0) || (n >= l->nitems));
|
||||||
|
|
@ -180,8 +173,7 @@ List_get(DOH *lo, int n) {
|
||||||
|
|
||||||
static int
|
static int
|
||||||
List_set(DOH *lo, int n, DOH *val) {
|
List_set(DOH *lo, int n, DOH *val) {
|
||||||
List *l;
|
List *l = (List *) ObjData(lo);
|
||||||
l = (List *) lo;
|
|
||||||
if (!val) return -1;
|
if (!val) return -1;
|
||||||
assert((n < 0) || (n >= l->nitems));
|
assert((n < 0) || (n >= l->nitems));
|
||||||
if (!DohCheck(val)) {
|
if (!DohCheck(val)) {
|
||||||
|
|
@ -203,8 +195,7 @@ List_set(DOH *lo, int n, DOH *val) {
|
||||||
|
|
||||||
static DOH *
|
static DOH *
|
||||||
List_first(DOH *lo) {
|
List_first(DOH *lo) {
|
||||||
List *l;
|
List *l = (List *) ObjData(lo);
|
||||||
l = (List *) lo;
|
|
||||||
l->iter = 0;
|
l->iter = 0;
|
||||||
if (l->iter >= l->nitems) return 0;
|
if (l->iter >= l->nitems) return 0;
|
||||||
return l->items[l->iter];
|
return l->items[l->iter];
|
||||||
|
|
@ -218,8 +209,7 @@ List_first(DOH *lo) {
|
||||||
|
|
||||||
static DOH *
|
static DOH *
|
||||||
List_next(DOH *lo) {
|
List_next(DOH *lo) {
|
||||||
List *l;
|
List *l = (List *) ObjData(lo);
|
||||||
l = (List *) lo;
|
|
||||||
l->iter++;
|
l->iter++;
|
||||||
if (l->iter >= l->nitems) return 0;
|
if (l->iter >= l->nitems) return 0;
|
||||||
return l->items[l->iter];
|
return l->items[l->iter];
|
||||||
|
|
@ -228,20 +218,19 @@ List_next(DOH *lo) {
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* List_str()
|
* List_str()
|
||||||
*
|
*
|
||||||
* Create a string representation of the list
|
* Create a string representation of the list.
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
static DOH *
|
static DOH *
|
||||||
List_str(DOH *lo) {
|
List_str(DOH *lo) {
|
||||||
DOH *s;
|
DOH *s;
|
||||||
int i;
|
int i;
|
||||||
|
List *l = (List *) ObjData(lo);
|
||||||
List *l = (List *) lo;
|
|
||||||
s = NewString("");
|
s = NewString("");
|
||||||
if (l->flags & DOH_FLAG_PRINT) {
|
if (ObjGetMark(lo)) {
|
||||||
Printf(s,"List(0x%x)",l);
|
Printf(s,"List(%x)", lo);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
l->flags = l->flags | DOH_FLAG_PRINT;
|
ObjSetMark(lo,1);
|
||||||
Printf(s,"List[ ");
|
Printf(s,"List[ ");
|
||||||
for (i = 0; i < l->nitems; i++) {
|
for (i = 0; i < l->nitems; i++) {
|
||||||
Printf(s, "%s", l->items[i]);
|
Printf(s, "%s", l->items[i]);
|
||||||
|
|
@ -249,7 +238,7 @@ List_str(DOH *lo) {
|
||||||
Printf(s,", ");
|
Printf(s,", ");
|
||||||
}
|
}
|
||||||
Printf(s," ]\n");
|
Printf(s," ]\n");
|
||||||
l->flags = l->flags & ~DOH_FLAG_PRINT;
|
ObjSetMark(lo,0);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -263,7 +252,7 @@ static int
|
||||||
List_dump(DOH *lo, DOH *out) {
|
List_dump(DOH *lo, DOH *out) {
|
||||||
int nsent = 0;
|
int nsent = 0;
|
||||||
int i,ret;
|
int i,ret;
|
||||||
List *l = (List *) lo;
|
List *l = (List *) ObjData(lo);
|
||||||
for (i = 0; i < l->nitems; i++) {
|
for (i = 0; i < l->nitems; i++) {
|
||||||
ret = Dump(l->items[i],out);
|
ret = Dump(l->items[i],out);
|
||||||
if (ret < 0) return -1;
|
if (ret < 0) return -1;
|
||||||
|
|
@ -272,80 +261,12 @@ List_dump(DOH *lo, DOH *out) {
|
||||||
return nsent;
|
return nsent;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MAXLISTITEMS 8
|
|
||||||
|
|
||||||
static DohListMethods ListListMethods = {
|
|
||||||
List_get,
|
|
||||||
List_set,
|
|
||||||
List_remove,
|
|
||||||
List_insert,
|
|
||||||
List_first,
|
|
||||||
List_next,
|
|
||||||
};
|
|
||||||
|
|
||||||
static DohObjInfo ListType = {
|
|
||||||
"List", /* objname */
|
|
||||||
sizeof(List), /* List size */
|
|
||||||
DelList, /* doh_del */
|
|
||||||
CopyList, /* doh_copy */
|
|
||||||
List_clear, /* doh_clear */
|
|
||||||
List_str, /* doh_str */
|
|
||||||
0, /* doh_data */
|
|
||||||
List_dump, /* doh_dump */
|
|
||||||
0, /* doh_load */
|
|
||||||
List_len, /* doh_len */
|
|
||||||
0, /* doh_hash */
|
|
||||||
0, /* doh_cmp */
|
|
||||||
0, /* doh_mapping */
|
|
||||||
&ListListMethods, /* doh_sequence */
|
|
||||||
0, /* doh_file */
|
|
||||||
0, /* doh_string */
|
|
||||||
0, /* doh_callable */
|
|
||||||
0, /* doh_position */
|
|
||||||
};
|
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
|
||||||
* List_check()
|
|
||||||
*
|
|
||||||
* Return 1 if an object is a List object.
|
|
||||||
* ----------------------------------------------------------------------------- */
|
|
||||||
int
|
|
||||||
List_check(const DOH *lo) {
|
|
||||||
List *l = (List *) lo;
|
|
||||||
if (!l) return 0;
|
|
||||||
if (!DohCheck(lo)) return 0;
|
|
||||||
if (l->objinfo != &ListType) return 0;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
|
||||||
* NewList()
|
|
||||||
*
|
|
||||||
* Create a new list.
|
|
||||||
* ----------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
DOH *
|
|
||||||
NewList() {
|
|
||||||
List *l;
|
|
||||||
int i;
|
|
||||||
l = (List *) DohObjMalloc(sizeof(List));
|
|
||||||
l->objinfo = &ListType;
|
|
||||||
l->nitems = 0;
|
|
||||||
l->maxitems = MAXLISTITEMS;
|
|
||||||
l->items = (void **) DohMalloc(l->maxitems*sizeof(void *));
|
|
||||||
for (i = 0; i < MAXLISTITEMS; i++) {
|
|
||||||
l->items[i] = 0;
|
|
||||||
}
|
|
||||||
l->iter = 0;
|
|
||||||
return (DOH *) l;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* List_sort()
|
* List_sort()
|
||||||
*
|
|
||||||
* Sorts a list
|
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
static int objcmp(const void *s1, const void *s2) {
|
static int objcmp(const void *s1, const void *s2) {
|
||||||
DOH **so1, **so2;
|
DOH **so1, **so2;
|
||||||
so1 = (DOH **) s1;
|
so1 = (DOH **) s1;
|
||||||
|
|
@ -354,9 +275,72 @@ static int objcmp(const void *s1, const void *s2) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
List_sort(DOH *so) {
|
List_sort(DOH *lo, int opt) {
|
||||||
List *l;
|
List *l = (List *) ObjData(lo);
|
||||||
if (!List_check(so)) return;
|
qsort(l->items,l->nitems,sizeof(DOH *),objcmp);
|
||||||
l = (List *) so;
|
}
|
||||||
qsort(l->items,l->nitems,sizeof(DOH *), objcmp);
|
|
||||||
|
|
||||||
|
|
||||||
|
static DohListMethods ListListMethods = {
|
||||||
|
List_get,
|
||||||
|
List_set,
|
||||||
|
List_remove,
|
||||||
|
List_insert,
|
||||||
|
List_first,
|
||||||
|
List_next,
|
||||||
|
List_sort
|
||||||
|
};
|
||||||
|
|
||||||
|
static DohObjInfo ListType = {
|
||||||
|
"List", /* objname */
|
||||||
|
DelList, /* doh_del */
|
||||||
|
CopyList, /* doh_copy */
|
||||||
|
List_clear, /* doh_clear */
|
||||||
|
List_str, /* doh_str */
|
||||||
|
0, /* doh_data */
|
||||||
|
List_dump, /* doh_dump */
|
||||||
|
List_len, /* doh_len */
|
||||||
|
0, /* doh_hash */
|
||||||
|
0, /* doh_cmp */
|
||||||
|
0, /* doh_setfile */
|
||||||
|
0, /* doh_getfile */
|
||||||
|
0, /* doh_setline */
|
||||||
|
0, /* doh_getline */
|
||||||
|
0, /* doh_mapping */
|
||||||
|
&ListListMethods, /* doh_sequence */
|
||||||
|
0, /* doh_file */
|
||||||
|
0, /* doh_string */
|
||||||
|
0, /* doh_callable */
|
||||||
|
0, /* doh_position */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* NewList()
|
||||||
|
*
|
||||||
|
* Create a new list.
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
#define MAXLISTITEMS 8
|
||||||
|
|
||||||
|
DOH *
|
||||||
|
NewList() {
|
||||||
|
List *l;
|
||||||
|
int i;
|
||||||
|
static int init = 0;
|
||||||
|
if (!init) {
|
||||||
|
DohRegisterType(DOHTYPE_LIST, &ListType);
|
||||||
|
init = 1;
|
||||||
|
}
|
||||||
|
l = (List *) DohMalloc(sizeof(List));
|
||||||
|
l->nitems = 0;
|
||||||
|
l->maxitems = MAXLISTITEMS;
|
||||||
|
l->items = (void **) DohMalloc(l->maxitems*sizeof(void *));
|
||||||
|
for (i = 0; i < MAXLISTITEMS; i++) {
|
||||||
|
l->items[i] = 0;
|
||||||
|
}
|
||||||
|
l->iter = 0;
|
||||||
|
l->file = 0;
|
||||||
|
l->line = 0;
|
||||||
|
return DohObjMalloc(DOHTYPE_LIST,l);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,25 +15,22 @@ static char cvsroot[] = "$Header$";
|
||||||
#include "dohint.h"
|
#include "dohint.h"
|
||||||
|
|
||||||
#ifndef DOH_POOL_SIZE
|
#ifndef DOH_POOL_SIZE
|
||||||
#define DOH_POOL_SIZE 128000
|
#define DOH_POOL_SIZE 16384
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef DOH_MAX_FRAG
|
|
||||||
#define DOH_MAX_FRAG 1024
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int PoolSize = DOH_POOL_SIZE;
|
static int PoolSize = DOH_POOL_SIZE;
|
||||||
|
|
||||||
DOH *DohNone = 0; /* The DOH None object */
|
DOH *DohNone = 0; /* The DOH None object */
|
||||||
|
|
||||||
static DohBase *FreeFragments[DOH_MAX_FRAG]; /* Array of free memory fragments */
|
|
||||||
|
|
||||||
typedef struct pool {
|
typedef struct pool {
|
||||||
char *ptr; /* Start of pool */
|
DohBase *ptr; /* Start of pool */
|
||||||
int len; /* Length of pool */
|
int len; /* Length of pool */
|
||||||
int current; /* Current position for next allocation */
|
int current; /* Current position for next allocation */
|
||||||
struct pool *next; /* Next pool */
|
struct pool *next; /* Next pool */
|
||||||
} Pool;
|
} Pool;
|
||||||
|
|
||||||
|
DohBase *FreeList = 0; /* List of free objects */
|
||||||
|
|
||||||
static Pool *Pools = 0;
|
static Pool *Pools = 0;
|
||||||
static int pools_initialized = 0;
|
static int pools_initialized = 0;
|
||||||
|
|
||||||
|
|
@ -41,18 +38,15 @@ static int pools_initialized = 0;
|
||||||
* CreatePool() - Create a new memory pool
|
* CreatePool() - Create a new memory pool
|
||||||
* ---------------------------------------------------------------------- */
|
* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
static Pool *
|
static void
|
||||||
CreatePool(int size) {
|
CreatePool() {
|
||||||
Pool *p = 0;
|
Pool *p = 0;
|
||||||
char *c;
|
assert((p = (Pool *) DohMalloc(sizeof(Pool))));
|
||||||
c = (char *) DohMalloc(size);
|
assert((p->ptr = (DohBase *) DohMalloc(sizeof(DohBase)*PoolSize)));
|
||||||
if (!c) return 0;
|
p->len = PoolSize;
|
||||||
p = (Pool *) DohMalloc(sizeof(Pool));
|
|
||||||
p->ptr = c;
|
|
||||||
p->len = size;
|
|
||||||
p->current = 0;
|
p->current = 0;
|
||||||
p->next = 0;
|
p->next = Pools;
|
||||||
return p;
|
Pools = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
|
|
@ -63,10 +57,7 @@ static void
|
||||||
InitPools() {
|
InitPools() {
|
||||||
int i;
|
int i;
|
||||||
if (pools_initialized) return;
|
if (pools_initialized) return;
|
||||||
for (i = 0; i < DOH_MAX_FRAG; i++) {
|
CreatePool(); /* Create initial pool */
|
||||||
FreeFragments[i] = 0;
|
|
||||||
}
|
|
||||||
Pools = CreatePool(PoolSize); /* Create initial pool */
|
|
||||||
pools_initialized = 1;
|
pools_initialized = 1;
|
||||||
DohNone = NewVoid(0,0); /* Create the None object */
|
DohNone = NewVoid(0,0); /* Create the None object */
|
||||||
DohIntern(DohNone);
|
DohIntern(DohNone);
|
||||||
|
|
@ -78,59 +69,54 @@ InitPools() {
|
||||||
* Returns 1 if an arbitrary pointer is a DOH object.
|
* Returns 1 if an arbitrary pointer is a DOH object.
|
||||||
* ---------------------------------------------------------------------- */
|
* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
/* Possible optimization: Reorder pools to move last match to the beginning */
|
|
||||||
int
|
int
|
||||||
DohCheck(const DOH *ptr) {
|
DohCheck(const DOH *ptr) {
|
||||||
Pool *p = Pools;
|
Pool *p = Pools;
|
||||||
char *cptr = (char *) ptr;
|
char *cptr = (char *) ptr;
|
||||||
while (p) {
|
while (p) {
|
||||||
if ((cptr >= p->ptr) && (cptr < p->ptr+p->current)) {
|
if ((cptr >= (char *) p->ptr) && (cptr < ((char *) p->ptr)+(p->current*sizeof(DohBase)))) return 1;
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
p = p->next;
|
p = p->next;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -----------------------------------------------------------------------------
|
||||||
|
* DohIntern()
|
||||||
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
void
|
||||||
|
DohIntern(DOH *obj) {
|
||||||
|
DohBase *b = (DohBase *) obj;
|
||||||
|
b->flag_intern = 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
* DohObjMalloc()
|
* DohObjMalloc()
|
||||||
*
|
*
|
||||||
* Allocate memory for a new object.
|
* Allocate memory for a new object.
|
||||||
* ---------------------------------------------------------------------- */
|
* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
void *
|
DOH *
|
||||||
DohObjMalloc(size_t size) {
|
DohObjMalloc(int type, void *data) {
|
||||||
Pool *p;
|
DohBase *obj;
|
||||||
DohBase *f;
|
|
||||||
void *ptr = 0;
|
|
||||||
|
|
||||||
if (size > DOH_MAX_FRAG) return 0;
|
|
||||||
if (!pools_initialized) InitPools();
|
if (!pools_initialized) InitPools();
|
||||||
|
if (FreeList) {
|
||||||
/* adjust the size for double word alignment */
|
obj = FreeList;
|
||||||
size = (size + 7) & ~0x07;
|
FreeList = (DohBase *) obj->data;
|
||||||
|
} else {
|
||||||
p = Pools;
|
while (Pools->current == Pools->len) {
|
||||||
f = FreeFragments[size];
|
PoolSize *= 2;
|
||||||
if (f) {
|
CreatePool();
|
||||||
ptr = (void *) f;
|
}
|
||||||
FreeFragments[size] = (DohBase *) f->file;
|
obj = Pools->ptr + Pools->current;
|
||||||
DohInit(ptr);
|
Pools->current++;
|
||||||
return ptr;
|
|
||||||
}
|
}
|
||||||
|
obj->type = type;
|
||||||
/* No free fragments. See if the pool is large enough */
|
obj->data = data;
|
||||||
if ((int) size < (p->len - p->current)) {
|
obj->refcount = 1;
|
||||||
ptr = (void *) (p->ptr + p->current);
|
obj->flag_intern = 0;
|
||||||
p->current = p->current + size;
|
obj->flag_marked = 0;
|
||||||
DohInit(ptr);
|
return (DOH *) obj;
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
PoolSize *= 2;
|
|
||||||
p = CreatePool(PoolSize);
|
|
||||||
p->next = Pools;
|
|
||||||
Pools = p;
|
|
||||||
return DohObjMalloc(size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
|
|
@ -140,13 +126,9 @@ DohObjMalloc(size_t size) {
|
||||||
void
|
void
|
||||||
DohObjFree(DOH *ptr) {
|
DohObjFree(DOH *ptr) {
|
||||||
DohBase *b;
|
DohBase *b;
|
||||||
int len;
|
|
||||||
b = (DohBase *) ptr;
|
b = (DohBase *) ptr;
|
||||||
if (b->flags & DOH_FLAG_INTERN) return;
|
if (b->flag_intern) return;
|
||||||
if (b->file) DohDelete(b->file);
|
b->data = (void *) FreeList;
|
||||||
len = (b->objinfo->objsize + 7) & ~0x07;
|
b->type = 0;
|
||||||
b->file = (DOH *) FreeFragments[len];
|
FreeList = b;
|
||||||
FreeFragments[len] = b;
|
|
||||||
b->objinfo = 0;
|
|
||||||
b->flags = b->flags | DOH_FLAG_DELETED;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -15,7 +15,6 @@ static char cvsroot[] = "$Header$";
|
||||||
#include "dohint.h"
|
#include "dohint.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
DOHCOMMON;
|
|
||||||
void *ptr;
|
void *ptr;
|
||||||
void (*del)(void *);
|
void (*del)(void *);
|
||||||
} VoidObj;
|
} VoidObj;
|
||||||
|
|
@ -28,11 +27,10 @@ typedef struct {
|
||||||
|
|
||||||
static void
|
static void
|
||||||
Void_delete(DOH *vo) {
|
Void_delete(DOH *vo) {
|
||||||
VoidObj *v = (VoidObj *) vo;
|
VoidObj *v = (VoidObj *) ObjData(vo);
|
||||||
if (v->del)
|
if (v->del)
|
||||||
(*v->del)(v->ptr);
|
(*v->del)(v->ptr);
|
||||||
v->del = 0;
|
DohFree(v);
|
||||||
DohObjFree(v);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
|
|
@ -44,7 +42,7 @@ Void_delete(DOH *vo) {
|
||||||
|
|
||||||
static DOH *
|
static DOH *
|
||||||
Void_copy(DOH *vo) {
|
Void_copy(DOH *vo) {
|
||||||
VoidObj *v = (VoidObj *) vo;
|
VoidObj *v = (VoidObj *) ObjData(vo);
|
||||||
return NewVoid(v->ptr,0);
|
return NewVoid(v->ptr,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,29 +54,31 @@ Void_copy(DOH *vo) {
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
Void_data(DOH *vo) {
|
Void_data(DOH *vo) {
|
||||||
VoidObj *v = (VoidObj *) vo;
|
VoidObj *v = (VoidObj *) ObjData(vo);
|
||||||
return v->ptr;
|
return v->ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static DohObjInfo DohVoidType = {
|
static DohObjInfo DohVoidType = {
|
||||||
"VoidObj", /* objname */
|
"VoidObj", /* objname */
|
||||||
sizeof(VoidObj), /* objsize */
|
|
||||||
Void_delete, /* doh_del */
|
Void_delete, /* doh_del */
|
||||||
Void_copy, /* doh_copy */
|
Void_copy, /* doh_copy */
|
||||||
0, /* doh_clear */
|
0, /* doh_clear */
|
||||||
0, /* doh_str */
|
0, /* doh_str */
|
||||||
Void_data, /* doh_data */
|
Void_data, /* doh_data */
|
||||||
0, /* doh_dump */
|
0, /* doh_dump */
|
||||||
0, /* doh_load */
|
|
||||||
0, /* doh_len */
|
0, /* doh_len */
|
||||||
0, /* doh_hash */
|
0, /* doh_hash */
|
||||||
0, /* doh_cmp */
|
0, /* doh_cmp */
|
||||||
|
0, /* doh_setfile */
|
||||||
|
0, /* doh_getfile */
|
||||||
|
0, /* doh_setline */
|
||||||
|
0, /* doh_getline */
|
||||||
0, /* doh_mapping */
|
0, /* doh_mapping */
|
||||||
0, /* doh_sequence */
|
0, /* doh_sequence */
|
||||||
0, /* doh_file */
|
0, /* doh_file */
|
||||||
0, /* doh_string */
|
0, /* doh_string */
|
||||||
0, /* doh_reserved1 */
|
0, /* doh_reserved */
|
||||||
0, /* doh_reserved2 */
|
0, /* clientdata */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
|
|
@ -89,10 +89,14 @@ static DohObjInfo DohVoidType = {
|
||||||
|
|
||||||
DOH *
|
DOH *
|
||||||
NewVoid(void *obj, void (*del)(void *)) {
|
NewVoid(void *obj, void (*del)(void *)) {
|
||||||
|
static int init = 0;
|
||||||
VoidObj *v;
|
VoidObj *v;
|
||||||
v = (VoidObj *) DohObjMalloc(sizeof(VoidObj));
|
if (!init) {
|
||||||
v->objinfo = &DohVoidType;
|
DohRegisterType(DOHTYPE_VOID, &DohVoidType);
|
||||||
|
init = 1;
|
||||||
|
}
|
||||||
|
v = (VoidObj *) DohMalloc(sizeof(VoidObj));
|
||||||
v->ptr = obj;
|
v->ptr = obj;
|
||||||
v->del = del;
|
v->del = del;
|
||||||
return (DOH *) v;
|
return DohObjMalloc(DOHTYPE_VOID,v);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,6 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define DOH_MAJOR_VERSION 0
|
#define DOH_MAJOR_VERSION 0
|
||||||
#define DOH_MINOR_VERSION 1
|
#define DOH_MINOR_VERSION 1
|
||||||
|
|
||||||
|
|
@ -40,89 +36,10 @@ typedef void DOH;
|
||||||
#define DOHString_or_char DOH
|
#define DOHString_or_char DOH
|
||||||
#define DOHObj_or_char DOH
|
#define DOHObj_or_char DOH
|
||||||
|
|
||||||
#define DOH_BEGIN -1
|
#define DOH_BEGIN -1
|
||||||
#define DOH_END -2
|
#define DOH_END -2
|
||||||
#define DOH_CUR -3
|
#define DOH_CUR -3
|
||||||
#define DOH_CURRENT -3
|
#define DOH_CURRENT -3
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
|
||||||
* These structures define the interface to various categories of objects.
|
|
||||||
* ----------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
/* Hash objects */
|
|
||||||
typedef struct {
|
|
||||||
DOH *(*doh_getattr)(DOH *obj, DOH *name); /* Get attribute */
|
|
||||||
int (*doh_setattr)(DOH *obj, DOH *name, DOH *value); /* Set attribute */
|
|
||||||
int (*doh_delattr)(DOH *obj, DOH *name); /* Del attribute */
|
|
||||||
DOH *(*doh_firstkey)(DOH *obj); /* First key */
|
|
||||||
DOH *(*doh_nextkey)(DOH *obj); /* Next key */
|
|
||||||
} DohHashMethods;
|
|
||||||
|
|
||||||
/* List objects */
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
DOH *(*doh_getitem)(DOH *obj, int index); /* Get item */
|
|
||||||
int (*doh_setitem)(DOH *obj, int index, DOH *value); /* Set item */
|
|
||||||
int (*doh_delitem)(DOH *obj, int index); /* Delete item */
|
|
||||||
int (*doh_insitem)(DOH *obj, int index, DOH *value); /* Insert item */
|
|
||||||
DOH *(*doh_firstitem)(DOH *obj); /* Iterators */
|
|
||||||
DOH *(*doh_nextitem)(DOH *obj);
|
|
||||||
} DohListMethods;
|
|
||||||
|
|
||||||
/* File methods */
|
|
||||||
typedef struct {
|
|
||||||
int (*doh_read)(DOH *obj, void *buffer, int nbytes); /* Read bytes */
|
|
||||||
int (*doh_write)(DOH *obj, void *buffer, int nbytes); /* Write bytes */
|
|
||||||
int (*doh_putc)(DOH *obj, int ch); /* Put character */
|
|
||||||
int (*doh_getc)(DOH *obj); /* Get character */
|
|
||||||
int (*doh_ungetc)(DOH *obj, int ch); /* Unget character */
|
|
||||||
int (*doh_seek)(DOH *obj, long offset, int whence); /* Seek */
|
|
||||||
long (*doh_tell)(DOH *obj); /* Tell */
|
|
||||||
int (*doh_close)(DOH *obj); /* Close */
|
|
||||||
} DohFileMethods;
|
|
||||||
|
|
||||||
/* String methods */
|
|
||||||
typedef struct {
|
|
||||||
int (*doh_replace)(DOH *obj, DOH *old, DOH *rep, int flags);
|
|
||||||
void (*doh_chop)(DOH *obj);
|
|
||||||
} DohStringMethods;
|
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
|
||||||
* DohObjInfo
|
|
||||||
*
|
|
||||||
* A pointer to this structure is included in all DOH types and is used to
|
|
||||||
* describe the properties of various objects.
|
|
||||||
* ----------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
typedef struct DohObjInfo {
|
|
||||||
char *objname; /* Object name */
|
|
||||||
int objsize; /* Object size */
|
|
||||||
|
|
||||||
/* Basic object methods */
|
|
||||||
void (*doh_del)(DOH *obj); /* Delete object */
|
|
||||||
DOH *(*doh_copy)(DOH *obj); /* Copy and object */
|
|
||||||
void (*doh_clear)(DOH *obj); /* Clear an object */
|
|
||||||
|
|
||||||
/* Output methods */
|
|
||||||
DOH *(*doh_str)(DOH *obj); /* Make a full string */
|
|
||||||
void *(*doh_data)(DOH *obj); /* Return raw data */
|
|
||||||
int (*doh_dump)(DOH *obj, DOH *out); /* Serialize on out */
|
|
||||||
DOH *(*doh_load)(DOH *in); /* Unserialize from in */
|
|
||||||
|
|
||||||
/* Length and hash values */
|
|
||||||
int (*doh_len)(DOH *obj);
|
|
||||||
int (*doh_hashval)(DOH *obj);
|
|
||||||
|
|
||||||
/* Compare */
|
|
||||||
int (*doh_cmp)(DOH *obj1, DOH *obj2);
|
|
||||||
|
|
||||||
DohHashMethods *doh_hash; /* Hash methods */
|
|
||||||
DohListMethods *doh_list; /* List methods */
|
|
||||||
DohFileMethods *doh_file; /* File methods */
|
|
||||||
DohStringMethods *doh_string; /* String methods */
|
|
||||||
void *reserved1;
|
|
||||||
void *reserved2;
|
|
||||||
} DohObjInfo;
|
|
||||||
|
|
||||||
/* Memory management */
|
/* Memory management */
|
||||||
|
|
||||||
|
|
@ -136,83 +53,80 @@ typedef struct DohObjInfo {
|
||||||
#define DohFree free
|
#define DohFree free
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern void *DohObjMalloc(size_t size); /* Allocate a DOH object */
|
extern int DohCheck(const DOH *ptr); /* Check if a DOH object */
|
||||||
extern void DohObjFree(DOH *ptr); /* Free a DOH object */
|
extern void DohIntern(DOH *); /* Intern an object */
|
||||||
extern void DohInit(DOH *obj); /* Initialize an object */
|
|
||||||
extern int DohCheck(const DOH *ptr); /* Check if a DOH object */
|
|
||||||
extern void DohIntern(DOH *); /* Intern an object */
|
|
||||||
|
|
||||||
/* Basic object methods. Common to most objects */
|
/* Basic object methods. Common to most objects */
|
||||||
|
|
||||||
extern void DohDelete(DOH *obj); /* Delete an object */
|
extern void DohDelete(DOH *obj); /* Delete an object */
|
||||||
extern DOH *DohCopy(const DOH *obj);
|
extern DOH *DohCopy(const DOH *obj);
|
||||||
extern void DohClear(DOH *obj);
|
extern void DohClear(DOH *obj);
|
||||||
extern DOHString *DohStr(const DOH *obj);
|
extern DOHString *DohStr(const DOH *obj);
|
||||||
extern void *DohData(const DOH *obj);
|
extern void *DohData(const DOH *obj);
|
||||||
extern int DohDump(const DOH *obj, DOHFile *out);
|
extern int DohDump(const DOH *obj, DOHFile *out);
|
||||||
extern int DohLen(const DOH *obj);
|
extern int DohLen(const DOH *obj);
|
||||||
extern int DohHashval(const DOH *obj);
|
extern int DohHashval(const DOH *obj);
|
||||||
extern int DohCmp(const DOH *obj1, const DOH *obj2);
|
extern int DohCmp(const DOH *obj1, const DOH *obj2);
|
||||||
|
|
||||||
/* Mapping methods */
|
/* Mapping methods */
|
||||||
|
|
||||||
extern DOH *DohGetattr(DOH *obj, const DOHString_or_char *name);
|
extern DOH *DohGetattr(DOH *obj, const DOHString_or_char *name);
|
||||||
extern int DohSetattr(DOH *obj, const DOHString_or_char *name, const DOHObj_or_char *value);
|
extern int DohSetattr(DOH *obj, const DOHString_or_char *name, const DOHObj_or_char *value);
|
||||||
extern void DohDelattr(DOH *obj, const DOHString_or_char *name);
|
extern void DohDelattr(DOH *obj, const DOHString_or_char *name);
|
||||||
extern DOH *DohFirstkey(DOH *obj);
|
extern DOH *DohFirstkey(DOH *obj);
|
||||||
extern DOH *DohNextkey(DOH *obj);
|
extern DOH *DohNextkey(DOH *obj);
|
||||||
extern int DohGetInt(DOH *obj, const DOHString_or_char *name);
|
extern int DohGetInt(DOH *obj, const DOHString_or_char *name);
|
||||||
extern double DohGetDouble(DOH *obj, const DOHString_or_char *name);
|
extern double DohGetDouble(DOH *obj, const DOHString_or_char *name);
|
||||||
extern char *DohGetChar(DOH *obj, const DOHString_or_char *name);
|
extern char *DohGetChar(DOH *obj, const DOHString_or_char *name);
|
||||||
extern void DohSetInt(DOH *obj, const DOHString_or_char *name, int);
|
extern void DohSetInt(DOH *obj, const DOHString_or_char *name, int);
|
||||||
extern void DohSetDouble(DOH *obj, const DOHString_or_char *name, double);
|
extern void DohSetDouble(DOH *obj, const DOHString_or_char *name, double);
|
||||||
extern void *DohGetVoid(DOH *obj, const DOHString_or_char *name);
|
extern void *DohGetVoid(DOH *obj, const DOHString_or_char *name);
|
||||||
extern void DohSetVoid(DOH *obj, const DOHString_or_char *name, void *value);
|
extern void DohSetVoid(DOH *obj, const DOHString_or_char *name, void *value);
|
||||||
|
|
||||||
/* Sequence methods */
|
/* Sequence methods */
|
||||||
|
|
||||||
extern DOH *DohGetitem(DOH *obj, int index);
|
extern DOH *DohGetitem(DOH *obj, int index);
|
||||||
extern int DohSetitem(DOH *obj, int index, const DOHObj_or_char *value);
|
extern int DohSetitem(DOH *obj, int index, const DOHObj_or_char *value);
|
||||||
extern int DohDelitem(DOH *obj, int index);
|
extern int DohDelitem(DOH *obj, int index);
|
||||||
extern int DohInsertitem(DOH *obj, int index, const DOHObj_or_char *value);
|
extern int DohInsertitem(DOH *obj, int index, const DOHObj_or_char *value);
|
||||||
extern DOH *DohFirstitem(DOH *obj);
|
extern DOH *DohFirstitem(DOH *obj);
|
||||||
extern DOH *DohNextitem(DOH *obj);
|
extern DOH *DohNextitem(DOH *obj);
|
||||||
|
|
||||||
/* File methods */
|
/* File methods */
|
||||||
|
|
||||||
extern int DohWrite(DOHFile *obj, void *buffer, int length);
|
extern int DohWrite(DOHFile *obj, void *buffer, int length);
|
||||||
extern int DohRead(DOHFile *obj, void *buffer, int length);
|
extern int DohRead(DOHFile *obj, void *buffer, int length);
|
||||||
extern int DohSeek(DOHFile *obj, long offset, int whence);
|
extern int DohSeek(DOHFile *obj, long offset, int whence);
|
||||||
extern long DohTell(DOHFile *obj);
|
extern long DohTell(DOHFile *obj);
|
||||||
extern int DohGetc(DOHFile *obj);
|
extern int DohGetc(DOHFile *obj);
|
||||||
extern int DohPutc(int ch, DOHFile *obj);
|
extern int DohPutc(int ch, DOHFile *obj);
|
||||||
extern int DohUngetc(int ch, DOHFile *obj);
|
extern int DohUngetc(int ch, DOHFile *obj);
|
||||||
|
|
||||||
/* Positional */
|
/* Positional */
|
||||||
|
|
||||||
extern int DohGetline(DOH *obj);
|
extern int DohGetline(DOH *obj);
|
||||||
extern void DohSetline(DOH *obj, int line);
|
extern void DohSetline(DOH *obj, int line);
|
||||||
extern DOH *DohGetfile(DOH *obj);
|
extern DOH *DohGetfile(DOH *obj);
|
||||||
extern void DohSetfile(DOH *obj, DOH *file);
|
extern void DohSetfile(DOH *obj, DOH *file);
|
||||||
|
|
||||||
/* String Methods */
|
/* String Methods */
|
||||||
|
|
||||||
extern int DohReplace(DOHString *src, const DOHString_or_char *token, const DOHString_or_char *rep, int flags);
|
extern int DohReplace(DOHString *src, const DOHString_or_char *token, const DOHString_or_char *rep, int flags);
|
||||||
extern void DohChop(DOHString *src);
|
extern void DohChop(DOHString *src);
|
||||||
|
|
||||||
/* Utility functions */
|
/* Utility functions */
|
||||||
|
|
||||||
extern void DohEncoding(char *name, DOH *(*fn)(DOH *s));
|
extern void DohEncoding(char *name, DOH *(*fn)(DOH *s));
|
||||||
extern int DohPrintf(DOHFile *obj, const char *format, ...);
|
extern int DohPrintf(DOHFile *obj, const char *format, ...);
|
||||||
extern int DohvPrintf(DOHFile *obj, const char *format, va_list ap);
|
extern int DohvPrintf(DOHFile *obj, const char *format, va_list ap);
|
||||||
extern DOH *DohReadline(DOHFile *in);
|
extern DOH *DohReadline(DOHFile *in);
|
||||||
|
|
||||||
/* Miscellaneous */
|
/* Miscellaneous */
|
||||||
|
|
||||||
extern int DohIsMapping(const DOH *obj);
|
extern int DohIsMapping(const DOH *obj);
|
||||||
extern int DohIsSequence(const DOH *obj);
|
extern int DohIsSequence(const DOH *obj);
|
||||||
extern int DohIsString(const DOH *obj);
|
extern int DohIsString(const DOH *obj);
|
||||||
extern int DohIsFile(const DOH *obj);
|
extern int DohIsFile(const DOH *obj);
|
||||||
|
|
||||||
#ifndef DOH_LONG_NAMES
|
#ifndef DOH_LONG_NAMES
|
||||||
/* Macros to invoke the above functions. Includes the location of
|
/* Macros to invoke the above functions. Includes the location of
|
||||||
|
|
@ -267,35 +181,6 @@ typedef struct DohObjInfo {
|
||||||
#define Chop DohChop
|
#define Chop DohChop
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
|
||||||
* DohBase
|
|
||||||
*
|
|
||||||
* DohBase object type. Attributes common to all objects.
|
|
||||||
* ----------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
#define DOHCOMMON \
|
|
||||||
DohObjInfo *objinfo; \
|
|
||||||
int refcount; \
|
|
||||||
DOH *file; \
|
|
||||||
int line; \
|
|
||||||
unsigned char flags
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
DOHCOMMON;
|
|
||||||
} DohBase;
|
|
||||||
|
|
||||||
/* Macros for decrefing and increfing (safe for null objects). */
|
|
||||||
#define Decref(a) if (a) ((DohBase *) a)->refcount--
|
|
||||||
#define Incref(a) if (a) ((DohBase *) a)->refcount++
|
|
||||||
#define Refcount(a) ((DohBase *) a)->refcount
|
|
||||||
#define Objname(a) ((DohBase *) a)->objinfo->objname
|
|
||||||
|
|
||||||
/* Flags for various internal operations */
|
|
||||||
|
|
||||||
#define DOH_FLAG_PRINT 0x02
|
|
||||||
#define DOH_FLAG_DELETED 0x04
|
|
||||||
#define DOH_FLAG_INTERN 0x10
|
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* Strings.
|
* Strings.
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
@ -303,14 +188,12 @@ typedef struct {
|
||||||
extern DOHString *NewString(const DOH *c);
|
extern DOHString *NewString(const DOH *c);
|
||||||
extern DOHString *NewStringf(const DOH *fmt, ...);
|
extern DOHString *NewStringf(const DOH *fmt, ...);
|
||||||
|
|
||||||
extern int String_check(const DOH *s);
|
|
||||||
|
|
||||||
/* String replacement flags */
|
/* String replacement flags */
|
||||||
|
|
||||||
#define DOH_REPLACE_ANY 0x00
|
#define DOH_REPLACE_ANY 0x01
|
||||||
#define DOH_REPLACE_NOQUOTE 0x01
|
#define DOH_REPLACE_NOQUOTE 0x02
|
||||||
#define DOH_REPLACE_ID 0x02
|
#define DOH_REPLACE_ID 0x04
|
||||||
#define DOH_REPLACE_FIRST 0x04
|
#define DOH_REPLACE_FIRST 0x08
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* Files
|
* Files
|
||||||
|
|
@ -318,7 +201,6 @@ extern int String_check(const DOH *s);
|
||||||
|
|
||||||
extern DOHFile *NewFile(DOH *file, char *mode);
|
extern DOHFile *NewFile(DOH *file, char *mode);
|
||||||
extern DOHFile *NewFileFromFile(FILE *f);
|
extern DOHFile *NewFileFromFile(FILE *f);
|
||||||
extern DOHFile *NewFileFromFd(int fd);
|
|
||||||
extern int DohCopyto(DOHFile *input, DOHFile *output);
|
extern int DohCopyto(DOHFile *input, DOHFile *output);
|
||||||
|
|
||||||
#define Copyto DohCopyto
|
#define Copyto DohCopyto
|
||||||
|
|
@ -328,15 +210,12 @@ extern int DohCopyto(DOHFile *input, DOHFile *output);
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
extern DOHList *NewList();
|
extern DOHList *NewList();
|
||||||
extern int List_check(const DOH *);
|
|
||||||
extern void List_sort(DOHList *);
|
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* Hash
|
* Hash
|
||||||
* ----------------------------------------------------------------------------- */
|
* ----------------------------------------------------------------------------- */
|
||||||
|
|
||||||
extern DOHHash *NewHash();
|
extern DOHHash *NewHash();
|
||||||
extern int Hash_check(const DOH *h);
|
|
||||||
extern DOHList *Hash_keys(DOHHash *);
|
extern DOHList *Hash_keys(DOHHash *);
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
|
|
@ -350,20 +229,6 @@ extern DOHList *DohSplit(DOHFile *input, char *chs, int nsplits);
|
||||||
|
|
||||||
extern DOH *DohNone;
|
extern DOH *DohNone;
|
||||||
|
|
||||||
/* -----------------------------------------------------------------------------
|
|
||||||
* Error handling levels.
|
|
||||||
* ----------------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
#define DOH_UNSUPPORTED 0x01
|
|
||||||
#define DOH_UNKNOWN 0x02
|
|
||||||
#define DOH_MEMORY 0x04
|
|
||||||
#define DOH_CONVERSION 0x08
|
|
||||||
#define DOH_CALLS 0x10
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* DOH_H */
|
#endif /* DOH_H */
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,3 +6,4 @@
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
#include "doh.h"
|
#include "doh.h"
|
||||||
|
#include "dohobj.h"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue