Cleanup
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@452 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
f4ab07f9b7
commit
945c7fc2e8
10 changed files with 67 additions and 357 deletions
|
|
@ -22,14 +22,14 @@ AR = @AR@
|
|||
# Normally, you shouldn't have to change anything below this point #
|
||||
########################################################################
|
||||
|
||||
LIBOBJS = callable.o void.o fio.o memory.o base.o file.o list.o hash.o string.o
|
||||
LIBOBJS = void.o fio.o memory.o base.o file.o list.o hash.o string.o
|
||||
|
||||
LIBSRCS = callable.c void.c fio.c memory.c base.c file.c list.c hash.c string.c
|
||||
LIBSRCS = void.c fio.c memory.c base.c file.c list.c hash.c string.c
|
||||
|
||||
LIBHEADERS = $(srcdir)/../Include/doh.h
|
||||
LIB = libdoh.a
|
||||
INCLUDE = -I$(srcdir)/../Include
|
||||
CFLAGS = @CFLAGS@ -DDOH_STRING_UPDATE_LINES
|
||||
CFLAGS = @CFLAGS@
|
||||
SHELL = /bin/sh
|
||||
|
||||
#
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ static DohObjInfo DohBaseType = {
|
|||
0, /* doh_del */
|
||||
0, /* doh_copy */
|
||||
0, /* doh_clear */
|
||||
0, /* doh_scope */
|
||||
0, /* doh_str */
|
||||
0, /* doh_data */
|
||||
0, /* doh_dump */
|
||||
|
|
@ -262,91 +261,6 @@ DohData(const DOH *obj) {
|
|||
return (char *) obj;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohGetLine()
|
||||
*
|
||||
* Return the line number associated with an object or -1 if unspecified.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
DohGetline(DOH *obj) {
|
||||
DohBase *b = (DohBase *) obj;
|
||||
DohTrace(DOH_CALLS,"DohGetline %x\n",obj);
|
||||
if (DohCheck(obj)) {
|
||||
if (b->objinfo->doh_position && b->objinfo->doh_position->doh_getline) {
|
||||
return (b->objinfo->doh_position->doh_getline)(b);
|
||||
} else {
|
||||
DohTrace(DOH_UNSUPPORTED,"No getline method defined for type '%s'\n", b->objinfo->objname);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
DohTrace(DOH_UNKNOWN, "Unknown object %x passed to Getline.\n", obj);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohSetLine()
|
||||
*
|
||||
* Set the line number associated with an object.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
DohSetline(DOH *obj, int line) {
|
||||
DohBase *b = (DohBase *) obj;
|
||||
DohTrace(DOH_CALLS,"DohSetline %x, %d\n",obj, line);
|
||||
if (DohCheck(obj)) {
|
||||
if (b->objinfo->doh_position && b->objinfo->doh_position->doh_setline) {
|
||||
(b->objinfo->doh_position->doh_setline)(obj, line);
|
||||
return;
|
||||
}
|
||||
DohTrace(DOH_UNSUPPORTED,"No setline method defined for type '%s'\n", b->objinfo->objname);
|
||||
} else {
|
||||
DohTrace(DOH_UNKNOWN, "Unknown object %x passed to Setline.\n", obj);
|
||||
}
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohGetfile()
|
||||
*
|
||||
* Get the file associated with an object.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *
|
||||
DohGetfile(DOH *obj) {
|
||||
DohBase *b = (DohBase *) obj;
|
||||
DohTrace(DOH_CALLS,"DohGetfile %x\n",obj);
|
||||
if (DohCheck(obj)) {
|
||||
if (b->objinfo->doh_position && b->objinfo->doh_position->doh_getfile) {
|
||||
return (b->objinfo->doh_position->doh_getfile)(b);
|
||||
}
|
||||
DohTrace(DOH_UNSUPPORTED,"No getfile method defined for type '%s'\n", b->objinfo->objname);
|
||||
} else {
|
||||
DohTrace(DOH_UNKNOWN, "Unknown object %x passed to Getfile.\n", obj);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohSetfile()
|
||||
*
|
||||
* Set the file associated with an object.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
DohSetfile(DOH *obj, DOH *file) {
|
||||
DohBase *b = (DohBase *) obj;
|
||||
DohTrace(DOH_CALLS,"DohSetfile %x, %x\n",obj,file);
|
||||
if (DohCheck(obj)) {
|
||||
if (b->objinfo->doh_position && b->objinfo->doh_position->doh_setfile) {
|
||||
(b->objinfo->doh_position->doh_setfile)(obj,file);
|
||||
return;
|
||||
}
|
||||
DohTrace(DOH_UNSUPPORTED,"No setfile method defined for type '%s'\n", b->objinfo->objname);
|
||||
} else {
|
||||
DohTrace(DOH_UNKNOWN, "Unknown object %x passed to Setfile.\n", obj);
|
||||
}
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohCmp()
|
||||
*
|
||||
|
|
@ -1050,43 +964,6 @@ DohChop(DOH *src) {
|
|||
}
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Callable methods
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohIsCallable()
|
||||
*
|
||||
* Return 1 if an object supports callable methods.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
DohIsCallable(const DOH *obj) {
|
||||
DohBase *b = (DohBase *) obj;
|
||||
if (!DohCheck(b)) return 0;
|
||||
if (b->objinfo->doh_callable) return 1;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohCall()
|
||||
*
|
||||
* Perform a function call on an object.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *
|
||||
DohCall(DOH *obj, DOH *args) {
|
||||
DohBase *b = (DohBase *) obj;
|
||||
DohTrace(DOH_CALLS,"DohCall %x\n",obj);
|
||||
if (DohCheck(b)) {
|
||||
if ((b->objinfo->doh_callable) && (b->objinfo->doh_callable->doh_call)) {
|
||||
return (b->objinfo->doh_callable->doh_call)(b,args);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohInit()
|
||||
*
|
||||
|
|
@ -1099,67 +976,67 @@ DohInit(DOH *b) {
|
|||
bs->refcount = 1;
|
||||
bs->objinfo = &DohBaseType;
|
||||
bs->flags = 0;
|
||||
bs->file = 0;
|
||||
bs->line = 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohXBase_setfile()
|
||||
* DohSetFile()
|
||||
*
|
||||
* Set file location (default method).
|
||||
* ----------------------------------------------------------------------------- */
|
||||
void
|
||||
DohXBase_setfile(DOH *ho, DOH *file) {
|
||||
DohXBase *h = (DohXBase *) ho;
|
||||
if (!DohCheck(file)) file = NewString(file);
|
||||
h->file = file;
|
||||
Incref(h->file);
|
||||
DohSetFile(DOH *ho, DOH *file) {
|
||||
DohBase *h = (DohBase *) ho;
|
||||
if (DohCheck(h)) {
|
||||
if (!DohCheck(file)) file = NewString(file);
|
||||
h->file = file;
|
||||
Incref(h->file);
|
||||
} else {
|
||||
DohTrace(DOH_UNKNOWN,"Unknown object %x passed to Setfile.\n",h);
|
||||
}
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohXBase_getfile()
|
||||
* DohGetFile()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *
|
||||
DohXBase_getfile(DOH *ho) {
|
||||
DohXBase *h = (DohXBase *) ho;
|
||||
return h->file;
|
||||
DohGetfile(DOH *ho) {
|
||||
DohBase *h = (DohBase *) ho;
|
||||
if (DohCheck(h)) {
|
||||
return h->file;
|
||||
} else {
|
||||
DohTrace(DOH_UNKNOWN,"Unknown object %x passed to Getfile.\n", h);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohXBase_setline()
|
||||
* DohSetLine()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
void
|
||||
DohXBase_setline(DOH *ho, int l) {
|
||||
DohXBase *h = (DohXBase *) ho;
|
||||
h->line = l;
|
||||
DohSetline(DOH *ho, int l) {
|
||||
DohBase *h = (DohBase *) ho;
|
||||
if (DohCheck(h)) {
|
||||
h->line = l;
|
||||
} else {
|
||||
DohTrace(DOH_UNKNOWN, "Unknown object %x passed to Setline.\n", h);
|
||||
}
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohXBase_getline()
|
||||
* DohGetLine()
|
||||
* ----------------------------------------------------------------------------- */
|
||||
int
|
||||
DohXBase_getline(DOH *ho) {
|
||||
DohXBase *h = (DohXBase *) ho;
|
||||
return h->line;
|
||||
}
|
||||
|
||||
static DohPositionalMethods XBasePositionalMethods = {
|
||||
DohXBase_setfile,
|
||||
DohXBase_getfile,
|
||||
DohXBase_setline,
|
||||
DohXBase_getline
|
||||
};
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohXInit()
|
||||
*
|
||||
* Initialize an extended object.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
void
|
||||
DohXInit(DOH *b) {
|
||||
DohXBase *bs = (DohXBase *) b;
|
||||
bs->file = 0;
|
||||
bs->line = 0;
|
||||
bs->objinfo->doh_position = &XBasePositionalMethods;
|
||||
DohGetline(DOH *ho) {
|
||||
DohBase *h = (DohBase *) ho;
|
||||
if (DohCheck(h)) {
|
||||
return h->line;
|
||||
} else {
|
||||
DohTrace(DOH_UNKNOWN, "Unknown object %x passed to GetLine.\n", h);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,105 +0,0 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* callable.c
|
||||
*
|
||||
* This file implements a simple callable object supporting a function call
|
||||
* operation.
|
||||
*
|
||||
* Author(s) : David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* Copyright (C) 1999-2000. The University of Chicago
|
||||
* See the file LICENSE for information on usage and redistribution.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static char cvsroot[] = "$Header$";
|
||||
|
||||
#include "dohint.h"
|
||||
|
||||
typedef struct {
|
||||
DOHCOMMON;
|
||||
DOH *(*func)(DOH *, DOH *);
|
||||
} CallableObj;
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Callable_delete()
|
||||
*
|
||||
* Destroy a callable object.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
Callable_delete(DOH *co) {
|
||||
DohObjFree(co);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Callable_copy()
|
||||
*
|
||||
* Copy a callable object.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static DOH *
|
||||
Callable_copy(DOH *co) {
|
||||
CallableObj *c = (CallableObj *) co;
|
||||
return NewCallable(c->func);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Callable_call()
|
||||
*
|
||||
* Call an object. The object itself is passed as the first argument and remaining
|
||||
* arguments are passed as a second argument.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
static DOH *
|
||||
Callable_call(DOH *co, DOH *args) {
|
||||
CallableObj *c = (CallableObj *) co;
|
||||
return (*c->func)(c,args);
|
||||
}
|
||||
|
||||
/* Method tables */
|
||||
|
||||
static DohCallableMethods doh_callable_methods = {
|
||||
Callable_call
|
||||
};
|
||||
|
||||
static DohObjInfo DohCallableType = {
|
||||
"CallableObj", /* objname */
|
||||
sizeof(CallableObj), /* objsize */
|
||||
Callable_delete, /* doh_del */
|
||||
Callable_copy, /* doh_copy */
|
||||
0, /* doh_clear */
|
||||
0, /* doh_scope */
|
||||
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_sequence */
|
||||
0, /* doh_file */
|
||||
0, /* doh_string */
|
||||
&doh_callable_methods, /* doh_callable */
|
||||
0, /* doh_position */
|
||||
0, /* reserved5 */
|
||||
0, /* reserved6 */
|
||||
0, /* user1 */
|
||||
0, /* user2 */
|
||||
0, /* user3 */
|
||||
0, /* user4 */
|
||||
};
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* NewCallable()
|
||||
*
|
||||
* Create a new callable object.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *
|
||||
NewCallable(DOH *(*func)(DOH *, DOH *)) {
|
||||
CallableObj *c;
|
||||
c = (CallableObj *) DohObjMalloc(sizeof(CallableObj));
|
||||
c->objinfo = &DohCallableType;
|
||||
c->func = func;
|
||||
return (DOH *) c;
|
||||
}
|
||||
|
|
@ -156,7 +156,6 @@ static DohObjInfo DohFileType = {
|
|||
DelFile, /* doh_del */
|
||||
0, /* doh_copy */
|
||||
0, /* doh_clear */
|
||||
0, /* doh_scope */
|
||||
0, /* doh_str */
|
||||
0, /* doh_data */
|
||||
0, /* doh_dump */
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ typedef struct HashNode {
|
|||
|
||||
/* Hash object */
|
||||
typedef struct Hash {
|
||||
DOHXCOMMON;
|
||||
DOHCOMMON;
|
||||
HashNode **hashtable;
|
||||
int hashsize;
|
||||
int currentindex;
|
||||
|
|
@ -115,7 +115,6 @@ DelHash(DOH *ho) {
|
|||
DohFree(h->hashtable);
|
||||
h->hashtable = 0;
|
||||
h->hashsize = 0;
|
||||
Delete(h->file);
|
||||
DohObjFree(h);
|
||||
}
|
||||
|
||||
|
|
@ -433,7 +432,6 @@ CopyHash(DOH *ho) {
|
|||
h = (Hash *) ho;
|
||||
nh = (Hash *) DohObjMalloc(sizeof(Hash));
|
||||
nh->objinfo = h->objinfo;
|
||||
DohXInit(h);
|
||||
nh->hashsize = h->hashsize;
|
||||
nh->hashtable = (HashNode **) DohMalloc(nh->hashsize*sizeof(HashNode *));
|
||||
for (i = 0; i < nh->hashsize; i++) {
|
||||
|
|
@ -475,7 +473,6 @@ static DohObjInfo HashType = {
|
|||
DelHash, /* doh_del */
|
||||
CopyHash, /* doh_copy */
|
||||
Hash_clear, /* doh_clear */
|
||||
0, /* doh_scope */
|
||||
Hash_str, /* doh_str */
|
||||
0, /* doh_data */
|
||||
0, /* doh_dump */
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ static char cvsroot[] = "$Header$";
|
|||
#include "dohint.h"
|
||||
|
||||
typedef struct List {
|
||||
DOHXCOMMON;
|
||||
DOHCOMMON;
|
||||
int maxitems; /* Max size */
|
||||
int nitems; /* Num items */
|
||||
int iter; /* Iterator */
|
||||
|
|
@ -52,7 +52,6 @@ CopyList(DOH *lo) {
|
|||
l = (List *) lo;
|
||||
nl = (List *) DohObjMalloc(sizeof(List));
|
||||
nl->objinfo = l->objinfo;
|
||||
DohXInit(nl);
|
||||
nl->nitems = l->nitems;
|
||||
nl->maxitems = l->maxitems;
|
||||
nl->items = (void **) DohMalloc(l->maxitems*sizeof(void *));
|
||||
|
|
@ -86,7 +85,6 @@ DelList(DOH *lo) {
|
|||
}
|
||||
DohFree(l->items);
|
||||
l->items = 0;
|
||||
Delete(l->file);
|
||||
DohObjFree(l);
|
||||
}
|
||||
|
||||
|
|
@ -318,7 +316,6 @@ static DohObjInfo ListType = {
|
|||
DelList, /* doh_del */
|
||||
CopyList, /* doh_copy */
|
||||
List_clear, /* doh_clear */
|
||||
0, /* doh_scope */
|
||||
List_str, /* doh_str */
|
||||
0, /* doh_data */
|
||||
List_dump, /* doh_dump */
|
||||
|
|
|
|||
|
|
@ -211,6 +211,7 @@ DohObjFree(DOH *ptr) {
|
|||
DohTrace(DOH_MEMORY,"DohObjFree. %x not properly defined. No objinfo structure.\n", ptr);
|
||||
return; /* Improperly initialized object. leak some more */
|
||||
}
|
||||
if (b->file) DohDelete(b->file);
|
||||
f = (Fragment *) DohMalloc(sizeof(Fragment));
|
||||
f->ptr = (char *) ptr;
|
||||
f->len = (b->objinfo->objsize + 7) & ~0x07;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ static char cvsroot[] = "$Header$";
|
|||
#endif
|
||||
|
||||
typedef struct String {
|
||||
DOHXCOMMON;
|
||||
DOHCOMMON;
|
||||
int maxsize; /* Max size allocated */
|
||||
int len; /* Current length */
|
||||
int hashkey; /* Hash key value */
|
||||
|
|
@ -83,7 +83,6 @@ static DohObjInfo StringType = {
|
|||
DelString, /* doh_del */
|
||||
CopyString, /* doh_copy */
|
||||
String_clear, /* doh_clear */
|
||||
0, /* doh_scope */
|
||||
String_str, /* doh_str */
|
||||
String_data, /* doh_data */
|
||||
String_dump, /* doh_dump */
|
||||
|
|
@ -148,7 +147,6 @@ NewString(const DOH *so)
|
|||
else s = (char *) so;
|
||||
str = (String *) DohObjMalloc(sizeof(String));
|
||||
str->objinfo = &StringType;
|
||||
DohXInit(str);
|
||||
str->hashkey = -1;
|
||||
str->sp = 0;
|
||||
str->line = 1;
|
||||
|
|
@ -226,7 +224,6 @@ DelString(DOH *so) {
|
|||
if (s->str)
|
||||
DohFree(s->str);
|
||||
s->str = 0;
|
||||
Delete(s->file);
|
||||
DohObjFree(s);
|
||||
}
|
||||
|
||||
|
|
@ -324,11 +321,9 @@ add(String *s, const char *newstr) {
|
|||
}
|
||||
strcpy(s->str+s->len,newstr);
|
||||
if (s->sp >= s->len) {
|
||||
#ifdef DOH_STRING_UPDATE_LINES
|
||||
for (i = s->sp; i < s->len+l; i++) {
|
||||
if (s->str[i] == '\n') s->line++;
|
||||
}
|
||||
#endif
|
||||
s->sp = s->len+l;
|
||||
}
|
||||
s->len += l;
|
||||
|
|
@ -348,9 +343,7 @@ String_addchar(DOH *so, char c) {
|
|||
if (s->sp >= s->len) {
|
||||
s->sp = s->len+1;
|
||||
s->str[s->len+1] = 0;
|
||||
#ifdef DOH_STRING_UPDATE_LINES
|
||||
if (c == '\n') s->line++;
|
||||
#endif
|
||||
}
|
||||
s->len++;
|
||||
}
|
||||
|
|
@ -406,11 +399,9 @@ raw_insert(String *s, int pos, char *data, int len)
|
|||
if (s->sp >= pos) {
|
||||
int i;
|
||||
|
||||
#ifdef DOH_STRING_UPDATE_LINES
|
||||
for (i = 0; i < len; i++) {
|
||||
if (data[i] == '\n') s->line++;
|
||||
}
|
||||
#endif
|
||||
s->sp+=len;
|
||||
}
|
||||
|
||||
|
|
@ -458,9 +449,7 @@ int String_delitem(DOH *so, int pos)
|
|||
if (s->sp > pos) {
|
||||
s->sp--;
|
||||
assert (s->sp >= 0);
|
||||
#ifdef DOH_STRING_UPDATE_LINES
|
||||
if (s->str[pos] == '\n') s->line--;
|
||||
#endif
|
||||
}
|
||||
memmove(s->str+pos, s->str+pos+1, ((s->len-1) - pos));
|
||||
s->len--;
|
||||
|
|
@ -534,9 +523,7 @@ String_write(DOH *so, void *buffer, int len) {
|
|||
int
|
||||
String_seek(DOH *so, long offset, int whence) {
|
||||
int pos, nsp, inc;
|
||||
#ifdef DOH_STRING_UPDATE_LINES
|
||||
int prev;
|
||||
#endif
|
||||
String *s = (String *) so;
|
||||
if (whence == SEEK_SET) pos = 0;
|
||||
else if (whence == SEEK_CUR) pos = s->sp;
|
||||
|
|
@ -554,16 +541,12 @@ String_seek(DOH *so, long offset, int whence) {
|
|||
|
||||
inc = (nsp > s->sp) ? 1 : -1;
|
||||
|
||||
#ifdef DOH_STRING_UPDATE_LINES
|
||||
while (s->sp != nsp) {
|
||||
prev = s->sp + inc;
|
||||
if (prev>=0 && prev<=s->len && s->str[prev] == '\n')
|
||||
s->line += inc;
|
||||
s->sp += inc;
|
||||
}
|
||||
#else
|
||||
s->sp = nsp;
|
||||
#endif
|
||||
assert (s->sp >= 0);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -594,9 +577,7 @@ String_putc(DOH *so, int ch) {
|
|||
} else {
|
||||
s->str[s->sp] = (char) ch;
|
||||
s->sp++;
|
||||
#ifdef DOH_STRING_UPDATE_LINES
|
||||
if (ch == '\n') s->line++;
|
||||
#endif
|
||||
}
|
||||
return ch;
|
||||
}
|
||||
|
|
@ -615,9 +596,7 @@ int String_getc(DOH *so) {
|
|||
c = EOF;
|
||||
else
|
||||
c = (int) s->str[s->sp++];
|
||||
#ifdef DOH_STRING_UPDATE_LINES
|
||||
if (c == '\n') s->line++;
|
||||
#endif
|
||||
return c;
|
||||
}
|
||||
|
||||
|
|
@ -631,9 +610,7 @@ int String_ungetc(DOH *so, int ch) {
|
|||
if (ch == EOF) return ch;
|
||||
if (s->sp <= 0) return EOF;
|
||||
s->sp--;
|
||||
#ifdef DOH_STRING_UPDATE_LINES
|
||||
if (ch == '\n') s->line--;
|
||||
#endif
|
||||
return ch;
|
||||
}
|
||||
|
||||
|
|
@ -795,9 +772,7 @@ String_chop(DOH *s) {
|
|||
while ((str->len > 0) && (isspace(*c))) {
|
||||
if (str->sp >= str->len) {
|
||||
str->sp--;
|
||||
#ifdef DOH_STRING_UPDATE_LINES
|
||||
if (*c == '\n') str->line--;
|
||||
#endif
|
||||
}
|
||||
str->len--;
|
||||
c--;
|
||||
|
|
|
|||
|
|
@ -67,7 +67,6 @@ static DohObjInfo DohVoidType = {
|
|||
Void_delete, /* doh_del */
|
||||
Void_copy, /* doh_copy */
|
||||
0, /* doh_clear */
|
||||
0, /* doh_scope */
|
||||
0, /* doh_str */
|
||||
Void_data, /* doh_data */
|
||||
0, /* doh_dump */
|
||||
|
|
|
|||
|
|
@ -26,13 +26,16 @@ extern "C" {
|
|||
|
||||
typedef void DOH;
|
||||
|
||||
/* Symbolic names used to clarify the reading of code using DOH objects */
|
||||
/*
|
||||
* With dynamic typing, all DOH objects are technically of type 'void *'.
|
||||
* However, to clarify the reading of source code, the following symbolic
|
||||
* names are used.
|
||||
*/
|
||||
|
||||
#define DOHString DOH
|
||||
#define DOHList DOH
|
||||
#define DOHHash DOH
|
||||
#define DOHFile DOH
|
||||
#define DOHFunction DOH
|
||||
#define DOHVoid DOH
|
||||
#define DOHString_or_char DOH
|
||||
#define DOHObj_or_char DOH
|
||||
|
|
@ -67,14 +70,14 @@ typedef struct {
|
|||
|
||||
/* File methods */
|
||||
typedef struct {
|
||||
int (*doh_read)(DOH *obj, void *buffer, int nbytes);
|
||||
int (*doh_write)(DOH *obj, void *buffer, int nbytes);
|
||||
int (*doh_putc)(DOH *obj, int ch);
|
||||
int (*doh_getc)(DOH *obj);
|
||||
int (*doh_ungetc)(DOH *obj, int ch);
|
||||
int (*doh_seek)(DOH *obj, long offset, int whence);
|
||||
long (*doh_tell)(DOH *obj);
|
||||
int (*doh_close)(DOH *obj);
|
||||
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 */
|
||||
|
|
@ -83,19 +86,6 @@ typedef struct {
|
|||
void (*doh_chop)(DOH *obj);
|
||||
} DohStringMethods;
|
||||
|
||||
/* Callable */
|
||||
typedef struct {
|
||||
DOH *(*doh_call)(DOH *obj, DOH *args); /* Callable */
|
||||
} DohCallableMethods;
|
||||
|
||||
/* Positional */
|
||||
typedef struct {
|
||||
void (*doh_setfile)(DOH *obj, DOH *file);
|
||||
DOH *(*doh_getfile)(DOH *obj);
|
||||
void (*doh_setline)(DOH *obj, int line);
|
||||
int (*doh_getline)(DOH *obj);
|
||||
} DohPositionalMethods;
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohObjInfo
|
||||
*
|
||||
|
|
@ -111,7 +101,6 @@ typedef struct DohObjInfo {
|
|||
void (*doh_del)(DOH *obj); /* Delete object */
|
||||
DOH *(*doh_copy)(DOH *obj); /* Copy and object */
|
||||
void (*doh_clear)(DOH *obj); /* Clear an object */
|
||||
void (*doh_scope)(DOH *obj, int sc); /* Scope */
|
||||
|
||||
/* Output methods */
|
||||
DOH *(*doh_str)(DOH *obj); /* Make a full string */
|
||||
|
|
@ -120,18 +109,18 @@ typedef struct DohObjInfo {
|
|||
DOH *(*doh_load)(DOH *in); /* Unserialize from in */
|
||||
|
||||
/* Length and hash values */
|
||||
int (*doh_len)(DOH *obj);
|
||||
int (*doh_hash)(DOH *obj);
|
||||
int (*doh_len)(DOH *obj);
|
||||
int (*doh_hash)(DOH *obj);
|
||||
|
||||
/* Compare */
|
||||
int (*doh_cmp)(DOH *obj1, DOH *obj2);
|
||||
int (*doh_cmp)(DOH *obj1, DOH *obj2);
|
||||
|
||||
DohMappingMethods *doh_mapping; /* Mapping methods */
|
||||
DohSequenceMethods *doh_sequence; /* Sequence methods */
|
||||
DohFileMethods *doh_file; /* File methods */
|
||||
DohStringMethods *doh_string; /* String methods */
|
||||
DohCallableMethods *doh_callable; /* Callable methods */
|
||||
DohPositionalMethods *doh_position; /* Positional methods */
|
||||
void *reserved2;
|
||||
void *reserved3;
|
||||
void *reserved4;
|
||||
void *reserved5;
|
||||
void *reserved6;
|
||||
|
|
@ -142,6 +131,7 @@ typedef struct DohObjInfo {
|
|||
} DohObjInfo;
|
||||
|
||||
/* Memory management */
|
||||
|
||||
extern void *DohMalloc(size_t size); /* Allocate memory */
|
||||
extern void *DohRealloc(void *, size_t size); /* Reallocate memory */
|
||||
extern void DohFree(DOH *ptr); /* Free memory */
|
||||
|
|
@ -149,7 +139,6 @@ typedef struct DohObjInfo {
|
|||
extern void DohObjFree(DOH *ptr); /* Free a DOH object */
|
||||
extern int DohObjFreeCheck(DOH *ptr); /* Check if already free */
|
||||
extern void DohInit(DOH *obj); /* Initialize an object */
|
||||
extern void DohXInit(DOH *obj); /* Initialize extended object */
|
||||
extern int DohCheck(const DOH *ptr); /* Check if a DOH object */
|
||||
extern int DohPoolSize(int); /* Set memory alloc size */
|
||||
extern void DohIntern(DOH *); /* Intern an object */
|
||||
|
|
@ -201,11 +190,7 @@ typedef struct DohObjInfo {
|
|||
extern int DohPutc(int ch, DOHFile *obj);
|
||||
extern int DohUngetc(int ch, DOHFile *obj);
|
||||
|
||||
/* Callable Methods */
|
||||
|
||||
extern DOH *DohCall(DOHFunction *obj, DOH *args);
|
||||
|
||||
/* Position Methods */
|
||||
/* Positional */
|
||||
|
||||
extern int DohGetline(DOH *obj);
|
||||
extern void DohSetline(DOH *obj, int line);
|
||||
|
|
@ -233,7 +218,6 @@ typedef struct DohObjInfo {
|
|||
extern int DohIsSequence(const DOH *obj);
|
||||
extern int DohIsString(const DOH *obj);
|
||||
extern int DohIsFile(const DOH *obj);
|
||||
extern int DohIsCallable(const DOH *obj);
|
||||
|
||||
#ifndef DOH_LONG_NAMES
|
||||
/* Macros to invoke the above functions. Includes the location of
|
||||
|
|
@ -286,7 +270,6 @@ typedef struct DohObjInfo {
|
|||
#define Readline DohReadline
|
||||
#define Replace DohReplace
|
||||
#define Chop DohChop
|
||||
#define Call DohCall
|
||||
#endif
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
|
|
@ -299,21 +282,14 @@ typedef struct DohObjInfo {
|
|||
DohObjInfo *objinfo; \
|
||||
DOH *nextptr; \
|
||||
int refcount; \
|
||||
DOH *file; \
|
||||
int line; \
|
||||
unsigned char flags
|
||||
|
||||
typedef struct {
|
||||
DOHCOMMON;
|
||||
} DohBase;
|
||||
|
||||
#define DOHXCOMMON \
|
||||
DOHCOMMON; \
|
||||
DOH *file; \
|
||||
int line
|
||||
|
||||
typedef struct {
|
||||
DOHXCOMMON;
|
||||
} DohXBase;
|
||||
|
||||
/* 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++
|
||||
|
|
@ -379,12 +355,6 @@ extern DOHList *DohSplit(DOHFile *input, char *chs, int nsplits);
|
|||
|
||||
extern DOH *DohNone;
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Callable
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
extern DOHFunction *NewCallable(DOH *(*func)(DOH *, DOH *));
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Error handling levels.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue