The great merge

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@4141 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dave Beazley 2002-11-30 22:01:28 +00:00
commit 516036631c
89 changed files with 125431 additions and 43485 deletions

View file

@ -0,0 +1,9 @@
Makefile
.deps
parser.c
parser.h
libcparse.a
cscanner.o
parser.o
y.tab.c
y.tab.h

View file

@ -0,0 +1,69 @@
#######################################################################
# $Header$
#######################################################################
srcdir = @srcdir@
VPATH = @srcdir@
SHELL = /bin/sh
CC = @CC@
CFLAGS = @CFLAGS@
YACC = @YACC@
AR = @AR@
RANLIB = @RANLIB@
TARGET = libcparse.a
OBJS = parser.@OBJEXT@ cscanner.@OBJEXT@ templ.@OBJEXT@ util.@OBJEXT@
SRCS = cscanner.c templ.c util.c
PARSER = $(srcdir)/parser.y
INCLUDES = -I$(srcdir)/../Include \
-I$(srcdir)/. \
-I$(srcdir)/../Swig \
-I$(srcdir)/../Preprocessor \
-I$(srcdir)/../DOH/Include \
-I../Include \
-I.
.c.@OBJEXT@:
$(CC) $(CFLAGS) $(INCLUDES) -c -o $*.@OBJEXT@ $<
cparse: $(TARGET)
$(TARGET): $(OBJS)
$(AR) cr $(TARGET) $(OBJS)
$(RANLIB) $(TARGET)
parser.@OBJEXT@: parser.c
$(CC) $(INCLUDES) $(CFLAGS) $< -c -o parser.@OBJEXT@
parser.c parser.h: $(PARSER)
$(YACC) @YFLAGS@ $(PARSER)
@cp y.tab.h parser.h
@cp y.tab.c parser.c
scanner.@OBJEXT@: parser.h
parser::
@cp y.tab.c.bison parser.c
@cp y.tab.h.bison parser.h
@cp y.tab.h.bison y.tab.h
$(CC) $(CFLAGS) parser.c -c -o parser.@OBJEXT@
clean::
rm -f *.@OBJEXT@ $(TARGET) y.tab.c y.tab.h
nuke::
rm -f Makefile *~

View file

@ -0,0 +1,12 @@
#include "swig.h"
#include "swigwarn.h"
#include "swigver.h"
extern char *cparse_file;
extern int cparse_line;
extern int cparse_cplusplus;
extern int cparse_start_line;
extern void Swig_cparse_replace_descriptor(String *s);
extern void Swig_cparse_cplusplus(int);
extern void Swig_cparse_debug_templates(int);

File diff suppressed because it is too large Load diff

4568
SWIG/Source/CParse/parser.y Normal file

File diff suppressed because it is too large Load diff

495
SWIG/Source/CParse/templ.c Normal file
View file

@ -0,0 +1,495 @@
/* -----------------------------------------------------------------------------
* templ.c
*
* Expands a template into a specialized version.
*
* 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.
* ----------------------------------------------------------------------------- */
char cvsroot_templ_c[] = "$Header$";
#include "swig.h"
#include "cparse.h"
static int template_debug = 0;
static void add_parms(ParmList *p, List *patchlist, List *typelist) {
while (p) {
SwigType *ty = Getattr(p,"type");
SwigType *val = Getattr(p,"value");
Append(typelist,ty);
Append(patchlist,val);
p = nextSibling(p);
}
}
void Swig_cparse_debug_templates(int x) {
template_debug = x;
}
/* -----------------------------------------------------------------------------
* Swig_cparse_template_expand()
*
* Expands a template node into a specialized version. This is done by
* patching typenames and other aspects of the node according to a list of
* template parameters
* ----------------------------------------------------------------------------- */
static int
cparse_template_expand(Node *n, String *tname, String *rname, String *templateargs, List *patchlist, List *typelist, List *cpatchlist) {
static int expanded = 0;
int ret;
if (!n) return 0;
if (Getattr(n,"error")) return 0;
if (Strcmp(nodeType(n),"template") == 0) {
/* Change the node type back to normal */
if (!expanded) {
expanded = 1;
set_nodeType(n,Getattr(n,"templatetype"));
ret = cparse_template_expand(n,tname, rname, templateargs, patchlist,typelist, cpatchlist);
expanded = 0;
return ret;
} else {
/* Called when template appears inside another template */
/* Member templates */
set_nodeType(n,Getattr(n,"templatetype"));
ret = cparse_template_expand(n,tname, rname, templateargs, patchlist,typelist, cpatchlist);
set_nodeType(n,"template");
return ret;
}
} else if (Strcmp(nodeType(n),"cdecl") == 0) {
/* A simple C declaration */
SwigType *t, *v, *d;
String *code;
t = Getattr(n,"type");
v = Getattr(n,"value");
d = Getattr(n,"decl");
code = Getattr(n,"code");
Append(typelist,t);
Append(typelist,d);
Append(patchlist,v);
Append(cpatchlist,code);
if (Getattr(n,"conversion_operator")) {
Append(cpatchlist, Getattr(n,"name"));
if (Getattr(n,"sym:name")) {
Append(cpatchlist, Getattr(n,"sym:name"));
}
}
add_parms(Getattr(n,"parms"), cpatchlist, typelist);
add_parms(Getattr(n,"throws"), cpatchlist, typelist);
} else if (Strcmp(nodeType(n),"class") == 0) {
/* Patch base classes */
{
List *bases = Getattr(n,"baselist");
if (bases) {
int i;
for (i = 0; i < Len(bases); i++) {
String *name = Copy(Getitem(bases,i));
Setitem(bases,i,name);
Append(typelist,name);
}
}
}
/* Patch children */
{
Node *cn = firstChild(n);
while (cn) {
cparse_template_expand(cn,tname, rname, templateargs, patchlist,typelist,cpatchlist);
cn = nextSibling(cn);
}
}
} else if (Strcmp(nodeType(n),"constructor") == 0) {
String *name = Getattr(n,"name");
if (!(Getattr(n,"templatetype"))) {
String *symname;
String *stripped_name = SwigType_templateprefix(name);
if (Strstr(tname,stripped_name)) {
Replaceid(name,stripped_name,tname);
}
Delete(stripped_name);
symname = Getattr(n,"sym:name");
if (symname) {
stripped_name = SwigType_templateprefix(symname);
if (Strstr(tname,stripped_name)) {
Replaceid(symname,stripped_name,tname);
}
Delete(stripped_name);
}
if (Strstr(name,"<")) {
Append(patchlist,Getattr(n,"name"));
} else {
Append(name,templateargs);
}
name = Getattr(n,"sym:name");
if (name && (Strstr(name,"<"))) {
Clear(name);
Append(name,rname);
} else {
Replace(name,tname,rname, DOH_REPLACE_ANY);
}
Setattr(n,"sym:name",name);
}
Append(cpatchlist,Getattr(n,"code"));
Append(typelist, Getattr(n,"decl"));
add_parms(Getattr(n,"parms"), cpatchlist, typelist);
add_parms(Getattr(n,"throws"), cpatchlist, typelist);
} else if (Strcmp(nodeType(n),"destructor") == 0) {
String *name = Getattr(n,"name");
if (Strstr(name,"<")) {
Append(patchlist,Getattr(n,"name"));
} else {
Append(name,templateargs);
}
name = Getattr(n,"sym:name");
if (name && Strstr(name,"<")) {
Setattr(n,"sym:name", Copy(tname));
} else {
Replace(name,tname,rname, DOH_REPLACE_ANY);
}
Setattr(n,"sym:name",name);
Append(cpatchlist,Getattr(n,"code"));
} else if (Strcmp(nodeType(n),"using") == 0) {
String *uname = Getattr(n,"uname");
if (uname) {
if (Strstr(uname,"<")) {
Append(patchlist, uname);
}
}
if (Getattr(n,"namespace")) {
/* Namespace link. This is nasty. Is other namespace defined? */
}
} else {
/* Look for obvious parameters */
Node *cn;
Append(cpatchlist,Getattr(n,"code"));
Append(typelist, Getattr(n,"type"));
Append(typelist, Getattr(n,"decl"));
add_parms(Getattr(n,"parms"), cpatchlist, typelist);
add_parms(Getattr(n,"pattern"), cpatchlist, typelist);
add_parms(Getattr(n,"throws"), cpatchlist, typelist);
cn = firstChild(n);
while (cn) {
cparse_template_expand(cn,tname, rname, templateargs, patchlist, typelist, cpatchlist);
cn = nextSibling(cn);
}
}
return 0;
}
int
Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms) {
List *patchlist, *cpatchlist, *typelist;
String *templateargs;
String *tname;
String *iname;
String *tbase;
patchlist = NewList();
cpatchlist = NewList();
typelist = NewList();
{
String *tmp = NewString("");
if (tparms) {
SwigType_add_template(tmp,tparms);
}
templateargs = Copy(tmp);
Delete(tmp);
}
tname = Copy(Getattr(n,"name"));
tbase = Swig_scopename_last(tname);
if (0) {
Parm *p = tparms;
while (p) {
Printf(stdout,"tparm: '%s' '%s'\n", Getattr(p,"name"), Getattr(p,"value"));
p = nextSibling(p);
}
}
cparse_template_expand(n,tname, rname, templateargs, patchlist, typelist, cpatchlist);
/* Set the name */
{
String *name = Getattr(n,"name");
if (name) {
Append(name,templateargs);
}
iname = name;
}
/* Patch all of the types */
{
Parm *tp = Getattr(n,"templateparms");
Parm *p = tparms;
if (tp) {
while (p && tp) {
String *name, *value, *valuestr, *tydef, *tmp, *tmpr;
int sz, i;
name = Getattr(tp,"name");
value = Getattr(p,"value");
tydef = Getattr(p,"typedef");
if (name) {
if (!value) {
value = Getattr(p,"type");
valuestr = SwigType_str(value,0);
} else {
valuestr = SwigType_namestr(value);
}
assert(value);
/* Need to patch default arguments */
{
Parm *rp = nextSibling(p);
while (rp) {
String *rvalue = Getattr(rp,"value");
if (rvalue) {
Replace(rvalue,name,value, DOH_REPLACE_ID);
}
rp = nextSibling(rp);
}
}
sz = Len(patchlist);
for (i = 0; i < sz; i++) {
String *s = Getitem(patchlist,i);
Replace(s,name,value, DOH_REPLACE_ID);
}
sz = Len(typelist);
for (i = 0; i < sz; i++) {
String *s = Getitem(typelist,i);
Replace(s,name,value, DOH_REPLACE_ID);
SwigType_typename_replace(s,tbase,iname);
}
if (!tydef) {
tydef = value;
}
tmp = NewStringf("#%s",name);
tmpr = NewStringf("\"%s\"", value);
sz = Len(cpatchlist);
for (i = 0; i < sz; i++) {
String *s = Getitem(cpatchlist,i);
Replace(s,tmp,tmpr, DOH_REPLACE_ID);
/* Replace(s,name,tydef, DOH_REPLACE_ID); */
Replace(s,name,valuestr, DOH_REPLACE_ID);
}
Delete(tmp);
Delete(tmpr);
Delete(valuestr);
}
p = nextSibling(p);
tp = nextSibling(tp);
if (!p) p = tp;
}
} else {
/* No template parameters at all. This could be a specialization */
int i, sz;
sz = Len(typelist);
for (i = 0; i < sz; i++) {
String *s = Getitem(typelist,i);
SwigType_typename_replace(s,tbase,iname);
}
}
}
/* Patch bases */
{
List *bases = Getattr(n,"baselist");
if (bases) {
String *b;
for (b = Firstitem(bases); b; b = Nextitem(bases)) {
String *qn = Swig_symbol_type_qualify(b,0);
Clear(b);
Append(b,qn);
}
}
}
Delete(patchlist);
Delete(cpatchlist);
Delete(typelist);
Delete(tbase);
/* set_nodeType(n,"template");*/
return 0;
}
/* -----------------------------------------------------------------------------
* cparse_template_locate()
*
* Search for a template that matches name with given parameters.
* ----------------------------------------------------------------------------- */
Node *
Swig_cparse_template_locate(String *name, Parm *tparms) {
Node *n;
String *tname, *rname = 0;
Node *templ;
List *mpartials = 0;
Parm *p;
Parm *parms;
tname = NewString(name);
parms = CopyParmList(tparms);
p = parms;
while (p) {
SwigType *ty = Getattr(p,"type");
if (ty) {
SwigType *nt = Swig_symbol_typedef_reduce(ty,0);
nt = Swig_symbol_type_qualify(nt,0);
Setattr(p,"type",nt);
}
p = nextSibling(p);
}
SwigType_add_template(tname,parms);
if (template_debug) {
Printf(stdout,"\n%s:%d: template_debug: Searching for %s\n", cparse_file, cparse_line, tname);
}
/* Search for an exact specialization.
Example: template<> class name<int> { ... } */
{
if (template_debug) {
Printf(stdout," searching: '%s' (exact specialization)\n", tname);
}
n = Swig_symbol_clookup_local(tname,0);
if (n) {
Node *tn;
if (Strcmp(nodeType(n),"template") == 0) goto success;
tn = Getattr(n,"template");
if (tn) {
n = tn;
goto success; /* Previously wrapped by a template return that */
}
Swig_error(cparse_file, cparse_line, "'%s' is not defined as a template. (%s)\n", name, nodeType(n));
Delete(tname);
Delete(parms);
return 0; /* Found a match, but it's not a template of any kind. */
}
}
/* Search for generic template */
templ = Swig_symbol_clookup_local(name,0);
/* Search for partial specialization.
Example: template<typename T> class name<T *> { ... } */
/* Generate reduced template name (stripped of extraneous pointers, etc.) */
rname = NewStringf("%s<(",name);
p = parms;
while (p) {
String *t;
t = Getattr(p,"type");
if (t) {
String *tbase = SwigType_base(t);
t = SwigType_default(t);
Replaceid(t,"SWIGTYPE",tbase);
Replaceid(t,"SWIGENUM",tbase);
Printf(rname,"%s",t);
Delete(t);
} else {
String *v = Getattr(p,"value");
Printf(rname,"%s",v);
}
p = nextSibling(p);
if (p) {
Printf(rname,",");
}
}
Printf(rname,")>");
mpartials = NewList();
if (templ) {
/* First, we search using an exact type prototype */
Parm *p;
char tmp[32];
int i;
List *partials;
String *s, *ss;
partials = Getattr(templ,"partials");
if (partials) {
for (s = Firstitem(partials); s; s= Nextitem(partials)) {
ss = Copy(s);
p = parms;
i = 1;
while (p) {
String *t,*tn;
sprintf(tmp,"$%d",i);
t = Getattr(p,"type");
if (t) {
tn = SwigType_base(t);
Replaceid(ss,tmp,tn);
Delete(tn);
} else {
String *v = Getattr(p,"value");
Replaceid(ss,tmp,v);
}
i++;
p = nextSibling(p);
}
if (template_debug) {
Printf(stdout," searching: '%s' (partial specialization - %s)\n", ss, s);
}
if ((Strcmp(ss,tname) == 0) || (Strcmp(ss,rname) == 0)) {
Append(mpartials,s);
}
Delete(ss);
}
}
}
if (template_debug) {
Printf(stdout," Matched partials: %s\n", mpartials);
}
if (Len(mpartials)) {
String *s = Getitem(mpartials,0);
n = Swig_symbol_clookup_local(s,0);
if (Len(mpartials) > 1) {
if (n) {
Swig_warning(WARN_PARSE_TEMPLATE_AMBIG,cparse_file,cparse_line,"Instantiation of template %s is ambiguous. Using %s at %s:%d\n",
SwigType_namestr(tname), SwigType_namestr(Getattr(n,"name")), Getfile(n),Getline(n));
}
}
}
if (!n) {
n = templ;
}
if (!n) {
Swig_error(cparse_file, cparse_line, "Template '%s' undefined.\n", name);
} else if (n && (Strcmp(nodeType(n),"template") != 0)) {
Swig_error(cparse_file, cparse_line, "'%s' is not defined as a template. (%s)\n", name, nodeType(n));
n = 0;
}
success:
Delete(tname);
Delete(rname);
Delete(mpartials);
if ((template_debug) && (n)) {
Printf(stdout,"Node: %x\n", n);
Swig_print_node(n);
}
Delete(parms);
return n;
}

71
SWIG/Source/CParse/util.c Normal file
View file

@ -0,0 +1,71 @@
/* -----------------------------------------------------------------------------
* util.c
*
* Parsing utilities
*
* 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.
* ----------------------------------------------------------------------------- */
char cvsroot_util_c[] = "$Header$";
#include "swig.h"
extern SwigType *Swig_cparse_type(String *);
/* -----------------------------------------------------------------------------
* Swig_cparse_replace_descriptor()
*
* Replaces type descriptor string $descriptor() with the SWIG type descriptor
* string.
* ----------------------------------------------------------------------------- */
void Swig_cparse_replace_descriptor(String *s) {
char tmp[512];
String *arg = 0;
SwigType *t;
while (Strstr(s,"$descriptor(")) {
char *d = tmp;
int level = 0;
char *c = Strstr(s,"$descriptor(");
while (*c) {
if (*c == '(') level++;
if (*c == ')') {
level--;
if (level == 0) {
break;
}
}
*d = *c;
d++;
c++;
}
*d = 0;
arg = NewString(tmp+12);
t = Swig_cparse_type(arg);
Delete(arg);
arg = 0;
if (t) {
String *mangle;
String *descriptor;
mangle = SwigType_manglestr(t);
descriptor = NewStringf("SWIGTYPE%s",mangle);
SwigType_remember(t);
*d = ')';
d++;
*d = 0;
Replace(s,tmp,descriptor,DOH_REPLACE_ANY);
Delete(mangle);
Delete(descriptor);
} else {
Swig_error(Getfile(s),Getline(s),"Bad $descriptor() macro.\n");
break;
}
}
}

View file

@ -2,3 +2,4 @@ Makefile
config.*
*.tar.gz
configure
autom4te.cache

View file

@ -1,50 +0,0 @@
# Generated automatically from Makefile.in by configure.
#######################################################################
# $Header$
# DOH
#######################################################################
#.KEEP_STATE:
# Set your C++ compiler here. g++ works on most machines,
# but you might have to change it depending on your installation.
#
CC = cc
prefix = /r0/beazley/Projects
# Comment out the following line if you're on an SGI or don't have ranlib!
RANLIB = ranlib
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
LIBSRCS = callable.c void.c fio.c memory.c base.c file.c list.c hash.c string.c
LIBHEADERS = ../Include/doh.h
LIB = ../libdoh.a
INCLUDE = -I../Include
CFLAGS = -DDOH_STRING_UPDATE_LINES
SHELL = /bin/sh
#
# Rules for creation of a .o file from .cxx
.SUFFIXES: .c
.c.o:
$(CC) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
all: $(LIB)
$(LIB): $(LIBOBJS)
@echo "Building library"
$(AR) cr $(LIB) $(LIBOBJS)
$(RANLIB) $(LIB)
clean::
rm -f *.o ../libdoh.a
nuke::
rm -f Makefile *~ #* core a.out

View file

@ -24,21 +24,21 @@ DOHOPT =
# Normally, you shouldn't have to change anything below this point #
########################################################################
LIBOBJS = void.o fio.o memory.o base.o file.o list.o hash.o string.o
LIBOBJS = void.@OBJEXT@ fio.@OBJEXT@ memory.@OBJEXT@ base.@OBJEXT@ file.@OBJEXT@ list.@OBJEXT@ hash.@OBJEXT@ string.@OBJEXT@
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
INCLUDES = -I$(srcdir)/../Include
CFLAGS = @CFLAGS@
SHELL = /bin/sh
#
# Rules for creation of a .o file from .c
# Rules for creation of a .@OBJEXT@ file from .c
.SUFFIXES: .c
.c.o:
$(CC) $(DOHOPT) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
.c.@OBJEXT@:
$(CC) $(DOHOPT) $(INCLUDES) $(CFLAGS) -c -o $*.@OBJEXT@ $<
all: $(LIB)
@ -49,6 +49,6 @@ $(LIB): $(LIBOBJS)
cp -f $(LIB) ..
clean::
rm -f *.o $(LIB) ../$(LIB)
rm -f *.@OBJEXT@ $(LIB) ../$(LIB)
nuke::
rm -f Makefile *~ #* core a.out
rm -f Makefile *~

View file

@ -10,21 +10,10 @@
* See the file LICENSE for information on usage and redistribution.
* ----------------------------------------------------------------------------- */
static char cvsroot[] = "$Header$";
char cvsroot_base_c[] = "$Header$";
#include "dohint.h"
static DohObjInfo *dohtypes[MAX_DOHTYPE];
/* -----------------------------------------------------------------------------
* DohRegisterType()
* ----------------------------------------------------------------------------- */
void
DohRegisterType(int type, DohObjInfo *objinfo) {
dohtypes[type] = objinfo;
}
/* -----------------------------------------------------------------------------
* DohDelete()
* ----------------------------------------------------------------------------- */
@ -43,7 +32,7 @@ DohDelete(DOH *obj) {
assert(b->refcount > 0);
b->refcount--;
if (b->refcount <= 0) {
objinfo = dohtypes[b->type];
objinfo = b->type;
if (objinfo->doh_del) {
(objinfo->doh_del)(b);
} else {
@ -63,9 +52,14 @@ DohCopy(const DOH *obj) {
DohObjInfo *objinfo;
if (!obj) return 0;
objinfo = dohtypes[b->type];
if (objinfo->doh_copy)
return (objinfo->doh_copy)(b);
objinfo = b->type;
if (objinfo->doh_copy) {
DohBase *bc = (DohBase *) (objinfo->doh_copy)(b);
if ((bc) && b->meta) {
bc->meta = Copy(b->meta);
}
return (DOH *) bc;
}
return 0;
}
@ -81,7 +75,7 @@ DohIncref(DOH *obj) {
void
DohClear(DOH *obj) {
DohBase *b = (DohBase *) obj;
DohObjInfo *objinfo = dohtypes[b->type];
DohObjInfo *objinfo = b->type;
if (objinfo->doh_clear)
(objinfo->doh_clear)(b);
}
@ -96,11 +90,11 @@ DohStr(const DOH *obj) {
DohBase *b = (DohBase *) obj;
DohObjInfo *objinfo;
if (DohCheck(b)) {
objinfo = dohtypes[b->type];
objinfo = b->type;
if (objinfo->doh_str) {
return (objinfo->doh_str)(b);
}
sprintf(buffer,"<Object '%s' at %x>", objinfo->objname, b);
sprintf(buffer,"<Object '%s' at %x>", objinfo->objname, (unsigned int)b);
return NewString(buffer);
} else {
return NewString(obj);
@ -114,7 +108,7 @@ DohStr(const DOH *obj) {
int
DohDump(const DOH *obj, DOH *out) {
DohBase *b = (DohBase *) obj;
DohObjInfo *objinfo = dohtypes[b->type];
DohObjInfo *objinfo = b->type;
if (objinfo->doh_dump) {
return (objinfo->doh_dump)(b,out);
}
@ -130,7 +124,7 @@ DohLen(const DOH *obj) {
DohObjInfo *objinfo;
if (!b) return 0;
if (DohCheck(b)) {
objinfo = dohtypes[b->type];
objinfo = b->type;
if (objinfo->doh_len) {
return (objinfo->doh_len)(b);
}
@ -149,7 +143,7 @@ DohHashval(const DOH *obj) {
DohBase *b = (DohBase *) obj;
DohObjInfo *objinfo;
if (DohCheck(b)) {
objinfo = dohtypes[b->type];
objinfo = b->type;
if (objinfo->doh_hashval) {
return (objinfo->doh_hashval)(b);
}
@ -166,7 +160,7 @@ DohData(const DOH *obj) {
DohBase *b = (DohBase *) obj;
DohObjInfo *objinfo;
if (DohCheck(obj)) {
objinfo = dohtypes[b->type];
objinfo = b->type;
if (objinfo->doh_data) {
return (objinfo->doh_data)(b);
}
@ -191,8 +185,8 @@ DohCmp(const DOH *obj1, const DOH *obj2) {
if (!b1 && b2) return -1;
return strcmp((char *) DohData(b1),(char *) DohData(b2));
}
b1info = dohtypes[b1->type];
b2info = dohtypes[b2->type];
b1info = b1->type;
b2info = b2->type;
if ((b1info == b2info) && (b1info->doh_cmp))
return (b1info->doh_cmp)(b1,b2);
return 1;
@ -206,7 +200,7 @@ DohIsMapping(const DOH *obj) {
DohBase *b = (DohBase *) obj;
DohObjInfo *objinfo;
if (!DohCheck(b)) return 0;
objinfo = dohtypes[b->type];
objinfo = b->type;
if (objinfo->doh_hash) return 1;
else return 0;
}
@ -218,7 +212,7 @@ DohIsMapping(const DOH *obj) {
DOH *
DohGetattr(DOH *obj, const DOH *name) {
DohBase *b = (DohBase *) obj;
DohObjInfo *objinfo = dohtypes[b->type];
DohObjInfo *objinfo = b->type;
if (objinfo->doh_hash && objinfo->doh_hash->doh_getattr) {
return (objinfo->doh_hash->doh_getattr)(b,(DOH *) name);
}
@ -232,7 +226,7 @@ DohGetattr(DOH *obj, const DOH *name) {
int
DohSetattr(DOH *obj, const DOH *name, const DOH *value) {
DohBase *b = (DohBase *) obj;
DohObjInfo *objinfo = dohtypes[b->type];
DohObjInfo *objinfo = b->type;
if (objinfo->doh_hash && objinfo->doh_hash->doh_setattr) {
return (objinfo->doh_hash->doh_setattr)(b,(DOH *) name,(DOH *) value);
}
@ -243,13 +237,14 @@ DohSetattr(DOH *obj, const DOH *name, const DOH *value) {
* DohDelattr()
* ----------------------------------------------------------------------------- */
void
int
DohDelattr(DOH *obj, const DOH *name) {
DohBase *b = (DohBase *) obj;
DohObjInfo *objinfo = dohtypes[b->type];
DohObjInfo *objinfo = b->type;
if (objinfo->doh_hash && objinfo->doh_hash->doh_delattr) {
(objinfo->doh_hash->doh_delattr)(b,(DOH *) name);
return (objinfo->doh_hash->doh_delattr)(b,(DOH *) name);
}
return 0;
}
/* -----------------------------------------------------------------------------
@ -259,7 +254,7 @@ DohDelattr(DOH *obj, const DOH *name) {
DOH *
DohFirstkey(DOH *obj) {
DohBase *b = (DohBase *) obj;
DohObjInfo *objinfo = dohtypes[b->type];
DohObjInfo *objinfo = b->type;
if (objinfo->doh_hash && objinfo->doh_hash->doh_firstkey) {
return (objinfo->doh_hash->doh_firstkey)(b);
}
@ -273,13 +268,27 @@ DohFirstkey(DOH *obj) {
DOH *
DohNextkey(DOH *obj) {
DohBase *b = (DohBase *) obj;
DohObjInfo *objinfo = dohtypes[b->type];
DohObjInfo *objinfo = b->type;
if (objinfo && objinfo->doh_hash->doh_nextkey) {
return (objinfo->doh_hash->doh_nextkey)(b);
}
return 0;
}
/* -----------------------------------------------------------------------------
* DohNextkey()
* ----------------------------------------------------------------------------- */
DOH *
DohKeys(DOH *obj) {
DohBase *b = (DohBase *) obj;
DohObjInfo *objinfo = b->type;
if (objinfo && objinfo->doh_hash->doh_keys) {
return (objinfo->doh_hash->doh_keys)(b);
}
return 0;
}
/* -----------------------------------------------------------------------------
* DohGetInt()
* ----------------------------------------------------------------------------- */
@ -388,7 +397,7 @@ DohIsSequence(const DOH *obj) {
DohBase *b = (DohBase *) obj;
DohObjInfo *objinfo;
if (!DohCheck(b)) return 0;
objinfo = dohtypes[b->type];
objinfo = b->type;
if (objinfo->doh_list) return 1;
else return 0;
}
@ -400,7 +409,7 @@ DohIsSequence(const DOH *obj) {
DOH *
DohGetitem(DOH *obj, int index) {
DohBase *b = (DohBase *) obj;
DohObjInfo *objinfo = dohtypes[b->type];
DohObjInfo *objinfo = b->type;
if (objinfo->doh_list && objinfo->doh_list->doh_getitem) {
return (objinfo->doh_list->doh_getitem)(b,index);
}
@ -414,7 +423,7 @@ DohGetitem(DOH *obj, int index) {
int
DohSetitem(DOH *obj, int index, const DOH *value) {
DohBase *b = (DohBase *) obj;
DohObjInfo *objinfo = dohtypes[b->type];
DohObjInfo *objinfo = b->type;
if (objinfo->doh_list && objinfo->doh_list->doh_setitem) {
return (objinfo->doh_list->doh_setitem)(b,index,(DOH *) value);
}
@ -428,7 +437,7 @@ DohSetitem(DOH *obj, int index, const DOH *value) {
int
DohDelitem(DOH *obj, int index) {
DohBase *b = (DohBase *) obj;
DohObjInfo *objinfo = dohtypes[b->type];
DohObjInfo *objinfo = b->type;
if (objinfo->doh_list && objinfo->doh_list->doh_delitem) {
return (objinfo->doh_list->doh_delitem)(b,index);
}
@ -442,7 +451,7 @@ DohDelitem(DOH *obj, int index) {
int
DohInsertitem(DOH *obj, int index, const DOH *value) {
DohBase *b = (DohBase *) obj;
DohObjInfo *objinfo = dohtypes[b->type];
DohObjInfo *objinfo = b->type;
if (objinfo->doh_list && objinfo->doh_list->doh_insitem) {
return (objinfo->doh_list->doh_insitem)(b,index,(DOH *) value);
}
@ -456,7 +465,7 @@ DohInsertitem(DOH *obj, int index, const DOH *value) {
DOH *
DohFirstitem(DOH *obj) {
DohBase *b = (DohBase *) obj;
DohObjInfo *objinfo = dohtypes[b->type];
DohObjInfo *objinfo = b->type;
if (objinfo->doh_list && objinfo->doh_list->doh_firstitem) {
return (objinfo->doh_list->doh_firstitem)(b);
}
@ -470,7 +479,7 @@ DohFirstitem(DOH *obj) {
DOH *
DohNextitem(DOH *obj) {
DohBase *b = (DohBase *) obj;
DohObjInfo *objinfo = dohtypes[b->type];
DohObjInfo *objinfo = b->type;
if (objinfo->doh_list && objinfo->doh_list->doh_nextitem) {
return (objinfo->doh_list->doh_nextitem)(b);
}
@ -486,7 +495,7 @@ DohIsFile(const DOH *obj) {
DohBase *b = (DohBase *) obj;
DohObjInfo *objinfo;
if (!DohCheck(b)) return 0;
objinfo = dohtypes[b->type];
objinfo = b->type;
if (objinfo->doh_file) return 1;
else return 0;
}
@ -500,7 +509,7 @@ DohRead(DOH *obj, void *buffer, int length) {
DohBase *b = (DohBase *) obj;
DohObjInfo *objinfo;
if (DohCheck(obj)) {
objinfo = dohtypes[b->type];
objinfo = b->type;
if ((objinfo->doh_file) && (objinfo->doh_file->doh_read)) {
return (objinfo->doh_file->doh_read)(b,buffer,length);
}
@ -519,7 +528,7 @@ DohWrite(DOH *obj, void *buffer, int length) {
DohBase *b = (DohBase *) obj;
DohObjInfo *objinfo;
if (DohCheck(obj)) {
objinfo = dohtypes[b->type];
objinfo = b->type;
if ((objinfo->doh_file) && (objinfo->doh_file->doh_write)) {
return (objinfo->doh_file->doh_write)(b,buffer,length);
}
@ -538,7 +547,7 @@ DohSeek(DOH *obj, long offset, int whence) {
DohBase *b = (DohBase *) obj;
DohObjInfo *objinfo;
if (DohCheck(obj)) {
objinfo = dohtypes[b->type];
objinfo = b->type;
if ((objinfo->doh_file) && (objinfo->doh_file->doh_seek)) {
return (objinfo->doh_file->doh_seek)(b,offset,whence);
}
@ -556,7 +565,7 @@ DohTell(DOH *obj) {
DohBase *b = (DohBase *) obj;
DohObjInfo *objinfo;
if (DohCheck(obj)) {
objinfo = dohtypes[b->type];
objinfo = b->type;
if ((objinfo->doh_file) && (objinfo->doh_file->doh_tell)) {
return (objinfo->doh_file->doh_tell)(b);
}
@ -575,11 +584,11 @@ DohGetc(DOH *obj) {
DohBase *b = (DohBase *) obj;
DohObjInfo *objinfo;
if (obj == lastdoh) {
objinfo = dohtypes[b->type];
objinfo = b->type;
return (objinfo->doh_file->doh_getc)(b);
}
if (DohCheck(obj)) {
objinfo = dohtypes[b->type];
objinfo = b->type;
if (objinfo->doh_file->doh_getc) {
lastdoh = obj;
return (objinfo->doh_file->doh_getc)(b);
@ -600,11 +609,11 @@ DohPutc(int ch, DOH *obj) {
DohObjInfo *objinfo;
if (obj == lastdoh) {
objinfo = dohtypes[b->type];
objinfo = b->type;
return (objinfo->doh_file->doh_putc)(b,ch);
}
if (DohCheck(obj)) {
objinfo = dohtypes[b->type];
objinfo = b->type;
if (objinfo->doh_file->doh_putc) {
lastdoh = obj;
return (objinfo->doh_file->doh_putc)(b,ch);
@ -623,7 +632,7 @@ DohUngetc(int ch, DOH *obj) {
DohBase *b = (DohBase *) obj;
DohObjInfo *objinfo;
if (DohCheck(obj)) {
objinfo = dohtypes[b->type];
objinfo = b->type;
if (objinfo->doh_file->doh_ungetc) {
return (objinfo->doh_file->doh_ungetc)(b,ch);
}
@ -641,7 +650,7 @@ DohClose(DOH *obj) {
DohBase *b = (DohBase *) obj;
DohObjInfo *objinfo;
if (DohCheck(obj)) {
objinfo = dohtypes[b->type];
objinfo = b->type;
if (objinfo->doh_file->doh_close) {
return (objinfo->doh_file->doh_close)(b);
}
@ -659,7 +668,7 @@ DohIsString(const DOH *obj) {
DohBase *b = (DohBase *) obj;
DohObjInfo *objinfo;
if (!DohCheck(b)) return 0;
objinfo = dohtypes[b->type];
objinfo = b->type;
if (objinfo->doh_string) return 1;
else return 0;
}
@ -672,8 +681,10 @@ int
DohReplace(DOH *src, const DOH *token, const DOH *rep, int flags) {
DohBase *b = (DohBase *) src;
DohObjInfo *objinfo;
if (!token) return 0;
if (!rep) rep = "";
if (DohIsString(src)) {
objinfo = dohtypes[b->type];
objinfo = b->type;
if (objinfo->doh_string->doh_replace) {
return (objinfo->doh_string->doh_replace)(b,(DOH *) token, (DOH *) rep,flags);
}
@ -690,7 +701,7 @@ DohChop(DOH *src) {
DohBase *b = (DohBase *) src;
DohObjInfo *objinfo;
if (DohIsString(src)) {
objinfo = dohtypes[b->type];
objinfo = b->type;
if (objinfo->doh_string->doh_chop) {
(objinfo->doh_string->doh_chop)(b);
}
@ -705,7 +716,7 @@ DohSetfile(DOH *ho, DOH *file) {
DohBase *h = (DohBase *) ho;
DohObjInfo *objinfo;
if (!h) return;
objinfo = dohtypes[h->type];
objinfo = h->type;
if (objinfo->doh_setfile)
(objinfo->doh_setfile)(h,file);
}
@ -718,7 +729,7 @@ DohGetfile(DOH *ho) {
DohBase *h = (DohBase *) ho;
DohObjInfo *objinfo;
if (!h) return 0;
objinfo = dohtypes[h->type];
objinfo = h->type;
if (objinfo->doh_getfile)
return (objinfo->doh_getfile)(h);
return 0;
@ -732,7 +743,7 @@ DohSetline(DOH *ho, int l) {
DohBase *h = (DohBase *) ho;
DohObjInfo *objinfo;
if (!h) return;
objinfo = dohtypes[h->type];
objinfo = h->type;
if (objinfo->doh_setline)
(objinfo->doh_setline)(h,l);
}
@ -745,12 +756,60 @@ DohGetline(DOH *ho) {
DohBase *h = (DohBase *) ho;
DohObjInfo *objinfo;
if (!h) return 0;
objinfo = dohtypes[h->type];
objinfo = h->type;
if (objinfo->doh_getline)
return (objinfo->doh_getline)(h);
return 0;
}
/* -----------------------------------------------------------------------------
* DohGetmeta()
* ----------------------------------------------------------------------------- */
DOH *
DohGetmeta(DOH *ho, const DOH *name) {
DohBase *h = (DohBase *) ho;
if (!DohCheck(ho)) return 0;
if (!h->meta) return 0;
return DohGetattr(h->meta,name);
}
/* -----------------------------------------------------------------------------
* DohGetmeta()
* ----------------------------------------------------------------------------- */
int
DohSetmeta(DOH *ho, const DOH *name, const DOH *value) {
DohBase *h = (DohBase *) ho;
if (!DohCheck(ho)) return 0;
if (!h->meta) h->meta = NewHash();
return DohSetattr(h->meta, name, value);
}
/* -----------------------------------------------------------------------------
* DohDelmeta()
* ----------------------------------------------------------------------------- */
int
DohDelmeta(DOH *ho, const DOH *name) {
DohBase *h = (DohBase *) ho;
if (!DohCheck(ho)) return 0;
if (!h->meta) return 0;
return DohDelattr(h->meta, name);
}
/* -----------------------------------------------------------------------------
* DohSetmark()
* ----------------------------------------------------------------------------- */
void
DohSetmark(DOH *ho, int x) {
DohBase *h = (DohBase *) ho;
h->flag_usermark = x;
}
int
DohGetmark(DOH *ho) {
DohBase *h = (DohBase *) ho;
return h->flag_usermark;
}

View file

@ -10,7 +10,7 @@
* See the file LICENSE for information on usage and redistribution.
* ----------------------------------------------------------------------------- */
static char cvsroot[] = "$Header$";
char cvsroot_file_c[] = "$Header$";
#include "dohint.h"
@ -41,6 +41,7 @@ DelFile(DOH *fo) {
}
#endif
}
DohFree(f);
}
/* -----------------------------------------------------------------------------
@ -118,12 +119,12 @@ File_tell(DOH *fo) {
static int
File_putc(DOH *fo, int ch) {
char c;
DohFile *f = (DohFile *) ObjData(fo);
if (f->filep) {
return fputc(ch,f->filep);
} else if (f->fd) {
#ifdef DOH_INTFILE
char c;
c = (char) ch;
return write(f->fd,&c,1);
#endif
@ -137,12 +138,12 @@ File_putc(DOH *fo, int ch) {
static int
File_getc(DOH *fo) {
char c;
DohFile *f = (DohFile *) ObjData(fo);
if (f->filep) {
return fgetc(f->filep);
} else if (f->fd) {
#ifdef DOH_INTFILE
char c;
if (read(f->fd,&c,1) < 0) return EOF;
return c;
#endif
@ -169,6 +170,28 @@ File_ungetc(DOH *fo, int ch) {
return -1;
}
/* -----------------------------------------------------------------------------
* File_close()
*
* Close the file
* ----------------------------------------------------------------------------- */
static int
File_close(DOH *fo) {
int ret = 0;
DohFile *f = (DohFile *) ObjData(fo);
if (f->filep) {
ret = fclose(f->filep);
f->filep = 0;
} else if (f->fd) {
#ifdef DOH_INTFILE
ret = close(f->fd);
f->fd = 0;
#endif
}
return ret;
}
static DohFileMethods FileFileMethods = {
File_read,
File_write,
@ -177,7 +200,7 @@ static DohFileMethods FileFileMethods = {
File_ungetc,
File_seek,
File_tell,
0, /* close */
File_close, /* close */
};
static DohObjInfo DohFileType = {
@ -209,20 +232,13 @@ static DohObjInfo DohFileType = {
* Create a new file from a given filename and mode.
* ----------------------------------------------------------------------------- */
static int init = 0;
DOH *
NewFile(DOH *fn, char *mode)
DohNewFile(DOH *fn, const char *mode)
{
DohFile *f;
FILE *file;
char *filename;
if (!init) {
DohRegisterType(DOHTYPE_FILE, &DohFileType);
init = 1;
}
filename = Char(fn);
file = fopen(filename,mode);
if (!file) return 0;
@ -235,7 +251,7 @@ NewFile(DOH *fn, char *mode)
f->filep = file;
f->fd = 0;
f->closeondel = 1;
return DohObjMalloc(DOHTYPE_FILE,f);
return DohObjMalloc(&DohFileType,f);
}
/* -----------------------------------------------------------------------------
@ -245,20 +261,15 @@ NewFile(DOH *fn, char *mode)
* ----------------------------------------------------------------------------- */
DOH *
NewFileFromFile(FILE *file)
DohNewFileFromFile(FILE *file)
{
DohFile *f;
if (!init) {
DohRegisterType(DOHTYPE_FILE, &DohFileType);
init = 1;
}
f = (DohFile *) DohMalloc(sizeof(DohFile));
if (!f) return 0;
f->filep = file;
f->fd = 0;
f->closeondel = 0;
return DohObjMalloc(DOHTYPE_FILE,f);
return DohObjMalloc(&DohFileType,f);
}
/* -----------------------------------------------------------------------------
@ -268,17 +279,13 @@ NewFileFromFile(FILE *file)
* ----------------------------------------------------------------------------- */
DOH *
NewFileFromFd(int fd)
DohNewFileFromFd(int fd)
{
DohFile *f;
if (!init) {
DohRegisterType(DOHTYPE_FILE, &DohFileType);
init = 1;
}
f = (DohFile *) DohMalloc(sizeof(DohFile));
if (!f) return 0;
f->filep = 0;
f->fd = fd;
f->closeondel = 0;
return DohObjMalloc(DOHTYPE_FILE,f);
return DohObjMalloc(&DohFileType,f);
}

View file

@ -10,7 +10,7 @@
* See the file LICENSE for information on usage and redistribution.
* ----------------------------------------------------------------------------- */
static char cvsroot[] = "$Header$";
char cvsroot_fio_c[] = "$Header$";
#include "dohint.h"
@ -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 (DohIsString(doh) && (ObjType(doh) == DOHTYPE_STRING)) {
if (DohIsString(doh)) {
Sval = doh;
} else {
Sval = Str(doh);
@ -411,7 +411,7 @@ int DohPrintv(DOHFile *f, ...) {
va_start(ap,f);
while(1) {
obj = va_arg(ap,void *);
if (!obj) break;
if ((!obj) || (obj == DohNone)) break;
if (DohCheck(obj)) {
ret += DohDump(obj,f);
} else {
@ -459,12 +459,12 @@ DohCopyto(DOH *in, DOH *out) {
/* -----------------------------------------------------------------------------
* DohSplit()
*
* Split an input stream into a list of strings delimeted by characters in a
* string. Optionally accepts a maximum number of splits to perform.
* Split an input stream into a list of strings delimited by the specified
* character. Optionally accepts a maximum number of splits to perform.
* ----------------------------------------------------------------------------- */
DOH *
DohSplit(DOH *in, char *chs, int nsplits) {
DohSplit(DOH *in, char ch, int nsplits) {
DOH *list;
DOH *str;
int c;
@ -479,17 +479,18 @@ DohSplit(DOH *in, char *chs, int nsplits) {
str = NewString("");
do {
c = Getc(in);
} while ((c != EOF) && (c == *chs));
} while ((c != EOF) && (c == ch));
if (c != EOF) {
Putc(c,str);
while (1) {
c = Getc(in);
if ((c == EOF) || ((c == *chs) && (nsplits != 0))) break;
if ((c == EOF) || ((c == ch) && (nsplits != 0))) break;
Putc(c,str);
}
nsplits--;
}
Append(list,str);
Delete(str);
if (c == EOF) break;
}
return list;

View file

@ -9,10 +9,12 @@
* See the file LICENSE for information on usage and redistribution.
* ----------------------------------------------------------------------------- */
static char cvsroot[] = "$Header$";
char cvsroot_hash_c[] = "$Header$";
#include "dohint.h"
extern DohObjInfo DohHashType;
/* Hash node */
typedef struct HashNode {
DOH *key;
@ -46,6 +48,9 @@ static DOH *find_key (DOH *doh_c) {
char *c = (char *) doh_c;
KeyValue *r, *s;
int d = 0;
/* OK, sure, we use a binary tree for maintaining interned
symbols. Then we use their hash values for accessing secondary
hash tables. */
r = root;
s = 0;
while (r) {
@ -199,8 +204,10 @@ Hash_setattr(DOH *ho, DOH *k, DOH *obj) {
int hv;
HashNode *n, *prev;
Hash *h = (Hash *) ObjData(ho);
if (!obj) return 0;
if (!obj) {
return DohDelattr(ho,k);
}
if (!DohCheck(k)) k = find_key(k);
if (!DohCheck(obj)) {
obj = NewString((char *) obj);
@ -211,16 +218,15 @@ Hash_setattr(DOH *ho, DOH *k, DOH *obj) {
prev = 0;
while (n) {
if (Cmp(n->key,k) == 0) {
HashNode *nn;
if (prev) {
prev->next = n->next;
} else {
h->hashtable[hv] = n->next;
/* Node already exists. Just replace its contents */
if (n->object == obj) {
/* Whoa. Same object. Do nothing */
return 1;
}
nn = n->next;
DelNode(n);
h->nitems--;
n = nn;
Delete(n->object);
n->object = obj;
Incref(obj);
return 1; /* Return 1 to indicate a replacement */
} else {
prev = n;
n = n->next;
@ -276,11 +282,17 @@ Hash_delattr(DOH *ho, DOH *k) {
while (n) {
if (Cmp(n->key, k) == 0) {
/* Found it, kill it */
if (prev) {
prev->next = n->next;
} else {
h->hashtable[hv] = n->next;
}
/* Need to check for iterator location */
if (n == h->current) {
h->current = prev; /* Move back to previous node. When next is called, will move to next node */
if (!h->current) h->currentindex--; /* No previous node. Move back one slot */
}
DelNode(n);
h->nitems--;
return 1;
@ -307,10 +319,12 @@ hash_first(DOH *ho) {
static HashNode *
hash_next(DOH *ho) {
Hash *h = (Hash *) ObjData(ho);
if (h->currentindex < 0) return hash_first(h);
if (h->currentindex < 0) return hash_first(ho);
/* Try to move to the next entry */
h->current = h->current->next;
if (h->current) {
h->current = h->current->next;
}
if (h->current) {
return h->current;
}
@ -348,6 +362,26 @@ Hash_nextkey(DOH *ho) {
return 0;
}
/* -----------------------------------------------------------------------------
* Hash_keys(DOH *)
*
* Return a list of keys
* ----------------------------------------------------------------------------- */
static DOH *
Hash_keys(DOH *so) {
DOH *keys;
DOH *k;
keys = NewList();
k = Firstkey(so);
while (k) {
Append(keys,k);
k = Nextkey(so);
}
return keys;
}
/* -----------------------------------------------------------------------------
* Hash_str()
*
@ -397,26 +431,6 @@ Hash_len(DOH *ho) {
return h->nitems;
}
/* -----------------------------------------------------------------------------
* Hash_keys(DOH *)
*
* Return a list of keys
* ----------------------------------------------------------------------------- */
DOH *
Hash_keys(DOH *so) {
DOH *keys;
DOH *k;
keys = NewList();
k = Firstkey(so);
while (k) {
Append(keys,k);
k = Nextkey(so);
}
/* List_sort(keys); */
return keys;
}
/* -----------------------------------------------------------------------------
* CopyHash()
*
@ -444,7 +458,7 @@ CopyHash(DOH *ho) {
nh->file = h->file;
if (nh->file) Incref(nh->file);
nho = DohObjMalloc(DOHTYPE_HASH, nh);
nho = DohObjMalloc(&DohHashType, nh);
for (i = 0; i < h->hashsize; i++) {
if ((n = h->hashtable[i])) {
while (n) {
@ -458,7 +472,8 @@ CopyHash(DOH *ho) {
void Hash_setfile(DOH *ho, DOH *file) {
static void
Hash_setfile(DOH *ho, DOH *file) {
DOH *fo;
Hash *h = (Hash *) ObjData(ho);
@ -471,17 +486,20 @@ void Hash_setfile(DOH *ho, DOH *file) {
h->file = fo;
}
DOH *Hash_getfile(DOH *ho) {
static DOH *
Hash_getfile(DOH *ho) {
Hash *h = (Hash *) ObjData(ho);
return h->file;
}
void Hash_setline(DOH *ho, int line) {
static void
Hash_setline(DOH *ho, int line) {
Hash *h = (Hash *) ObjData(ho);
h->line = line;
}
int Hash_getline(DOH *ho) {
static int
Hash_getline(DOH *ho) {
Hash *h = (Hash *) ObjData(ho);
return h->line;
}
@ -496,9 +514,10 @@ static DohHashMethods HashHashMethods = {
Hash_delattr,
Hash_firstkey,
Hash_nextkey,
Hash_keys,
};
static DohObjInfo HashType = {
DohObjInfo DohHashType = {
"Hash", /* objname */
DelHash, /* doh_del */
CopyHash, /* doh_copy */
@ -528,14 +547,9 @@ static DohObjInfo HashType = {
* ----------------------------------------------------------------------------- */
DOH *
NewHash() {
DohNewHash() {
Hash *h;
int i;
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 *));
@ -547,6 +561,5 @@ NewHash() {
h->nitems = 0;
h->file = 0;
h->line = 0;
return DohObjMalloc(DOHTYPE_HASH,h);
return DohObjMalloc(&DohHashType,h);
}

View file

@ -9,7 +9,7 @@
* See the file LICENSE for information on usage and redistribution.
* ----------------------------------------------------------------------------- */
static char cvsroot[] = "$Header$";
char cvsroot_list_c[] = "$Header$";
#include "dohint.h"
@ -22,6 +22,8 @@ typedef struct List {
DOH **items;
} List;
extern DohObjInfo DohListType;
/* Doubles amount of memory in a list */
static
void more(List *l) {
@ -52,7 +54,7 @@ CopyList(DOH *lo) {
nl->file = l->file;
if (nl->file) Incref(nl->file);
nl->line = l->line;
return DohObjMalloc(DOHTYPE_LIST, nl);
return DohObjMalloc(&DohListType, nl);
}
/* -----------------------------------------------------------------------------
@ -261,27 +263,8 @@ List_dump(DOH *lo, DOH *out) {
return nsent;
}
/* -----------------------------------------------------------------------------
* List_sort()
* ----------------------------------------------------------------------------- */
static int objcmp(const void *s1, const void *s2) {
DOH **so1, **so2;
so1 = (DOH **) s1;
so2 = (DOH **) s2;
return Cmp(*so1,*so2);
}
void
List_sort(DOH *lo, int opt) {
List *l = (List *) ObjData(lo);
qsort(l->items,l->nitems,sizeof(DOH *),objcmp);
}
void List_setfile(DOH *lo, DOH *file) {
static void
List_setfile(DOH *lo, DOH *file) {
DOH *fo;
List *l = (List *) ObjData(lo);
@ -294,17 +277,19 @@ void List_setfile(DOH *lo, DOH *file) {
l->file = fo;
}
DOH *List_getfile(DOH *lo) {
static DOH *
List_getfile(DOH *lo) {
List *l = (List *) ObjData(lo);
return l->file;
}
void List_setline(DOH *lo, int line) {
static void
List_setline(DOH *lo, int line) {
List *l = (List *) ObjData(lo);
l->line = line;
}
int List_getline(DOH *lo) {
static int List_getline(DOH *lo) {
List *l = (List *) ObjData(lo);
return l->line;
}
@ -316,10 +301,9 @@ static DohListMethods ListListMethods = {
List_insert,
List_first,
List_next,
List_sort
};
static DohObjInfo ListType = {
DohObjInfo DohListType = {
"List", /* objname */
DelList, /* doh_del */
CopyList, /* doh_copy */
@ -351,14 +335,9 @@ static DohObjInfo ListType = {
#define MAXLISTITEMS 8
DOH *
NewList() {
DohNewList() {
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;
@ -369,5 +348,6 @@ NewList() {
l->iter = 0;
l->file = 0;
l->line = 0;
return DohObjMalloc(DOHTYPE_LIST,l);
return DohObjMalloc(&DohListType,l);
}

View file

@ -10,7 +10,7 @@
* See the file LICENSE for information on usage and redistribution.
* ----------------------------------------------------------------------------- */
static char cvsroot[] = "$Header$";
char cvsroot_memory_c[] = "$Header$";
#include "dohint.h"
@ -30,8 +30,7 @@ typedef struct pool {
struct pool *next; /* Next pool */
} Pool;
DohBase *FreeList = 0; /* List of free objects */
static DohBase *FreeList = 0; /* List of free objects */
static Pool *Pools = 0;
static int pools_initialized = 0;
@ -105,7 +104,7 @@ DohIntern(DOH *obj) {
* ---------------------------------------------------------------------- */
DOH *
DohObjMalloc(int type, void *data) {
DohObjMalloc(DohObjInfo *type, void *data) {
DohBase *obj;
if (!pools_initialized) InitPools();
if (FreeList) {
@ -121,9 +120,12 @@ DohObjMalloc(int type, void *data) {
}
obj->type = type;
obj->data = data;
obj->meta = 0;
obj->refcount = 1;
obj->flag_intern = 0;
obj->flag_marked = 0;
obj->flag_user = 0;
obj->flag_usermark = 0;
return (DOH *) obj;
}
@ -137,6 +139,10 @@ DohObjFree(DOH *ptr) {
b = (DohBase *) ptr;
if (b->flag_intern) return;
b->data = (void *) FreeList;
if (b->meta) {
Delete(b->meta);
b->meta = 0;
}
b->type = 0;
FreeList = b;
}

View file

@ -10,13 +10,11 @@
* See the file LICENSE for information on usage and redistribution.
* ----------------------------------------------------------------------------- */
static char cvsroot[] = "$Header$";
char cvsroot_string_c[] = "$Header$";
#include "dohint.h"
#ifndef DOH_STRING_UPDATE_LINES
#define DOH_STRING_UPDATE_LINES
#endif
extern DohObjInfo DohStringType;
typedef struct String {
DOH *file;
@ -31,7 +29,9 @@ typedef struct String {
/* -----------------------------------------------------------------------------
* void *String_data() - Return as a 'void *'
* ----------------------------------------------------------------------------- */
void *String_data(DOH *so) {
static void *
String_data(DOH *so) {
String *s = (String *) ObjData(so);
s->str[s->len] = 0;
return (void *) s->str;
@ -41,7 +41,8 @@ void *String_data(DOH *so) {
* int String_dump() - Serialize a string onto out
* ----------------------------------------------------------------------------- */
int String_dump(DOH *so, DOH *out) {
static int
String_dump(DOH *so, DOH *out) {
int nsent;
int ret;
String *s = (String *) ObjData(so);
@ -57,32 +58,37 @@ int String_dump(DOH *so, DOH *out) {
/* -----------------------------------------------------------------------------
* CopyString() - Copy a string
* ----------------------------------------------------------------------------- */
DOH *
static DOH *
CopyString(DOH *so) {
String *s = (String *) ObjData(so);
int max;
String *str;
String *s = (String *) ObjData(so);
str = (String *) DohMalloc(sizeof(String));
str->hashkey = -1;
str->sp = 0;
str->sp = s->sp;
str->line = s->line;
str->file = s->file;
if (str->file) Incref(str->file);
max = s->maxsize;
str->str = (char *) DohMalloc(max);
str->str = (char *) DohMalloc(max+1);
memmove(str->str, s->str, max);
str->maxsize= max;
str->len = s->len;
str->str[str->len] = 0;
return DohObjMalloc(DOHTYPE_STRING,str);
return DohObjMalloc(&DohStringType,str);
}
/* -----------------------------------------------------------------------------
* DelString() - Delete a string
* ----------------------------------------------------------------------------- */
void
static void
DelString(DOH *so) {
String *s = (String *) ObjData(so);
s->hashkey = -1;
s->str = 0;
DohFree(s->str);
DohFree(s);
}
@ -91,7 +97,7 @@ DelString(DOH *so) {
* String_len() - Length of a string
* ----------------------------------------------------------------------------- */
int
static int
String_len(DOH *so) {
String *s = (String *) ObjData(so);
return s->len;
@ -102,7 +108,7 @@ String_len(DOH *so) {
* int String_cmp() - Compare two strings
* ----------------------------------------------------------------------------- */
int
static int
String_cmp(DOH *so1, DOH *so2)
{
String *s1, *s2;
@ -130,7 +136,8 @@ String_cmp(DOH *so1, DOH *so2)
* int String_hash() - Compute string hash value
* ----------------------------------------------------------------------------- */
int String_hash(DOH *so) {
static int
String_hash(DOH *so) {
String *s = (String *) ObjData(so);
char *c;
int i, h = 0, len;
@ -179,43 +186,11 @@ add(String *s, const char *newstr) {
s->len += l;
}
/* Add a single character to s */
void
String_addchar(String *s, char c) {
register char *tc;
register int len = s->len;
register int maxsize = s->maxsize;
s->hashkey = -1;
if (len > (maxsize-2)) {
s->str = (char *) DohRealloc(s->str,2*maxsize);
assert(s->str);
s->maxsize = 2*maxsize;
}
tc = s->str;
tc[len] = c;
if (s->sp >= len) {
s->sp = len+1;
tc[len+1] = 0;
if (c == '\n') s->line++;
}
s->len++;
}
/* Expand a string to accomodate a write */
void
String_expand(String *s, int width) {
if ((s->len + width) > (s->maxsize-1)) {
s->str = (char *) DohRealloc(s->str,(s->len + width)+1);
assert(s->str);
s->maxsize = s->len + width + 1;
}
}
/* -----------------------------------------------------------------------------
* void String_clear() - Clear a string
* ----------------------------------------------------------------------------- */
void
static void
String_clear(DOH *so)
{
String *s = (String *) ObjData(so);
@ -230,7 +205,9 @@ String_clear(DOH *so)
* void String_insert() - Insert a string
* ----------------------------------------------------------------------------- */
int String_insert(DOH *so, int pos, DOH *str) {
static int
String_insert(DOH *so, int pos, DOH *str)
{
String *s = (String *) ObjData(so);
char *nstr;
int len;
@ -274,7 +251,8 @@ int String_insert(DOH *so, int pos, DOH *str) {
* int String_delitem() - Delete a character
* ----------------------------------------------------------------------------- */
int String_delitem(DOH *so, int pos)
static int
String_delitem(DOH *so, int pos)
{
String *s = (String *) ObjData(so);
s->hashkey = -1;
@ -297,8 +275,9 @@ int String_delitem(DOH *so, int pos)
* DOH *String_str() - Returns a string (used by printing commands)
* ----------------------------------------------------------------------------- */
DOH *
String_str(DOH *so) {
static DOH *
String_str(DOH *so)
{
String *s = (String *) ObjData(so);
s->str[s->len] = 0;
return NewString(s->str);
@ -307,8 +286,10 @@ String_str(DOH *so) {
/* -----------------------------------------------------------------------------
* int String_read() - Read data from a string
* ----------------------------------------------------------------------------- */
int
String_read(DOH *so, void *buffer, int len) {
static int
String_read(DOH *so, void *buffer, int len)
{
int reallen, retlen;
char *cb;
String *s = (String *) ObjData(so);
@ -328,8 +309,9 @@ String_read(DOH *so, void *buffer, int len) {
/* -----------------------------------------------------------------------------
* int String_write() - Write data to a string
* ----------------------------------------------------------------------------- */
int
String_write(DOH *so, void *buffer, int len) {
static int
String_write(DOH *so, void *buffer, int len)
{
int newlen;
String *s = (String *) ObjData(so);
s->hashkey = -1;
@ -351,8 +333,10 @@ String_write(DOH *so, void *buffer, int len) {
/* -----------------------------------------------------------------------------
* int String_seek() - Seek to a new position
* ----------------------------------------------------------------------------- */
int
String_seek(DOH *so, long offset, int whence) {
static int
String_seek(DOH *so, long offset, int whence)
{
int pos, nsp, inc;
int prev;
String *s = (String *) ObjData(so);
@ -391,8 +375,10 @@ String_seek(DOH *so, long offset, int whence) {
/* -----------------------------------------------------------------------------
* long String_tell() - Return current position
* ----------------------------------------------------------------------------- */
long
String_tell(DOH *so) {
static long
String_tell(DOH *so)
{
String *s = (String *) ObjData(so);
return (long) (s->sp);
}
@ -401,8 +387,9 @@ String_tell(DOH *so) {
* int String_putc()
* ----------------------------------------------------------------------------- */
int
String_putc(DOH *so, int ch) {
static int
String_putc(DOH *so, int ch)
{
register int len, maxsize, sp;
String *s = (String *) ObjData(so);
s->hashkey = -1;
@ -435,7 +422,9 @@ String_putc(DOH *so, int ch) {
* int String_getc()
* ----------------------------------------------------------------------------- */
int String_getc(DOH *so) {
static int
String_getc(DOH *so)
{
int c;
String *s = (String *) ObjData(so);
if (s->sp >= s->len)
@ -450,7 +439,9 @@ int String_getc(DOH *so) {
* int String_ungetc()
* ----------------------------------------------------------------------------- */
int String_ungetc(DOH *so, int ch) {
static int
String_ungetc(DOH *so, int ch)
{
String *s = (String *) ObjData(so);
if (ch == EOF) return ch;
if (s->sp <= 0) return EOF;
@ -466,7 +457,9 @@ int String_ungetc(DOH *so, int ch) {
* Replaces count non-overlapping occurrences of token with rep in a string.
* ----------------------------------------------------------------------------- */
static char *end_quote(char *s) {
static char *
end_quote(char *s)
{
char qc;
char *q;
qc = *s;
@ -478,11 +471,15 @@ static char *end_quote(char *s) {
}
}
static char *match_simple(char *base, char *s, char *token, int tokenlen) {
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) {
static char *
match_identifier(char *base, char *s, char *token, int tokenlen)
{
while (s) {
s = strstr(s,token);
if (!s) return 0;
@ -499,8 +496,8 @@ static char *match_identifier(char *base, char *s, char *token, int tokenlen) {
return 0;
}
static
int replace_simple(String *str, char *token, char *rep, int flags, int count, char *(*match)(char *, char *, char *, int))
static int
replace_simple(String *str, char *token, char *rep, int flags, int count, char *(*match)(char *, char *, char *, int))
{
int tokenlen; /* Length of the token */
int replen; /* Length of the replacement */
@ -513,7 +510,10 @@ int replace_simple(String *str, char *token, char *rep, int flags, int count, ch
register char *base;
int i;
str->hashkey = -1;
/* Figure out if anything gets replaced */
if (!strlen(token)) return 0;
base = str->str;
tokenlen = strlen(token);
@ -706,11 +706,12 @@ int replace_simple(String *str, char *token, char *rep, int flags, int count, ch
* int String_replace()
* ----------------------------------------------------------------------------- */
int
static int
String_replace(DOH *stro, DOH *token, DOH *rep, int flags)
{
int count = -1;
String *str = (String *) ObjData(stro);
if (flags & DOH_REPLACE_FIRST) count = 1;
if (flags & DOH_REPLACE_ID) {
@ -724,8 +725,9 @@ String_replace(DOH *stro, DOH *token, DOH *rep, int flags)
* void String_chop(DOH *str)
* ----------------------------------------------------------------------------- */
void
String_chop(DOH *so) {
static void
String_chop(DOH *so)
{
char *c;
String *str = (String *) ObjData(so);
/* Replace trailing whitespace */
@ -743,7 +745,9 @@ String_chop(DOH *so) {
str->hashkey = -1;
}
void String_setfile(DOH *so, DOH *file) {
static void
String_setfile(DOH *so, DOH *file)
{
DOH *fo;
String *str = (String *) ObjData(so);
@ -756,17 +760,23 @@ void String_setfile(DOH *so, DOH *file) {
str->file = fo;
}
DOH *String_getfile(DOH *so) {
static DOH *
String_getfile(DOH *so)
{
String *str = (String *) ObjData(so);
return str->file;
}
void String_setline(DOH *so, int line) {
static void
String_setline(DOH *so, int line)
{
String *str = (String *) ObjData(so);
str->line = line;
}
int String_getline(DOH *so) {
static int
String_getline(DOH *so)
{
String *str = (String *) ObjData(so);
return str->line;
}
@ -778,7 +788,6 @@ static DohListMethods StringListMethods = {
String_insert, /* doh_insitem */
0, /* doh_first */
0, /* doh_next */
0, /* doh_sort */
};
static DohFileMethods StringFileMethods = {
@ -797,7 +806,7 @@ static DohStringMethods StringStringMethods = {
String_chop,
};
static DohObjInfo StringType = {
DohObjInfo DohStringType = {
"String", /* objname */
DelString, /* doh_del */
CopyString, /* doh_copy */
@ -823,21 +832,16 @@ static DohObjInfo StringType = {
#define INIT_MAXSIZE 16
/* -----------------------------------------------------------------------------
* NewString(const char *c) - Create a new string
* ----------------------------------------------------------------------------- */
DOHString *
NewString(const DOH *so)
DohNewString(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));
@ -860,7 +864,7 @@ NewString(const DOH *so)
str->str[0] = 0;
str->len = 0;
}
return DohObjMalloc(DOHTYPE_STRING,str);
return DohObjMalloc(&DohStringType,str);
}
/* -----------------------------------------------------------------------------
@ -870,7 +874,7 @@ NewString(const DOH *so)
* ----------------------------------------------------------------------------- */
DOHString *
NewStringf(const DOH *fmt, ...)
DohNewStringf(const DOH *fmt, ...)
{
va_list ap;
DOH *r;
@ -880,3 +884,28 @@ NewStringf(const DOH *fmt, ...)
va_end(ap);
return (DOHString *) r;
}
/* -----------------------------------------------------------------------------
* Strcmp()
* Strncmp()
* Strstr()
* Strchr()
*
* Some utility functions.
* ----------------------------------------------------------------------------- */
int DohStrcmp(const DOHString_or_char *s1, const DOHString_or_char *s2) {
return strcmp(Char(s1),Char(s2));
}
int DohStrncmp(const DOHString_or_char *s1, const DOHString_or_char *s2, int n) {
return strncmp(Char(s1),Char(s2),n);
}
char *DohStrstr(const DOHString_or_char *s1, const DOHString_or_char *s2) {
return strstr(Char(s1),Char(s2));
}
char *DohStrchr(const DOHString_or_char *s1, int ch) {
return strchr(Char(s1),ch);
}

View file

@ -10,7 +10,7 @@
* See the file LICENSE for information on usage and redistribution.
* ----------------------------------------------------------------------------- */
static char cvsroot[] = "$Header$";
char cvsroot_void_c[] = "$Header$";
#include "dohint.h"
@ -88,15 +88,10 @@ static DohObjInfo DohVoidType = {
* ----------------------------------------------------------------------------- */
DOH *
NewVoid(void *obj, void (*del)(void *)) {
static int init = 0;
DohNewVoid(void *obj, void (*del)(void *)) {
VoidObj *v;
if (!init) {
DohRegisterType(DOHTYPE_VOID, &DohVoidType);
init = 1;
}
v = (VoidObj *) DohMalloc(sizeof(VoidObj));
v->ptr = obj;
v->del = del;
return DohObjMalloc(DOHTYPE_VOID,v);
return DohObjMalloc(&DohVoidType,v);
}

View file

@ -14,6 +14,105 @@
#ifndef _DOH_H
#define _DOH_H
/* Set the namespace prefix for DOH API functions. This can be used to control
visibility of the functions in libraries */
/* Set this macro if you want to change DOH linkage. You would do this if you
wanted to hide DOH in a library using a different set of names. Note: simply
change "Doh" to a new name. */
/*
#define DOH_NAMESPACE(x) Doh ## x
*/
#ifdef DOH_NAMESPACE
/* Namespace control. These macros define all of the public API names in DOH */
#define DohCheck DOH_NAMESPACE(Check)
#define DohIntern DOH_NAMESPACE(Intern)
#define DohDelete DOH_NAMESPACE(Delete)
#define DohCopy DOH_NAMESPACE(Copy)
#define DohClear DOH_NAMESPACE(Clear)
#define DohStr DOH_NAMESPACE(Str)
#define DohData DOH_NAMESPACE(Data)
#define DohDump DOH_NAMESPACE(Dump)
#define DohLen DOH_NAMESPACE(Len)
#define DohHashval DOH_NAMESPACE(Hashval)
#define DohCmp DOH_NAMESPACE(Cmp)
#define DohIncref DOH_NAMESPACE(Incref)
#define DohGetattr DOH_NAMESPACE(Getattr)
#define DohSetattr DOH_NAMESPACE(Setattr)
#define DohDelattr DOH_NAMESPACE(Delattr)
#define DohFirstkey DOH_NAMESPACE(Firstkey)
#define DohNextkey DOH_NAMESPACE(Nextkey)
#define DohKeys DOH_NAMESPACE(Keys)
#define DohGetInt DOH_NAMESPACE(GetInt)
#define DohGetDouble DOH_NAMESPACE(GetDouble)
#define DohGetChar DOH_NAMESPACE(GetChar)
#define DohSetChar DOH_NAMESPACE(SetChar)
#define DohSetInt DOH_NAMESPACE(SetInt)
#define DohSetDouble DOH_NAMESPACE(SetDouble)
#define DohSetVoid DOH_NAMESPACE(SetVoid)
#define DohGetVoid DOH_NAMESPACE(GetVoid)
#define DohGetitem DOH_NAMESPACE(Getitem)
#define DohSetitem DOH_NAMESPACE(Setitem)
#define DohDelitem DOH_NAMESPACE(Delitem)
#define DohInsertitem DOH_NAMESPACE(Insertitem)
#define DohFirstitem DOH_NAMESPACE(Firstitem)
#define DohNextitem DOH_NAMESPACE(Nextitem)
#define DohWrite DOH_NAMESPACE(Write)
#define DohRead DOH_NAMESPACE(Read)
#define DohSeek DOH_NAMESPACE(Seek)
#define DohTell DOH_NAMESPACE(Tell)
#define DohGetc DOH_NAMESPACE(Getc)
#define DohPutc DOH_NAMESPACE(Putc)
#define DohUngetc DOH_NAMESPACE(Ungetc)
#define DohGetline DOH_NAMESPACE(Getline)
#define DohSetline DOH_NAMESPACE(Setline)
#define DohGetfile DOH_NAMESPACE(Getfile)
#define DohSetfile DOH_NAMESPACE(Setfile)
#define DohReplace DOH_NAMESPACE(Replace)
#define DohChop DOH_NAMESPACE(Chop)
#define DohGetmeta DOH_NAMESPACE(Getmeta)
#define DohSetmeta DOH_NAMESPACE(Setmeta)
#define DohDelmeta DOH_NAMESPACE(Delmeta)
#define DohEncoding DOH_NAMESPACE(Encoding)
#define DohPrintf DOH_NAMESPACE(Printf)
#define DohvPrintf DOH_NAMESPACE(vPrintf)
#define DohPrintv DOH_NAMESPACE(Printv)
#define DohReadline DOH_NAMESPACE(Readline)
#define DohIsMapping DOH_NAMESPACE(IsMapping)
#define DohIsSequence DOH_NAMESPACE(IsSequence)
#define DohIsString DOH_NAMESPACE(IsString)
#define DohIsFile DOH_NAMESPACE(IsFile)
#define DohNewString DOH_NAMESPACE(NewString)
#define DohNewStringf DOH_NAMESPACE(NewStringf)
#define DohStrcmp DOH_NAMESPACE(Strcmp)
#define DohStrncmp DOH_NAMESPACE(Strncmp)
#define DohStrstr DOH_NAMESPACE(Strstr)
#define DohStrchr DOH_NAMESPACE(Strchr)
#define DohNewFile DOH_NAMESPACE(NewFile)
#define DohNewFileFromFile DOH_NAMESPACE(NewFileFromFile)
#define DohNewFileFromFd DOH_NAMESPACE(NewFileFromFd)
#define DohClose DOH_NAMESPACE(Close)
#define DohCopyto DOH_NAMESPACE(Copyto)
#define DohNewList DOH_NAMESPACE(NewList)
#define DohNewHash DOH_NAMESPACE(NewHash)
#define DohNewVoid DOH_NAMESPACE(NewVoid)
#define DohSplit DOH_NAMESPACE(Split)
#define DohNone DOH_NAMESPACE(None)
#define DohObjMalloc DOH_NAMESPACE(ObjMalloc)
#define DohObjFree DOH_NAMESPACE(ObjFree)
#define DohStringType DOH_NAMESPACE(StringType)
#define DohListType DOH_NAMESPACE(ListType)
#define DohHashType DOH_NAMESPACE(HashType)
#define DohFileType DOH_NAMESPACE(FileType)
#define DohVoidType DOH_NAMESPACE(VoidType)
#endif
#include <stdio.h>
#include <stdarg.h>
@ -53,8 +152,8 @@ typedef void DOH;
#define DohFree free
#endif
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 */
@ -71,64 +170,126 @@ extern void DohIncref(DOH *obj);
/* 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 int DohDelattr(DOH *obj, const DOHString_or_char *name);
extern DOH *DohFirstkey(DOH *obj);
extern DOH *DohNextkey(DOH *obj);
extern DOH *DohKeys(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 */
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 */
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);
/* Meta-variables */
extern DOH *DohGetmeta(DOH *, const DOH *);
extern int DohSetmeta(DOH *, const DOH *, const DOH *value);
extern int DohDelmeta(DOH *, const DOH *);
/* 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 int DohPrintv(DOHFile *obj, ...);
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 int DohPrintv(DOHFile *obj, ...);
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);
extern void DohSetmark(DOH *obj, int x);
extern int DohGetmark(DOH *obj);
/* -----------------------------------------------------------------------------
* Strings.
* ----------------------------------------------------------------------------- */
extern DOHString *DohNewString(const DOH *c);
extern DOHString *DohNewStringf(const DOH *fmt, ...);
extern int DohStrcmp(const DOHString_or_char *s1, const DOHString_or_char *s2);
extern int DohStrncmp(const DOHString_or_char *s1, const DOHString_or_char *s2, int n);
extern char *DohStrstr(const DOHString_or_char *s1, const DOHString_or_char *s2);
extern char *DohStrchr(const DOHString_or_char *s1, int ch);
/* String replacement flags */
#define DOH_REPLACE_ANY 0x01
#define DOH_REPLACE_NOQUOTE 0x02
#define DOH_REPLACE_ID 0x04
#define DOH_REPLACE_FIRST 0x08
#define Replaceall(s,t,r) DohReplace(s,t,r,DOH_REPLACE_ANY)
#define Replaceid(s,t,r) DohReplace(s,t,r,DOH_REPLACE_ID)
/* -----------------------------------------------------------------------------
* Files
* ----------------------------------------------------------------------------- */
extern DOHFile *DohNewFile(DOH *file, const char *mode);
extern DOHFile *DohNewFileFromFile(FILE *f);
extern DOHFile *DohNewFileFromFd(int fd);
extern int DohClose(DOH *file);
extern int DohCopyto(DOHFile *input, DOHFile *output);
/* -----------------------------------------------------------------------------
* List
* ----------------------------------------------------------------------------- */
extern DOHList *DohNewList();
/* -----------------------------------------------------------------------------
* Hash
* ----------------------------------------------------------------------------- */
extern DOHHash *DohNewHash();
/* -----------------------------------------------------------------------------
* Void
* ----------------------------------------------------------------------------- */
extern DOHVoid *DohNewVoid(void *ptr, void (*del)(void *));
extern DOHList *DohSplit(DOHFile *input, char ch, int nsplits);
extern DOH *DohNone;
#ifndef DOH_LONG_NAMES
/* Macros to invoke the above functions. Includes the location of
@ -168,6 +329,7 @@ extern int DohIsFile(const DOH *obj);
#define Getc DohGetc
#define Putc DohPutc
#define Ungetc DohUngetc
#define Close DohClose
#define vPrintf DohvPrintf
#define GetInt DohGetInt
#define GetDouble DohGetDouble
@ -182,57 +344,36 @@ extern int DohIsFile(const DOH *obj);
#define Readline DohReadline
#define Replace DohReplace
#define Chop DohChop
#define Getmeta DohGetmeta
#define Setmeta DohSetmeta
#define Delmeta DohDelmeta
#define NewString DohNewString
#define NewStringf DohNewStringf
#define NewHash DohNewHash
#define NewList DohNewList
#define NewFile DohNewFile
#define NewFileFromFile DohNewFileFromFile
#define NewFileFromFd DohNewFileFromFd
#define Close DohClose
#define NewVoid DohNewVoid
#define Keys DohKeys
#define Strcmp DohStrcmp
#define Strncmp DohStrncmp
#define Strstr DohStrstr
#define Strchr DohStrchr
#define Copyto DohCopyto
#define Split DohSplit
#define Setmark DohSetmark
#define Getmark DohGetmark
#define None DohNone
#endif
/* -----------------------------------------------------------------------------
* Strings.
* ----------------------------------------------------------------------------- */
#ifdef NIL
#undef NIL
#endif
extern DOHString *NewString(const DOH *c);
extern DOHString *NewStringf(const DOH *fmt, ...);
#define NIL (char *) NULL
/* String replacement flags */
#define DOH_REPLACE_ANY 0x01
#define DOH_REPLACE_NOQUOTE 0x02
#define DOH_REPLACE_ID 0x04
#define DOH_REPLACE_FIRST 0x08
/* -----------------------------------------------------------------------------
* Files
* ----------------------------------------------------------------------------- */
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
/* -----------------------------------------------------------------------------
* List
* ----------------------------------------------------------------------------- */
extern DOHList *NewList();
/* -----------------------------------------------------------------------------
* Hash
* ----------------------------------------------------------------------------- */
extern DOHHash *NewHash();
extern DOHList *Hash_keys(DOHHash *);
/* -----------------------------------------------------------------------------
* Void
* ----------------------------------------------------------------------------- */
extern DOHVoid *NewVoid(void *ptr, void (*del)(void *));
extern DOHList *DohSplit(DOHFile *input, char *chs, int nsplits);
#define Split DohSplit
extern DOH *DohNone;
#endif /* DOH_H */

View file

@ -23,6 +23,7 @@ typedef struct {
int (*doh_delattr)(DOH *obj, DOH *name); /* Del attribute */
DOH *(*doh_firstkey)(DOH *obj); /* First key */
DOH *(*doh_nextkey)(DOH *obj); /* Next key */
DOH *(*doh_keys)(DOH *obj); /* All keys as a list */
} DohHashMethods;
/* List objects */
@ -33,7 +34,6 @@ typedef struct {
int (*doh_insitem)(DOH *obj, int index, DOH *value); /* Insert item */
DOH *(*doh_firstitem)(DOH *obj); /* Iterators */
DOH *(*doh_nextitem)(DOH *obj);
void (*doh_sort)(DOH *obj, int opt); /* Sort */
} DohListMethods;
/* File methods */
@ -93,37 +93,29 @@ typedef struct DohObjInfo {
} DohObjInfo;
typedef struct {
void *data; /* Data pointer */
unsigned int type : 4; /* Object type (max 16 -- deal with it) */
void *data; /* Data pointer */
DohObjInfo *type;
void *meta; /* Meta data */
int flag_intern : 1; /* Interned object */
int flag_marked : 1; /* Mark flag. Used to avoid recursive loops in places */
int flag_user : 1; /* User flag */
int flag_reserved : 1; /* Reserved flag */
int refcount : 24; /* Reference count (max 16 million) */
int flag_usermark : 1; /* User marked */
int refcount : 28; /* Reference count (max 16 million) */
} 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 Decref(a) if (a) ((DohBase *) a)->refcount--
#define Incref(a) if (a) ((DohBase *) a)->refcount++
#define Refcount(a) ((DohBase *) a)->refcount
/* Macros for manipulating objects in a safe manner */
#define ObjData(a) ((DohBase *)a)->data
#define ObjSetMark(a,x) ((DohBase *)a)->flag_marked = x
#define ObjGetMark(a) ((DohBase *)a)->flag_marked
#define ObjType(a) ((DohBase *)a)->type
#define ObjData(a) ((DohBase *)a)->data
#define ObjSetMark(a,x) ((DohBase *)a)->flag_marked = x
#define ObjGetMark(a) ((DohBase *)a)->flag_marked
#define ObjType(a) ((DohBase *)a)->type
extern DOH *DohObjMalloc(int type, void *data); /* Allocate a DOH object */
extern DOH *DohObjMalloc(DohObjInfo *type, void *data); /* Allocate a DOH object */
extern void DohObjFree(DOH *ptr); /* Free a DOH object */
extern void DohRegisterType(int type, DohObjInfo *objinfo);
#define MAX_DOHTYPE 16
#define DOHTYPE_STRING 1
#define DOHTYPE_LIST 2
#define DOHTYPE_HASH 3
#define DOHTYPE_VOID 4
#define DOHTYPE_FILE 5
#endif /* DOHOBJ_H */

Some files were not shown because too many files have changed in this diff Show more