From 2750f2338542523b46ad71908fca6c958590fd90 Mon Sep 17 00:00:00 2001 From: Dave Beazley Date: Wed, 14 Jun 2000 22:00:46 +0000 Subject: [PATCH] Substantial cleanup. Performance optimizations. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@460 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/DOH/Doh/base.c | 298 ++++++------ Source/DOH/Doh/file.c | 155 ++----- Source/DOH/Doh/fio.c | 6 +- Source/DOH/Doh/hash.c | 89 ++-- Source/DOH/Doh/list.c | 202 ++++---- Source/DOH/Doh/memory.c | 112 ++--- Source/DOH/Doh/string.c | 885 +++++++++++++++++++----------------- Source/DOH/Doh/void.c | 30 +- Source/DOH/Include/doh.h | 259 +++-------- Source/DOH/Include/dohint.h | 1 + 10 files changed, 944 insertions(+), 1093 deletions(-) diff --git a/Source/DOH/Doh/base.c b/Source/DOH/Doh/base.c index 8be711dad..5ef5b6fd1 100644 --- a/Source/DOH/Doh/base.c +++ b/Source/DOH/Doh/base.c @@ -14,26 +14,16 @@ static char cvsroot[] = "$Header$"; #include "dohint.h" -static DohObjInfo DohBaseType = { - "Base", /* objname */ - sizeof(DohBase), /* objsize */ - 0, /* doh_del */ - 0, /* doh_copy */ - 0, /* doh_clear */ - 0, /* doh_str */ - 0, /* doh_data */ - 0, /* doh_dump */ - 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 */ -}; +static DohObjInfo *dohtypes[MAX_DOHTYPE]; + +/* ----------------------------------------------------------------------------- + * DohRegisterType() + * ----------------------------------------------------------------------------- */ + +void +DohRegisterType(int type, DohObjInfo *objinfo) { + dohtypes[type] = objinfo; +} /* ----------------------------------------------------------------------------- * DohDelete() @@ -42,24 +32,22 @@ static DohObjInfo DohBaseType = { void DohDelete(DOH *obj) { DohBase *b = (DohBase *) obj; + DohObjInfo *objinfo; + if (!DohCheck(b)) return; - if (b->flags & DOH_FLAG_INTERN) return; + if (b->flag_intern) return; b->refcount--; 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() * ----------------------------------------------------------------------------- */ @@ -67,8 +55,10 @@ DohIntern(DOH *obj) { DOH * DohCopy(const DOH *obj) { DohBase *b = (DohBase *) obj; - if (b->objinfo->doh_copy) - return (b->objinfo->doh_copy)(b); + DohObjInfo *objinfo = dohtypes[b->type]; + objinfo = dohtypes[b->type]; + if (objinfo->doh_copy) + return (objinfo->doh_copy)(b); } /* ----------------------------------------------------------------------------- @@ -78,8 +68,9 @@ DohCopy(const DOH *obj) { void DohClear(DOH *obj) { DohBase *b = (DohBase *) obj; - if (b->objinfo->doh_clear) - (b->objinfo->doh_clear)(obj); + DohObjInfo *objinfo = dohtypes[b->type]; + if (objinfo->doh_clear) + (objinfo->doh_clear)(b); } /* ----------------------------------------------------------------------------- @@ -90,11 +81,13 @@ DOH * DohStr(const DOH *obj) { char buffer[512]; DohBase *b = (DohBase *) obj; + DohObjInfo *objinfo; if (DohCheck(b)) { - if (b->objinfo->doh_str) { - return (b->objinfo->doh_str)(b); + objinfo = dohtypes[b->type]; + if (objinfo->doh_str) { + return (objinfo->doh_str)(b); } - sprintf(buffer,"", b->objinfo->objname, b); + sprintf(buffer,"", objinfo->objname, b); return NewString(buffer); } else { return NewString(obj); @@ -108,22 +101,25 @@ DohStr(const DOH *obj) { int DohDump(const DOH *obj, DOH *out) { DohBase *b = (DohBase *) obj; - if (b->objinfo->doh_dump) { - return (b->objinfo->doh_dump)(b,out); + DohObjInfo *objinfo = dohtypes[b->type]; + if (objinfo->doh_dump) { + return (objinfo->doh_dump)(b,out); } return 0; } /* ----------------------------------------------------------------------------- - * DohLen() + * DohLen() - Defaults to strlen() if not a DOH object * ----------------------------------------------------------------------------- */ int DohLen(const DOH *obj) { DohBase *b = (DohBase *) obj; + DohObjInfo *objinfo; if (!b) return 0; if (DohCheck(b)) { - if (b->objinfo->doh_len) { - return (b->objinfo->doh_len)(b); + objinfo = dohtypes[b->type]; + if (objinfo->doh_len) { + return (objinfo->doh_len)(b); } return 0; } else { @@ -138,9 +134,11 @@ DohLen(const DOH *obj) { int DohHashval(const DOH *obj) { DohBase *b = (DohBase *) obj; + DohObjInfo *objinfo; if (DohCheck(b)) { - if (b->objinfo->doh_hash) { - return (b->objinfo->doh_hashval)(b); + objinfo = dohtypes[b->type]; + if (objinfo->doh_hashval) { + return (objinfo->doh_hashval)(b); } } return 0; @@ -153,11 +151,11 @@ DohHashval(const DOH *obj) { void * DohData(const DOH *obj) { DohBase *b = (DohBase *) obj; + DohObjInfo *objinfo; if (DohCheck(obj)) { - if (b->objinfo) { - if (b->objinfo->doh_data) { - return (b->objinfo->doh_data)(b); - } + objinfo = dohtypes[b->type]; + if (objinfo->doh_data) { + return (objinfo->doh_data)(b); } return 0; } @@ -171,26 +169,29 @@ DohData(const DOH *obj) { int DohCmp(const DOH *obj1, const DOH *obj2) { DohBase *b1, *b2; + DohObjInfo *b1info, *b2info; b1 = (DohBase *) obj1; b2 = (DohBase *) obj2; if ((!DohCheck(b1)) || (!DohCheck(b2))) { return strcmp((char *) DohData(b1),(char *) DohData(b2)); } - if (b1->objinfo->doh_cmp) { - return (b1->objinfo->doh_cmp)(b1,b2); - } + b1info = dohtypes[b1->type]; + b2info = dohtypes[b2->type]; + if ((b1info == b2info) && (b1info->doh_cmp)) + return (b1info->doh_cmp)(b1,b2); return 1; } /* ----------------------------------------------------------------------------- * DohIsMapping() * ----------------------------------------------------------------------------- */ - int DohIsMapping(const DOH *obj) { DohBase *b = (DohBase *) obj; + DohObjInfo *objinfo; 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; } @@ -201,8 +202,9 @@ DohIsMapping(const DOH *obj) { DOH * DohGetattr(DOH *obj, const DOH *name) { DohBase *b = (DohBase *) obj; - if (b->objinfo->doh_hash->doh_getattr) { - return (b->objinfo->doh_hash->doh_getattr)(b,(DOH *) name); + DohObjInfo *objinfo = dohtypes[b->type]; + if (objinfo->doh_hash && objinfo->doh_hash->doh_getattr) { + return (objinfo->doh_hash->doh_getattr)(b,(DOH *) name); } return 0; } @@ -214,8 +216,9 @@ DohGetattr(DOH *obj, const DOH *name) { int DohSetattr(DOH *obj, const DOH *name, const DOH *value) { DohBase *b = (DohBase *) obj; - if (b->objinfo->doh_hash->doh_setattr) { - return (b->objinfo->doh_hash->doh_setattr)(b,(DOH *) name,(DOH *) value); + DohObjInfo *objinfo = dohtypes[b->type]; + if (objinfo->doh_hash && objinfo->doh_hash->doh_setattr) { + return (objinfo->doh_hash->doh_setattr)(b,(DOH *) name,(DOH *) value); } return 0; } @@ -227,8 +230,9 @@ DohSetattr(DOH *obj, const DOH *name, const DOH *value) { void DohDelattr(DOH *obj, const DOH *name) { DohBase *b = (DohBase *) obj; - if (b->objinfo->doh_hash->doh_delattr) { - (b->objinfo->doh_hash->doh_delattr)(b,(DOH *) name); + DohObjInfo *objinfo = dohtypes[b->type]; + 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 * DohFirstkey(DOH *obj) { DohBase *b = (DohBase *) obj; - if (b->objinfo->doh_hash->doh_firstkey) { - return (b->objinfo->doh_hash->doh_firstkey)(obj); + DohObjInfo *objinfo = dohtypes[b->type]; + if (objinfo->doh_hash && objinfo->doh_hash->doh_firstkey) { + return (objinfo->doh_hash->doh_firstkey)(b); } return 0; } @@ -252,8 +257,9 @@ DohFirstkey(DOH *obj) { DOH * DohNextkey(DOH *obj) { DohBase *b = (DohBase *) obj; - if (b->objinfo->doh_hash->doh_nextkey) { - return (b->objinfo->doh_hash->doh_nextkey)(obj); + DohObjInfo *objinfo = dohtypes[b->type]; + if (objinfo && objinfo->doh_hash->doh_nextkey) { + return (objinfo->doh_hash->doh_nextkey)(b); } return 0; } @@ -345,9 +351,7 @@ DohSetDouble(DOH *obj, const DOH *name, double value) { void DohSetChar(DOH *obj, const DOH *name, char *value) { - DOH *temp; - temp = NewString(value); - Setattr(obj,(DOH *) name,temp); + Setattr(obj,(DOH *) name,NewString(value)); } /* ----------------------------------------------------------------------------- @@ -356,9 +360,7 @@ DohSetChar(DOH *obj, const DOH *name, char *value) { void DohSetVoid(DOH *obj, const DOH *name, void *value) { - DOH *temp; - temp = NewVoid(value,0); - Setattr(obj,(DOH *) name,temp); + Setattr(obj,(DOH *) name,NewVoid(value,0)); } /* ----------------------------------------------------------------------------- @@ -368,8 +370,10 @@ DohSetVoid(DOH *obj, const DOH *name, void *value) { int DohIsSequence(const DOH *obj) { DohBase *b = (DohBase *) obj; + DohObjInfo *objinfo; 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; } @@ -380,8 +384,9 @@ DohIsSequence(const DOH *obj) { DOH * DohGetitem(DOH *obj, int index) { DohBase *b = (DohBase *) obj; - if (b->objinfo->doh_list->doh_getitem) { - return (b->objinfo->doh_list->doh_getitem)(obj,index); + DohObjInfo *objinfo = dohtypes[b->type]; + if (objinfo->doh_list && objinfo->doh_list->doh_getitem) { + return (objinfo->doh_list->doh_getitem)(b,index); } return 0; } @@ -393,10 +398,11 @@ DohGetitem(DOH *obj, int index) { int DohSetitem(DOH *obj, int index, const DOH *value) { DohBase *b = (DohBase *) obj; - if (b->objinfo->doh_list->doh_setitem) { - return (b->objinfo->doh_list->doh_setitem)(obj,index,(DOH *) value); + DohObjInfo *objinfo = dohtypes[b->type]; + 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 DohDelitem(DOH *obj, int index) { DohBase *b = (DohBase *) obj; - if (b->objinfo->doh_list->doh_delitem) { - return (b->objinfo->doh_list->doh_delitem)(obj,index); + DohObjInfo *objinfo = dohtypes[b->type]; + 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 DohInsertitem(DOH *obj, int index, const DOH *value) { - int no = 0; DohBase *b = (DohBase *) obj; - if (b->objinfo->doh_list->doh_insitem) { - return (b->objinfo->doh_list->doh_insitem)(obj,index,(DOH *) value); + DohObjInfo *objinfo = dohtypes[b->type]; + 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 * DohFirstitem(DOH *obj) { DohBase *b = (DohBase *) obj; - if (b->objinfo->doh_list->doh_firstitem) { - return (b->objinfo->doh_list->doh_firstitem)(obj); + DohObjInfo *objinfo = dohtypes[b->type]; + if (objinfo->doh_list && objinfo->doh_list->doh_firstitem) { + return (objinfo->doh_list->doh_firstitem)(b); } return 0; } @@ -444,8 +454,9 @@ DohFirstitem(DOH *obj) { DOH * DohNextitem(DOH *obj) { DohBase *b = (DohBase *) obj; - if (b->objinfo->doh_list->doh_nextitem) { - return (b->objinfo->doh_list->doh_nextitem)(obj); + DohObjInfo *objinfo = dohtypes[b->type]; + if (objinfo->doh_list && objinfo->doh_list->doh_nextitem) { + return (objinfo->doh_list->doh_nextitem)(b); } return 0; } @@ -457,8 +468,10 @@ DohNextitem(DOH *obj) { int DohIsFile(const DOH *obj) { DohBase *b = (DohBase *) obj; + DohObjInfo *objinfo; 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; } @@ -469,9 +482,11 @@ DohIsFile(const DOH *obj) { int DohRead(DOH *obj, void *buffer, int length) { DohBase *b = (DohBase *) obj; + DohObjInfo *objinfo; if (DohCheck(obj)) { - if ((b->objinfo->doh_file) && (b->objinfo->doh_file->doh_read)) { - return (b->objinfo->doh_file->doh_read)(obj,buffer,length); + objinfo = dohtypes[b->type]; + if ((objinfo->doh_file) && (objinfo->doh_file->doh_read)) { + return (objinfo->doh_file->doh_read)(b,buffer,length); } return -1; } @@ -486,9 +501,11 @@ DohRead(DOH *obj, void *buffer, int length) { int DohWrite(DOH *obj, void *buffer, int length) { DohBase *b = (DohBase *) obj; + DohObjInfo *objinfo; if (DohCheck(obj)) { - if ((b->objinfo->doh_file) && (b->objinfo->doh_file->doh_write)) { - return (b->objinfo->doh_file->doh_write)(obj,buffer,length); + objinfo = dohtypes[b->type]; + if ((objinfo->doh_file) && (objinfo->doh_file->doh_write)) { + return (objinfo->doh_file->doh_write)(b,buffer,length); } return -1; } @@ -503,9 +520,11 @@ DohWrite(DOH *obj, void *buffer, int length) { int DohSeek(DOH *obj, long offset, int whence) { DohBase *b = (DohBase *) obj; + DohObjInfo *objinfo; if (DohCheck(obj)) { - if ((b->objinfo->doh_file) && (b->objinfo->doh_file->doh_seek)) { - return (b->objinfo->doh_file->doh_seek)(obj,offset,whence); + objinfo = dohtypes[b->type]; + if ((objinfo->doh_file) && (objinfo->doh_file->doh_seek)) { + return (objinfo->doh_file->doh_seek)(b,offset,whence); } return -1; } @@ -519,9 +538,11 @@ DohSeek(DOH *obj, long offset, int whence) { long DohTell(DOH *obj) { DohBase *b = (DohBase *) obj; + DohObjInfo *objinfo; if (DohCheck(obj)) { - if ((b->objinfo->doh_file) && (b->objinfo->doh_file->doh_tell)) { - return (b->objinfo->doh_file->doh_tell)(obj); + objinfo = dohtypes[b->type]; + if ((objinfo->doh_file) && (objinfo->doh_file->doh_tell)) { + return (objinfo->doh_file->doh_tell)(b); } return -1; } @@ -535,9 +556,11 @@ DohTell(DOH *obj) { int DohGetc(DOH *obj) { DohBase *b = (DohBase *) obj; + DohObjInfo *objinfo; if (DohCheck(obj)) { - if (b->objinfo->doh_file->doh_getc) { - return (b->objinfo->doh_file->doh_getc)(obj); + objinfo = dohtypes[b->type]; + if (objinfo->doh_file->doh_getc) { + return (objinfo->doh_file->doh_getc)(b); } return EOF; } @@ -551,9 +574,11 @@ DohGetc(DOH *obj) { int DohPutc(int ch, DOH *obj) { DohBase *b = (DohBase *) obj; + DohObjInfo *objinfo; if (DohCheck(obj)) { - if (b->objinfo->doh_file->doh_putc) { - return (b->objinfo->doh_file->doh_putc)(obj,ch); + objinfo = dohtypes[b->type]; + if (objinfo->doh_file->doh_putc) { + return (objinfo->doh_file->doh_putc)(b,ch); } return EOF; } @@ -567,9 +592,11 @@ DohPutc(int ch, DOH *obj) { int DohUngetc(int ch, DOH *obj) { DohBase *b = (DohBase *) obj; + DohObjInfo *objinfo; if (DohCheck(obj)) { - if (b->objinfo->doh_file->doh_ungetc) { - return (b->objinfo->doh_file->doh_ungetc)(obj,ch); + objinfo = dohtypes[b->type]; + if (objinfo->doh_file->doh_ungetc) { + return (objinfo->doh_file->doh_ungetc)(b,ch); } return EOF; } @@ -583,9 +610,11 @@ DohUngetc(int ch, DOH *obj) { int DohClose(DOH *obj) { DohBase *b = (DohBase *) obj; + DohObjInfo *objinfo; if (DohCheck(obj)) { - if (b->objinfo->doh_file->doh_close) { - return (b->objinfo->doh_file->doh_close)(obj); + objinfo = dohtypes[b->type]; + if (objinfo->doh_file->doh_close) { + return (objinfo->doh_file->doh_close)(b); } return 0; } @@ -599,8 +628,10 @@ DohClose(DOH *obj) { int DohIsString(const DOH *obj) { DohBase *b = (DohBase *) obj; + DohObjInfo *objinfo; 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; } @@ -611,9 +642,11 @@ DohIsString(const DOH *obj) { int DohReplace(DOH *src, const DOH *token, const DOH *rep, int flags) { DohBase *b = (DohBase *) src; + DohObjInfo *objinfo; if (DohIsString(src)) { - if (b->objinfo->doh_string->doh_replace) { - return (b->objinfo->doh_string->doh_replace)(src,(DOH *) token, (DOH *) rep,flags); + objinfo = dohtypes[b->type]; + if (objinfo->doh_string->doh_replace) { + return (objinfo->doh_string->doh_replace)(b,(DOH *) token, (DOH *) rep,flags); } } return 0; @@ -626,37 +659,26 @@ DohReplace(DOH *src, const DOH *token, const DOH *rep, int flags) { void DohChop(DOH *src) { DohBase *b = (DohBase *) src; + DohObjInfo *objinfo; if (DohIsString(src)) { - if (b->objinfo->doh_string->doh_chop) { - (b->objinfo->doh_string->doh_chop)(src); + objinfo = dohtypes[b->type]; + 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() * ----------------------------------------------------------------------------- */ void DohSetfile(DOH *ho, DOH *file) { DohBase *h = (DohBase *) ho; + DohObjInfo *objinfo; if (!h) return; - if (!DohCheck(file)) file = NewString(file); - h->file = file; - Incref(h->file); + objinfo = dohtypes[h->type]; + if (objinfo->doh_setfile) + (objinfo->doh_setfile)(h,file); } /* ----------------------------------------------------------------------------- @@ -664,8 +686,13 @@ DohSetfile(DOH *ho, DOH *file) { * ----------------------------------------------------------------------------- */ DOH * DohGetfile(DOH *ho) { - if (!ho) return 0; - return ((DohBase *)ho)->file; + DohBase *h = (DohBase *) ho; + 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 DohSetline(DOH *ho, int l) { - if (!ho) return; - ((DohBase *) ho)->line = l; + DohBase *h = (DohBase *) ho; + 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 DohGetline(DOH *ho) { - if (!ho) return 0; - return ((DohBase *)ho)->line; + DohBase *h = (DohBase *) ho; + DohObjInfo *objinfo; + if (!h) return; + objinfo = dohtypes[h->type]; + if (objinfo->doh_getline) + return (objinfo->doh_getline)(h); + return 0; } diff --git a/Source/DOH/Doh/file.c b/Source/DOH/Doh/file.c index fb3efe231..99e5900f4 100644 --- a/Source/DOH/Doh/file.c +++ b/Source/DOH/Doh/file.c @@ -13,116 +13,81 @@ static char cvsroot[] = "$Header$"; #include "dohint.h" -#include typedef struct { - DOHCOMMON; FILE *filep; - int fd; - int closeondel; + int closeondel; } DohFile; /* ----------------------------------------------------------------------------- * DelFile() - * - * Delete a file. Closes the file if the closeondel flag is set. * ----------------------------------------------------------------------------- */ static void -DelFile(DOH *so) { - DohFile *f = (DohFile *) so; - assert(f->refcount <= 0); +DelFile(DOH *fo) { + DohFile *f = (DohFile *) ObjData(fo); if (f->closeondel) fclose(f->filep); - DohObjFree(f); } /* ----------------------------------------------------------------------------- * File_read() - * - * Reads data from a file into a buffer. * ----------------------------------------------------------------------------- */ static int -File_read(DOH *so, void *buffer, int len) { - DohFile *s = (DohFile *) so; - if (s->filep) - return fread(buffer,1,len,s->filep); - else - return read(s->fd,buffer,len); +File_read(DOH *fo, void *buffer, int len) { + DohFile *f = (DohFile *) ObjData(fo); + return fread(buffer,1,len,f->filep); } /* ----------------------------------------------------------------------------- * File_write() - * - * Write data from a buffer to a file. * ----------------------------------------------------------------------------- */ static int -File_write(DOH *so, void *buffer, int len) { - DohFile *s = (DohFile *) so; - if (s->filep) - return fwrite(buffer,1,len,s->filep); - else - return write(s->fd, buffer, len); +File_write(DOH *fo, void *buffer, int len) { + DohFile *f = (DohFile *) ObjData(fo); + return fwrite(buffer,1,len,f->filep); } /* ----------------------------------------------------------------------------- * File_seek() - * - * Seek to a new file position. * ----------------------------------------------------------------------------- */ static int -File_seek(DOH *so, long offset, int whence) { - DohFile *s = (DohFile *) so; - if (s->filep) - return fseek(s->filep,offset,whence); - else - return lseek(s->fd,offset,whence); +File_seek(DOH *fo, long offset, int whence) { + DohFile *f = (DohFile *) ObjData(fo); + return fseek(f->filep,offset,whence); } /* ----------------------------------------------------------------------------- * File_tell() - * - * Return current file pointer. * ----------------------------------------------------------------------------- */ static long -File_tell(DOH *so) { - DohFile *s = (DohFile *) so; - if (s->filep) - return ftell(s->filep); - else - return lseek(s->fd,0,SEEK_CUR); +File_tell(DOH *fo) { + DohFile *f = (DohFile *) ObjData(fo); + return ftell(f->filep); } /* ----------------------------------------------------------------------------- * File_putc() - * - * Put a character on the output * ----------------------------------------------------------------------------- */ static int -File_putc(DOH *obj, int ch) { - DohFile *s = (DohFile *) obj; - if (s->filep) - return fputc(ch,s->filep); - return EOF; +File_putc(DOH *fo, int ch) { + DohFile *f = (DohFile *) ObjData(fo); + return fputc(ch,f->filep); } /* ----------------------------------------------------------------------------- * File_getc() - * - * Get a character * ----------------------------------------------------------------------------- */ static int -File_getc(DOH *obj) { - DohFile *s = (DohFile *) obj; - if (s->filep) - return fgetc(s->filep); - return EOF; +File_getc(DOH *fo) { + DohFile *f = (DohFile *) ObjData(fo); + return fgetc(f->filep); } /* ----------------------------------------------------------------------------- @@ -132,11 +97,9 @@ File_getc(DOH *obj) { * ----------------------------------------------------------------------------- */ static int -File_ungetc(DOH *obj, int ch) { - DohFile *s = (DohFile *) obj; - if (s->filep) - return ungetc(ch, s->filep); - return EOF; +File_ungetc(DOH *fo, int ch) { + DohFile *f = (DohFile *) ObjData(fo); + return ungetc(ch, f->filep); } static DohFileMethods FileFileMethods = { @@ -152,17 +115,19 @@ static DohFileMethods FileFileMethods = { static DohObjInfo DohFileType = { "DohFile", /* objname */ - sizeof(DohFile), /* objsize */ DelFile, /* doh_del */ 0, /* doh_copy */ 0, /* doh_clear */ 0, /* doh_str */ 0, /* doh_data */ 0, /* doh_dump */ - 0, /* doh_load */ 0, /* doh_len */ 0, /* doh_hash */ 0, /* doh_cmp */ + 0, /* doh_setfile */ + 0, /* doh_getfile */ + 0, /* doh_setline */ + 0, /* doh_getline */ 0, /* doh_mapping */ 0, /* doh_sequence */ &FileFileMethods,/* doh_file */ @@ -183,21 +148,25 @@ NewFile(DOH *fn, char *mode) DohFile *f; FILE *file; char *filename; + static int init = 0; + + if (!init) { + DohRegisterType(DOHTYPE_FILE, &DohFileType); + init = 1; + } filename = Char(fn); file = fopen(filename,mode); if (!file) return 0; - f = (DohFile *) DohObjMalloc(sizeof(DohFile)); + f = (DohFile *) DohMalloc(sizeof(DohFile)); if (!f) { fclose(file); return 0; } - f->objinfo = &DohFileType; f->filep = file; - f->fd = fileno(file); f->closeondel = 1; - return (DOH *) f; + return DohObjMalloc(DOHTYPE_FILE,f); } /* ----------------------------------------------------------------------------- @@ -210,52 +179,14 @@ DOH * NewFileFromFile(FILE *file) { 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; - f->objinfo = &DohFileType; f->filep = file; - f->fd = fileno(file); 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; -} - - - - - - diff --git a/Source/DOH/Doh/fio.c b/Source/DOH/Doh/fio.c index cde7865dd..ece5fd775 100644 --- a/Source/DOH/Doh/fio.c +++ b/Source/DOH/Doh/fio.c @@ -265,7 +265,7 @@ DohvPrintf(DOH *so, const char *format, va_list ap) doh = va_arg(ap, DOH *); if (DohCheck(doh)) { /* Is a DOH object. */ - if (String_check(doh)) { + if (DohIsString(doh)) { Sval = doh; } else { Sval = Str(doh); @@ -435,9 +435,11 @@ DohSplit(DOH *in, char *chs, int nsplits) { int c; list = NewList(); - if (String_check(in)) { + /* if (String_check(in)) { Seek(in,0,SEEK_SET); } + */ + while (1) { str = NewString(""); do { diff --git a/Source/DOH/Doh/hash.c b/Source/DOH/Doh/hash.c index 3d2f2eb57..9a112ffd7 100644 --- a/Source/DOH/Doh/hash.c +++ b/Source/DOH/Doh/hash.c @@ -22,12 +22,13 @@ typedef struct HashNode { /* Hash object */ typedef struct Hash { - DOHCOMMON; - HashNode **hashtable; - int hashsize; - int currentindex; - int nitems; - HashNode *current; + DOH *file; + int line; + HashNode **hashtable; + int hashsize; + int currentindex; + int nitems; + HashNode *current; } Hash; /* Key interning structure */ @@ -98,11 +99,10 @@ static void DelNode(HashNode *hn) { static void DelHash(DOH *ho) { - Hash *h; + Hash *h = (Hash *) ObjData(ho); HashNode *n,*next; int i; - h = (Hash *) ho; for (i = 0; i < h->hashsize; i++) { if ((n = h->hashtable[i])) { while (n) { @@ -115,7 +115,7 @@ DelHash(DOH *ho) { DohFree(h->hashtable); h->hashtable = 0; h->hashsize = 0; - DohObjFree(h); + DohFree(h); } /* ----------------------------------------------------------------------------- @@ -126,11 +126,10 @@ DelHash(DOH *ho) { static void Hash_clear(DOH *ho) { - Hash *h; + Hash *h = (Hash *) ObjData(ho); HashNode *n,*next; int i; - h = (Hash *) ho; for (i = 0; i < h->hashsize; i++) { if ((n = h->hashtable[i])) { while (n) { @@ -199,7 +198,7 @@ static int Hash_setattr(DOH *ho, DOH *k, DOH *obj) { int hv; HashNode *n, *prev; - Hash *h; + Hash *h = (Hash *) ObjData(ho); if (!obj) return 0; if (!DohCheck(k)) k = find_key(k); @@ -207,7 +206,6 @@ Hash_setattr(DOH *ho, DOH *k, DOH *obj) { obj = NewString((char *) obj); Decref(obj); } - h = (Hash *) ho; hv = (Hashval(k)) % h->hashsize; n = h->hashtable[hv]; prev = 0; @@ -247,10 +245,9 @@ static DOH * Hash_getattr(DOH *ho, DOH *k) { int hv; HashNode *n; - Hash *h; + Hash *h = (Hash *) ObjData(ho); if (!DohCheck(k)) k = find_key(k); - h = (Hash *) ho; hv = Hashval(k) % h->hashsize; n = h->hashtable[hv]; while (n) { @@ -270,10 +267,9 @@ static int Hash_delattr(DOH *ho, DOH *k) { HashNode *n, *prev; int hv; - Hash *h; + Hash *h = (Hash *) ObjData(ho); if (!DohCheck(k)) k = find_key(k); - h = (Hash *) ho; hv = Hashval(k) % h->hashsize; n = h->hashtable[hv]; prev = 0; @@ -298,7 +294,7 @@ Hash_delattr(DOH *ho, DOH *k) { /* General purpose iterators */ static HashNode * hash_first(DOH *ho) { - Hash *h = (Hash *) ho; + Hash *h = (Hash *) ObjData(ho); h->currentindex = 0; h->current = 0; while (!h->hashtable[h->currentindex] && (h->currentindex < h->hashsize)) @@ -310,7 +306,7 @@ hash_first(DOH *ho) { static HashNode * hash_next(DOH *ho) { - Hash *h = (Hash *) ho; + Hash *h = (Hash *) ObjData(ho); if (h->currentindex < 0) return hash_first(h); /* Try to move to the next entry */ @@ -363,15 +359,14 @@ Hash_str(DOH *ho) { int i; HashNode *n; DOH *s; - Hash *h; + Hash *h = (Hash *) ObjData(ho); - h = (Hash *) ho; s = NewString(""); - if (h->flags & DOH_FLAG_PRINT) { - Printf(s,"Hash(0x%x)",h); + if (ObjGetMark(ho)) { + Printf(s,"Hash(0x%x)",ho); return s; } - h->flags = h->flags | DOH_FLAG_PRINT; + ObjSetMark(ho,1); Printf(s,"Hash {\n"); for (i = 0; i < h->hashsize; i++) { n = h->hashtable[i]; @@ -381,7 +376,7 @@ Hash_str(DOH *ho) { } } Printf(s,"}\n"); - h->flags = h->flags & ~DOH_FLAG_PRINT; + ObjSetMark(ho,0); return s; } @@ -393,7 +388,7 @@ Hash_str(DOH *ho) { static int Hash_len(DOH *ho) { - Hash *h = (Hash *) ho; + Hash *h = (Hash *) ObjData(ho); return h->nitems; } @@ -428,9 +423,8 @@ CopyHash(DOH *ho) { Hash *h, *nh; HashNode *n; int i; - h = (Hash *) ho; - nh = (Hash *) DohObjMalloc(sizeof(Hash)); - nh->objinfo = h->objinfo; + h = (Hash *) ObjData(ho); + nh = (Hash *) DohMalloc(sizeof(Hash)); nh->hashsize = h->hashsize; nh->hashtable = (HashNode **) DohMalloc(nh->hashsize*sizeof(HashNode *)); 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 = { "Hash", /* objname */ - sizeof(Hash), /* size */ DelHash, /* doh_del */ CopyHash, /* doh_copy */ Hash_clear, /* doh_clear */ Hash_str, /* doh_str */ 0, /* doh_data */ 0, /* doh_dump */ - 0, /* doh_load */ Hash_len, /* doh_len */ 0, /* doh_hash */ 0, /* doh_cmp */ + 0, /* doh_setfile */ + 0, /* doh_getfile */ + 0, /* doh_setline */ + 0, /* doh_getline */ &HashHashMethods, /* doh_mapping */ 0, /* doh_sequence */ 0, /* doh_file */ 0, /* doh_string */ - 0, /* doh_callable */ 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() * @@ -512,8 +493,12 @@ DOH * NewHash() { Hash *h; int i; - h = (Hash *) DohObjMalloc(sizeof(Hash)); - h->objinfo = &HashType; + static int init = 0; + if (!init) { + DohRegisterType(DOHTYPE_HASH, &HashType); + init = 1; + } + h = (Hash *) DohMalloc(sizeof(Hash)); h->hashsize = HASH_INIT_SIZE; h->hashtable = (HashNode **) DohMalloc(h->hashsize*sizeof(HashNode *)); for (i = 0; i < h->hashsize; i++) { @@ -522,5 +507,7 @@ NewHash() { h->currentindex = -1; h->current = 0; h->nitems = 0; - return (DOH *) h; + h->file = 0; + h->line = 0; + return DohObjMalloc(DOHTYPE_HASH,h); } diff --git a/Source/DOH/Doh/list.c b/Source/DOH/Doh/list.c index c05f720a1..bed927cfb 100644 --- a/Source/DOH/Doh/list.c +++ b/Source/DOH/Doh/list.c @@ -14,10 +14,11 @@ static char cvsroot[] = "$Header$"; #include "dohint.h" typedef struct List { - DOHCOMMON; int maxitems; /* Max size */ int nitems; /* Num items */ int iter; /* Iterator */ + DOH *file; + int line; DOH **items; } List; @@ -38,9 +39,8 @@ static DOH * CopyList(DOH *lo) { List *l,*nl; int i; - l = (List *) lo; - nl = (List *) DohObjMalloc(sizeof(List)); - nl->objinfo = l->objinfo; + l = (List *) ObjData(lo); + nl = (List *) DohMalloc(sizeof(List)); nl->nitems = l->nitems; nl->maxitems = l->maxitems; nl->items = (void **) DohMalloc(l->maxitems*sizeof(void *)); @@ -52,7 +52,7 @@ CopyList(DOH *lo) { nl->file = l->file; if (nl->file) Incref(nl->file); nl->line = l->line; - return (DOH *) nl; + return DohObjMalloc(DOHTYPE_LIST, nl); } /* ----------------------------------------------------------------------------- @@ -63,13 +63,12 @@ CopyList(DOH *lo) { static void DelList(DOH *lo) { - List *l; + List *l = (List *) ObjData(lo); int i; - l = (List *) lo; for (i = 0; i < l->nitems; i++) Delete(l->items[i]); DohFree(l->items); - DohObjFree(l); + DohFree(l); } /* ----------------------------------------------------------------------------- @@ -80,9 +79,8 @@ DelList(DOH *lo) { static void List_clear(DOH *lo) { - List *l; + List *l = (List *) lo; int i; - l = (List *) lo; for (i = 0; i < l->nitems; i++) { Delete(l->items[i]); } @@ -98,18 +96,14 @@ List_clear(DOH *lo) { static int List_insert(DOH *lo, int pos, DOH *item) { - List *l; - DohBase *b; + List *l = (List *) ObjData(lo); int i; if (!item) return -1; - l = (List *) lo; - if (!DohCheck(item)) { item = NewString(item); Decref(item); } - b = (DohBase *) item; if (pos == DOH_END) pos = l->nitems; if (pos < 0) pos = 0; 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[pos] = item; - b->refcount++; + Incref(item); l->nitems++; return 0; } @@ -131,9 +125,8 @@ List_insert(DOH *lo, int pos, DOH *item) { static int List_remove(DOH *lo, int pos) { - List *l; + List *l = (List *) ObjData(lo); int i; - l = (List *) lo; if (pos == DOH_END) pos = l->nitems-1; if (pos == DOH_BEGIN) pos = 0; assert((pos < 0) || (pos >= l->nitems)); @@ -153,7 +146,8 @@ List_remove(DOH *lo, int pos) { static int 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 * List_get(DOH *lo, int n) { - List *l; - l = (List *) lo; + List *l = (List *) ObjData(lo); if (n == DOH_END) n = l->nitems-1; if (n == DOH_BEGIN) n = 0; assert((n < 0) || (n >= l->nitems)); @@ -180,8 +173,7 @@ List_get(DOH *lo, int n) { static int List_set(DOH *lo, int n, DOH *val) { - List *l; - l = (List *) lo; + List *l = (List *) ObjData(lo); if (!val) return -1; assert((n < 0) || (n >= l->nitems)); if (!DohCheck(val)) { @@ -203,8 +195,7 @@ List_set(DOH *lo, int n, DOH *val) { static DOH * List_first(DOH *lo) { - List *l; - l = (List *) lo; + List *l = (List *) ObjData(lo); l->iter = 0; if (l->iter >= l->nitems) return 0; return l->items[l->iter]; @@ -218,8 +209,7 @@ List_first(DOH *lo) { static DOH * List_next(DOH *lo) { - List *l; - l = (List *) lo; + List *l = (List *) ObjData(lo); l->iter++; if (l->iter >= l->nitems) return 0; return l->items[l->iter]; @@ -228,20 +218,19 @@ List_next(DOH *lo) { /* ----------------------------------------------------------------------------- * List_str() * - * Create a string representation of the list + * Create a string representation of the list. * ----------------------------------------------------------------------------- */ static DOH * List_str(DOH *lo) { DOH *s; int i; - - List *l = (List *) lo; + List *l = (List *) ObjData(lo); s = NewString(""); - if (l->flags & DOH_FLAG_PRINT) { - Printf(s,"List(0x%x)",l); + if (ObjGetMark(lo)) { + Printf(s,"List(%x)", lo); return s; } - l->flags = l->flags | DOH_FLAG_PRINT; + ObjSetMark(lo,1); Printf(s,"List[ "); for (i = 0; i < l->nitems; i++) { Printf(s, "%s", l->items[i]); @@ -249,7 +238,7 @@ List_str(DOH *lo) { Printf(s,", "); } Printf(s," ]\n"); - l->flags = l->flags & ~DOH_FLAG_PRINT; + ObjSetMark(lo,0); return s; } @@ -263,7 +252,7 @@ static int List_dump(DOH *lo, DOH *out) { int nsent = 0; int i,ret; - List *l = (List *) lo; + List *l = (List *) ObjData(lo); for (i = 0; i < l->nitems; i++) { ret = Dump(l->items[i],out); if (ret < 0) return -1; @@ -272,80 +261,12 @@ List_dump(DOH *lo, DOH *out) { 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() - * - * Sorts a list * ----------------------------------------------------------------------------- */ + static int objcmp(const void *s1, const void *s2) { DOH **so1, **so2; so1 = (DOH **) s1; @@ -354,9 +275,72 @@ static int objcmp(const void *s1, const void *s2) { } void -List_sort(DOH *so) { - List *l; - if (!List_check(so)) return; - l = (List *) so; - qsort(l->items,l->nitems,sizeof(DOH *), objcmp); +List_sort(DOH *lo, int opt) { + List *l = (List *) ObjData(lo); + 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); } diff --git a/Source/DOH/Doh/memory.c b/Source/DOH/Doh/memory.c index 67e3225e1..16b1d0d11 100644 --- a/Source/DOH/Doh/memory.c +++ b/Source/DOH/Doh/memory.c @@ -15,25 +15,22 @@ static char cvsroot[] = "$Header$"; #include "dohint.h" #ifndef DOH_POOL_SIZE -#define DOH_POOL_SIZE 128000 -#endif - -#ifndef DOH_MAX_FRAG -#define DOH_MAX_FRAG 1024 +#define DOH_POOL_SIZE 16384 #endif static int PoolSize = DOH_POOL_SIZE; + DOH *DohNone = 0; /* The DOH None object */ -static DohBase *FreeFragments[DOH_MAX_FRAG]; /* Array of free memory fragments */ - typedef struct pool { - char *ptr; /* Start of pool */ + DohBase *ptr; /* Start of pool */ int len; /* Length of pool */ int current; /* Current position for next allocation */ struct pool *next; /* Next pool */ } Pool; +DohBase *FreeList = 0; /* List of free objects */ + static Pool *Pools = 0; static int pools_initialized = 0; @@ -41,18 +38,15 @@ static int pools_initialized = 0; * CreatePool() - Create a new memory pool * ---------------------------------------------------------------------- */ -static Pool * -CreatePool(int size) { +static void +CreatePool() { Pool *p = 0; - char *c; - c = (char *) DohMalloc(size); - if (!c) return 0; - p = (Pool *) DohMalloc(sizeof(Pool)); - p->ptr = c; - p->len = size; + assert((p = (Pool *) DohMalloc(sizeof(Pool)))); + assert((p->ptr = (DohBase *) DohMalloc(sizeof(DohBase)*PoolSize))); + p->len = PoolSize; p->current = 0; - p->next = 0; - return p; + p->next = Pools; + Pools = p; } /* ---------------------------------------------------------------------- @@ -63,10 +57,7 @@ static void InitPools() { int i; if (pools_initialized) return; - for (i = 0; i < DOH_MAX_FRAG; i++) { - FreeFragments[i] = 0; - } - Pools = CreatePool(PoolSize); /* Create initial pool */ + CreatePool(); /* Create initial pool */ pools_initialized = 1; DohNone = NewVoid(0,0); /* Create the None object */ DohIntern(DohNone); @@ -78,59 +69,54 @@ InitPools() { * Returns 1 if an arbitrary pointer is a DOH object. * ---------------------------------------------------------------------- */ -/* Possible optimization: Reorder pools to move last match to the beginning */ int DohCheck(const DOH *ptr) { Pool *p = Pools; char *cptr = (char *) ptr; while (p) { - if ((cptr >= p->ptr) && (cptr < p->ptr+p->current)) { - return 1; - } + if ((cptr >= (char *) p->ptr) && (cptr < ((char *) p->ptr)+(p->current*sizeof(DohBase)))) return 1; p = p->next; } return 0; } +/* ----------------------------------------------------------------------------- + * DohIntern() + * ----------------------------------------------------------------------------- */ + +void +DohIntern(DOH *obj) { + DohBase *b = (DohBase *) obj; + b->flag_intern = 1; +} + /* ---------------------------------------------------------------------- * DohObjMalloc() * * Allocate memory for a new object. * ---------------------------------------------------------------------- */ -void * -DohObjMalloc(size_t size) { - Pool *p; - DohBase *f; - void *ptr = 0; - - if (size > DOH_MAX_FRAG) return 0; +DOH * +DohObjMalloc(int type, void *data) { + DohBase *obj; if (!pools_initialized) InitPools(); - - /* adjust the size for double word alignment */ - size = (size + 7) & ~0x07; - - p = Pools; - f = FreeFragments[size]; - if (f) { - ptr = (void *) f; - FreeFragments[size] = (DohBase *) f->file; - DohInit(ptr); - return ptr; + if (FreeList) { + obj = FreeList; + FreeList = (DohBase *) obj->data; + } else { + while (Pools->current == Pools->len) { + PoolSize *= 2; + CreatePool(); + } + obj = Pools->ptr + Pools->current; + Pools->current++; } - - /* No free fragments. See if the pool is large enough */ - if ((int) size < (p->len - p->current)) { - ptr = (void *) (p->ptr + p->current); - p->current = p->current + size; - DohInit(ptr); - return ptr; - } - PoolSize *= 2; - p = CreatePool(PoolSize); - p->next = Pools; - Pools = p; - return DohObjMalloc(size); + obj->type = type; + obj->data = data; + obj->refcount = 1; + obj->flag_intern = 0; + obj->flag_marked = 0; + return (DOH *) obj; } /* ---------------------------------------------------------------------- @@ -140,13 +126,9 @@ DohObjMalloc(size_t size) { void DohObjFree(DOH *ptr) { DohBase *b; - int len; b = (DohBase *) ptr; - if (b->flags & DOH_FLAG_INTERN) return; - if (b->file) DohDelete(b->file); - len = (b->objinfo->objsize + 7) & ~0x07; - b->file = (DOH *) FreeFragments[len]; - FreeFragments[len] = b; - b->objinfo = 0; - b->flags = b->flags | DOH_FLAG_DELETED; + if (b->flag_intern) return; + b->data = (void *) FreeList; + b->type = 0; + FreeList = b; } diff --git a/Source/DOH/Doh/string.c b/Source/DOH/Doh/string.c index 14f186eca..e03f72a91 100644 --- a/Source/DOH/Doh/string.c +++ b/Source/DOH/Doh/string.c @@ -19,112 +19,32 @@ static char cvsroot[] = "$Header$"; #endif typedef struct String { - DOHCOMMON; - int maxsize; /* Max size allocated */ - int len; /* Current length */ - int hashkey; /* Hash key value */ - int sp; /* Current position */ - char *str; /* String data */ + DOH *file; + int line; + int maxsize; /* Max size allocated */ + int len; /* Current length */ + int hashkey; /* Hash key value */ + int sp; /* Current position */ + char *str; /* String data */ } String; -/* Forward references */ - -void DelString(DOH *s); -DOH *CopyString(DOH *s); -void String_clear(DOH *s); -DOH *String_str(DOH *s); -int String_delitem(DOH *s, int where); -int String_len(DOH *s); -void String_appendfv(DOH *s, char *fmt, va_list ap); -int String_insertfv(DOH *s, int pos, char *fmt, va_list ap); -int String_insert(DOH *s, int pos, DOH *DOH); -void *String_data(DOH *s); -int String_cmp(DOH *, DOH *); -int String_hash(DOH *s); -int String_dump(DOH *s, DOH *out); -int String_read(DOH *s, void *buffer, int length); -int String_write(DOH *s, void *buffer, int length); -int String_getc(DOH *s); -int String_putc(DOH *s, int ch); -int String_ungetc(DOH *s, int ch); -int String_seek(DOH *s, long offset, int whence); -long String_tell(DOH *s); -int String_replace(DOH *str, DOH *token, DOH *rep, int flags); -void String_chop(DOH *str); - -static DohListMethods StringListMethods = { - 0, /* doh_getitem */ - 0, /* doh_setitem */ - String_delitem, /* doh_delitem */ - String_insert, /* doh_insitem */ - 0, /* doh_first */ - 0, /* doh_next */ -}; - -static DohFileMethods StringFileMethods = { - String_read, - String_write, - String_putc, - String_getc, - String_ungetc, - String_seek, - String_tell, - 0, /* close */ -}; - -static DohStringMethods StringStringMethods = { - String_replace, - String_chop, -}; - -static DohObjInfo StringType = { - "String", /* objname */ - sizeof(String), /* objsize */ - DelString, /* doh_del */ - CopyString, /* doh_copy */ - String_clear, /* doh_clear */ - String_str, /* doh_str */ - String_data, /* doh_data */ - String_dump, /* doh_dump */ - 0, /* doh_load */ - String_len, /* doh_len */ - String_hash, /* doh_hash */ - String_cmp, /* doh_cmp */ - 0, /* doh_mapping */ - &StringListMethods, /* doh_sequence */ - &StringFileMethods,/* doh_file */ - &StringStringMethods, /* doh_string */ - 0, /* doh_callable */ - 0, /* doh_position */ -}; - -#define INIT_MAXSIZE 16 - -DohObjInfo *String_type() { - return &StringType; -} - /* ----------------------------------------------------------------------------- - * void *String_data(DOH *so) - Return as a 'void *' + * void *String_data() - Return as a 'void *' * ----------------------------------------------------------------------------- */ void *String_data(DOH *so) { - String *s = (String *) so; + String *s = (String *) ObjData(so); s->str[s->len] = 0; return (void *) s->str; } /* ----------------------------------------------------------------------------- - * int String_dump(DOH *so, DOH *out) - * - * Serialize a string onto out + * int String_dump() - Serialize a string onto out * ----------------------------------------------------------------------------- */ int String_dump(DOH *so, DOH *out) { int nsent; int ret; - String *s; - - s = (String *) so; + String *s = (String *) ObjData(so); nsent = 0; while (nsent < s->len) { ret = Write(out,s->str+nsent,(s->len-nsent)); @@ -135,69 +55,14 @@ int String_dump(DOH *so, DOH *out) { } /* ----------------------------------------------------------------------------- - * NewString(const char *c) - Create a new string - * ----------------------------------------------------------------------------- */ -DOHString * -NewString(const DOH *so) -{ - int l = 0, max; - String *str; - char *s; - if (DohCheck(so)) s = Char(so); - else s = (char *) so; - str = (String *) DohObjMalloc(sizeof(String)); - str->objinfo = &StringType; - str->hashkey = -1; - str->sp = 0; - str->line = 1; - str->file = 0; - max = INIT_MAXSIZE; - if (s) { - l = (int) strlen(s); - if ((l+1) > max) max = l+1; - } - str->str = (char *) DohMalloc(max); - str->maxsize = max; - if (s) { - strcpy(str->str,s); - str->len = l; - } else { - str->str[0] = 0; - str->len = 0; - } - /* str->sp = str->len; */ - return (DOHString *) str; -} - -/* ----------------------------------------------------------------------------- - * NewStringf(DOH *fmt, ...) - * - * Create a new string from a list of objects. - * ----------------------------------------------------------------------------- */ - -DOHString * -NewStringf(const DOH *fmt, ...) -{ - va_list ap; - DOH *r; - va_start(ap,fmt); - r = NewString(""); - DohvPrintf(r,Char(fmt),ap); - va_end(ap); - return (DOHString *) r; -} - -/* ----------------------------------------------------------------------------- - * CopyString(DOH *s) - Copy a string + * CopyString() - Copy a string * ----------------------------------------------------------------------------- */ DOH * CopyString(DOH *so) { - String *s; + String *s = (String *) ObjData(so); int max; String *str; - s = (String *) so; - str = (String *) DohObjMalloc(sizeof(String)); - str->objinfo = &StringType; + str = (String *) DohMalloc(sizeof(String)); str->hashkey = -1; str->sp = 0; str->line = s->line; @@ -209,87 +74,67 @@ CopyString(DOH *so) { str->maxsize= max; str->len = s->len; str->str[str->len] = 0; - /* str->sp = s->len;*/ - return (DOH *) str; + return DohObjMalloc(DOHTYPE_STRING,str); } /* ----------------------------------------------------------------------------- - * DelString(DOH *s) - Delete a string + * DelString() - Delete a string * ----------------------------------------------------------------------------- */ void DelString(DOH *so) { - String *s; - s = (String *) so; - assert(s->refcount <= 0); - if (s->str) - DohFree(s->str); - s->str = 0; - DohObjFree(s); + String *s = (String *) ObjData(so); + DohFree(s->str); + DohFree(s); } /* ----------------------------------------------------------------------------- - * int String_check(DOH *s) - Check if s is a string - * ----------------------------------------------------------------------------- */ -int -String_check(const DOH *s) -{ - char *c = (char *) s; - if (!s) return 0; - if (DohCheck(s)) { - if (((String *) c)->objinfo == &StringType) - return 1; - return 0; - } - else return 0; -} - -/* ----------------------------------------------------------------------------- - * int String_len(DOH *s) - Length of a string + * String_len() - Length of a string * ----------------------------------------------------------------------------- */ int String_len(DOH *so) { - String *s = (String *)so; + String *s = (String *) ObjData(so); return s->len; } /* ----------------------------------------------------------------------------- - * int String_cmp(DOH *s1, DOH *s2) - Compare two strings + * int String_cmp() - Compare two strings * ----------------------------------------------------------------------------- */ int String_cmp(DOH *so1, DOH *so2) { - String *s1, *s2; - char *c1, *c2; - int maxlen,i; - s1 = (String *) so1; - s2 = (String *) so2; - maxlen = s1->len; - if (s2->len < maxlen) maxlen = s2->len; - c1 = s1->str; - c2 = s2->str; - for (i = 0; i < maxlen; i++,c1++,c2++) { - if (*c1 != *c2) break; - } - if (i < maxlen) { - if (*c1 < *c2) return -1; - else return 1; - } - if (s1->len == s2->len) return 0; - if (s1->len > s2->len) return 1; - return -1; + String *s1, *s2; + char *c1, *c2; + int maxlen,i; + s1 = (String *) ObjData(so1); + s2 = (String *) ObjData(so2); + maxlen = s1->len; + if (s2->len < maxlen) maxlen = s2->len; + c1 = s1->str; + c2 = s2->str; + for (i = 0; i < maxlen; i++,c1++,c2++) { + if (*c1 != *c2) break; + } + if (i < maxlen) { + if (*c1 < *c2) return -1; + else return 1; + } + if (s1->len == s2->len) return 0; + if (s1->len > s2->len) return 1; + return -1; } /* ----------------------------------------------------------------------------- - * int String_hash(DOH *s) - Compute string hash value + * int String_hash() - Compute string hash value * ----------------------------------------------------------------------------- */ int String_hash(DOH *so) { - String *s = (String *) so; + String *s = (String *) ObjData(so); char *c; int i, h = 0, len; + if (s->hashkey >= 0) return s->hashkey; c = s->str; len = s->len > 50 ? 50 : s->len; @@ -331,8 +176,7 @@ add(String *s, const char *newstr) { /* Add a single character to s */ void -String_addchar(DOH *so, char c) { - String *s = (String *) so; +String_addchar(String *s, char c) { s->hashkey = -1; if ((s->len+1) > (s->maxsize-1)) { s->str = (char *) DohRealloc(s->str,2*s->maxsize); @@ -359,14 +203,13 @@ String_expand(String *s, int width) { } /* ----------------------------------------------------------------------------- - * void String_clear(DOH *s) - Clear a string + * void String_clear() - Clear a string * ----------------------------------------------------------------------------- */ void String_clear(DOH *so) { - String *s; - s = (String *) so; + String *s = (String *) ObjData(so); s->hashkey = -1; s->len = 0; *(s->str) = 0; @@ -374,72 +217,57 @@ String_clear(DOH *so) s->line = 1; } -void -raw_insert(String *s, int pos, char *data, int len) -{ - char *nstr; - nstr = s->str; - s->hashkey = -1; - if (pos == DOH_END) { - add(s, data); - return; +/* ----------------------------------------------------------------------------- + * void String_insert() - Insert a string + * ----------------------------------------------------------------------------- */ + +int String_insert(DOH *so, int pos, DOH *str) { + String *s = (String *) ObjData(so); + char *nstr; + int len; + char *data; + + data = (char *) DohData(str); + nstr = s->str; + + s->hashkey = -1; + if (pos == DOH_END) { + add(s, data); + return 0; + } + + if (pos < 0) pos = 0; + else if (pos > s->len) pos = s->len; + + /* See if there is room to insert the new data */ + len = Len(str); + while (s->maxsize <= s->len+len) { + s->str = (char *) DohRealloc(s->str,2*s->maxsize); + assert(s->str); + s->maxsize *= 2; + } + memmove(s->str+pos+len, s->str+pos, (s->len - pos)); + memcpy(s->str+pos,data,len); + if (s->sp >= pos) { + int i; + + for (i = 0; i < len; i++) { + if (data[i] == '\n') s->line++; } - if (pos < 0) pos = 0; - else if (pos > s->len) pos = s->len; - - /* See if there is room to insert the new data */ - - while (s->maxsize <= s->len+len) { - s->str = (char *) DohRealloc(s->str,2*s->maxsize); - assert(s->str); - s->maxsize *= 2; - } - memmove(s->str+pos+len, s->str+pos, (s->len - pos)); - memcpy(s->str+pos,data,len); - if (s->sp >= pos) { - int i; - - for (i = 0; i < len; i++) { - if (data[i] == '\n') s->line++; - } - s->sp+=len; - } - - s->len += len; - s->str[s->len] = 0; + s->sp+=len; + } + s->len += len; + s->str[s->len] = 0; + return 0; } /* ----------------------------------------------------------------------------- - * void String_insert(DOH *so, int pos, SO *str) - Insert a string - * ----------------------------------------------------------------------------- */ -int -String_insert(DOH *so, int pos, DOH *str) -{ - String *s, *s1; - char *c; - int len; - s = (String *) so; - if (!DohCheck(str)) { - c = (char *) str; - len = strlen(c); - } else { - s1 = (String *) str; - len = s1->len; - c = s1->str; - } - raw_insert(s,pos,c,len); - return 0; -} - -/* ----------------------------------------------------------------------------- - * int String_delitem(DOH *so, int pos) - * - * Delete an individual item + * int String_delitem() - Delete a character * ----------------------------------------------------------------------------- */ int String_delitem(DOH *so, int pos) { - String *s = (String *) so; + String *s = (String *) ObjData(so); s->hashkey = -1; if (pos == DOH_END) pos = s->len-1; if (pos == DOH_BEGIN) pos = 0; @@ -457,27 +285,23 @@ int String_delitem(DOH *so, int pos) } /* ----------------------------------------------------------------------------- - * DOH *String_str(DOH *so) - Returns a string (used by printing commands) + * DOH *String_str() - Returns a string (used by printing commands) * ----------------------------------------------------------------------------- */ DOH * String_str(DOH *so) { - DOH *nstr; - String *s = (String *) so; - nstr = CopyString(s); - return nstr; + String *s = (String *) ObjData(so); + return NewString(s->str); } /* ----------------------------------------------------------------------------- - * int String_read(DOH *so, void *buffer, int len) - * - * Read data from the string + * int String_read() - Read data from a string * ----------------------------------------------------------------------------- */ int String_read(DOH *so, void *buffer, int len) { int reallen, retlen; char *cb; - String *s = (String *) so; + String *s = (String *) ObjData(so); if ((s->sp + len) > s->len) reallen = (s->len - s->sp); else reallen = len; @@ -492,14 +316,12 @@ String_read(DOH *so, void *buffer, int len) { } /* ----------------------------------------------------------------------------- - * int String_write(DOH *so, void *buffer, int len) - * - * Write data to the string + * int String_write() - Write data to a string * ----------------------------------------------------------------------------- */ int String_write(DOH *so, void *buffer, int len) { int newlen; - String *s = (String *) so; + String *s = (String *) ObjData(so); s->hashkey = -1; newlen = s->sp + len+1; if (newlen > s->maxsize) { @@ -515,15 +337,13 @@ String_write(DOH *so, void *buffer, int len) { } /* ----------------------------------------------------------------------------- - * int String_seek(DOH *so, long offset, int whence) - * - * Seek to a new position + * int String_seek() - Seek to a new position * ----------------------------------------------------------------------------- */ int String_seek(DOH *so, long offset, int whence) { int pos, nsp, inc; int prev; - String *s = (String *) so; + String *s = (String *) ObjData(so); if (whence == SEEK_SET) pos = 0; else if (whence == SEEK_CUR) pos = s->sp; else if (whence == SEEK_END) { @@ -551,25 +371,21 @@ String_seek(DOH *so, long offset, int whence) { } /* ----------------------------------------------------------------------------- - * long String_tell(DOH *so) - * - * Return current position + * long String_tell() - Return current position * ----------------------------------------------------------------------------- */ long String_tell(DOH *so) { - String *s = (String *) so; + String *s = (String *) ObjData(so); return (long) (s->sp); } /* ----------------------------------------------------------------------------- - * int String_putc(DOH *so, int ch) - * - * Put a character into the string. + * int String_putc() * ----------------------------------------------------------------------------- */ int String_putc(DOH *so, int ch) { - String *s = (String *) so; + String *s = (String *) ObjData(so); s->hashkey = -1; if (s->sp >= s->len) { String_addchar(s,(char) ch); @@ -582,15 +398,12 @@ String_putc(DOH *so, int ch) { } /* ----------------------------------------------------------------------------- - * int String_getc(DOH *so) - * - * Get a character from the string. Updates the line number. + * int String_getc() * ----------------------------------------------------------------------------- */ int String_getc(DOH *so) { int c; - String *s = (String *) so; - + String *s = (String *) ObjData(so); if (s->sp >= s->len) c = EOF; else @@ -600,12 +413,11 @@ int String_getc(DOH *so) { } /* ----------------------------------------------------------------------------- - * int String_ungetc(DOH *so, int ch) - * - * Put a character back on to the input stream. Updates the line count. + * int String_ungetc() * ----------------------------------------------------------------------------- */ + int String_ungetc(DOH *so, int ch) { - String *s = (String *) so; + String *s = (String *) ObjData(so); if (ch == EOF) return ch; if (s->sp <= 0) return EOF; s->sp--; @@ -613,146 +425,260 @@ int String_ungetc(DOH *so, int ch) { return ch; } + /* ----------------------------------------------------------------------------- - * int replace_internal(String *str, char *token, char *rep, int flags, char *start, int count) + * replace_simple(String *str, char *token, char *rep, int flags, int count) * - * Replaces token with rep. flags is as follows: - * - * DOH_REPLACE_ANY - Replace all occurrences - * DOH_REPLACE_NOQUOTE - Don't replace in quotes - * DOH_REPLACE_ID - Only replace valid identifiers - * DOH_REPLACE_FIRST - Only replace first occurrence - * - * start is a starting position. count is a count. + * Replaces count non-overlapping occurrences of token with rep in a string. * ----------------------------------------------------------------------------- */ +static char *end_quote(char *s) { + char qc; + char *q; + qc = *s; + while (1) { + q = strpbrk(s+1,"\"\'"); + if (!q) return 0; + if ((*q == qc) && (*(q-1) != '\\')) return q; + s = q; + } +} + +static char *match_simple(char *base, char *s, char *token, int tokenlen) { + return strstr(s,token); +} + +static char *match_identifier(char *base, char *s, char *token, int tokenlen) { + while (s) { + s = strstr(s,token); + if (!s) return 0; + if ((s > base) && (isalnum(*(s-1)) || (*(s-1) == '_'))) { + s += tokenlen; + continue; + } + if (isalnum(*(s+tokenlen)) || (*(s+tokenlen) == '_')) { + s += tokenlen; + continue; + } + return s; + } +} + static -int replace_internal(String *str, char *token, char *rep, int flags, char *start, int count) +int replace_simple(String *str, char *token, char *rep, int flags, int count, char *(*match)(char *, char *, char *, int)) { - char *s, *c, *t; - int tokenlen; - int state; - int repcount = 0; + int tokenlen; /* Length of the token */ + int replen; /* Length of the replacement */ + int delta, expand = 0; + int ic; + int rcount = 0; + int noquote = 0; + char *c, *s, *t, *end, *first; + char *q, *q2; + register char *base; + int i; - /* Copy the current string representation */ + /* Figure out if anything gets replaced */ - s = str->str; - str->hashkey = -1; + base = str->str; + tokenlen = strlen(token); + s = (*match)(base,base,token,tokenlen); - tokenlen = strlen(token); + if (!s) return 0; /* No matches. Who cares */ - /* If a starting position was given, dump those characters first */ + if (flags & DOH_REPLACE_NOQUOTE) noquote = 1; - if (start) { - c = start; + /* If we are not replacing inside quotes, we need to do a little extra work */ + if (noquote) { + q = strpbrk(base,"\"\'"); + if (!q) { + noquote = 0; /* Well, no quotes to worry about. Oh well */ } else { - c = s; + while (q && (q < s)) { + /* First match was found inside a quote. Try to find another match */ + q2 = end_quote(q); + if (!q2) { + return 0; + } + if (q2 > s) + s = (*match)(base,q2+1,token,tokenlen); + if (!s) return 0; /* Oh well, no matches */ + q = strpbrk(q2+1,"\"\'"); + if (!q) noquote = 0; /* No more quotes */ + } } + } - /* Now walk down the old string and search for tokens */ - t = strstr(c,token); - if (t) { - str->len = 0; - str->str = (char *) DohMalloc(str->maxsize); - if (start) { - char temp = *start; - *start = 0; - add(str,s); - *start = temp; - } + first = s; + replen = strlen(rep); - /* Depending on flags. We compare in different ways */ - state = 0; - t = c; - while ((*c) && (count)) { - switch(state) { - case 0: - if (*c == *token) { - if (!(flags & DOH_REPLACE_ID)) { - if (strncmp(c,token,tokenlen) == 0) { - char temp = *c; - *c = 0; - add(str,t); - *c = temp; - add(str,rep); - c += (tokenlen-1); - t = c+1; - count--; - repcount++; - } - } else if (isalpha(*c) || (*c == '_') || (*c == '$')) { - char temp = *c; - *c = 0; - add(str,t); - *c = temp; - t = c; - state = 10; - } - } else if (flags & DOH_REPLACE_NOQUOTE) { - if (*c == '\"') state = 20; - else if (*c == '\'') state = 30; - else if (*c == '\\' && - (*(c+1) == '\'' || *(c+1) == '\"')) - c++; - } - break; - case 10: /* The start of an identifier */ - if (isalnum(*c) || (*c == '_') || (*c == '$')) state = 10; - else { - char temp = *c; - *c = 0; - if (strcmp(token,t) == 0) { - add(str,rep); - count--; - repcount++; - } else { - add(str,t); - } - *c = temp; - t = c; - state = 0; - } - break; - case 20: /* A string */ - if (*c == '\"') state = 0; - else if (*c == '\\') c++; - break; - case 30: /* A Single quoted string */ - if (*c == '\'') state = 0; - else if (*c == '\\') c++; - break; - } - c++; - } - if ((count) && (state == 10)) { - if (strcmp(token,t) == 0) { - add(str,rep); - } else { - add(str,t); - } + delta = (replen - tokenlen); + + if (delta <= 0) { + /* String is either shrinking or staying the same size */ + /* In this case, we do the replacement in place without memory reallocation */ + ic = count; + t = s; /* Target of memory copies */ + while (ic && s) { + if (replen) { + memcpy(t,rep,replen); + t += replen; + } + rcount++; + expand += delta; + /* Find the next location */ + s += tokenlen; + if (ic == 1) break; + c = (*match)(base,s,token,tokenlen); + + if (noquote) { + q = strpbrk(s,"\"\'"); + if (!q) { + noquote = 0; } else { - add(str,t); + while (q && (q < c)) { + /* First match was found inside a quote. Try to find another match */ + q2 = end_quote(q); + if (!q2) { + c = 0; + break; + } + if (q2 > c) + c = (*match)(base,q2+1,token,tokenlen); + if (!c) break; + q = strpbrk(q2+1,"\"\'"); + if (!q) noquote = 0; /* No more quotes */ + } } - DohFree(s); + } + if (delta) { + if (c) { + memmove(t,s,c-s); + t += (c-s); + } else { + memmove(t,s,(str->str + str->len) - s + 1); + } + } else { + t += (c-s); + } + s = c; + ic--; } - return repcount; + if (s && delta) { + memmove(t,s,(str->str + str->len) - s + 1); + } + str->len += expand; + return rcount; + } + /* The string is expanding as a result of the replacement */ + /* Figure out how much expansion is going to occur and allocate a new string */ + { + char *ns; + int newsize; + + rcount++; + ic = count -1; + s += tokenlen; + while (ic && (c = (*match)(base,s,token,tokenlen))) { + if (noquote) { + q = strpbrk(s,"\"\'"); + if (!q) { + break; + } else { + while (q && (q < c)) { + /* First match was found inside a quote. Try to find another match */ + q2 = end_quote(q); + if (!q2) { + c = 0; + break; + } + if (q2 > c) + c = (*match)(base,q2+1,token,tokenlen); + if (!c) break; + q = strpbrk(q2+1,"\"\'"); + } + } + } + if (c) { + rcount++; + ic--; + s = c + tokenlen; + } else { + break; + } + } + expand = delta*rcount; /* Total amount of expansion for the replacement */ + newsize = str->maxsize; + while ((str->len + expand) > newsize) newsize *= 2; + + ns = (char *) DohMalloc(newsize); + assert(ns); + t = ns; + s = first; + + /* Copy the first part of the string */ + if (first > str->str) { + memcpy(t,str->str,(first - str->str)); + t += (first-str->str); + } + for (i = 0; i < rcount; i++) { + memcpy(t,rep,replen); + t += replen; + s += tokenlen; + c = (*match)(base,s,token,tokenlen); + if (noquote) { + q = strpbrk(s,"\"\'"); + if (!q) { + noquote = 0; + } else { + while (q && (q < c)) { + /* First match was found inside a quote. Try to find another match */ + q2 = end_quote(q); + if (!q2) { + c = 0; + break; + } + if (q2 > c) + c = (*match)(base,q2+1,token,tokenlen); + if (!c) break; + q = strpbrk(q2+1,"\"\'"); + if (!q) noquote = 0; /* No more quotes */ + } + } + } + if (i < (rcount - 1)) { + memcpy(t,s,c-s); + t += (c-s); + } else { + memcpy(t,s,(str->str + str->len) - s + 1); + } + s = c; + } + c = str->str; + str->str = ns; + str->len += expand; + str->maxsize = newsize; + DohFree(c); + return rcount; + } } /* ----------------------------------------------------------------------------- - * int String_replace(DOH *str, DOH *token, DOH *rep, int flags) + * int String_replace() * ----------------------------------------------------------------------------- */ int String_replace(DOH *stro, DOH *token, DOH *rep, int flags) { int count = -1; - String *str; - if (!String_check(stro)) return 0; - str = (String *) stro; - /* assert(str->refcount); */ - /* assert(!str->refcount); */ + String *str = (String *) ObjData(stro); if (flags & DOH_REPLACE_FIRST) count = 1; - return replace_internal(str,Char(token),Char(rep),flags,str->str,count); + + if (flags & DOH_REPLACE_ID) { + return replace_simple(str,Char(token),Char(rep),flags, count, match_identifier); + } else { + return replace_simple(str,Char(token), Char(rep), flags, count, match_simple); + } } /* ----------------------------------------------------------------------------- @@ -760,12 +686,9 @@ String_replace(DOH *stro, DOH *token, DOH *rep, int flags) * ----------------------------------------------------------------------------- */ void -String_chop(DOH *s) { +String_chop(DOH *so) { char *c; - String *str = (String *) s; - if (!String_check(s)) return; - /* assert(!str->refcount); */ - + String *str = (String *) ObjData(so); /* Replace trailing whitespace */ c = str->str + str->len - 1; while ((str->len > 0) && (isspace(*c))) { @@ -780,3 +703,139 @@ String_chop(DOH *s) { str->hashkey = -1; } +void String_setfile(DOH *so, DOH *file) { + DOH *fo; + String *str = (String *) ObjData(so); + + if (!DohCheck(file)) { + fo = NewString(file); + Decref(fo); + } else fo = file; + Incref(fo); + Delete(str->file); + str->file = fo; +} + +DOH *String_getfile(DOH *so) { + String *str = (String *) ObjData(so); + return str->file; +} + +void String_setline(DOH *so, int line) { + String *str = (String *) ObjData(so); + str->line = line; +} + +int String_getline(DOH *so) { + String *str = (String *) ObjData(so); + return str->line; +} + +static DohListMethods StringListMethods = { + 0, /* doh_getitem */ + 0, /* doh_setitem */ + String_delitem, /* doh_delitem */ + String_insert, /* doh_insitem */ + 0, /* doh_first */ + 0, /* doh_next */ + 0, /* doh_sort */ +}; + +static DohFileMethods StringFileMethods = { + String_read, + String_write, + String_putc, + String_getc, + String_ungetc, + String_seek, + String_tell, + 0, /* close */ +}; + +static DohStringMethods StringStringMethods = { + String_replace, + String_chop, +}; + +static DohObjInfo StringType = { + "String", /* objname */ + DelString, /* doh_del */ + CopyString, /* doh_copy */ + String_clear, /* doh_clear */ + String_str, /* doh_str */ + String_data, /* doh_data */ + String_dump, /* doh_dump */ + String_len, /* doh_len */ + String_hash, /* doh_hash */ + String_cmp, /* doh_cmp */ + String_setfile, /* doh_setfile */ + String_getfile, /* doh_getfile */ + String_setline, /* doh_setline */ + String_getline, /* doh_getline */ + 0, /* doh_mapping */ + &StringListMethods, /* doh_sequence */ + &StringFileMethods, /* doh_file */ + &StringStringMethods, /* doh_string */ + 0, /* doh_position */ + 0, +}; + + +#define INIT_MAXSIZE 16 + + +/* ----------------------------------------------------------------------------- + * NewString(const char *c) - Create a new string + * ----------------------------------------------------------------------------- */ +DOHString * +NewString(const DOH *so) +{ + int l = 0, max; + String *str; + char *s; + static int init = 0; + if (!init) { + DohRegisterType(DOHTYPE_STRING, &StringType); + init = 1; + } + if (DohCheck(so)) s = Char(so); + else s = (char *) so; + str = (String *) DohMalloc(sizeof(String)); + str->hashkey = -1; + str->sp = 0; + str->line = 1; + str->file = 0; + max = INIT_MAXSIZE; + if (s) { + l = (int) strlen(s); + if ((l+1) > max) max = l+1; + } + str->str = (char *) DohMalloc(max); + str->maxsize = max; + if (s) { + strcpy(str->str,s); + str->len = l; + } else { + str->str[0] = 0; + str->len = 0; + } + return DohObjMalloc(DOHTYPE_STRING,str); +} + +/* ----------------------------------------------------------------------------- + * NewStringf(DOH *fmt, ...) + * + * Create a new string from a list of objects. + * ----------------------------------------------------------------------------- */ + +DOHString * +NewStringf(const DOH *fmt, ...) +{ + va_list ap; + DOH *r; + va_start(ap,fmt); + r = NewString(""); + DohvPrintf(r,Char(fmt),ap); + va_end(ap); + return (DOHString *) r; +} diff --git a/Source/DOH/Doh/void.c b/Source/DOH/Doh/void.c index 6084a8278..63a94ea91 100644 --- a/Source/DOH/Doh/void.c +++ b/Source/DOH/Doh/void.c @@ -15,7 +15,6 @@ static char cvsroot[] = "$Header$"; #include "dohint.h" typedef struct { - DOHCOMMON; void *ptr; void (*del)(void *); } VoidObj; @@ -28,11 +27,10 @@ typedef struct { static void Void_delete(DOH *vo) { - VoidObj *v = (VoidObj *) vo; + VoidObj *v = (VoidObj *) ObjData(vo); if (v->del) (*v->del)(v->ptr); - v->del = 0; - DohObjFree(v); + DohFree(v); } /* ----------------------------------------------------------------------------- @@ -44,7 +42,7 @@ Void_delete(DOH *vo) { static DOH * Void_copy(DOH *vo) { - VoidObj *v = (VoidObj *) vo; + VoidObj *v = (VoidObj *) ObjData(vo); return NewVoid(v->ptr,0); } @@ -56,29 +54,31 @@ Void_copy(DOH *vo) { static void * Void_data(DOH *vo) { - VoidObj *v = (VoidObj *) vo; + VoidObj *v = (VoidObj *) ObjData(vo); return v->ptr; } static DohObjInfo DohVoidType = { "VoidObj", /* objname */ - sizeof(VoidObj), /* objsize */ Void_delete, /* doh_del */ Void_copy, /* doh_copy */ 0, /* doh_clear */ 0, /* doh_str */ Void_data, /* doh_data */ 0, /* doh_dump */ - 0, /* doh_load */ 0, /* doh_len */ 0, /* doh_hash */ 0, /* doh_cmp */ + 0, /* doh_setfile */ + 0, /* doh_getfile */ + 0, /* doh_setline */ + 0, /* doh_getline */ 0, /* doh_mapping */ 0, /* doh_sequence */ 0, /* doh_file */ 0, /* doh_string */ - 0, /* doh_reserved1 */ - 0, /* doh_reserved2 */ + 0, /* doh_reserved */ + 0, /* clientdata */ }; /* ----------------------------------------------------------------------------- @@ -89,10 +89,14 @@ static DohObjInfo DohVoidType = { DOH * NewVoid(void *obj, void (*del)(void *)) { + static int init = 0; VoidObj *v; - v = (VoidObj *) DohObjMalloc(sizeof(VoidObj)); - v->objinfo = &DohVoidType; + if (!init) { + DohRegisterType(DOHTYPE_VOID, &DohVoidType); + init = 1; + } + v = (VoidObj *) DohMalloc(sizeof(VoidObj)); v->ptr = obj; v->del = del; - return (DOH *) v; + return DohObjMalloc(DOHTYPE_VOID,v); } diff --git a/Source/DOH/Include/doh.h b/Source/DOH/Include/doh.h index e42bff9ba..3ef22be2e 100644 --- a/Source/DOH/Include/doh.h +++ b/Source/DOH/Include/doh.h @@ -17,10 +17,6 @@ #include #include -#ifdef __cplusplus -extern "C" { -#endif - #define DOH_MAJOR_VERSION 0 #define DOH_MINOR_VERSION 1 @@ -40,89 +36,10 @@ typedef void DOH; #define DOHString_or_char DOH #define DOHObj_or_char DOH -#define DOH_BEGIN -1 -#define DOH_END -2 -#define DOH_CUR -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; +#define DOH_BEGIN -1 +#define DOH_END -2 +#define DOH_CUR -3 +#define DOH_CURRENT -3 /* Memory management */ @@ -136,83 +53,80 @@ typedef struct DohObjInfo { #define DohFree free #endif - extern void *DohObjMalloc(size_t size); /* Allocate a DOH object */ - extern void DohObjFree(DOH *ptr); /* Free a DOH 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 */ +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 DOH *DohCopy(const DOH *obj); - extern void DohClear(DOH *obj); - extern DOHString *DohStr(const DOH *obj); - extern void *DohData(const DOH *obj); - extern int DohDump(const DOH *obj, DOHFile *out); - extern int DohLen(const DOH *obj); - extern int DohHashval(const DOH *obj); - extern int DohCmp(const DOH *obj1, const DOH *obj2); +extern void DohDelete(DOH *obj); /* Delete an object */ +extern DOH *DohCopy(const DOH *obj); +extern void DohClear(DOH *obj); +extern DOHString *DohStr(const DOH *obj); +extern void *DohData(const DOH *obj); +extern int DohDump(const DOH *obj, DOHFile *out); +extern int DohLen(const DOH *obj); +extern int DohHashval(const DOH *obj); +extern int DohCmp(const DOH *obj1, const DOH *obj2); - /* Mapping methods */ +/* Mapping methods */ - 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 void DohDelattr(DOH *obj, const DOHString_or_char *name); - extern DOH *DohFirstkey(DOH *obj); - extern DOH *DohNextkey(DOH *obj); - extern int DohGetInt(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 void DohSetInt(DOH *obj, const DOHString_or_char *name, int); - extern void DohSetDouble(DOH *obj, const DOHString_or_char *name, double); - extern void *DohGetVoid(DOH *obj, const DOHString_or_char *name); - extern void DohSetVoid(DOH *obj, const DOHString_or_char *name, void *value); +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 void DohDelattr(DOH *obj, const DOHString_or_char *name); +extern DOH *DohFirstkey(DOH *obj); +extern DOH *DohNextkey(DOH *obj); +extern int DohGetInt(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 void DohSetInt(DOH *obj, const DOHString_or_char *name, int); +extern void DohSetDouble(DOH *obj, const DOHString_or_char *name, double); +extern void *DohGetVoid(DOH *obj, const DOHString_or_char *name); +extern void DohSetVoid(DOH *obj, const DOHString_or_char *name, void *value); - /* Sequence methods */ +/* Sequence methods */ - extern DOH *DohGetitem(DOH *obj, int index); - extern int DohSetitem(DOH *obj, int index, const DOHObj_or_char *value); - extern int DohDelitem(DOH *obj, int index); - extern int DohInsertitem(DOH *obj, int index, const DOHObj_or_char *value); - extern DOH *DohFirstitem(DOH *obj); - extern DOH *DohNextitem(DOH *obj); +extern DOH *DohGetitem(DOH *obj, int index); +extern int DohSetitem(DOH *obj, int index, const DOHObj_or_char *value); +extern int DohDelitem(DOH *obj, int index); +extern int DohInsertitem(DOH *obj, int index, const DOHObj_or_char *value); +extern DOH *DohFirstitem(DOH *obj); +extern DOH *DohNextitem(DOH *obj); - /* File methods */ +/* File methods */ - extern int DohWrite(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 long DohTell(DOHFile *obj); - extern int DohGetc(DOHFile *obj); - extern int DohPutc(int ch, DOHFile *obj); - extern int DohUngetc(int ch, DOHFile *obj); +extern int DohWrite(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 long DohTell(DOHFile *obj); +extern int DohGetc(DOHFile *obj); +extern int DohPutc(int ch, DOHFile *obj); +extern int DohUngetc(int ch, DOHFile *obj); /* Positional */ - extern int DohGetline(DOH *obj); - extern void DohSetline(DOH *obj, int line); - extern DOH *DohGetfile(DOH *obj); - extern void DohSetfile(DOH *obj, DOH *file); +extern int DohGetline(DOH *obj); +extern void DohSetline(DOH *obj, int line); +extern DOH *DohGetfile(DOH *obj); +extern void DohSetfile(DOH *obj, DOH *file); /* String Methods */ - extern int DohReplace(DOHString *src, const DOHString_or_char *token, const DOHString_or_char *rep, int flags); - extern void DohChop(DOHString *src); +extern int DohReplace(DOHString *src, const DOHString_or_char *token, const DOHString_or_char *rep, int flags); +extern void DohChop(DOHString *src); /* Utility functions */ - extern void DohEncoding(char *name, DOH *(*fn)(DOH *s)); - extern int DohPrintf(DOHFile *obj, const char *format, ...); - extern int DohvPrintf(DOHFile *obj, const char *format, va_list ap); - extern DOH *DohReadline(DOHFile *in); +extern void DohEncoding(char *name, DOH *(*fn)(DOH *s)); +extern int DohPrintf(DOHFile *obj, const char *format, ...); +extern int DohvPrintf(DOHFile *obj, const char *format, va_list ap); +extern DOH *DohReadline(DOHFile *in); /* Miscellaneous */ - extern int DohIsMapping(const DOH *obj); - extern int DohIsSequence(const DOH *obj); - extern int DohIsString(const DOH *obj); - extern int DohIsFile(const DOH *obj); +extern int DohIsMapping(const DOH *obj); +extern int DohIsSequence(const DOH *obj); +extern int DohIsString(const DOH *obj); +extern int DohIsFile(const DOH *obj); #ifndef DOH_LONG_NAMES /* Macros to invoke the above functions. Includes the location of @@ -267,35 +181,6 @@ typedef struct DohObjInfo { #define Chop DohChop #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. * ----------------------------------------------------------------------------- */ @@ -303,14 +188,12 @@ typedef struct { extern DOHString *NewString(const DOH *c); extern DOHString *NewStringf(const DOH *fmt, ...); -extern int String_check(const DOH *s); - /* String replacement flags */ -#define DOH_REPLACE_ANY 0x00 -#define DOH_REPLACE_NOQUOTE 0x01 -#define DOH_REPLACE_ID 0x02 -#define DOH_REPLACE_FIRST 0x04 +#define DOH_REPLACE_ANY 0x01 +#define DOH_REPLACE_NOQUOTE 0x02 +#define DOH_REPLACE_ID 0x04 +#define DOH_REPLACE_FIRST 0x08 /* ----------------------------------------------------------------------------- * Files @@ -318,7 +201,6 @@ extern int String_check(const DOH *s); extern DOHFile *NewFile(DOH *file, char *mode); extern DOHFile *NewFileFromFile(FILE *f); -extern DOHFile *NewFileFromFd(int fd); extern int DohCopyto(DOHFile *input, DOHFile *output); #define Copyto DohCopyto @@ -328,15 +210,12 @@ extern int DohCopyto(DOHFile *input, DOHFile *output); * ----------------------------------------------------------------------------- */ extern DOHList *NewList(); -extern int List_check(const DOH *); -extern void List_sort(DOHList *); /* ----------------------------------------------------------------------------- * Hash * ----------------------------------------------------------------------------- */ extern DOHHash *NewHash(); -extern int Hash_check(const DOH *h); extern DOHList *Hash_keys(DOHHash *); /* ----------------------------------------------------------------------------- @@ -350,20 +229,6 @@ extern DOHList *DohSplit(DOHFile *input, char *chs, int nsplits); 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 */ diff --git a/Source/DOH/Include/dohint.h b/Source/DOH/Include/dohint.h index 2dff347fa..f2f5d2ac9 100644 --- a/Source/DOH/Include/dohint.h +++ b/Source/DOH/Include/dohint.h @@ -6,3 +6,4 @@ #include #include "doh.h" +#include "dohobj.h"