beautify/format source code with gnu indent

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9505 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2006-11-01 23:54:54 +00:00
commit 68891541d1
72 changed files with 27237 additions and 28215 deletions

View file

@ -20,55 +20,51 @@ extern "C" {
#endif
/* cscanner.c */
extern char *cparse_file;
extern int cparse_line;
extern int cparse_cplusplus;
extern int cparse_start_line;
extern char *cparse_file;
extern int cparse_line;
extern int cparse_cplusplus;
extern int cparse_start_line;
extern void Swig_cparse_cplusplus(int);
extern void scanner_file(File *);
extern void scanner_next_token(int);
extern void skip_balanced(int startchar, int endchar);
extern void skip_decl(void);
extern void scanner_check_typedef(void);
extern void scanner_ignore_typedef(void);
extern void scanner_last_id(int);
extern void scanner_clear_rename(void);
extern void start_inline(char *, int);
extern String *scanner_ccode;
extern int yylex();
extern void Swig_cparse_cplusplus(int);
extern void scanner_file(File *);
extern void scanner_next_token(int);
extern void skip_balanced(int startchar, int endchar);
extern void skip_decl(void);
extern void scanner_check_typedef(void);
extern void scanner_ignore_typedef(void);
extern void scanner_last_id(int);
extern void scanner_clear_rename(void);
extern void start_inline(char *, int);
extern String *scanner_ccode;
extern int yylex();
/* parser.y */
extern SwigType *Swig_cparse_type(String *);
extern Node *Swig_cparse(File *);
extern Hash *Swig_cparse_features();
extern void SWIG_cparse_set_compact_default_args(int defargs);
extern int SWIG_cparse_template_reduce(int treduce);
extern SwigType *Swig_cparse_type(String *);
extern Node *Swig_cparse(File *);
extern Hash *Swig_cparse_features();
extern void SWIG_cparse_set_compact_default_args(int defargs);
extern int SWIG_cparse_template_reduce(int treduce);
/* util.c */
extern void Swig_cparse_replace_descriptor(String *s);
extern void cparse_normalize_void(Node *);
extern Parm *Swig_cparse_parm(String *s);
extern ParmList *Swig_cparse_parms(String *s);
extern void Swig_cparse_replace_descriptor(String *s);
extern void cparse_normalize_void(Node *);
extern Parm *Swig_cparse_parm(String *s);
extern ParmList *Swig_cparse_parms(String *s);
/* templ.c */
extern int Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab *tscope);
extern Node *Swig_cparse_template_locate(String *name, ParmList *tparms, Symtab *tscope);
extern void Swig_cparse_debug_templates(int);
extern int Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab *tscope);
extern Node *Swig_cparse_template_locate(String *name, ParmList *tparms, Symtab *tscope);
extern void Swig_cparse_debug_templates(int);
#ifdef __cplusplus
}
#endif
#define SWIG_WARN_NODE_BEGIN(Node) \
{ \
String *wrnfilter = Node ? Getattr(Node,"feature:warnfilter") : 0; \
if (wrnfilter) Swig_warnfilter(wrnfilter,1)
if (wrnfilter) Swig_warnfilter(wrnfilter,1)
#define SWIG_WARN_NODE_END(Node) \
if (wrnfilter) Swig_warnfilter(wrnfilter,0); \
}
#endif

File diff suppressed because it is too large Load diff

View file

@ -18,8 +18,7 @@ static int template_debug = 0;
String *baselists[3];
void SwigType_template_init()
{
void SwigType_template_init() {
baselists[0] = k_baselist;
baselists[1] = k_protectedbaselist;
baselists[2] = k_privatebaselist;
@ -28,17 +27,17 @@ void SwigType_template_init()
static void add_parms(ParmList *p, List *patchlist, List *typelist) {
while (p) {
SwigType *ty = Getattr(p,k_type);
SwigType *val = Getattr(p,k_value);
Append(typelist,ty);
Append(typelist,val);
Append(patchlist,val);
SwigType *ty = Getattr(p, k_type);
SwigType *val = Getattr(p, k_value);
Append(typelist, ty);
Append(typelist, val);
Append(patchlist, val);
p = nextSibling(p);
}
}
void Swig_cparse_debug_templates(int x) {
template_debug = x;
template_debug = x;
}
/* -----------------------------------------------------------------------------
@ -49,69 +48,70 @@ void Swig_cparse_debug_templates(int x) {
* template parameters
* ----------------------------------------------------------------------------- */
static int
cparse_template_expand(Node *n, String *tname, String *rname, String *templateargs, List *patchlist, List *typelist, List *cpatchlist) {
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;
String *nodeType = Getattr(n,k_nodetype);
if (!n) return 0;
if (Getattr(n,k_error)) return 0;
String *nodeType = Getattr(n, k_nodetype);
if (!n)
return 0;
if (Getattr(n, k_error))
return 0;
if (StringEqual(nodeType,k_template)) {
if (StringEqual(nodeType, k_template)) {
/* Change the node type back to normal */
if (!expanded) {
expanded = 1;
Setattr(n,k_nodetype,Getattr(n,k_templatetype));
ret = cparse_template_expand(n,tname, rname, templateargs, patchlist,typelist, cpatchlist);
Setattr(n, k_nodetype, Getattr(n, k_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 */
/* Called when template appears inside another template */
/* Member templates */
Setattr(n,k_nodetype,Getattr(n,k_templatetype));
ret = cparse_template_expand(n,tname, rname, templateargs, patchlist,typelist, cpatchlist);
Setattr(n,k_nodetype,k_template);
Setattr(n, k_nodetype, Getattr(n, k_templatetype));
ret = cparse_template_expand(n, tname, rname, templateargs, patchlist, typelist, cpatchlist);
Setattr(n, k_nodetype, k_template);
return ret;
}
} else if (StringEqual(nodeType,k_cdecl)) {
} else if (StringEqual(nodeType, k_cdecl)) {
/* A simple C declaration */
SwigType *t, *v, *d;
String *code;
t = Getattr(n,k_type);
v = Getattr(n,k_value);
d = Getattr(n,k_decl);
String *code;
t = Getattr(n, k_type);
v = Getattr(n, k_value);
d = Getattr(n, k_decl);
code = Getattr(n,k_code);
Append(typelist,t);
Append(typelist,d);
Append(patchlist,v);
Append(cpatchlist,code);
if (Getattr(n,k_conversionoperator)) {
Append(cpatchlist, Getattr(n,k_name));
if (Getattr(n,k_symname)) {
Append(cpatchlist, Getattr(n,k_symname));
code = Getattr(n, k_code);
Append(typelist, t);
Append(typelist, d);
Append(patchlist, v);
Append(cpatchlist, code);
if (Getattr(n, k_conversionoperator)) {
Append(cpatchlist, Getattr(n, k_name));
if (Getattr(n, k_symname)) {
Append(cpatchlist, Getattr(n, k_symname));
}
}
add_parms(Getattr(n,k_parms), cpatchlist, typelist);
add_parms(Getattr(n,k_throws), cpatchlist, typelist);
} else if (StringEqual(nodeType,k_class)) {
add_parms(Getattr(n, k_parms), cpatchlist, typelist);
add_parms(Getattr(n, k_throws), cpatchlist, typelist);
} else if (StringEqual(nodeType, k_class)) {
/* Patch base classes */
{
int b = 0;
for (b = 0; b < 3; ++b) {
List *bases = Getattr(n,baselists[b]);
List *bases = Getattr(n, baselists[b]);
if (bases) {
int i;
int ilen = Len(bases);
int ilen = Len(bases);
for (i = 0; i < ilen; i++) {
String *name = Copy(Getitem(bases,i));
Setitem(bases,i,name);
Append(typelist,name);
String *name = Copy(Getitem(bases, i));
Setitem(bases, i, name);
Append(typelist, name);
}
}
}
@ -120,90 +120,90 @@ cparse_template_expand(Node *n, String *tname, String *rname, String *templatear
{
Node *cn = firstChild(n);
while (cn) {
cparse_template_expand(cn,tname, rname, templateargs, patchlist,typelist,cpatchlist);
cparse_template_expand(cn, tname, rname, templateargs, patchlist, typelist, cpatchlist);
cn = nextSibling(cn);
}
}
} else if (StringEqual(nodeType,k_constructor)) {
String *name = Getattr(n,k_name);
if (!(Getattr(n,k_templatetype))) {
} else if (StringEqual(nodeType, k_constructor)) {
String *name = Getattr(n, k_name);
if (!(Getattr(n, k_templatetype))) {
String *symname;
String *stripped_name = SwigType_templateprefix(name);
if (Strstr(tname,stripped_name)) {
Replaceid(name,stripped_name,tname);
if (Strstr(tname, stripped_name)) {
Replaceid(name, stripped_name, tname);
}
Delete(stripped_name);
symname = Getattr(n,k_symname);
symname = Getattr(n, k_symname);
if (symname) {
stripped_name = SwigType_templateprefix(symname);
if (Strstr(tname,stripped_name)) {
Replaceid(symname,stripped_name,tname);
if (Strstr(tname, stripped_name)) {
Replaceid(symname, stripped_name, tname);
}
Delete(stripped_name);
}
if (strchr(Char(name),'<')) {
Append(patchlist,Getattr(n,k_name));
if (strchr(Char(name), '<')) {
Append(patchlist, Getattr(n, k_name));
} else {
Append(name,templateargs);
Append(name, templateargs);
}
name = Getattr(n,k_symname);
name = Getattr(n, k_symname);
if (name) {
if (strchr(Char(name),'<')) {
if (strchr(Char(name), '<')) {
Clear(name);
Append(name,rname);
Append(name, rname);
} else {
String *tmp = Copy(name);
Replace(tmp,tname,rname, DOH_REPLACE_ANY);
Replace(tmp, tname, rname, DOH_REPLACE_ANY);
Clear(name);
Append(name,tmp);
Append(name, tmp);
Delete(tmp);
}
}
/* Setattr(n,k_symname,name); */
}
Append(cpatchlist,Getattr(n,k_code));
Append(typelist, Getattr(n,k_decl));
add_parms(Getattr(n,k_parms), cpatchlist, typelist);
add_parms(Getattr(n,k_throws), cpatchlist, typelist);
} else if (StringEqual(nodeType,k_destructor)) {
String *name = Getattr(n,k_name);
if (name && strchr(Char(name),'<')) {
Append(patchlist,Getattr(n,k_name));
Append(cpatchlist, Getattr(n, k_code));
Append(typelist, Getattr(n, k_decl));
add_parms(Getattr(n, k_parms), cpatchlist, typelist);
add_parms(Getattr(n, k_throws), cpatchlist, typelist);
} else if (StringEqual(nodeType, k_destructor)) {
String *name = Getattr(n, k_name);
if (name && strchr(Char(name), '<')) {
Append(patchlist, Getattr(n, k_name));
} else {
Append(name,templateargs);
Append(name, templateargs);
}
name = Getattr(n,k_symname);
if (name && strchr(Char(name),'<')) {
name = Getattr(n, k_symname);
if (name && strchr(Char(name), '<')) {
String *sn = Copy(tname);
Setattr(n,k_symname, sn);
Setattr(n, k_symname, sn);
Delete(sn);
} else {
Replace(name,tname,rname, DOH_REPLACE_ANY);
Replace(name, tname, rname, DOH_REPLACE_ANY);
}
/* Setattr(n,k_symname,name); */
Append(cpatchlist,Getattr(n,k_code));
} else if (StringEqual(nodeType,k_using)) {
String *uname = Getattr(n,k_uname);
if (uname && strchr(Char(uname),'<')) {
Append(cpatchlist, Getattr(n, k_code));
} else if (StringEqual(nodeType, k_using)) {
String *uname = Getattr(n, k_uname);
if (uname && strchr(Char(uname), '<')) {
Append(patchlist, uname);
}
if (Getattr(n,k_namespace)) {
if (Getattr(n, k_namespace)) {
/* Namespace link. This is nasty. Is other namespace defined? */
}
} else {
/* Look for obvious parameters */
Node *cn;
Append(cpatchlist,Getattr(n,k_code));
Append(typelist, Getattr(n,k_type));
Append(typelist, Getattr(n,k_decl));
add_parms(Getattr(n,k_parms), cpatchlist, typelist);
add_parms(Getattr(n,k_kwargs), cpatchlist, typelist);
add_parms(Getattr(n,k_pattern), cpatchlist, typelist);
add_parms(Getattr(n,k_throws), cpatchlist, typelist);
Append(cpatchlist, Getattr(n, k_code));
Append(typelist, Getattr(n, k_type));
Append(typelist, Getattr(n, k_decl));
add_parms(Getattr(n, k_parms), cpatchlist, typelist);
add_parms(Getattr(n, k_kwargs), cpatchlist, typelist);
add_parms(Getattr(n, k_pattern), cpatchlist, typelist);
add_parms(Getattr(n, k_throws), cpatchlist, typelist);
cn = firstChild(n);
while (cn) {
cparse_template_expand(cn,tname, rname, templateargs, patchlist, typelist, cpatchlist);
cparse_template_expand(cn, tname, rname, templateargs, patchlist, typelist, cpatchlist);
cn = nextSibling(cn);
}
}
@ -219,19 +219,18 @@ String *partial_arg(String *s, String *p) {
/* Find the prefix on the partial argument */
c = strchr(cp,'$');
c = strchr(cp, '$');
if (!c) {
return Copy(s);
}
prefix = NewStringWithSize(cp,c-cp);
prefix = NewStringWithSize(cp, c - cp);
newarg = Copy(s);
Replace(newarg,prefix,"",DOH_REPLACE_ANY | DOH_REPLACE_FIRST);
Replace(newarg, prefix, "", DOH_REPLACE_ANY | DOH_REPLACE_FIRST);
Delete(prefix);
return newarg;
}
int
Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab *tscope) {
int Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab *tscope) {
List *patchlist, *cpatchlist, *typelist;
String *templateargs;
String *tname;
@ -244,31 +243,31 @@ Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab *ts
{
String *tmp = NewStringEmpty();
if (tparms) {
SwigType_add_template(tmp,tparms);
SwigType_add_template(tmp, tparms);
}
templateargs = Copy(tmp);
Delete(tmp);
}
tname = Copy(Getattr(n,k_name));
tname = Copy(Getattr(n, k_name));
tbase = Swig_scopename_last(tname);
/* Look for partial specialization matching */
if (Getattr(n,k_partialargs)) {
if (Getattr(n, k_partialargs)) {
Parm *p, *tp;
ParmList *ptargs = SwigType_function_parms(Getattr(n,k_partialargs));
ParmList *ptargs = SwigType_function_parms(Getattr(n, k_partialargs));
p = ptargs;
tp = tparms;
while (p && tp) {
SwigType *ptype;
SwigType *tptype;
SwigType *partial_type;
ptype = Getattr(p,k_type);
tptype = Getattr(tp,k_type);
ptype = Getattr(p, k_type);
tptype = Getattr(tp, k_type);
if (ptype && tptype) {
partial_type = partial_arg(tptype,ptype);
/* Printf(stdout,"partial '%s' '%s' ---> '%s'\n", tptype, ptype, partial_type); */
Setattr(tp,k_type,partial_type);
partial_type = partial_arg(tptype, ptype);
/* Printf(stdout,"partial '%s' '%s' ---> '%s'\n", tptype, ptype, partial_type); */
Setattr(tp, k_type, partial_type);
Delete(partial_type);
}
p = nextSibling(p);
@ -281,93 +280,94 @@ Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab *ts
if (0) {
Parm *p = tparms;
while (p) {
Printf(stdout,"tparm: '%s' '%s' '%s'\n", Getattr(p,k_name), Getattr(p,k_type), Getattr(p,k_value));
Printf(stdout, "tparm: '%s' '%s' '%s'\n", Getattr(p, k_name), Getattr(p, k_type), Getattr(p, k_value));
p = nextSibling(p);
}
}
/* Printf(stdout,"targs = '%s'\n", templateargs);
Printf(stdout,"rname = '%s'\n", rname);
Printf(stdout,"tname = '%s'\n", tname); */
cparse_template_expand(n,tname, rname, templateargs, patchlist, typelist, cpatchlist);
Printf(stdout,"rname = '%s'\n", rname);
Printf(stdout,"tname = '%s'\n", tname); */
cparse_template_expand(n, tname, rname, templateargs, patchlist, typelist, cpatchlist);
/* Set the name */
{
String *name = Getattr(n,k_name);
String *name = Getattr(n, k_name);
if (name) {
Append(name,templateargs);
Append(name, templateargs);
}
iname = name;
}
/* Patch all of the types */
{
Parm *tp = Getattr(n,k_templateparms);
Parm *p = tparms;
Parm *tp = Getattr(n, k_templateparms);
Parm *p = tparms;
/* Printf(stdout,"%s\n", ParmList_str_defaultargs(tp)); */
if (tp) {
Symtab *tsdecl = Getattr(n,k_symsymtab);
Symtab *tsdecl = Getattr(n, k_symsymtab);
while (p && tp) {
String *name, *value, *valuestr, *tydef, *tmp, *tmpr;
int sz, i;
int sz, i;
String *dvalue = 0;
String *qvalue = 0;
name = Getattr(tp,k_name);
value = Getattr(p,k_value);
tydef = Getattr(p,k_typedef);
name = Getattr(tp, k_name);
value = Getattr(p, k_value);
tydef = Getattr(p, k_typedef);
if (name) {
if (!value) value = Getattr(p,k_type);
if (!value)
value = Getattr(p, k_type);
qvalue = Swig_symbol_typedef_reduce(value, tsdecl);
dvalue = Swig_symbol_type_qualify(qvalue,tsdecl);
dvalue = Swig_symbol_type_qualify(qvalue, tsdecl);
if (SwigType_istemplate(dvalue)) {
String *ty = Swig_symbol_template_deftype(dvalue, tscope);
Delete(dvalue);
dvalue = ty;
}
assert(dvalue);
valuestr = SwigType_str(dvalue,0);
valuestr = SwigType_str(dvalue, 0);
/* Need to patch default arguments */
{
Parm *rp = nextSibling(p);
while (rp) {
String *rvalue = Getattr(rp,k_value);
String *rvalue = Getattr(rp, k_value);
if (rvalue) {
Replace(rvalue,name,dvalue, DOH_REPLACE_ID);
Replace(rvalue, name, dvalue, DOH_REPLACE_ID);
}
rp = nextSibling(rp);
}
}
sz = Len(patchlist);
for (i = 0; i < sz; i++) {
String *s = Getitem(patchlist,i);
Replace(s,name,dvalue, DOH_REPLACE_ID);
String *s = Getitem(patchlist, i);
Replace(s, name, dvalue, DOH_REPLACE_ID);
}
sz = Len(typelist);
for (i = 0; i < sz; i++) {
String *s = Getitem(typelist,i);
/* Replace(s,name,value, DOH_REPLACE_ID); */
/* Printf(stdout,"name = '%s', value = '%s', tbase = '%s', iname='%s' s = '%s' --> ", name, dvalue, tbase, iname, s); */
SwigType_typename_replace(s,name,dvalue);
SwigType_typename_replace(s,tbase,iname);
/* Printf(stdout,"'%s'\n", s);*/
String *s = Getitem(typelist, i);
/* Replace(s,name,value, DOH_REPLACE_ID); */
/* Printf(stdout,"name = '%s', value = '%s', tbase = '%s', iname='%s' s = '%s' --> ", name, dvalue, tbase, iname, s); */
SwigType_typename_replace(s, name, dvalue);
SwigType_typename_replace(s, tbase, iname);
/* Printf(stdout,"'%s'\n", s); */
}
if (!tydef) {
tydef = dvalue;
}
tmp = NewStringf("#%s",name);
tmp = NewStringf("#%s", name);
tmpr = NewStringf("\"%s\"", valuestr);
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);
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);
@ -377,28 +377,29 @@ Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab *ts
}
p = nextSibling(p);
tp = nextSibling(tp);
if (!p) p = 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);
String *s = Getitem(typelist, i);
SwigType_typename_replace(s, tbase, iname);
}
}
}
/* Patch bases */
{
List *bases = Getattr(n,k_baselist);
List *bases = Getattr(n, k_baselist);
if (bases) {
Iterator b;
for (b = First(bases); b.item; b = Next(b)) {
String *qn = Swig_symbol_type_qualify(b.item,tscope);
String *qn = Swig_symbol_type_qualify(b.item, tscope);
Clear(b.item);
Append(b.item,qn);
Append(b.item, qn);
Delete(qn);
}
}
@ -410,7 +411,7 @@ Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab *ts
Delete(tname);
Delete(templateargs);
/* set_nodeType(n,k_template);*/
/* set_nodeType(n,k_template); */
return 0;
}
@ -420,168 +421,166 @@ Swig_cparse_template_expand(Node *n, String *rname, ParmList *tparms, Symtab *ts
* Search for a template that matches name with given parameters.
* ----------------------------------------------------------------------------- */
static Node *
template_locate(String *name, Parm *tparms, Symtab *tscope) {
Node *n;
static Node *template_locate(String *name, Parm *tparms, Symtab *tscope) {
Node *n;
String *tname, *rname = 0;
Node *templ;
List *mpartials = 0;
Parm *p;
Parm *parms;
Parm *targs;
Node *templ;
List *mpartials = 0;
Parm *p;
Parm *parms;
Parm *targs;
tname = Copy(name);
parms = CopyParmList(tparms);
/* Search for generic template */
templ = Swig_symbol_clookup(name,0);
templ = Swig_symbol_clookup(name, 0);
/* Add default values from generic template */
if (templ) {
Symtab *tsdecl = Getattr(templ,k_symsymtab);
Symtab *tsdecl = Getattr(templ, k_symsymtab);
targs = Getattr(templ,k_templateparms);
targs = Getattr(templ, k_templateparms);
Swig_symbol_template_defargs(parms, targs, tscope, tsdecl);
}
/* reduce the typedef */
p = parms;
while (p) {
SwigType *ty = Getattr(p,k_type);
SwigType *ty = Getattr(p, k_type);
if (ty) {
SwigType *nt = Swig_symbol_type_qualify(ty,tscope);
Setattr(p,k_type,nt);
SwigType *nt = Swig_symbol_type_qualify(ty, tscope);
Setattr(p, k_type, nt);
Delete(nt);
}
p = nextSibling(p);
}
SwigType_add_template(tname,parms);
SwigType_add_template(tname, parms);
if (template_debug) {
Printf(stdout,"\n%s:%d: template_debug: Searching for %s\n", cparse_file, cparse_line, tname);
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);
Printf(stdout, " searching: '%s' (exact specialization)\n", tname);
}
n = Swig_symbol_clookup_local(tname,0);
n = Swig_symbol_clookup_local(tname, 0);
if (!n) {
SwigType *rname = Swig_symbol_typedef_reduce(tname,tscope);
if (!StringEqual(rname,tname)) {
SwigType *rname = Swig_symbol_typedef_reduce(tname, tscope);
if (!StringEqual(rname, tname)) {
if (template_debug) {
Printf(stdout," searching: '%s' (exact specialization)\n", rname);
Printf(stdout, " searching: '%s' (exact specialization)\n", rname);
}
n = Swig_symbol_clookup_local(rname,0);
n = Swig_symbol_clookup_local(rname, 0);
}
Delete(rname);
}
if (n) {
Node *tn;
String *nodeType = Getattr(n,k_nodetype);
if (StringEqual(nodeType,k_template)) goto success;
tn = Getattr(n,k_template);
String *nodeType = Getattr(n, k_nodetype);
if (StringEqual(nodeType, k_template))
goto success;
tn = Getattr(n, k_template);
if (tn) {
n = tn;
goto success; /* Previously wrapped by a template return that */
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, Getattr(n,k_nodetype));
Swig_error(cparse_file, cparse_line, "'%s' is not defined as a template. (%s)\n", name, Getattr(n, k_nodetype));
Delete(tname);
Delete(parms);
return 0; /* Found a match, but it's not a template of any kind. */
return 0; /* Found a match, but it's not a template of any kind. */
}
}
/* Search for partial specialization.
Example: template<typename T> class name<T *> { ... } */
/* Generate reduced template name (stripped of extraneous pointers, etc.) */
rname = NewStringf("%s<(",name);
rname = NewStringf("%s<(", name);
p = parms;
while (p) {
String *t;
t = Getattr(p,k_type);
if (!t) t = Getattr(p,k_value);
t = Getattr(p, k_type);
if (!t)
t = Getattr(p, k_value);
if (t) {
String *ty = Swig_symbol_typedef_reduce(t,tscope);
String *tb = SwigType_base(ty);
String *ty = Swig_symbol_typedef_reduce(t, tscope);
String *tb = SwigType_base(ty);
String *td = SwigType_default(ty);
Replaceid(td,"enum SWIGTYPE",tb);
Replaceid(td,"SWIGTYPE",tb);
Append(rname,td);
Replaceid(td, "enum SWIGTYPE", tb);
Replaceid(td, "SWIGTYPE", tb);
Append(rname, td);
Delete(tb);
Delete(ty);
Delete(td);
}
p = nextSibling(p);
if (p) {
Append(rname,",");
Append(rname, ",");
}
}
Append(rname,")>");
Append(rname, ")>");
mpartials = NewList();
if (templ) {
/* First, we search using an exact type prototype */
Parm *p;
char tmp[32];
int i;
List *partials;
String *ss;
Iterator pi;
/* First, we search using an exact type prototype */
Parm *p;
char tmp[32];
int i;
List *partials;
String *ss;
Iterator pi;
partials = Getattr(templ,k_partials);
if (partials) {
for (pi = First(partials); pi.item; pi = Next(pi)) {
ss = Copy(pi.item);
p = parms;
i = 1;
while (p) {
String *t,*tn;
sprintf(tmp,"$%d",i);
t = Getattr(p,k_type);
if (!t) t = Getattr(p,k_value);
if (t) {
String *ty = Swig_symbol_typedef_reduce(t,tscope);
tn = SwigType_base(ty);
Replaceid(ss,tmp,tn);
Delete(tn);
Delete(ty);
}
i++;
p = nextSibling(p);
partials = Getattr(templ, k_partials);
if (partials) {
for (pi = First(partials); pi.item; pi = Next(pi)) {
ss = Copy(pi.item);
p = parms;
i = 1;
while (p) {
String *t, *tn;
sprintf(tmp, "$%d", i);
t = Getattr(p, k_type);
if (!t)
t = Getattr(p, k_value);
if (t) {
String *ty = Swig_symbol_typedef_reduce(t, tscope);
tn = SwigType_base(ty);
Replaceid(ss, tmp, tn);
Delete(tn);
Delete(ty);
}
if (template_debug) {
Printf(stdout," searching: '%s' (partial specialization - %s)\n", ss, pi.item);
}
if ((StringEqual(ss,tname)) || (StringEqual(ss,rname))) {
Append(mpartials,pi.item);
}
Delete(ss);
i++;
p = nextSibling(p);
}
if (template_debug) {
Printf(stdout, " searching: '%s' (partial specialization - %s)\n", ss, pi.item);
}
if ((StringEqual(ss, tname)) || (StringEqual(ss, rname))) {
Append(mpartials, pi.item);
}
Delete(ss);
}
}
}
if (template_debug) {
Printf(stdout," Matched partials: %s\n", mpartials);
Printf(stdout, " Matched partials: %s\n", mpartials);
}
if (Len(mpartials)) {
String *s = Getitem(mpartials,0);
n = Swig_symbol_clookup_local(s,0);
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,\n",
SwigType_namestr(tname));
Swig_warning(WARN_PARSE_TEMPLATE_AMBIG,Getfile(n),Getline(n),
" instantiation '%s' is used.\n",
SwigType_namestr(Getattr(n,k_name)));
Swig_warning(WARN_PARSE_TEMPLATE_AMBIG, cparse_file, cparse_line, "Instantiation of template '%s' is ambiguous,\n", SwigType_namestr(tname));
Swig_warning(WARN_PARSE_TEMPLATE_AMBIG, Getfile(n), Getline(n), " instantiation '%s' is used.\n", SwigType_namestr(Getattr(n, k_name)));
}
}
}
@ -591,20 +590,20 @@ template_locate(String *name, Parm *tparms, Symtab *tscope) {
}
if (!n) {
Swig_error(cparse_file, cparse_line, "Template '%s' undefined.\n", name);
} else if (n) {
String *nodeType = Getattr(n,k_nodetype);
if (!StringEqual(nodeType,k_template)) {
Swig_error(cparse_file, cparse_line, "'%s' is not defined as a template. (%s)\n", name, nodeType);
} else if (n) {
String *nodeType = Getattr(n, k_nodetype);
if (!StringEqual(nodeType, k_template)) {
Swig_error(cparse_file, cparse_line, "'%s' is not defined as a template. (%s)\n", name, nodeType);
n = 0;
}
}
success:
success:
Delete(tname);
Delete(rname);
Delete(mpartials);
if ((template_debug) && (n)) {
Printf(stdout,"Node: %p\n", n);
Swig_print_node(n);
Printf(stdout, "Node: %p\n", n);
Swig_print_node(n);
}
Delete(parms);
return n;
@ -620,15 +619,14 @@ template_locate(String *name, Parm *tparms, Symtab *tscope) {
* template exists.
* ----------------------------------------------------------------------------- */
Node *
Swig_cparse_template_locate(String *name, Parm *tparms, Symtab *tscope) {
Node *n = template_locate(name, tparms, tscope); /* this function does what we want for templated classes */
Node *Swig_cparse_template_locate(String *name, Parm *tparms, Symtab *tscope) {
Node *n = template_locate(name, tparms, tscope); /* this function does what we want for templated classes */
if (n) {
String *nodeType = Getattr(n,k_nodetype);
String *nodeType = Getattr(n, k_nodetype);
int isclass = 0;
assert(StringEqual(nodeType,k_template));
isclass = (StringEqual(Getattr(n,k_templatetype),k_class));
assert(StringEqual(nodeType, k_template));
isclass = (StringEqual(Getattr(n, k_templatetype), k_class));
if (!isclass) {
/* If not a templated class we must have a templated function.
The template found is not necessarily the one we want when dealing with templated
@ -638,31 +636,30 @@ Swig_cparse_template_locate(String *name, Parm *tparms, Symtab *tscope) {
templated function with different numbers of template parameters. */
if (template_debug) {
Printf(stdout," Not a templated class, seeking most appropriate templated function\n");
Printf(stdout, " Not a templated class, seeking most appropriate templated function\n");
}
n = Swig_symbol_clookup_local(name,0);
n = Swig_symbol_clookup_local(name, 0);
while (n) {
Parm *tparmsfound = Getattr(n,k_templateparms);
if (ParmList_len(tparms) == ParmList_len(tparmsfound)) {
/* successful match */
break;
}
/* repeat until we find a match with correct number of templated parameters */
n = Getattr(n,k_symnextSibling);
Parm *tparmsfound = Getattr(n, k_templateparms);
if (ParmList_len(tparms) == ParmList_len(tparmsfound)) {
/* successful match */
break;
}
/* repeat until we find a match with correct number of templated parameters */
n = Getattr(n, k_symnextSibling);
}
if (!n) {
Swig_error(cparse_file, cparse_line, "Template '%s' undefined.\n", name);
Swig_error(cparse_file, cparse_line, "Template '%s' undefined.\n", name);
}
if ((template_debug) && (n)) {
Printf(stdout,"Templated function found: %p\n", n);
Swig_print_node(n);
Printf(stdout, "Templated function found: %p\n", n);
Swig_print_node(n);
}
}
}
return n;
}

View file

@ -21,16 +21,17 @@ char cvsroot_util_c[] = "$Header$";
* ----------------------------------------------------------------------------- */
void Swig_cparse_replace_descriptor(String *s) {
char tmp[512];
char tmp[512];
String *arg = 0;
SwigType *t;
char *c = 0;
while ((c = strstr(Char(s),"$descriptor("))) {
while ((c = strstr(Char(s), "$descriptor("))) {
char *d = tmp;
int level = 0;
int level = 0;
while (*c) {
if (*c == '(') level++;
if (*c == '(')
level++;
if (*c == ')') {
level--;
if (level == 0) {
@ -42,7 +43,7 @@ void Swig_cparse_replace_descriptor(String *s) {
c++;
}
*d = 0;
arg = NewString(tmp+12);
arg = NewString(tmp + 12);
t = Swig_cparse_type(arg);
Delete(arg);
arg = 0;
@ -50,19 +51,19 @@ void Swig_cparse_replace_descriptor(String *s) {
if (t) {
String *mangle;
String *descriptor;
mangle = SwigType_manglestr(t);
descriptor = NewStringf("SWIGTYPE%s",mangle);
descriptor = NewStringf("SWIGTYPE%s", mangle);
SwigType_remember(t);
*d = ')';
d++;
*d = 0;
Replace(s,tmp,descriptor,DOH_REPLACE_ANY);
Replace(s, tmp, descriptor, DOH_REPLACE_ANY);
Delete(mangle);
Delete(descriptor);
Delete(t);
} else {
Swig_error(Getfile(s),Getline(s),"Bad $descriptor() macro.\n");
Swig_error(Getfile(s), Getline(s), "Bad $descriptor() macro.\n");
break;
}
}
@ -76,15 +77,13 @@ void Swig_cparse_replace_descriptor(String *s) {
* ----------------------------------------------------------------------------- */
void cparse_normalize_void(Node *n) {
String *decl = Getattr(n,k_decl);
Parm *parms = Getattr(n,k_parms);
String *decl = Getattr(n, k_decl);
Parm *parms = Getattr(n, k_parms);
if (SwigType_isfunction(decl)) {
if ((ParmList_len(parms) == 1) && (SwigType_type(Getattr(parms,k_type)) == T_VOID)) {
Replaceall(decl,"f(void).","f().");
Delattr(n,k_parms);
if ((ParmList_len(parms) == 1) && (SwigType_type(Getattr(parms, k_type)) == T_VOID)) {
Replaceall(decl, "f(void).", "f().");
Delattr(n, k_parms);
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -165,11 +165,11 @@ typedef void DOH;
/* Iterator objects */
typedef struct {
void *key; /* Current key (if any) */
void *item; /* Current item */
void *object; /* Object being iterated over */
void *_current; /* Internal use */
int _index; /* Internal use */
void *key; /* Current key (if any) */
void *item; /* Current item */
void *object; /* Object being iterated over */
void *_current; /* Internal use */
int _index; /* Internal use */
} DohIterator;
/* Memory management */
@ -184,77 +184,77 @@ typedef struct {
#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 */
extern void DohDelete(DOH *obj); /* Delete an object */
extern DOH *DohCopy(const DOH *obj);
extern void DohClear(DOH *obj);
extern DOHString *DohStr(const DOH *obj);
extern void *DohData(const DOH *obj);
extern int DohDump(const DOH *obj, DOHFile *out);
extern int DohLen(const DOH *obj);
extern int DohHashval(const DOH *obj);
extern int DohCmp(const DOH *obj1, const DOH *obj2);
extern int DohEqual(const DOH *obj1, const DOH *obj2);
extern void DohIncref(DOH *obj);
extern void DohDelete(DOH *obj); /* Delete an object */
extern DOH *DohCopy(const DOH *obj);
extern void DohClear(DOH *obj);
extern DOHString *DohStr(const DOH *obj);
extern void *DohData(const DOH *obj);
extern int DohDump(const DOH *obj, DOHFile * out);
extern int DohLen(const DOH *obj);
extern int DohHashval(const DOH *obj);
extern int DohCmp(const DOH *obj1, const DOH *obj2);
extern int DohEqual(const DOH *obj1, const DOH *obj2);
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 int DohDelattr(DOH *obj, const DOHString_or_char *name);
extern DOH *DohKeys(DOH *obj);
extern int DohGetInt(DOH *obj, const DOHString_or_char *name);
extern void DohSetInt(DOH *obj, const DOHString_or_char *name, int);
extern double DohGetDouble(DOH *obj, const DOHString_or_char *name);
extern void DohSetDouble(DOH *obj, const DOHString_or_char *name, double);
extern char *DohGetChar(DOH *obj, const DOHString_or_char *name);
extern void DohSetChar(DOH *obj, const DOH *name, char *value);
extern void *DohGetFlagAttr(DOH *obj, const DOHString_or_char *name);
extern int DohGetFlag(DOH *obj, const DOHString_or_char *name);
extern void DohSetFlagAttr(DOH *obj, const DOHString_or_char *name, const DOHString_or_char *attr);
extern void DohSetFlag(DOH *obj, const DOHString_or_char *name);
extern void *DohGetVoid(DOH *obj, const DOHString_or_char *name);
extern void DohSetVoid(DOH *obj, const DOHString_or_char *name, void *value);
extern 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 *DohKeys(DOH *obj);
extern int DohGetInt(DOH *obj, const DOHString_or_char *name);
extern void DohSetInt(DOH *obj, const DOHString_or_char *name, int);
extern double DohGetDouble(DOH *obj, const DOHString_or_char *name);
extern void DohSetDouble(DOH *obj, const DOHString_or_char *name, double);
extern char *DohGetChar(DOH *obj, const DOHString_or_char *name);
extern void DohSetChar(DOH *obj, const DOH *name, char *value);
extern void *DohGetFlagAttr(DOH *obj, const DOHString_or_char *name);
extern int DohGetFlag(DOH *obj, const DOHString_or_char *name);
extern void DohSetFlagAttr(DOH *obj, const DOHString_or_char *name, const DOHString_or_char *attr);
extern void DohSetFlag(DOH *obj, const DOHString_or_char *name);
extern void *DohGetVoid(DOH *obj, const DOHString_or_char *name);
extern void DohSetVoid(DOH *obj, const DOHString_or_char *name, void *value);
/* 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 int DohDelslice(DOH *obj, int sindex, int eindex);
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 int DohDelslice(DOH *obj, int sindex, int eindex);
/* 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);
/* Iterators */
extern DohIterator DohFirst(DOH *obj);
extern DohIterator DohNext(DohIterator x);
extern DohIterator DohFirst(DOH *obj);
extern DohIterator DohNext(DohIterator x);
/* 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);
extern int DohString_putc(DOH *so, int ch);
extern int DohString_getc(DOH *so);
@ -274,39 +274,39 @@ extern int DohString_delslice(DOH *so, int sindex, int eindex);
#define DohStringEqual(s1,s2) DohString_equal((DOH *)s1, (DOH *)s2)
/* Meta-variables */
extern DOH *DohGetmeta(DOH *, const DOH *);
extern int DohSetmeta(DOH *, const DOH *, const DOH *value);
extern int DohDelmeta(DOH *, const DOH *);
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);
extern void DohSetmark(DOH *obj, int x);
extern int DohGetmark(DOH *obj);
/* -----------------------------------------------------------------------------
* Strings.
* ----------------------------------------------------------------------------- */
extern DOHString *DohNewStringEmpty();
extern DOHString *DohNewString(const DOH *c);
extern DOHString *DohNewStringWithSize(const DOH *c, int len);
extern DOHString *DohNewStringf(const DOH *fmt, ...);
extern DOHString *DohNewStringEmpty();
extern DOHString *DohNewString(const DOH *c);
extern DOHString *DohNewStringWithSize(const DOH *c, int len);
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 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);
@ -329,36 +329,36 @@ extern char *DohStrchr(const DOHString_or_char *s1, int ch);
extern DOHFile *DohNewFile(DOH *file, const char *mode);
extern DOHFile *DohNewFileFromFile(FILE *f);
extern DOHFile *DohNewFileFromFd(int fd);
extern void DohFileErrorDisplay(DOHString *filename);
extern int DohClose(DOH *file);
extern int DohCopyto(DOHFile *input, DOHFile *output);
extern void DohFileErrorDisplay(DOHString * filename);
extern int DohClose(DOH *file);
extern int DohCopyto(DOHFile * input, DOHFile * output);
/* -----------------------------------------------------------------------------
* List
* ----------------------------------------------------------------------------- */
extern DOHList *DohNewList();
extern void DohSortList(DOH *lo, int (*cmp)(const DOH *, const DOH *));
extern DOHList *DohNewList();
extern void DohSortList(DOH *lo, int (*cmp) (const DOH *, const DOH *));
/* -----------------------------------------------------------------------------
* Hash
* ----------------------------------------------------------------------------- */
extern DOHHash *DohNewHash();
extern DOH *DohHashGetAttr(DOH *hash, const DOH *key);
extern int DohHashCheckAttr(DOH *hash, DOH *key, DOH *value);
extern DOHHash *DohNewHash();
extern DOH *DohHashGetAttr(DOH *hash, const DOH *key);
extern int DohHashCheckAttr(DOH *hash, DOH *key, DOH *value);
/* -----------------------------------------------------------------------------
* Void
* ----------------------------------------------------------------------------- */
extern DOHVoid *DohNewVoid(void *ptr, void (*del)(void *));
extern DOHList *DohSplit(DOHFile *input, char ch, int nsplits);
extern DOHList *DohSplitLines(DOHFile *input);
extern DOH *DohNone;
extern DOHVoid *DohNewVoid(void *ptr, void (*del) (void *));
extern DOHList *DohSplit(DOHFile * input, char ch, int nsplits);
extern DOHList *DohSplitLines(DOHFile * input);
extern DOH *DohNone;
extern void DohMemoryDebug(void);
extern void DohMemoryDebug(void);
#ifndef DOH_LONG_NAMES
/* Macros to invoke the above functions. Includes the location of
@ -468,8 +468,4 @@ extern void DohMemoryDebug(void);
#define NIL (char *) NULL
#endif /* DOH_H */
#endif /* DOH_H */

View file

@ -26,37 +26,37 @@
/* Hash objects */
typedef struct {
DOH *(*doh_getattr)(DOH *obj, DOH *name); /* Get attribute */
int (*doh_setattr)(DOH *obj, DOH *name, DOH *value); /* Set attribute */
int (*doh_delattr)(DOH *obj, DOH *name); /* Del attribute */
DOH *(*doh_keys)(DOH *obj); /* All keys as a list */
DOH *(*doh_getattr) (DOH *obj, DOH *name); /* Get attribute */
int (*doh_setattr) (DOH *obj, DOH *name, DOH *value); /* Set attribute */
int (*doh_delattr) (DOH *obj, DOH *name); /* Del attribute */
DOH *(*doh_keys) (DOH *obj); /* All keys as a list */
} DohHashMethods;
/* List objects */
typedef struct {
DOH *(*doh_getitem)(DOH *obj, int index); /* Get item */
int (*doh_setitem)(DOH *obj, int index, DOH *value); /* Set item */
int (*doh_delitem)(DOH *obj, int index); /* Delete item */
int (*doh_insitem)(DOH *obj, int index, DOH *value); /* Insert item */
int (*doh_delslice)(DOH *obj, int sindex, int eindex); /* Delete slice */
DOH *(*doh_getitem) (DOH *obj, int index); /* Get item */
int (*doh_setitem) (DOH *obj, int index, DOH *value); /* Set item */
int (*doh_delitem) (DOH *obj, int index); /* Delete item */
int (*doh_insitem) (DOH *obj, int index, DOH *value); /* Insert item */
int (*doh_delslice) (DOH *obj, int sindex, int eindex); /* Delete slice */
} DohListMethods;
/* File methods */
typedef struct {
int (*doh_read)(DOH *obj, void *buffer, int nbytes); /* Read bytes */
int (*doh_write)(DOH *obj, void *buffer, int nbytes); /* Write bytes */
int (*doh_putc)(DOH *obj, int ch); /* Put character */
int (*doh_getc)(DOH *obj); /* Get character */
int (*doh_ungetc)(DOH *obj, int ch); /* Unget character */
int (*doh_seek)(DOH *obj, long offset, int whence); /* Seek */
long (*doh_tell)(DOH *obj); /* Tell */
int (*doh_close)(DOH *obj); /* Close */
int (*doh_read) (DOH *obj, void *buffer, int nbytes); /* Read bytes */
int (*doh_write) (DOH *obj, void *buffer, int nbytes); /* Write bytes */
int (*doh_putc) (DOH *obj, int ch); /* Put character */
int (*doh_getc) (DOH *obj); /* Get character */
int (*doh_ungetc) (DOH *obj, int ch); /* Unget character */
int (*doh_seek) (DOH *obj, long offset, int whence); /* Seek */
long (*doh_tell) (DOH *obj); /* Tell */
int (*doh_close) (DOH *obj); /* Close */
} DohFileMethods;
/* String methods */
typedef struct {
int (*doh_replace)(DOH *obj, DOH *old, DOH *rep, int flags);
void (*doh_chop)(DOH *obj);
int (*doh_replace) (DOH *obj, DOH *old, DOH *rep, int flags);
void (*doh_chop) (DOH *obj);
} DohStringMethods;
/* -----------------------------------------------------------------------------
@ -64,55 +64,55 @@ typedef struct {
* ----------------------------------------------------------------------------- */
typedef struct DohObjInfo {
char *objname; /* Object name */
char *objname; /* Object name */
/* Basic object methods */
void (*doh_del)(DOH *obj); /* Delete object */
DOH *(*doh_copy)(DOH *obj); /* Copy and object */
void (*doh_clear)(DOH *obj); /* Clear an object */
void (*doh_del) (DOH *obj); /* Delete object */
DOH *(*doh_copy) (DOH *obj); /* Copy and object */
void (*doh_clear) (DOH *obj); /* Clear an object */
/* I/O methods */
DOH *(*doh_str)(DOH *obj); /* Make a full string */
void *(*doh_data)(DOH *obj); /* Return raw data */
int (*doh_dump)(DOH *obj, DOH *out); /* Serialize on out */
DOH *(*doh_str) (DOH *obj); /* Make a full string */
void *(*doh_data) (DOH *obj); /* Return raw data */
int (*doh_dump) (DOH *obj, DOH *out); /* Serialize on out */
/* Length and hash values */
int (*doh_len)(DOH *obj);
int (*doh_hashval)(DOH *obj);
int (*doh_len) (DOH *obj);
int (*doh_hashval) (DOH *obj);
/* Compare */
int (*doh_cmp)(DOH *obj1, DOH *obj2);
int (*doh_cmp) (DOH *obj1, DOH *obj2);
/* Equal */
int (*doh_equal)(DOH *obj1, DOH *obj2);
int (*doh_equal) (DOH *obj1, DOH *obj2);
/* Iterators */
DohIterator (*doh_first)(DOH *obj);
DohIterator (*doh_next)(DohIterator );
DohIterator (*doh_first) (DOH *obj);
DohIterator (*doh_next) (DohIterator);
/* Positional */
void (*doh_setfile)(DOH *obj, DOHString_or_char *file);
DOH *(*doh_getfile)(DOH *obj);
void (*doh_setline)(DOH *obj, int line);
int (*doh_getline)(DOH *obj);
void (*doh_setfile) (DOH *obj, DOHString_or_char *file);
DOH *(*doh_getfile) (DOH *obj);
void (*doh_setline) (DOH *obj, int line);
int (*doh_getline) (DOH *obj);
DohHashMethods *doh_hash; /* Hash methods */
DohListMethods *doh_list; /* List methods */
DohFileMethods *doh_file; /* File methods */
DohStringMethods *doh_string; /* String methods */
void *doh_reserved; /* Reserved */
void *clientdata; /* User data */
DohHashMethods *doh_hash; /* Hash methods */
DohListMethods *doh_list; /* List methods */
DohFileMethods *doh_file; /* File methods */
DohStringMethods *doh_string; /* String methods */
void *doh_reserved; /* Reserved */
void *clientdata; /* User data */
} DohObjInfo;
typedef struct {
void *data; /* Data pointer */
DohObjInfo *type;
void *meta; /* Meta data */
unsigned int flag_intern : 1; /* Interned object */
unsigned int flag_marked : 1; /* Mark flag. Used to avoid recursive loops in places */
unsigned int flag_user : 1; /* User flag */
unsigned int flag_usermark : 1; /* User marked */
unsigned int refcount : 28; /* Reference count (max 16 million) */
void *data; /* Data pointer */
DohObjInfo *type;
void *meta; /* Meta data */
unsigned int flag_intern:1; /* Interned object */
unsigned int flag_marked:1; /* Mark flag. Used to avoid recursive loops in places */
unsigned int flag_user:1; /* User flag */
unsigned int flag_usermark:1; /* User marked */
unsigned int refcount:28; /* Reference count (max 16 million) */
} DohBase;
/* Macros for decrefing and increfing (safe for null objects). */
@ -127,12 +127,7 @@ typedef struct {
#define ObjGetMark(a) ((DohBase *)a)->flag_marked
#define ObjType(a) ((DohBase *)a)->type
extern DOH *DohObjMalloc(DohObjInfo *type, void *data); /* Allocate a DOH object */
extern void DohObjFree(DOH *ptr); /* Free a DOH object */
#endif /* DOHINT_H */
extern DOH *DohObjMalloc(DohObjInfo *type, void *data); /* Allocate a DOH object */
extern void DohObjFree(DOH *ptr); /* Free a DOH object */
#endif /* DOHINT_H */

View file

@ -20,17 +20,16 @@ char cvsroot_file_c[] = "$Header$";
#include <errno.h>
typedef struct {
FILE *filep;
int fd;
int closeondel;
FILE *filep;
int fd;
int closeondel;
} DohFile;
/* -----------------------------------------------------------------------------
* DelFile()
* ----------------------------------------------------------------------------- */
static void
DelFile(DOH *fo) {
static void DelFile(DOH *fo) {
DohFile *f = (DohFile *) ObjData(fo);
if (f->closeondel) {
if (f->filep) {
@ -49,15 +48,14 @@ DelFile(DOH *fo) {
* File_read()
* ----------------------------------------------------------------------------- */
static int
File_read(DOH *fo, void *buffer, int len) {
static int File_read(DOH *fo, void *buffer, int len) {
DohFile *f = (DohFile *) ObjData(fo);
if (f->filep) {
return fread(buffer,1,len,f->filep);
return fread(buffer, 1, len, f->filep);
} else if (f->fd) {
#ifdef DOH_INTFILE
return read(f->fd,buffer,len);
return read(f->fd, buffer, len);
#endif
}
return -1;
@ -67,16 +65,15 @@ File_read(DOH *fo, void *buffer, int len) {
* File_write()
* ----------------------------------------------------------------------------- */
static int
File_write(DOH *fo, void *buffer, int len) {
static int File_write(DOH *fo, void *buffer, int len) {
DohFile *f = (DohFile *) ObjData(fo);
if (f->filep) {
int ret = (int) fwrite(buffer, 1, len, f->filep);
int err = (ret != len) ? ferror(f->filep) : 0;
return err ? -1: ret;
return err ? -1 : ret;
} else if (f->fd) {
#ifdef DOH_INTFILE
return write(f->fd,buffer,len);
return write(f->fd, buffer, len);
#endif
}
return -1;
@ -86,11 +83,10 @@ File_write(DOH *fo, void *buffer, int len) {
* File_seek()
* ----------------------------------------------------------------------------- */
static int
File_seek(DOH *fo, long offset, int whence) {
static int File_seek(DOH *fo, long offset, int whence) {
DohFile *f = (DohFile *) ObjData(fo);
if (f->filep) {
return fseek(f->filep,offset,whence);
return fseek(f->filep, offset, whence);
} else if (f->fd) {
#ifdef DOH_INTFILE
return lseek(f->fd, offset, whence);
@ -103,8 +99,7 @@ File_seek(DOH *fo, long offset, int whence) {
* File_tell()
* ----------------------------------------------------------------------------- */
static long
File_tell(DOH *fo) {
static long File_tell(DOH *fo) {
DohFile *f = (DohFile *) ObjData(fo);
if (f->filep) {
return ftell(f->filep);
@ -120,16 +115,15 @@ File_tell(DOH *fo) {
* File_putc()
* ----------------------------------------------------------------------------- */
static int
File_putc(DOH *fo, int ch) {
static int File_putc(DOH *fo, int ch) {
DohFile *f = (DohFile *) ObjData(fo);
if (f->filep) {
return fputc(ch,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);
return write(f->fd, &c, 1);
#endif
}
return -1;
@ -139,15 +133,15 @@ File_putc(DOH *fo, int ch) {
* File_getc()
* ----------------------------------------------------------------------------- */
static int
File_getc(DOH *fo) {
static int File_getc(DOH *fo) {
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;
if (read(f->fd, &c, 1) < 0)
return EOF;
return c;
#endif
}
@ -160,8 +154,7 @@ File_getc(DOH *fo) {
* Put a character back onto the input
* ----------------------------------------------------------------------------- */
static int
File_ungetc(DOH *fo, int ch) {
static int File_ungetc(DOH *fo, int ch) {
DohFile *f = (DohFile *) ObjData(fo);
if (f->filep) {
return ungetc(ch, f->filep);
@ -179,8 +172,7 @@ File_ungetc(DOH *fo, int ch) {
* Close the file
* ----------------------------------------------------------------------------- */
static int
File_close(DOH *fo) {
static int File_close(DOH *fo) {
int ret = 0;
DohFile *f = (DohFile *) ObjData(fo);
if (f->filep) {
@ -196,40 +188,40 @@ File_close(DOH *fo) {
}
static DohFileMethods FileFileMethods = {
File_read,
File_read,
File_write,
File_putc,
File_getc,
File_ungetc,
File_seek,
File_tell,
File_close, /* close */
File_close, /* close */
};
static DohObjInfo DohFileType = {
"DohFile", /* objname */
DelFile, /* doh_del */
0, /* doh_copy */
0, /* doh_clear */
0, /* doh_str */
0, /* doh_data */
0, /* doh_dump */
0, /* doh_len */
0, /* doh_hash */
0, /* doh_cmp */
0, /* doh_equal */
0, /* doh_first */
0, /* doh_next */
0, /* doh_setfile */
0, /* doh_getfile */
0, /* doh_setline */
0, /* doh_getline */
0, /* doh_mapping */
0, /* doh_sequence */
&FileFileMethods,/* doh_file */
0, /* doh_string */
0, /* doh_callable */
0, /* doh_position */
"DohFile", /* objname */
DelFile, /* doh_del */
0, /* doh_copy */
0, /* doh_clear */
0, /* doh_str */
0, /* doh_data */
0, /* doh_dump */
0, /* doh_len */
0, /* doh_hash */
0, /* doh_cmp */
0, /* doh_equal */
0, /* doh_first */
0, /* doh_next */
0, /* doh_setfile */
0, /* doh_getfile */
0, /* doh_setline */
0, /* doh_getline */
0, /* doh_mapping */
0, /* doh_sequence */
&FileFileMethods, /* doh_file */
0, /* doh_string */
0, /* doh_callable */
0, /* doh_position */
};
/* -----------------------------------------------------------------------------
@ -238,16 +230,15 @@ static DohObjInfo DohFileType = {
* Create a new file from a given filename and mode.
* ----------------------------------------------------------------------------- */
DOH *
DohNewFile(DOH *fn, const char *mode)
{
DOH *DohNewFile(DOH *fn, const char *mode) {
DohFile *f;
FILE *file;
char *filename;
filename = Char(fn);
file = fopen(filename,mode);
if (!file) return 0;
file = fopen(filename, mode);
if (!file)
return 0;
f = (DohFile *) DohMalloc(sizeof(DohFile));
if (!f) {
@ -257,7 +248,7 @@ DohNewFile(DOH *fn, const char *mode)
f->filep = file;
f->fd = 0;
f->closeondel = 1;
return DohObjMalloc(&DohFileType,f);
return DohObjMalloc(&DohFileType, f);
}
/* -----------------------------------------------------------------------------
@ -266,16 +257,15 @@ DohNewFile(DOH *fn, const char *mode)
* Create a file object from an already open FILE *.
* ----------------------------------------------------------------------------- */
DOH *
DohNewFileFromFile(FILE *file)
{
DOH *DohNewFileFromFile(FILE *file) {
DohFile *f;
f = (DohFile *) DohMalloc(sizeof(DohFile));
if (!f) return 0;
if (!f)
return 0;
f->filep = file;
f->fd = 0;
f->closeondel = 0;
return DohObjMalloc(&DohFileType,f);
return DohObjMalloc(&DohFileType, f);
}
/* -----------------------------------------------------------------------------
@ -284,16 +274,15 @@ DohNewFileFromFile(FILE *file)
* Create a file object from an already open FILE *.
* ----------------------------------------------------------------------------- */
DOH *
DohNewFileFromFd(int fd)
{
DOH *DohNewFileFromFd(int fd) {
DohFile *f;
f = (DohFile *) DohMalloc(sizeof(DohFile));
if (!f) return 0;
if (!f)
return 0;
f->filep = 0;
f->fd = fd;
f->closeondel = 0;
return DohObjMalloc(&DohFileType,f);
return DohObjMalloc(&DohFileType, f);
}
/* -----------------------------------------------------------------------------
@ -302,9 +291,6 @@ DohNewFileFromFd(int fd)
* Display cause of one of the NewFile functions failing.
* ----------------------------------------------------------------------------- */
void
DohFileErrorDisplay(DOHString *filename)
{
void DohFileErrorDisplay(DOHString * filename) {
Printf(stderr, "Unable to open file %s: %s\n", filename, strerror(errno));
}

View file

@ -16,7 +16,7 @@ char cvsroot_fio_c[] = "$Header$";
#define OBUFLEN 512
static DOH *encodings = 0; /* Encoding hash */
static DOH *encodings = 0; /* Encoding hash */
/* -----------------------------------------------------------------------------
* Writen()
@ -29,8 +29,9 @@ static int Writen(DOH *out, void *buffer, int len) {
int nw = len, ret;
char *cb = (char *) buffer;
while (nw) {
ret = Write(out,cb,nw);
if (ret < 0) return -1;
ret = Write(out, cb, nw);
if (ret < 0)
return -1;
nw = nw - ret;
cb += ret;
}
@ -44,36 +45,38 @@ static int Writen(DOH *out, void *buffer, int len) {
* two file-like objects and operate as a filter.
* ----------------------------------------------------------------------------- */
void
DohEncoding(char *name, DOH *(*fn)(DOH *s)) {
if (!encodings) encodings = NewHash();
Setattr(encodings,(void *) name, NewVoid((void *)fn,0));
void DohEncoding(char *name, DOH *(*fn) (DOH *s)) {
if (!encodings)
encodings = NewHash();
Setattr(encodings, (void *) name, NewVoid((void *) fn, 0));
}
/* internal function for processing an encoding */
static DOH *encode(char *name, DOH *s) {
static DOH *encode(char *name, DOH *s) {
DOH *handle, *ns;
DOH *(*fn)(DOH *);
long pos;
char *cfmt = strchr(name,':');
DOH *tmp = 0;
DOH *(*fn) (DOH *);
long pos;
char *cfmt = strchr(name, ':');
DOH *tmp = 0;
if (cfmt) {
tmp = NewString(cfmt + 1);
Append(tmp,s);
Setfile(tmp,Getfile((DOH *)s));
Setline(tmp,Getline((DOH *)s));
Append(tmp, s);
Setfile(tmp, Getfile((DOH *) s));
Setline(tmp, Getline((DOH *) s));
*cfmt = '\0';
}
if (!encodings || !(handle = Getattr(encodings,name))) {
if (!encodings || !(handle = Getattr(encodings, name))) {
return Copy(s);
}
if (tmp) s = tmp;
if (tmp)
s = tmp;
pos = Tell(s);
Seek(s,0,SEEK_SET);
Seek(s, 0, SEEK_SET);
fn = (DOH *(*)(DOH *)) Data(handle);
ns = (*fn)(s);
Seek(s,pos,SEEK_SET);
if (tmp) Delete(tmp);
ns = (*fn) (s);
Seek(s, pos, SEEK_SET);
if (tmp)
Delete(tmp);
return ns;
}
@ -95,37 +98,35 @@ static DOH *encode(char *name, DOH *s) {
* It's better to use Dump() or some other method instead.
* ----------------------------------------------------------------------------- */
int
DohvPrintf(DOH *so, const char *format, va_list ap)
{
int DohvPrintf(DOH *so, const char *format, va_list ap) {
static char *fmt_codes = "dioxXucsSfeEgGpn";
int state = 0;
const char *p = format;
char newformat[256];
char obuffer[OBUFLEN];
char newformat[256];
char obuffer[OBUFLEN];
char *fmt = 0;
char temp[64];
int widthval = 0;
int precval = 0;
int maxwidth;
char *w = 0;
int ivalue;
char temp[64];
int widthval = 0;
int precval = 0;
int maxwidth;
char *w = 0;
int ivalue;
double dvalue;
void *pvalue;
char *stemp;
int nbytes = 0;
char encoder[128], *ec = 0;
int plevel = 0;
void *pvalue;
char *stemp;
int nbytes = 0;
char encoder[128], *ec = 0;
int plevel = 0;
memset (newformat, 0, sizeof (newformat));
memset(newformat, 0, sizeof(newformat));
while (*p) {
switch(state) {
case 0: /* Ordinary text */
switch (state) {
case 0: /* Ordinary text */
if (*p != '%') {
Putc(*p,so);
Putc(*p, so);
nbytes++;
} else{
} else {
fmt = newformat;
widthval = 0;
precval = 0;
@ -134,26 +135,26 @@ DohvPrintf(DOH *so, const char *format, va_list ap)
state = 10;
}
break;
case 10: /* Look for a width and precision */
if (isdigit((int)*p) && (*p != '0')) {
case 10: /* Look for a width and precision */
if (isdigit((int) *p) && (*p != '0')) {
w = temp;
*(w++) = *p;
*(fmt++) = *p;
state = 20;
} else if (strchr(fmt_codes,*p)) {
} else if (strchr(fmt_codes, *p)) {
/* Got one of the formatting codes */
p--;
state = 100;
} else if (*p == '*') {
/* Width field is specified in the format list */
widthval = va_arg(ap,int);
sprintf(temp,"%d",widthval);
widthval = va_arg(ap, int);
sprintf(temp, "%d", widthval);
for (w = temp; *w; w++) {
*(fmt++) = *w;
}
state = 30;
} else if (*p == '%') {
Putc(*p,so);
Putc(*p, so);
fmt = newformat;
nbytes++;
state = 0;
@ -165,12 +166,12 @@ DohvPrintf(DOH *so, const char *format, va_list ap)
*(fmt++) = *p;
}
break;
case 20: /* Hmmm. At the start of a width field */
if (isdigit((int)*p)) {
case 20: /* Hmmm. At the start of a width field */
if (isdigit((int) *p)) {
*(w++) = *p;
*(fmt++) = *p;
} else if (strchr(fmt_codes,*p)) {
} else if (strchr(fmt_codes, *p)) {
/* Got one of the formatting codes */
/* Figure out width */
*w = 0;
@ -191,12 +192,12 @@ DohvPrintf(DOH *so, const char *format, va_list ap)
}
break;
case 30: /* Parsed a width from an argument. Look for a . */
case 30: /* Parsed a width from an argument. Look for a . */
if (*p == '.') {
w = temp;
*(fmt++) = *p;
state = 40;
} else if (strchr(fmt_codes,*p)) {
} else if (strchr(fmt_codes, *p)) {
/* Got one of the formatting codes */
/* Figure out width */
p--;
@ -209,19 +210,19 @@ DohvPrintf(DOH *so, const char *format, va_list ap)
case 40:
/* Start of precision expected */
if (isdigit((int)*p) && (*p != '0')) {
if (isdigit((int) *p) && (*p != '0')) {
*(fmt++) = *p;
*(w++) = *p;
state = 41;
} else if (*p == '*') {
/* Precision field is specified in the format list */
precval = va_arg(ap,int);
sprintf(temp,"%d",precval);
precval = va_arg(ap, int);
sprintf(temp, "%d", precval);
for (w = temp; *w; w++) {
*(fmt++) = *w;
}
state = 50;
} else if (strchr(fmt_codes,*p)) {
} else if (strchr(fmt_codes, *p)) {
p--;
state = 100;
} else {
@ -230,10 +231,10 @@ DohvPrintf(DOH *so, const char *format, va_list ap)
}
break;
case 41:
if (isdigit((int)*p)) {
if (isdigit((int) *p)) {
*(fmt++) = *p;
*(w++) = *p;
} else if (strchr(fmt_codes,*p)) {
} else if (strchr(fmt_codes, *p)) {
/* Got one of the formatting codes */
/* Figure out width */
*w = 0;
@ -249,7 +250,7 @@ DohvPrintf(DOH *so, const char *format, va_list ap)
break;
/* Hang out, wait for format specifier */
case 50:
if (strchr(fmt_codes,*p)) {
if (strchr(fmt_codes, *p)) {
p--;
state = 100;
} else {
@ -279,43 +280,47 @@ DohvPrintf(DOH *so, const char *format, va_list ap)
break;
case 100:
/* Got a formatting code */
if (widthval < precval) maxwidth = precval;
else maxwidth = widthval;
if ((*p == 's') || (*p == 'S')) { /* Null-Terminated string */
DOH *doh;
DOH *Sval;
DOH *enc = 0;
if (widthval < precval)
maxwidth = precval;
else
maxwidth = widthval;
if ((*p == 's') || (*p == 'S')) { /* Null-Terminated string */
DOH *doh;
DOH *Sval;
DOH *enc = 0;
doh = va_arg(ap, DOH *);
if (DohCheck(doh)) {
/* Is a DOH object. */
if (DohIsString(doh)) {
if (DohIsString(doh)) {
Sval = doh;
} else {
Sval = Str(doh);
}
if (strlen(encoder)) {
enc = encode(encoder,Sval);
maxwidth = maxwidth+strlen(newformat)+Len(enc);
enc = encode(encoder, Sval);
maxwidth = maxwidth + strlen(newformat) + Len(enc);
} else {
maxwidth = maxwidth+strlen(newformat)+Len(Sval);
maxwidth = maxwidth + strlen(newformat) + Len(Sval);
}
*(fmt++) = 's';
*fmt = 0;
if ((maxwidth + 1) < OBUFLEN) {
stemp = obuffer;
} else {
stemp = (char *) DohMalloc(maxwidth+1);
stemp = (char *) DohMalloc(maxwidth + 1);
}
if (enc) {
nbytes+=sprintf(stemp,newformat,Data(enc));
nbytes += sprintf(stemp, newformat, Data(enc));
} else {
nbytes+=sprintf(stemp,newformat,Data(Sval));
nbytes += sprintf(stemp, newformat, Data(Sval));
}
if (Writen(so,stemp,strlen(stemp)) < 0) return -1;
if (Writen(so, stemp, strlen(stemp)) < 0)
return -1;
if ((DOH *) Sval != doh) {
Delete(Sval);
}
if (enc) Delete(enc);
if (enc)
Delete(enc);
if (*p == 'S') {
Delete(doh);
}
@ -323,45 +328,48 @@ DohvPrintf(DOH *so, const char *format, va_list ap)
DohFree(stemp);
}
} else {
if (!doh) doh = (char *)"";
if (!doh)
doh = (char *) "";
if (strlen(encoder)) {
DOH *s = NewString(doh);
Seek(s,0, SEEK_SET);
enc = encode(encoder,s);
Seek(s, 0, SEEK_SET);
enc = encode(encoder, s);
Delete(s);
doh = Char(enc);
} else {
enc = 0;
}
maxwidth = maxwidth+strlen(newformat)+strlen((char *) doh);
maxwidth = maxwidth + strlen(newformat) + strlen((char *) doh);
*(fmt++) = 's';
*fmt = 0;
if ((maxwidth+1) < OBUFLEN) {
if ((maxwidth + 1) < OBUFLEN) {
stemp = obuffer;
} else {
stemp = (char *) DohMalloc(maxwidth + 1);
}
nbytes+=sprintf(stemp,newformat,doh);
if (Writen(so,stemp,strlen(stemp)) < 0) return -1;
nbytes += sprintf(stemp, newformat, doh);
if (Writen(so, stemp, strlen(stemp)) < 0)
return -1;
if (stemp != obuffer) {
DohFree(stemp);
}
if (enc) Delete(enc);
if (enc)
Delete(enc);
}
} else {
*(fmt++) = *p;
*fmt = 0;
maxwidth = maxwidth+strlen(newformat)+64;
maxwidth = maxwidth + strlen(newformat) + 64;
/* Only allocate a buffer if it is too big to fit. Shouldn't have to do
this very often */
this very often */
if (maxwidth < OBUFLEN)
stemp = obuffer;
else
stemp = (char *) DohMalloc(maxwidth+1);
switch(*p) {
else
stemp = (char *) DohMalloc(maxwidth + 1);
switch (*p) {
case 'd':
case 'i':
case 'o':
@ -369,26 +377,28 @@ DohvPrintf(DOH *so, const char *format, va_list ap)
case 'x':
case 'X':
case 'c':
ivalue = va_arg(ap,int);
nbytes+=sprintf(stemp,newformat,ivalue);
ivalue = va_arg(ap, int);
nbytes += sprintf(stemp, newformat, ivalue);
break;
case 'f':
case 'g':
case 'e':
case 'E':
case 'G':
dvalue = va_arg(ap,double);
nbytes+=sprintf(stemp,newformat,dvalue);
dvalue = va_arg(ap, double);
nbytes += sprintf(stemp, newformat, dvalue);
break;
case 'p':
pvalue = va_arg(ap,void *);
nbytes+=sprintf(stemp,newformat,pvalue);
pvalue = va_arg(ap, void *);
nbytes += sprintf(stemp, newformat, pvalue);
break;
default:
break;
}
if (Writen(so,stemp,strlen(stemp)) < 0) return -1;
if (stemp != obuffer) DohFree(stemp);
if (Writen(so, stemp, strlen(stemp)) < 0)
return -1;
if (stemp != obuffer)
DohFree(stemp);
}
state = 0;
break;
@ -398,8 +408,9 @@ DohvPrintf(DOH *so, const char *format, va_list ap)
if (state) {
int r;
*fmt = 0;
r = Writen(so,fmt,strlen(fmt));
if (r < 0) return -1;
r = Writen(so, fmt, strlen(fmt));
if (r < 0)
return -1;
nbytes += r;
}
return nbytes;
@ -411,12 +422,11 @@ DohvPrintf(DOH *so, const char *format, va_list ap)
* Variable length argument entry point to Printf
* ----------------------------------------------------------------------------- */
int
DohPrintf(DOH *obj, const char *format, ...) {
int DohPrintf(DOH *obj, const char *format, ...) {
va_list ap;
int ret;
va_start(ap,format);
ret = DohvPrintf(obj,format,ap);
va_start(ap, format);
ret = DohvPrintf(obj, format, ap);
va_end(ap);
return ret;
}
@ -427,18 +437,19 @@ DohPrintf(DOH *obj, const char *format, ...) {
* Print a null-terminated variable length list of DOH objects
* ----------------------------------------------------------------------------- */
int DohPrintv(DOHFile *f, ...) {
int DohPrintv(DOHFile * f, ...) {
va_list ap;
int ret = 0;
DOH *obj;
va_start(ap,f);
while(1) {
obj = va_arg(ap,void *);
if ((!obj) || (obj == DohNone)) break;
va_start(ap, f);
while (1) {
obj = va_arg(ap, void *);
if ((!obj) || (obj == DohNone))
break;
if (DohCheck(obj)) {
ret += DohDump(obj,f);
ret += DohDump(obj, f);
} else {
ret += DohWrite(f,obj,strlen((char *) obj));
ret += DohWrite(f, obj, strlen((char *) obj));
}
}
va_end(ap);
@ -452,22 +463,23 @@ int DohPrintv(DOHFile *f, ...) {
* number of bytes copied.
* ----------------------------------------------------------------------------- */
int
DohCopyto(DOH *in, DOH *out) {
int DohCopyto(DOH *in, DOH *out) {
int nbytes = 0, ret;
int nwrite = 0, wret;
char *cw;
char buffer[16384];
if ((!in) || (!out)) return 0;
if ((!in) || (!out))
return 0;
while (1) {
ret = Read(in,buffer,16384);
ret = Read(in, buffer, 16384);
if (ret > 0) {
nwrite = ret;
cw = buffer;
while (nwrite) {
wret = Write(out,cw,nwrite);
if (wret < 0) return -1;
wret = Write(out, cw, nwrite);
if (wret < 0)
return -1;
nwrite = nwrite - wret;
cw += wret;
}
@ -486,16 +498,15 @@ DohCopyto(DOH *in, DOH *out) {
* character. Optionally accepts a maximum number of splits to perform.
* ----------------------------------------------------------------------------- */
DOH *
DohSplit(DOH *in, char ch, int nsplits) {
DOH *DohSplit(DOH *in, char ch, int nsplits) {
DOH *list;
DOH *str;
int c;
list = NewList();
if (DohIsString(in)) {
Seek(in,0,SEEK_SET);
Seek(in, 0, SEEK_SET);
}
while (1) {
@ -504,17 +515,19 @@ DohSplit(DOH *in, char ch, int nsplits) {
c = Getc(in);
} while ((c != EOF) && (c == ch));
if (c != EOF) {
Putc(c,str);
Putc(c, str);
while (1) {
c = Getc(in);
if ((c == EOF) || ((c == ch) && (nsplits != 0))) break;
Putc(c,str);
if ((c == EOF) || ((c == ch) && (nsplits != 0)))
break;
Putc(c, str);
}
nsplits--;
}
Append(list,str);
Append(list, str);
Delete(str);
if (c == EOF) break;
if (c == EOF)
break;
}
return list;
}
@ -525,16 +538,15 @@ DohSplit(DOH *in, char ch, int nsplits) {
* Split an input stream into a list of strings delimited by newline characters.
* ----------------------------------------------------------------------------- */
DOH *
DohSplitLines(DOH *in) {
DOH *DohSplitLines(DOH *in) {
DOH *list;
DOH *str;
int c = 0;
int c = 0;
list = NewList();
if (DohIsString(in)) {
Seek(in,0,SEEK_SET);
Seek(in, 0, SEEK_SET);
}
while (c != EOF) {
@ -542,7 +554,7 @@ DohSplitLines(DOH *in) {
while ((c = Getc(in)) != '\n' && c != EOF) {
Putc(c, str);
}
Append(list,str);
Append(list, str);
Delete(str);
}
return list;
@ -555,24 +567,23 @@ DohSplitLines(DOH *in) {
* Read a single input line and return it as a string.
* ----------------------------------------------------------------------------- */
DOH *
DohReadline(DOH *in) {
DOH *DohReadline(DOH *in) {
char c;
int n = 0;
DOH *s = NewStringEmpty();
while (1) {
if (Read(in,&c,1) < 0) {
if (Read(in, &c, 1) < 0) {
if (n == 0) {
Delete(s);
return 0;
}
return s;
}
if (c == '\n') return s;
if (c == '\r') continue;
Putc(c,s);
if (c == '\n')
return s;
if (c == '\r')
continue;
Putc(c, s);
n++;
}
}

View file

@ -17,59 +17,65 @@ extern DohObjInfo DohHashType;
/* Hash node */
typedef struct HashNode {
DOH *key;
DOH *object;
struct HashNode *next;
DOH *key;
DOH *object;
struct HashNode *next;
} HashNode;
/* Hash object */
typedef struct Hash {
DOH *file;
int line;
HashNode **hashtable;
int hashsize;
int nitems;
DOH *file;
int line;
HashNode **hashtable;
int hashsize;
int nitems;
} Hash;
/* Key interning structure */
typedef struct KeyValue {
char *cstr;
DOH *sstr;
struct KeyValue *left;
struct KeyValue *right;
char *cstr;
DOH *sstr;
struct KeyValue *left;
struct KeyValue *right;
} KeyValue;
static KeyValue *root = 0;
/* Find or create a key in the interned key table */
static DOH *find_key (DOH *doh_c) {
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. */
hash tables. */
r = root;
s = 0;
while (r) {
s = r;
d = strcmp(r->cstr,c);
if (d == 0) return r->sstr;
if (d < 0) r = r->left;
else r = r->right;
d = strcmp(r->cstr, c);
if (d == 0)
return r->sstr;
if (d < 0)
r = r->left;
else
r = r->right;
}
/* fprintf(stderr,"Interning '%s'\n", c);*/
/* fprintf(stderr,"Interning '%s'\n", c); */
r = (KeyValue *) DohMalloc(sizeof(KeyValue));
r->cstr = (char *) DohMalloc(strlen(c)+1);
strcpy(r->cstr,c);
r->cstr = (char *) DohMalloc(strlen(c) + 1);
strcpy(r->cstr, c);
r->sstr = NewString(c);
DohIntern(r->sstr);
r->left = 0;
r->right = 0;
if (!s) { root = r; }
else {
if (d < 0) s->left = r;
else s->right = r;
if (!s) {
root = r;
} else {
if (d < 0)
s->left = r;
else
s->right = r;
}
return r->sstr;
}
@ -78,20 +84,20 @@ static DOH *find_key (DOH *doh_c) {
/* Create a new hash node */
static HashNode *NewNode(DOH *k, void *obj) {
HashNode *hn = (HashNode *) DohMalloc(sizeof(HashNode));
hn->key = k;
Incref(hn->key);
hn->object = obj;
Incref(obj);
hn->next = 0;
return hn;
HashNode *hn = (HashNode *) DohMalloc(sizeof(HashNode));
hn->key = k;
Incref(hn->key);
hn->object = obj;
Incref(obj);
hn->next = 0;
return hn;
}
/* Delete a hash node */
static void DelNode(HashNode *hn) {
Delete(hn->key);
Delete(hn->object);
DohFree(hn);
Delete(hn->key);
Delete(hn->object);
DohFree(hn);
}
/* -----------------------------------------------------------------------------
@ -100,25 +106,24 @@ static void DelNode(HashNode *hn) {
* Delete a hash table.
* ----------------------------------------------------------------------------- */
static void
DelHash(DOH *ho) {
Hash *h = (Hash *) ObjData(ho);
HashNode *n,*next;
int i;
static void DelHash(DOH *ho) {
Hash *h = (Hash *) ObjData(ho);
HashNode *n, *next;
int i;
for (i = 0; i < h->hashsize; i++) {
if ((n = h->hashtable[i])) {
while (n) {
next = n->next;
DelNode(n);
n = next;
}
}
for (i = 0; i < h->hashsize; i++) {
if ((n = h->hashtable[i])) {
while (n) {
next = n->next;
DelNode(n);
n = next;
}
}
DohFree(h->hashtable);
h->hashtable = 0;
h->hashsize = 0;
DohFree(h);
}
DohFree(h->hashtable);
h->hashtable = 0;
h->hashsize = 0;
DohFree(h);
}
/* -----------------------------------------------------------------------------
@ -127,67 +132,67 @@ DelHash(DOH *ho) {
* Clear all of the entries in the hash table.
* ----------------------------------------------------------------------------- */
static void
Hash_clear(DOH *ho) {
Hash *h = (Hash *) ObjData(ho);
HashNode *n,*next;
int i;
static void Hash_clear(DOH *ho) {
Hash *h = (Hash *) ObjData(ho);
HashNode *n, *next;
int i;
for (i = 0; i < h->hashsize; i++) {
if ((n = h->hashtable[i])) {
while (n) {
next = n->next;
DelNode(n);
n = next;
}
}
h->hashtable[i] = 0;
for (i = 0; i < h->hashsize; i++) {
if ((n = h->hashtable[i])) {
while (n) {
next = n->next;
DelNode(n);
n = next;
}
}
h->nitems = 0;
h->hashtable[i] = 0;
}
h->nitems = 0;
}
/* resize the hash table */
static void resize(Hash *h) {
HashNode *n, *next, **table;
int oldsize, newsize;
int i, p, hv;
HashNode *n, *next, **table;
int oldsize, newsize;
int i, p, hv;
if (h->nitems < 2*h->hashsize) return;
if (h->nitems < 2 * h->hashsize)
return;
/* Too big. We have to rescale everything now */
oldsize = h->hashsize;
/* Too big. We have to rescale everything now */
oldsize = h->hashsize;
/* Calculate a new size */
newsize = 2*oldsize+1;
p = 3;
while (p < (newsize >> 1)) {
if (((newsize/p)*p) == newsize) {
newsize+=2;
p = 3;
continue;
}
p = p + 2;
/* Calculate a new size */
newsize = 2 * oldsize + 1;
p = 3;
while (p < (newsize >> 1)) {
if (((newsize / p) * p) == newsize) {
newsize += 2;
p = 3;
continue;
}
p = p + 2;
}
table = (HashNode **) DohMalloc(newsize*sizeof(HashNode *));
for (i = 0; i < newsize; i++ ) {
table[i] = 0;
}
table = (HashNode **) DohMalloc(newsize * sizeof(HashNode *));
for (i = 0; i < newsize; i++) {
table[i] = 0;
}
/* Walk down the old set of nodes and re-place */
h->hashsize = newsize;
for (i = 0; i < oldsize; i++) {
n = h->hashtable[i];
while (n) {
hv = Hashval(n->key) % newsize;
next = n->next;
n->next = table[hv];
table[hv] = n;
n = next;
}
/* Walk down the old set of nodes and re-place */
h->hashsize = newsize;
for (i = 0; i < oldsize; i++) {
n = h->hashtable[i];
while (n) {
hv = Hashval(n->key) % newsize;
next = n->next;
n->next = table[hv];
table[hv] = n;
n = next;
}
DohFree(h->hashtable);
h->hashtable = table;
}
DohFree(h->hashtable);
h->hashtable = table;
}
/* -----------------------------------------------------------------------------
@ -197,46 +202,48 @@ static void resize(Hash *h) {
* exists.
* ----------------------------------------------------------------------------- */
static int
Hash_setattr(DOH *ho, DOH *k, DOH *obj) {
int hv;
HashNode *n, *prev;
Hash *h = (Hash *) ObjData(ho);
if (!obj) {
return DohDelattr(ho,k);
}
if (!DohCheck(k)) k = find_key(k);
if (!DohCheck(obj)) {
obj = NewString((char *) obj);
Decref(obj);
}
hv = (Hashval(k)) % h->hashsize;
n = h->hashtable[hv];
prev = 0;
while (n) {
if (Cmp(n->key,k) == 0) {
/* Node already exists. Just replace its contents */
if (n->object == obj) {
/* Whoa. Same object. Do nothing */
return 1;
}
Delete(n->object);
n->object = obj;
Incref(obj);
return 1; /* Return 1 to indicate a replacement */
} else {
prev = n;
n = n->next;
static int Hash_setattr(DOH *ho, DOH *k, DOH *obj) {
int hv;
HashNode *n, *prev;
Hash *h = (Hash *) ObjData(ho);
if (!obj) {
return DohDelattr(ho, k);
}
if (!DohCheck(k))
k = find_key(k);
if (!DohCheck(obj)) {
obj = NewString((char *) obj);
Decref(obj);
}
hv = (Hashval(k)) % h->hashsize;
n = h->hashtable[hv];
prev = 0;
while (n) {
if (Cmp(n->key, k) == 0) {
/* Node already exists. Just replace its contents */
if (n->object == obj) {
/* Whoa. Same object. Do nothing */
return 1;
}
Delete(n->object);
n->object = obj;
Incref(obj);
return 1; /* Return 1 to indicate a replacement */
} else {
prev = n;
n = n->next;
}
/* Add this to the table */
n = NewNode(k,obj);
if (prev) prev->next = n;
else h->hashtable[hv] = n;
h->nitems++;
resize(h);
return 0;
}
/* Add this to the table */
n = NewNode(k, obj);
if (prev)
prev->next = n;
else
h->hashtable[hv] = n;
h->nitems++;
resize(h);
return 0;
}
/* -----------------------------------------------------------------------------
@ -244,7 +251,7 @@ Hash_setattr(DOH *ho, DOH *k, DOH *obj) {
*
* Get an attribute from the hash table. Returns 0 if it doesn't exist.
* ----------------------------------------------------------------------------- */
typedef int (*binop)(DOH *obj1, DOH *obj2);
typedef int (*binop) (DOH *obj1, DOH *obj2);
#define _Hash_getattr(h, k, o) \
int hv = Hashval(k) % h->hashsize; \
@ -267,8 +274,7 @@ typedef int (*binop)(DOH *obj1, DOH *obj2);
}
static DOH *
Hash_getattr(DOH *h, DOH *k) {
static DOH *Hash_getattr(DOH *h, DOH *k) {
DOH *obj = 0;
Hash *ho = (Hash *) ObjData(h);
DOH *ko = DohCheck(k) ? k : find_key(k);
@ -276,8 +282,7 @@ Hash_getattr(DOH *h, DOH *k) {
return obj;
}
DOH *
DohHashGetAttr(DOH *h, const DOH *k) {
DOH *DohHashGetAttr(DOH *h, const DOH *k) {
DOH *obj = 0;
Hash *ho = (Hash *) ObjData(h);
_Hash_getattr(ho, (DOH *) k, obj);
@ -291,14 +296,13 @@ DohHashGetAttr(DOH *h, const DOH *k) {
* Check an attribute from the hash table.
* ----------------------------------------------------------------------------- */
int
DohHashCheckAttr(DOH *h, DOH *k, DOH *v) {
int DohHashCheckAttr(DOH *h, DOH *k, DOH *v) {
DOH *obj = 0;
Hash *ho = (Hash *) ObjData(h);
_Hash_getattr(ho, k, obj);
if (obj) {
DohObjInfo *o_type = ((DohBase*)obj)->type;
if (o_type == ((DohBase*)v)->type) {
DohObjInfo *o_type = ((DohBase *) obj)->type;
if (o_type == ((DohBase *) v)->type) {
binop equal = o_type->doh_equal;
return equal ? equal(obj, v) : (o_type->doh_cmp(obj, v) == 0);
}
@ -312,44 +316,43 @@ DohHashCheckAttr(DOH *h, DOH *k, DOH *v) {
* Delete an object from the hash table.
* ----------------------------------------------------------------------------- */
static int
Hash_delattr(DOH *ho, DOH *k) {
HashNode *n, *prev;
int hv;
Hash *h = (Hash *) ObjData(ho);
static int Hash_delattr(DOH *ho, DOH *k) {
HashNode *n, *prev;
int hv;
Hash *h = (Hash *) ObjData(ho);
if (!DohCheck(k)) k = find_key(k);
hv = Hashval(k) % h->hashsize;
n = h->hashtable[hv];
prev = 0;
while (n) {
if (Cmp(n->key, k) == 0) {
/* Found it, kill it */
if (!DohCheck(k))
k = find_key(k);
hv = Hashval(k) % h->hashsize;
n = h->hashtable[hv];
prev = 0;
while (n) {
if (Cmp(n->key, k) == 0) {
/* Found it, kill it */
if (prev) {
prev->next = n->next;
} else {
h->hashtable[hv] = n->next;
}
DelNode(n);
h->nitems--;
return 1;
}
prev = n;
n = n->next;
if (prev) {
prev->next = n->next;
} else {
h->hashtable[hv] = n->next;
}
DelNode(n);
h->nitems--;
return 1;
}
return 0;
prev = n;
n = n->next;
}
return 0;
}
static DohIterator
Hash_firstiter(DOH *ho) {
static DohIterator Hash_firstiter(DOH *ho) {
DohIterator iter;
Hash *h = (Hash *) ObjData(ho);
iter.object = ho;
iter._current = 0;
iter.item = 0;
iter.key = 0;
iter._index = 0; /* Index in hash table */
iter._index = 0; /* Index in hash table */
while ((iter._index < h->hashsize) && !h->hashtable[iter._index])
iter._index++;
@ -359,15 +362,14 @@ Hash_firstiter(DOH *ho) {
iter._current = h->hashtable[iter._index];
iter.item = ((HashNode *) iter._current)->object;
iter.key = ((HashNode *) iter._current)->key;
/* Actually save the next slot in the hash. This makes it possible to
delete the item being iterated over without trashing the universe */
iter._current = ((HashNode*)iter._current)->next;
iter._current = ((HashNode *) iter._current)->next;
return iter;
}
static DohIterator
Hash_nextiter(DohIterator iter) {
static DohIterator Hash_nextiter(DohIterator iter) {
Hash *h = (Hash *) ObjData(iter.object);
if (!iter._current) {
iter._index++;
@ -386,7 +388,7 @@ Hash_nextiter(DohIterator iter) {
iter.item = ((HashNode *) iter._current)->object;
/* Store the next node to iterator on */
iter._current = ((HashNode*)iter._current)->next;
iter._current = ((HashNode *) iter._current)->next;
return iter;
}
@ -396,14 +398,13 @@ Hash_nextiter(DohIterator iter) {
* Return a list of keys
* ----------------------------------------------------------------------------- */
static DOH *
Hash_keys(DOH *so) {
static DOH *Hash_keys(DOH *so) {
DOH *keys;
Iterator i;
keys = NewList();
for (i = First(so); i.key; i = Next(i)) {
Append(keys,i.key);
Append(keys, i.key);
}
return keys;
}
@ -414,35 +415,36 @@ Hash_keys(DOH *so) {
* Create a string representation of a hash table (mainly for debugging).
* ----------------------------------------------------------------------------- */
static DOH *
Hash_str(DOH *ho) {
int i,j;
HashNode *n;
DOH *s;
static int indent = 4;
Hash *h = (Hash *) ObjData(ho);
static DOH *Hash_str(DOH *ho) {
int i, j;
HashNode *n;
DOH *s;
static int indent = 4;
Hash *h = (Hash *) ObjData(ho);
s = NewStringEmpty();
if (ObjGetMark(ho)) {
Printf(s,"Hash(0x%x)",ho);
return s;
}
ObjSetMark(ho,1);
Printf(s,"Hash {\n");
for (i = 0; i < h->hashsize; i++) {
n = h->hashtable[i];
while (n) {
for (j = 0; j < indent; j++) Putc(' ',s);
indent+=4;
Printf(s,"'%s' : %s, \n", n->key, n->object);
indent-=4;
n = n->next;
}
}
for (j = 0; j < (indent-4); j++) Putc(' ',s);
Printf(s,"}\n");
ObjSetMark(ho,0);
s = NewStringEmpty();
if (ObjGetMark(ho)) {
Printf(s, "Hash(0x%x)", ho);
return s;
}
ObjSetMark(ho, 1);
Printf(s, "Hash {\n");
for (i = 0; i < h->hashsize; i++) {
n = h->hashtable[i];
while (n) {
for (j = 0; j < indent; j++)
Putc(' ', s);
indent += 4;
Printf(s, "'%s' : %s, \n", n->key, n->object);
indent -= 4;
n = n->next;
}
}
for (j = 0; j < (indent - 4); j++)
Putc(' ', s);
Printf(s, "}\n");
ObjSetMark(ho, 0);
return s;
}
/* -----------------------------------------------------------------------------
@ -451,8 +453,7 @@ Hash_str(DOH *ho) {
* Return number of entries in the hash table.
* ----------------------------------------------------------------------------- */
static int
Hash_len(DOH *ho) {
static int Hash_len(DOH *ho) {
Hash *h = (Hash *) ObjData(ho);
return h->nitems;
}
@ -463,67 +464,64 @@ Hash_len(DOH *ho) {
* Make a copy of a hash table. Note: this is a shallow copy.
* ----------------------------------------------------------------------------- */
static DOH *
CopyHash(DOH *ho) {
Hash *h, *nh;
HashNode *n;
DOH *nho;
int i;
h = (Hash *) ObjData(ho);
nh = (Hash *) DohMalloc(sizeof(Hash));
nh->hashsize = h->hashsize;
nh->hashtable = (HashNode **) DohMalloc(nh->hashsize*sizeof(HashNode *));
for (i = 0; i < nh->hashsize; i++) {
nh->hashtable[i] = 0;
}
nh->nitems = 0;
nh->line = h->line;
nh->file = h->file;
if (nh->file) Incref(nh->file);
static DOH *CopyHash(DOH *ho) {
Hash *h, *nh;
HashNode *n;
DOH *nho;
nho = DohObjMalloc(&DohHashType, nh);
for (i = 0; i < h->hashsize; i++) {
if ((n = h->hashtable[i])) {
while (n) {
Hash_setattr(nho, n->key, n->object);
n = n->next;
}
}
int i;
h = (Hash *) ObjData(ho);
nh = (Hash *) DohMalloc(sizeof(Hash));
nh->hashsize = h->hashsize;
nh->hashtable = (HashNode **) DohMalloc(nh->hashsize * sizeof(HashNode *));
for (i = 0; i < nh->hashsize; i++) {
nh->hashtable[i] = 0;
}
nh->nitems = 0;
nh->line = h->line;
nh->file = h->file;
if (nh->file)
Incref(nh->file);
nho = DohObjMalloc(&DohHashType, nh);
for (i = 0; i < h->hashsize; i++) {
if ((n = h->hashtable[i])) {
while (n) {
Hash_setattr(nho, n->key, n->object);
n = n->next;
}
}
return nho;
}
return nho;
}
static void
Hash_setfile(DOH *ho, DOH *file) {
static void Hash_setfile(DOH *ho, DOH *file) {
DOH *fo;
Hash *h = (Hash *) ObjData(ho);
if (!DohCheck(file)) {
fo = NewString(file);
Decref(fo);
} else fo = file;
} else
fo = file;
Incref(fo);
Delete(h->file);
h->file = fo;
}
static DOH *
Hash_getfile(DOH *ho) {
static DOH *Hash_getfile(DOH *ho) {
Hash *h = (Hash *) ObjData(ho);
return h->file;
}
static void
Hash_setline(DOH *ho, int line) {
static void Hash_setline(DOH *ho, int line) {
Hash *h = (Hash *) ObjData(ho);
h->line = line;
}
static int
Hash_getline(DOH *ho) {
static int Hash_getline(DOH *ho) {
Hash *h = (Hash *) ObjData(ho);
return h->line;
}
@ -540,29 +538,29 @@ static DohHashMethods HashHashMethods = {
};
DohObjInfo DohHashType = {
"Hash", /* objname */
DelHash, /* doh_del */
CopyHash, /* doh_copy */
Hash_clear, /* doh_clear */
Hash_str, /* doh_str */
0, /* doh_data */
0, /* doh_dump */
Hash_len, /* doh_len */
0, /* doh_hash */
0, /* doh_cmp */
0, /* doh_equal */
Hash_firstiter, /* doh_first */
Hash_nextiter, /* doh_next */
Hash_setfile, /* doh_setfile */
Hash_getfile, /* doh_getfile */
Hash_setline, /* doh_setline */
Hash_getline, /* doh_getline */
&HashHashMethods, /* doh_mapping */
0, /* doh_sequence */
0, /* doh_file */
0, /* doh_string */
0, /* doh_positional */
0,
"Hash", /* objname */
DelHash, /* doh_del */
CopyHash, /* doh_copy */
Hash_clear, /* doh_clear */
Hash_str, /* doh_str */
0, /* doh_data */
0, /* doh_dump */
Hash_len, /* doh_len */
0, /* doh_hash */
0, /* doh_cmp */
0, /* doh_equal */
Hash_firstiter, /* doh_first */
Hash_nextiter, /* doh_next */
Hash_setfile, /* doh_setfile */
Hash_getfile, /* doh_getfile */
Hash_setline, /* doh_setline */
Hash_getline, /* doh_getline */
&HashHashMethods, /* doh_mapping */
0, /* doh_sequence */
0, /* doh_file */
0, /* doh_string */
0, /* doh_positional */
0,
};
/* -----------------------------------------------------------------------------
@ -571,18 +569,17 @@ DohObjInfo DohHashType = {
* Create a new hash table.
* ----------------------------------------------------------------------------- */
DOH *
DohNewHash() {
Hash *h;
int i;
h = (Hash *) DohMalloc(sizeof(Hash));
h->hashsize = HASH_INIT_SIZE;
h->hashtable = (HashNode **) DohMalloc(h->hashsize*sizeof(HashNode *));
for (i = 0; i < h->hashsize; i++) {
h->hashtable[i] = 0;
}
h->nitems = 0;
h->file = 0;
h->line = 0;
return DohObjMalloc(&DohHashType,h);
DOH *DohNewHash() {
Hash *h;
int i;
h = (Hash *) DohMalloc(sizeof(Hash));
h->hashsize = HASH_INIT_SIZE;
h->hashtable = (HashNode **) DohMalloc(h->hashsize * sizeof(HashNode *));
for (i = 0; i < h->hashsize; i++) {
h->hashtable[i] = 0;
}
h->nitems = 0;
h->file = 0;
h->line = 0;
return DohObjMalloc(&DohHashType, h);
}

View file

@ -14,21 +14,21 @@ char cvsroot_list_c[] = "$Header$";
#include "dohint.h"
typedef struct List {
int maxitems; /* Max size */
int nitems; /* Num items */
DOH *file;
int line;
DOH **items;
int maxitems; /* Max size */
int nitems; /* Num items */
DOH *file;
int line;
DOH **items;
} List;
extern DohObjInfo DohListType;
/* Doubles amount of memory in a list */
static
static
void more(List *l) {
l->items = (void **) DohRealloc(l->items, l->maxitems*2*sizeof(void *));
assert(l->items);
l->maxitems *= 2;
l->items = (void **) DohRealloc(l->items, l->maxitems * 2 * sizeof(void *));
assert(l->items);
l->maxitems *= 2;
}
/* -----------------------------------------------------------------------------
@ -36,23 +36,23 @@ void more(List *l) {
*
* Make a shallow copy of a list.
* ----------------------------------------------------------------------------- */
static DOH *
CopyList(DOH *lo) {
List *l,*nl;
int i;
l = (List *) ObjData(lo);
nl = (List *) DohMalloc(sizeof(List));
nl->nitems = l->nitems;
nl->maxitems = l->maxitems;
nl->items = (void **) DohMalloc(l->maxitems*sizeof(void *));
for (i = 0; i < l->nitems; i++) {
nl->items[i] = l->items[i];
Incref(nl->items[i]);
}
nl->file = l->file;
if (nl->file) Incref(nl->file);
nl->line = l->line;
return DohObjMalloc(&DohListType, nl);
static DOH *CopyList(DOH *lo) {
List *l, *nl;
int i;
l = (List *) ObjData(lo);
nl = (List *) DohMalloc(sizeof(List));
nl->nitems = l->nitems;
nl->maxitems = l->maxitems;
nl->items = (void **) DohMalloc(l->maxitems * sizeof(void *));
for (i = 0; i < l->nitems; i++) {
nl->items[i] = l->items[i];
Incref(nl->items[i]);
}
nl->file = l->file;
if (nl->file)
Incref(nl->file);
nl->line = l->line;
return DohObjMalloc(&DohListType, nl);
}
/* -----------------------------------------------------------------------------
@ -61,14 +61,13 @@ CopyList(DOH *lo) {
* Delete a list.
* ----------------------------------------------------------------------------- */
static void
DelList(DOH *lo) {
List *l = (List *) ObjData(lo);
int i;
for (i = 0; i < l->nitems; i++)
Delete(l->items[i]);
DohFree(l->items);
DohFree(l);
static void DelList(DOH *lo) {
List *l = (List *) ObjData(lo);
int i;
for (i = 0; i < l->nitems; i++)
Delete(l->items[i]);
DohFree(l->items);
DohFree(l);
}
/* -----------------------------------------------------------------------------
@ -77,14 +76,13 @@ DelList(DOH *lo) {
* Remove all of the list entries, but keep the list object intact.
* ----------------------------------------------------------------------------- */
static void
List_clear(DOH *lo) {
List *l = (List *) ObjData(lo);
int i;
for (i = 0; i < l->nitems; i++) {
Delete(l->items[i]);
}
l->nitems = 0;
static void List_clear(DOH *lo) {
List *l = (List *) ObjData(lo);
int i;
for (i = 0; i < l->nitems; i++) {
Delete(l->items[i]);
}
l->nitems = 0;
}
/* -----------------------------------------------------------------------------
@ -94,22 +92,26 @@ List_clear(DOH *lo) {
* to be a 'char *' and is used to construct an equivalent string object.
* ----------------------------------------------------------------------------- */
static int
List_insert(DOH *lo, int pos, DOH *item) {
static int List_insert(DOH *lo, int pos, DOH *item) {
List *l = (List *) ObjData(lo);
int i;
if (!item) return -1;
if (!item)
return -1;
if (!DohCheck(item)) {
item = NewString(item);
Decref(item);
}
if (pos == DOH_END) pos = l->nitems;
if (pos < 0) pos = 0;
if (pos > l->nitems) pos = l->nitems;
if (l->nitems == l->maxitems) more(l);
if (pos == DOH_END)
pos = l->nitems;
if (pos < 0)
pos = 0;
if (pos > l->nitems)
pos = l->nitems;
if (l->nitems == l->maxitems)
more(l);
for (i = l->nitems; i > pos; i--) {
l->items[i] = l->items[i-1];
l->items[i] = l->items[i - 1];
}
l->items[pos] = item;
Incref(item);
@ -122,20 +124,21 @@ List_insert(DOH *lo, int pos, DOH *item) {
*
* Remove an item from a list.
* ----------------------------------------------------------------------------- */
static int
List_remove(DOH *lo, int pos) {
List *l = (List *) ObjData(lo);
int i;
if (pos == DOH_END) pos = l->nitems-1;
if (pos == DOH_BEGIN) pos = 0;
assert(!((pos < 0) || (pos >= l->nitems)));
Delete(l->items[pos]);
for (i = pos; i < l->nitems-1; i++) {
l->items[i] = l->items[i+1];
}
l->nitems--;
return 0;
static int List_remove(DOH *lo, int pos) {
List *l = (List *) ObjData(lo);
int i;
if (pos == DOH_END)
pos = l->nitems - 1;
if (pos == DOH_BEGIN)
pos = 0;
assert(!((pos < 0) || (pos >= l->nitems)));
Delete(l->items[pos]);
for (i = pos; i < l->nitems - 1; i++) {
l->items[i] = l->items[i + 1];
}
l->nitems--;
return 0;
}
/* -----------------------------------------------------------------------------
@ -144,8 +147,7 @@ List_remove(DOH *lo, int pos) {
* Return the number of elements in the list
* ----------------------------------------------------------------------------- */
static int
List_len(DOH *lo) {
static int List_len(DOH *lo) {
List *l = (List *) ObjData(lo);
return l->nitems;
}
@ -156,13 +158,14 @@ List_len(DOH *lo) {
* Get the nth item from the list.
* ----------------------------------------------------------------------------- */
static DOH *
List_get(DOH *lo, int n) {
List *l = (List *) ObjData(lo);
if (n == DOH_END) n = l->nitems-1;
if (n == DOH_BEGIN) n = 0;
assert(!((n < 0) || (n >= l->nitems)));
return l->items[n];
static DOH *List_get(DOH *lo, int n) {
List *l = (List *) ObjData(lo);
if (n == DOH_END)
n = l->nitems - 1;
if (n == DOH_BEGIN)
n = 0;
assert(!((n < 0) || (n >= l->nitems)));
return l->items[n];
}
/* -----------------------------------------------------------------------------
@ -171,20 +174,20 @@ List_get(DOH *lo, int n) {
* Set the nth item in the list replacing any previous item.
* ----------------------------------------------------------------------------- */
static int
List_set(DOH *lo, int n, DOH *val) {
List *l = (List *) ObjData(lo);
if (!val) return -1;
assert(!((n < 0) || (n >= l->nitems)));
if (!DohCheck(val)) {
val = NewString(val);
Decref(val);
}
Delete(l->items[n]);
l->items[n] = val;
Incref(val);
Delete(val);
return 0;
static int List_set(DOH *lo, int n, DOH *val) {
List *l = (List *) ObjData(lo);
if (!val)
return -1;
assert(!((n < 0) || (n >= l->nitems)));
if (!DohCheck(val)) {
val = NewString(val);
Decref(val);
}
Delete(l->items[n]);
l->items[n] = val;
Incref(val);
Delete(val);
return 0;
}
/* -----------------------------------------------------------------------------
@ -193,8 +196,7 @@ List_set(DOH *lo, int n, DOH *val) {
* Return the first item in the list.
* ----------------------------------------------------------------------------- */
static DohIterator
List_first(DOH *lo) {
static DohIterator List_first(DOH *lo) {
DohIterator iter;
List *l = (List *) ObjData(lo);
iter.object = lo;
@ -215,8 +217,7 @@ List_first(DOH *lo) {
* Return the next item in the list.
* ----------------------------------------------------------------------------- */
static DohIterator
List_next(DohIterator iter) {
static DohIterator List_next(DohIterator iter) {
List *l = (List *) ObjData(iter.object);
iter._index = iter._index + 1;
if (iter._index >= l->nitems) {
@ -233,26 +234,25 @@ List_next(DohIterator iter) {
*
* Create a string representation of the list.
* ----------------------------------------------------------------------------- */
static DOH *
List_str(DOH *lo) {
DOH *s;
int i;
List *l = (List *) ObjData(lo);
s = NewStringEmpty();
if (ObjGetMark(lo)) {
Printf(s,"List(%x)", lo);
return s;
}
ObjSetMark(lo,1);
Printf(s,"List[ ");
for (i = 0; i < l->nitems; i++) {
Printf(s, "%s", l->items[i]);
if ((i+1) < l->nitems)
Printf(s,", ");
}
Printf(s," ]\n");
ObjSetMark(lo,0);
static DOH *List_str(DOH *lo) {
DOH *s;
int i;
List *l = (List *) ObjData(lo);
s = NewStringEmpty();
if (ObjGetMark(lo)) {
Printf(s, "List(%x)", lo);
return s;
}
ObjSetMark(lo, 1);
Printf(s, "List[ ");
for (i = 0; i < l->nitems; i++) {
Printf(s, "%s", l->items[i]);
if ((i + 1) < l->nitems)
Printf(s, ", ");
}
Printf(s, " ]\n");
ObjSetMark(lo, 0);
return s;
}
/* -----------------------------------------------------------------------------
@ -261,41 +261,39 @@ List_str(DOH *lo) {
* Dump the items to an output stream.
* ----------------------------------------------------------------------------- */
static int
List_dump(DOH *lo, DOH *out) {
static int List_dump(DOH *lo, DOH *out) {
int nsent = 0;
int i,ret;
int i, ret;
List *l = (List *) ObjData(lo);
for (i = 0; i < l->nitems; i++) {
ret = Dump(l->items[i],out);
if (ret < 0) return -1;
ret = Dump(l->items[i], out);
if (ret < 0)
return -1;
nsent += ret;
}
return nsent;
}
static void
List_setfile(DOH *lo, DOH *file) {
static void List_setfile(DOH *lo, DOH *file) {
DOH *fo;
List *l = (List *) ObjData(lo);
if (!DohCheck(file)) {
fo = NewString(file);
Decref(fo);
} else fo = file;
} else
fo = file;
Incref(fo);
Delete(l->file);
l->file = fo;
}
static DOH *
List_getfile(DOH *lo) {
static DOH *List_getfile(DOH *lo) {
List *l = (List *) ObjData(lo);
return l->file;
}
static void
List_setline(DOH *lo, int line) {
static void List_setline(DOH *lo, int line) {
List *l = (List *) ObjData(lo);
l->line = line;
}
@ -310,33 +308,33 @@ static DohListMethods ListListMethods = {
List_set,
List_remove,
List_insert,
0, /* delslice */
0, /* delslice */
};
DohObjInfo DohListType = {
"List", /* objname */
DelList, /* doh_del */
CopyList, /* doh_copy */
List_clear, /* doh_clear */
List_str, /* doh_str */
0, /* doh_data */
List_dump, /* doh_dump */
List_len, /* doh_len */
0, /* doh_hash */
0, /* doh_cmp */
0, /* doh_equal */
List_first, /* doh_first */
List_next, /* doh_next */
List_setfile, /* doh_setfile */
List_getfile, /* doh_getfile */
List_setline, /* doh_setline */
List_getline, /* doh_getline */
0, /* doh_mapping */
&ListListMethods, /* doh_sequence */
0, /* doh_file */
0, /* doh_string */
0, /* doh_callable */
0, /* doh_position */
"List", /* objname */
DelList, /* doh_del */
CopyList, /* doh_copy */
List_clear, /* doh_clear */
List_str, /* doh_str */
0, /* doh_data */
List_dump, /* doh_dump */
List_len, /* doh_len */
0, /* doh_hash */
0, /* doh_cmp */
0, /* doh_equal */
List_first, /* doh_first */
List_next, /* doh_next */
List_setfile, /* doh_setfile */
List_getfile, /* doh_getfile */
List_setline, /* doh_setline */
List_getline, /* doh_getline */
0, /* doh_mapping */
&ListListMethods, /* doh_sequence */
0, /* doh_file */
0, /* doh_string */
0, /* doh_callable */
0, /* doh_position */
};
/* -----------------------------------------------------------------------------
@ -347,29 +345,28 @@ DohObjInfo DohListType = {
#define MAXLISTITEMS 8
DOH *
DohNewList() {
List *l;
int i;
l = (List *) DohMalloc(sizeof(List));
l->nitems = 0;
l->maxitems = MAXLISTITEMS;
l->items = (void **) DohMalloc(l->maxitems*sizeof(void *));
for (i = 0; i < MAXLISTITEMS; i++) {
l->items[i] = 0;
}
l->file = 0;
l->line = 0;
return DohObjMalloc(&DohListType,l);
DOH *DohNewList() {
List *l;
int i;
l = (List *) DohMalloc(sizeof(List));
l->nitems = 0;
l->maxitems = MAXLISTITEMS;
l->items = (void **) DohMalloc(l->maxitems * sizeof(void *));
for (i = 0; i < MAXLISTITEMS; i++) {
l->items[i] = 0;
}
l->file = 0;
l->line = 0;
return DohObjMalloc(&DohListType, l);
}
static int (*List_sort_compare_func)(const DOH *, const DOH *);
static int (*List_sort_compare_func) (const DOH *, const DOH *);
static int List_qsort_compare(const void *a, const void *b) {
return List_sort_compare_func(*((DOH **)a), *((DOH **)b));
return List_sort_compare_func(*((DOH **) a), *((DOH **) b));
}
/* Sort a list */
void DohSortList(DOH *lo, int (*cmp)(const DOH *, const DOH *)) {
void DohSortList(DOH *lo, int (*cmp) (const DOH *, const DOH *)) {
List *l = (List *) ObjData(lo);
if (cmp) {
List_sort_compare_func = cmp;

View file

@ -18,40 +18,39 @@ char cvsroot_memory_c[] = "$Header$";
#define DOH_POOL_SIZE 16384
#endif
static int PoolSize = DOH_POOL_SIZE;
static int PoolSize = DOH_POOL_SIZE;
DOH *DohNone = 0; /* The DOH None object */
DOH *DohNone = 0; /* The DOH None object */
typedef struct pool {
DohBase *ptr; /* Start of pool */
int len; /* Length of pool */
int blen; /* Byte length of pool */
int current; /* Current position for next allocation */
char* pbeg; /* Beg of pool */
char* pend; /* End of pool */
struct pool *next; /* Next pool */
DohBase *ptr; /* Start of pool */
int len; /* Length of pool */
int blen; /* Byte length of pool */
int current; /* Current position for next allocation */
char *pbeg; /* Beg of pool */
char *pend; /* End of pool */
struct pool *next; /* Next pool */
} Pool;
static DohBase *FreeList = 0; /* List of free objects */
static Pool *Pools = 0;
static int pools_initialized = 0;
static DohBase *FreeList = 0; /* List of free objects */
static Pool *Pools = 0;
static int pools_initialized = 0;
/* ----------------------------------------------------------------------
* CreatePool() - Create a new memory pool
* ---------------------------------------------------------------------- */
static void
CreatePool() {
static void CreatePool() {
Pool *p = 0;
p = (Pool *) DohMalloc(sizeof(Pool));
assert(p);
p->ptr = (DohBase *) DohMalloc(sizeof(DohBase)*PoolSize);
p->ptr = (DohBase *) DohMalloc(sizeof(DohBase) * PoolSize);
assert(p->ptr);
memset(p->ptr,0,sizeof(DohBase)*PoolSize);
memset(p->ptr, 0, sizeof(DohBase) * PoolSize);
p->len = PoolSize;
p->blen = PoolSize*sizeof(DohBase);
p->blen = PoolSize * sizeof(DohBase);
p->current = 0;
p->pbeg = ((char *)p->ptr);
p->pbeg = ((char *) p->ptr);
p->pend = p->pbeg + p->blen;
p->next = Pools;
Pools = p;
@ -61,12 +60,12 @@ CreatePool() {
* InitPools() - Initialize the memory allocator
* ---------------------------------------------------------------------- */
static void
InitPools() {
if (pools_initialized) return;
CreatePool(); /* Create initial pool */
static void InitPools() {
if (pools_initialized)
return;
CreatePool(); /* Create initial pool */
pools_initialized = 1;
DohNone = NewVoid(0,0); /* Create the None object */
DohNone = NewVoid(0, 0); /* Create the None object */
DohIntern(DohNone);
}
@ -76,15 +75,15 @@ InitPools() {
* Returns 1 if an arbitrary pointer is a DOH object.
* ---------------------------------------------------------------------- */
int
DohCheck(const DOH *ptr) {
int DohCheck(const DOH *ptr) {
register Pool *p = Pools;
register char *cptr = (char *) ptr;
while (p) {
if ((cptr >= p->pbeg) && (cptr < p->pend)) return 1;
if ((cptr >= p->pbeg) && (cptr < p->pend))
return 1;
/*
pptr = (char *) p->ptr;
if ((cptr >= pptr) && (cptr < (pptr+(p->current*sizeof(DohBase))))) return 1; */
pptr = (char *) p->ptr;
if ((cptr >= pptr) && (cptr < (pptr+(p->current*sizeof(DohBase))))) return 1; */
p = p->next;
}
return 0;
@ -94,8 +93,7 @@ DohCheck(const DOH *ptr) {
* DohIntern()
* ----------------------------------------------------------------------------- */
void
DohIntern(DOH *obj) {
void DohIntern(DOH *obj) {
DohBase *b = (DohBase *) obj;
b->flag_intern = 1;
}
@ -106,10 +104,10 @@ DohIntern(DOH *obj) {
* Allocate memory for a new object.
* ---------------------------------------------------------------------- */
DOH *
DohObjMalloc(DohObjInfo *type, void *data) {
DOH *DohObjMalloc(DohObjInfo *type, void *data) {
DohBase *obj;
if (!pools_initialized) InitPools();
if (!pools_initialized)
InitPools();
if (FreeList) {
obj = FreeList;
FreeList = (DohBase *) obj->data;
@ -135,12 +133,12 @@ DohObjMalloc(DohObjInfo *type, void *data) {
* DohObjFree() - Free a DOH object
* ---------------------------------------------------------------------- */
void
DohObjFree(DOH *ptr) {
DohBase *b, *meta;
void DohObjFree(DOH *ptr) {
DohBase *b, *meta;
b = (DohBase *) ptr;
if (b->flag_intern) return;
meta = (DohBase *)b->meta;
if (b->flag_intern)
return;
meta = (DohBase *) b->meta;
b->data = (void *) FreeList;
b->meta = 0;
b->type = 0;
@ -156,42 +154,45 @@ DohObjFree(DOH *ptr) {
* Display memory usage statistics
* ---------------------------------------------------------------------- */
void
DohMemoryDebug(void) {
void DohMemoryDebug(void) {
extern DohObjInfo DohStringType;
extern DohObjInfo DohListType;
extern DohObjInfo DohHashType;
Pool *p;
int totsize = 0;
int totused = 0;
int totfree = 0;
int totsize = 0;
int totused = 0;
int totfree = 0;
int numstring = 0;
int numlist = 0;
int numhash = 0;
int numstring = 0;
int numlist = 0;
int numhash = 0;
printf("Memory statistics:\n\n");
printf("Pools:\n");
p = Pools;
while(p) {
while (p) {
/* Calculate number of used, free items */
int i;
int nused = 0, nfree = 0;
for (i = 0; i < p->len; i++) {
if (p->ptr[i].refcount <= 0) nfree++;
if (p->ptr[i].refcount <= 0)
nfree++;
else {
nused++;
if (p->ptr[i].type == &DohStringType) numstring++;
else if (p->ptr[i].type == &DohListType) numlist++;
else if (p->ptr[i].type == &DohHashType) numhash++;
if (p->ptr[i].type == &DohStringType)
numstring++;
else if (p->ptr[i].type == &DohListType)
numlist++;
else if (p->ptr[i].type == &DohHashType)
numhash++;
}
}
printf(" Pool %8p: size = %10d. used = %10d. free = %10d\n", (void *)p, p->len, nused, nfree);
printf(" Pool %8p: size = %10d. used = %10d. free = %10d\n", (void *) p, p->len, nused, nfree);
totsize += p->len;
totused+= nused;
totfree+= nfree;
totused += nused;
totfree += nfree;
p = p->next;
}
printf("\n Total: size = %10d, used = %10d, free = %10d\n", totsize, totused, totfree);
@ -203,12 +204,12 @@ DohMemoryDebug(void) {
#if 0
p = Pools;
while(p) {
while (p) {
int i;
for (i = 0; i < p->len; i++) {
if (p->ptr[i].refcount > 0) {
if (p->ptr[i].type == &DohStringType) {
Printf(stdout,"%s\n", p->ptr+i);
Printf(stdout, "%s\n", p->ptr + i);
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -15,8 +15,8 @@ char cvsroot_void_c[] = "$Header$";
#include "dohint.h"
typedef struct {
void *ptr;
void (*del)(void *);
void *ptr;
void (*del) (void *);
} VoidObj;
/* -----------------------------------------------------------------------------
@ -25,11 +25,10 @@ typedef struct {
* Delete a void object. Invokes the destructor supplied at the time of creation.
* ----------------------------------------------------------------------------- */
static void
Void_delete(DOH *vo) {
static void Void_delete(DOH *vo) {
VoidObj *v = (VoidObj *) ObjData(vo);
if (v->del)
(*v->del)(v->ptr);
(*v->del) (v->ptr);
DohFree(v);
}
@ -40,10 +39,9 @@ Void_delete(DOH *vo) {
* function is not copied in order to avoid potential double-free problems.
* ----------------------------------------------------------------------------- */
static DOH *
Void_copy(DOH *vo) {
static DOH *Void_copy(DOH *vo) {
VoidObj *v = (VoidObj *) ObjData(vo);
return NewVoid(v->ptr,0);
return NewVoid(v->ptr, 0);
}
/* -----------------------------------------------------------------------------
@ -52,36 +50,35 @@ Void_copy(DOH *vo) {
* Returns the void * stored in the object.
* ----------------------------------------------------------------------------- */
static void *
Void_data(DOH *vo) {
static void *Void_data(DOH *vo) {
VoidObj *v = (VoidObj *) ObjData(vo);
return v->ptr;
}
static DohObjInfo DohVoidType = {
"VoidObj", /* objname */
Void_delete, /* doh_del */
Void_copy, /* doh_copy */
0, /* doh_clear */
0, /* doh_str */
Void_data, /* doh_data */
0, /* doh_dump */
0, /* doh_len */
0, /* doh_hash */
0, /* doh_cmp */
0, /* doh_equal */
0, /* doh_first */
0, /* doh_next */
0, /* doh_setfile */
0, /* doh_getfile */
0, /* doh_setline */
0, /* doh_getline */
0, /* doh_mapping */
0, /* doh_sequence */
0, /* doh_file */
0, /* doh_string */
0, /* doh_reserved */
0, /* clientdata */
"VoidObj", /* objname */
Void_delete, /* doh_del */
Void_copy, /* doh_copy */
0, /* doh_clear */
0, /* doh_str */
Void_data, /* doh_data */
0, /* doh_dump */
0, /* doh_len */
0, /* doh_hash */
0, /* doh_cmp */
0, /* doh_equal */
0, /* doh_first */
0, /* doh_next */
0, /* doh_setfile */
0, /* doh_getfile */
0, /* doh_setline */
0, /* doh_getline */
0, /* doh_mapping */
0, /* doh_sequence */
0, /* doh_file */
0, /* doh_string */
0, /* doh_reserved */
0, /* clientdata */
};
/* -----------------------------------------------------------------------------
@ -90,11 +87,10 @@ static DohObjInfo DohVoidType = {
* Creates a new Void object given a void * and an optional destructor function.
* ----------------------------------------------------------------------------- */
DOH *
DohNewVoid(void *obj, void (*del)(void *)) {
DOH *DohNewVoid(void *obj, void (*del) (void *)) {
VoidObj *v;
v = (VoidObj *) DohMalloc(sizeof(VoidObj));
v->ptr = obj;
v->del = del;
return DohObjMalloc(&DohVoidType,v);
return DohObjMalloc(&DohVoidType, v);
}

View file

@ -84,53 +84,53 @@
#define WARN_PARSE_REDUNDANT 322
#define WARN_PARSE_REC_INHERITANCE 323
#define WARN_IGNORE_OPERATOR_NEW 350 /* new */
#define WARN_IGNORE_OPERATOR_DELETE 351 /* delete */
#define WARN_IGNORE_OPERATOR_PLUS 352 /* + */
#define WARN_IGNORE_OPERATOR_MINUS 353 /* - */
#define WARN_IGNORE_OPERATOR_MUL 354 /* * */
#define WARN_IGNORE_OPERATOR_DIV 355 /* / */
#define WARN_IGNORE_OPERATOR_MOD 356 /* % */
#define WARN_IGNORE_OPERATOR_XOR 357 /* ^ */
#define WARN_IGNORE_OPERATOR_AND 358 /* & */
#define WARN_IGNORE_OPERATOR_OR 359 /* | */
#define WARN_IGNORE_OPERATOR_NOT 360 /* ~ */
#define WARN_IGNORE_OPERATOR_LNOT 361 /* ! */
#define WARN_IGNORE_OPERATOR_EQ 362 /* = */
#define WARN_IGNORE_OPERATOR_LT 363 /* < */
#define WARN_IGNORE_OPERATOR_GT 364 /* > */
#define WARN_IGNORE_OPERATOR_PLUSEQ 365 /* += */
#define WARN_IGNORE_OPERATOR_MINUSEQ 366 /* -= */
#define WARN_IGNORE_OPERATOR_MULEQ 367 /* *= */
#define WARN_IGNORE_OPERATOR_DIVEQ 368 /* /= */
#define WARN_IGNORE_OPERATOR_MODEQ 369 /* %= */
#define WARN_IGNORE_OPERATOR_XOREQ 370 /* ^= */
#define WARN_IGNORE_OPERATOR_ANDEQ 371 /* &= */
#define WARN_IGNORE_OPERATOR_OREQ 372 /* |= */
#define WARN_IGNORE_OPERATOR_LSHIFT 373 /* << */
#define WARN_IGNORE_OPERATOR_RSHIFT 374 /* >> */
#define WARN_IGNORE_OPERATOR_LSHIFTEQ 375 /* <<= */
#define WARN_IGNORE_OPERATOR_RSHIFTEQ 376 /* >>= */
#define WARN_IGNORE_OPERATOR_EQUALTO 377 /* == */
#define WARN_IGNORE_OPERATOR_NOTEQUAL 378 /* != */
#define WARN_IGNORE_OPERATOR_LTEQUAL 379 /* <= */
#define WARN_IGNORE_OPERATOR_GTEQUAL 380 /* >= */
#define WARN_IGNORE_OPERATOR_LAND 381 /* && */
#define WARN_IGNORE_OPERATOR_LOR 382 /* || */
#define WARN_IGNORE_OPERATOR_PLUSPLUS 383 /* ++ */
#define WARN_IGNORE_OPERATOR_MINUSMINUS 384 /* -- */
#define WARN_IGNORE_OPERATOR_COMMA 385 /* , */
#define WARN_IGNORE_OPERATOR_ARROWSTAR 386 /* ->* */
#define WARN_IGNORE_OPERATOR_ARROW 387 /* -> */
#define WARN_IGNORE_OPERATOR_CALL 388 /* () */
#define WARN_IGNORE_OPERATOR_INDEX 389 /* [] */
#define WARN_IGNORE_OPERATOR_UPLUS 390 /* + */
#define WARN_IGNORE_OPERATOR_UMINUS 391 /* - */
#define WARN_IGNORE_OPERATOR_UMUL 392 /* * */
#define WARN_IGNORE_OPERATOR_UAND 393 /* & */
#define WARN_IGNORE_OPERATOR_NEWARR 394 /* new [] */
#define WARN_IGNORE_OPERATOR_DELARR 395 /* delete [] */
#define WARN_IGNORE_OPERATOR_REF 396 /* operator *() */
#define WARN_IGNORE_OPERATOR_NEW 350 /* new */
#define WARN_IGNORE_OPERATOR_DELETE 351 /* delete */
#define WARN_IGNORE_OPERATOR_PLUS 352 /* + */
#define WARN_IGNORE_OPERATOR_MINUS 353 /* - */
#define WARN_IGNORE_OPERATOR_MUL 354 /* * */
#define WARN_IGNORE_OPERATOR_DIV 355 /* / */
#define WARN_IGNORE_OPERATOR_MOD 356 /* % */
#define WARN_IGNORE_OPERATOR_XOR 357 /* ^ */
#define WARN_IGNORE_OPERATOR_AND 358 /* & */
#define WARN_IGNORE_OPERATOR_OR 359 /* | */
#define WARN_IGNORE_OPERATOR_NOT 360 /* ~ */
#define WARN_IGNORE_OPERATOR_LNOT 361 /* ! */
#define WARN_IGNORE_OPERATOR_EQ 362 /* = */
#define WARN_IGNORE_OPERATOR_LT 363 /* < */
#define WARN_IGNORE_OPERATOR_GT 364 /* > */
#define WARN_IGNORE_OPERATOR_PLUSEQ 365 /* += */
#define WARN_IGNORE_OPERATOR_MINUSEQ 366 /* -= */
#define WARN_IGNORE_OPERATOR_MULEQ 367 /* *= */
#define WARN_IGNORE_OPERATOR_DIVEQ 368 /* /= */
#define WARN_IGNORE_OPERATOR_MODEQ 369 /* %= */
#define WARN_IGNORE_OPERATOR_XOREQ 370 /* ^= */
#define WARN_IGNORE_OPERATOR_ANDEQ 371 /* &= */
#define WARN_IGNORE_OPERATOR_OREQ 372 /* |= */
#define WARN_IGNORE_OPERATOR_LSHIFT 373 /* << */
#define WARN_IGNORE_OPERATOR_RSHIFT 374 /* >> */
#define WARN_IGNORE_OPERATOR_LSHIFTEQ 375 /* <<= */
#define WARN_IGNORE_OPERATOR_RSHIFTEQ 376 /* >>= */
#define WARN_IGNORE_OPERATOR_EQUALTO 377 /* == */
#define WARN_IGNORE_OPERATOR_NOTEQUAL 378 /* != */
#define WARN_IGNORE_OPERATOR_LTEQUAL 379 /* <= */
#define WARN_IGNORE_OPERATOR_GTEQUAL 380 /* >= */
#define WARN_IGNORE_OPERATOR_LAND 381 /* && */
#define WARN_IGNORE_OPERATOR_LOR 382 /* || */
#define WARN_IGNORE_OPERATOR_PLUSPLUS 383 /* ++ */
#define WARN_IGNORE_OPERATOR_MINUSMINUS 384 /* -- */
#define WARN_IGNORE_OPERATOR_COMMA 385 /* , */
#define WARN_IGNORE_OPERATOR_ARROWSTAR 386 /* ->* */
#define WARN_IGNORE_OPERATOR_ARROW 387 /* -> */
#define WARN_IGNORE_OPERATOR_CALL 388 /* () */
#define WARN_IGNORE_OPERATOR_INDEX 389 /* [] */
#define WARN_IGNORE_OPERATOR_UPLUS 390 /* + */
#define WARN_IGNORE_OPERATOR_UMINUS 391 /* - */
#define WARN_IGNORE_OPERATOR_UMUL 392 /* * */
#define WARN_IGNORE_OPERATOR_UAND 393 /* & */
#define WARN_IGNORE_OPERATOR_NEWARR 394 /* new [] */
#define WARN_IGNORE_OPERATOR_DELARR 395 /* delete [] */
#define WARN_IGNORE_OPERATOR_REF 396 /* operator *() */
/* 394-399 are reserved */
@ -157,10 +157,10 @@
#define WARN_TYPEMAP_TYPECHECK 467
#define WARN_TYPEMAP_THROW 468
#define WARN_TYPEMAP_DIRECTORIN_UNDEF 469
#define WARN_TYPEMAP_THREAD_UNSAFE 470 /* mostly used in directorout typemaps */
#define WARN_TYPEMAP_THREAD_UNSAFE 470 /* mostly used in directorout typemaps */
#define WARN_TYPEMAP_DIRECTOROUT_UNDEF 471
#define WARN_TYPEMAP_TYPECHECK_UNDEF 472
#define WARN_TYPEMAP_DIRECTOROUT_PTR 473
#define WARN_TYPEMAP_DIRECTOROUT_PTR 473
/* -- Fragments -- */
#define WARN_FRAGMENT_NOT_FOUND 490
@ -171,7 +171,7 @@
#define WARN_LANG_OVERLOAD_CONSTRUCT 502
#define WARN_LANG_IDENTIFIER 503
#define WARN_LANG_RETURN_TYPE 504
#define WARN_LANG_VARARGS 505
#define WARN_LANG_VARARGS 505
#define WARN_LANG_VARARGS_KEYWORD 506
#define WARN_LANG_NATIVE_UNIMPL 507
#define WARN_LANG_DEREF_SHADOW 508
@ -254,6 +254,3 @@
add an entry here */
#endif

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -15,62 +15,60 @@ char cvsroot_browser_cxx[] = "$Header$";
#ifdef SWIG_SWILL
extern "C" {
#include "swill.h"
}
static FILE *out = 0;
} static FILE *out = 0;
static Node *view_top = 0;
class Browser : public Dispatcher {
class Browser:public Dispatcher {
void show_checkbox(Node *t, Node *n) {
int v = 0;
if (Getmeta(n,"visible")) {
if (Getmeta(n, "visible")) {
v = 1;
}
if (v) {
Printf(out,"<a name=\"n%x\"></a>[<a href=\"hide.html?node=0x%x&hn=0x%x#n%x\">-</a>] ", n, t, n,n);
Printf(out, "<a name=\"n%x\"></a>[<a href=\"hide.html?node=0x%x&hn=0x%x#n%x\">-</a>] ", n, t, n, n);
} else {
Printf(out,"<a name=\"n%x\"></a>[<a href=\"show.html?node=0x%x&hn=0x%x#n%x\">+</a>] ", n, t, n,n);
Printf(out, "<a name=\"n%x\"></a>[<a href=\"show.html?node=0x%x&hn=0x%x#n%x\">+</a>] ", n, t, n, n);
}
}
void show_attributes(Node *obj) {
if (!Getmeta(obj,"visible")) return;
if (!Getmeta(obj, "visible"))
return;
String *os = NewString("");
String *k;
Iterator ki;
ki = First(obj);
while (ki.key) {
k = ki.key;
if ((Cmp(k,"nodeType") == 0) || (Cmp(k,"firstChild") == 0) || (Cmp(k,"lastChild") == 0) ||
(Cmp(k,"parentNode") == 0) || (Cmp(k,"nextSibling") == 0) ||
(Cmp(k,"previousSibling") == 0) || (*(Char(k)) == '$')) {
if ((Cmp(k, "nodeType") == 0) || (Cmp(k, "firstChild") == 0) || (Cmp(k, "lastChild") == 0) ||
(Cmp(k, "parentNode") == 0) || (Cmp(k, "nextSibling") == 0) || (Cmp(k, "previousSibling") == 0) || (*(Char(k)) == '$')) {
/* Do nothing */
} else if (Cmp(k,"parms") == 0) {
} else if (Cmp(k, "parms") == 0) {
String *o = NewString("");
Printf(o,"%s", ParmList_protostr(Getattr(obj,k)));
Replaceall(o,"&","&amp;");
Replaceall(o,"<","&lt;");
Replaceall(o,">","&gt;");
Printf(os,"<a href=\"data.html?n=0x%x\">?</a> %-12s - %s\n", Getattr(obj,k), k, o);
Printf(o, "%s", ParmList_protostr(Getattr(obj, k)));
Replaceall(o, "&", "&amp;");
Replaceall(o, "<", "&lt;");
Replaceall(o, ">", "&gt;");
Printf(os, "<a href=\"data.html?n=0x%x\">?</a> %-12s - %s\n", Getattr(obj, k), k, o);
Delete(o);
} else {
DOH *o;
char *trunc = "";
if (DohIsString(Getattr(obj,k))) {
o = Str(Getattr(obj,k));
if (DohIsString(Getattr(obj, k))) {
o = Str(Getattr(obj, k));
if (Len(o) > 70) {
trunc = "...";
}
Replaceall(o,"&","&amp;");
Replaceall(o,"<","&lt;");
Printf(os,"<a href=\"data.html?n=0x%x\">?</a> %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj,k), k, o, trunc);
Replaceall(o, "&", "&amp;");
Replaceall(o, "<", "&lt;");
Printf(os, "<a href=\"data.html?n=0x%x\">?</a> %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj, k), k, o, trunc);
Delete(o);
} else {
Printf(os,"<a href=\"data.html?n=0x%x\">?</a> %-12s - 0x%x\n", Getattr(obj,k), k, Getattr(obj,k));
Printf(os, "<a href=\"data.html?n=0x%x\">?</a> %-12s - 0x%x\n", Getattr(obj, k), k, Getattr(obj, k));
}
}
ki = Next(ki);
}
Printf(out,"<FONT color=\"#660000\"><pre>\n%s</pre></FONT>\n", Char(os));
Printf(out, "<FONT color=\"#660000\"><pre>\n%s</pre></FONT>\n", Char(os));
Delete(os);
}
@ -78,24 +76,24 @@ public:
virtual int emit_one(Node *n) {
char *tag = Char(nodeType(n));
char *file = Char(Getfile(n));
int line = Getline(n);
char *name = GetChar(n,"name");
int line = Getline(n);
char *name = GetChar(n, "name");
show_checkbox(view_top, n);
Printf(out,"<b><a href=\"index.html?node=0x%x\">%s</a></b>", n, tag);
Printf(out, "<b><a href=\"index.html?node=0x%x\">%s</a></b>", n, tag);
if (name) {
Printf(out," (%s)", name);
Printf(out, " (%s)", name);
}
Printf(out,". %s:%d\n", file, line);
Printf(out,"<br>");
Printf(out, ". %s:%d\n", file, line);
Printf(out, "<br>");
Dispatcher::emit_one(n);
return SWIG_OK;
}
virtual int emit_children(Node *n) {
if (Getmeta(n,"visible")) {
Printf(out,"<blockquote>\n");
if (Getmeta(n, "visible")) {
Printf(out, "<blockquote>\n");
Dispatcher::emit_children(n);
Printf(out,"</blockquote>\n");
Printf(out, "</blockquote>\n");
}
return SWIG_OK;
}
@ -169,7 +167,7 @@ static Browser *browse = 0;
void exit_handler(FILE *f) {
browser_exit = 1;
Printf(f,"Terminated.\n");
Printf(f, "Terminated.\n");
}
/* ----------------------------------------------------------------------
@ -178,23 +176,23 @@ void exit_handler(FILE *f) {
static void display(FILE *f, Node *n) {
/* Print standard HTML header */
Printf(f,"<HTML><HEAD><TITLE>SWIG-%s</TITLE></HEAD><BODY BGCOLOR=\"#ffffff\">\n", PACKAGE_VERSION);
Printf(f,"<b>SWIG-%s</b><br>\n", PACKAGE_VERSION);
Printf(f,"[ <a href=\"exit.html\">Exit</a> ]");
Printf(f," [ <a href=\"index.html?node=0x%x\">Top</a> ]", tree_top);
Printf(f, "<HTML><HEAD><TITLE>SWIG-%s</TITLE></HEAD><BODY BGCOLOR=\"#ffffff\">\n", PACKAGE_VERSION);
Printf(f, "<b>SWIG-%s</b><br>\n", PACKAGE_VERSION);
Printf(f, "[ <a href=\"exit.html\">Exit</a> ]");
Printf(f, " [ <a href=\"index.html?node=0x%x\">Top</a> ]", tree_top);
if (n != tree_top) {
Printf(f," [ <a href=\"index.html?node=0x%x\">Up</a> ]", parentNode(n));
Printf(f, " [ <a href=\"index.html?node=0x%x\">Up</a> ]", parentNode(n));
}
Printf(f," [ <a href=\"symbol.html\">Symbols</a> ]");
Printf(f,"<br><hr><p>\n");
Printf(f, " [ <a href=\"symbol.html\">Symbols</a> ]");
Printf(f, "<br><hr><p>\n");
out = f;
browse->emit_one(n);
/* Print standard footer */
Printf(f,"<br><hr></BODY></HTML>\n");
Printf(f, "<br><hr></BODY></HTML>\n");
}
@ -204,7 +202,7 @@ void node_handler(FILE *f) {
n = tree_top;
}
view_top = n;
display(f,n);
display(f, n);
}
@ -218,7 +216,7 @@ void hide_handler(FILE *f) {
n = 0;
}
if (n) {
Delmeta(n,"visible");
Delmeta(n, "visible");
}
node_handler(f);
}
@ -229,65 +227,66 @@ void show_handler(FILE *f) {
n = 0;
}
if (n) {
Setmeta(n,"visible","1");
Setmeta(n, "visible", "1");
}
node_handler(f);
}
void raw_data(FILE *out, Node *obj) {
if (!obj) return;
if (!obj)
return;
if (DohIsMapping(obj)) {
String *k;
Iterator ki;
String *os = NewString("");
Printf(os,"Hash {\n");
Printf(os, "Hash {\n");
ki = First(obj);
while (ki.key) {
k = ki.key;
DOH *o;
const char *trunc = "";
if (DohIsString(Getattr(obj,k))) {
o = Str(Getattr(obj,k));
if (DohIsString(Getattr(obj, k))) {
o = Str(Getattr(obj, k));
if (Len(o) > 70) {
trunc = "...";
}
Replaceall(o,"<","&lt;");
Printf(os," <a href=\"data.html?n=0x%x\">?</a> %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj,k), k, o, trunc);
Replaceall(o, "<", "&lt;");
Printf(os, " <a href=\"data.html?n=0x%x\">?</a> %-12s - \"%(escape)-0.70s%s\"\n", Getattr(obj, k), k, o, trunc);
Delete(o);
} else {
Printf(os," <a href=\"data.html?n=0x%x\">?</a> %-12s - 0x%x\n", Getattr(obj,k), k, Getattr(obj,k));
Printf(os, " <a href=\"data.html?n=0x%x\">?</a> %-12s - 0x%x\n", Getattr(obj, k), k, Getattr(obj, k));
}
ki = Next(ki);
}
Printf(os,"}\n");
Printf(out,"<FONT color=\"#660000\"><pre>\n%s</pre></FONT>\n", Char(os));
Printf(os, "}\n");
Printf(out, "<FONT color=\"#660000\"><pre>\n%s</pre></FONT>\n", Char(os));
Delete(os);
} else if (DohIsString(obj)) {
String *o = Str(obj);
Replaceall(o,"<","&lt;");
Printf(out,"<FONT color=\"#660000\"><pre>\n%s</pre></FONT>\n", Char(o));
Replaceall(o, "<", "&lt;");
Printf(out, "<FONT color=\"#660000\"><pre>\n%s</pre></FONT>\n", Char(o));
Delete(o);
} else if (DohIsSequence(obj)) {
int i;
String *os = NewString("");
Printf(os,"List [\n");
Printf(os, "List [\n");
for (i = 0; i < Len(obj); i++) {
DOH *o = Getitem(obj,i);
DOH *o = Getitem(obj, i);
const char *trunc = "";
if (DohIsString(o)) {
String *s = Str(o);
if (Len(s) > 70) {
trunc = "...";
}
Replaceall(o,"<","&lt;");
Printf(os," <a href=\"data.html?n=0x%x\">?</a> [%d] - \"%(escape)-0.70s%s\"\n", o,i,s, trunc);
Replaceall(o, "<", "&lt;");
Printf(os, " <a href=\"data.html?n=0x%x\">?</a> [%d] - \"%(escape)-0.70s%s\"\n", o, i, s, trunc);
Delete(s);
} else {
Printf(os," <a href=\"data.html?n=0x%x\">?</a> [%d] - 0x%x\n", o, i, o);
Printf(os, " <a href=\"data.html?n=0x%x\">?</a> [%d] - 0x%x\n", o, i, o);
}
}
Printf(os,"\n]\n");
Printf(out,"<FONT color=\"#660000\"><pre>\n%s</pre></FONT>\n", Char(os));
Printf(os, "\n]\n");
Printf(out, "<FONT color=\"#660000\"><pre>\n%s</pre></FONT>\n", Char(os));
Delete(os);
}
}
@ -297,86 +296,85 @@ void data_handler(FILE *f) {
if (!swill_getargs("p(n)", &n)) {
n = 0;
}
Printf(f,"<HTML><HEAD><TITLE>SWIG-%s</TITLE></HEAD><BODY BGCOLOR=\"#ffffff\">\n", PACKAGE_VERSION);
Printf(f,"<b>SWIG-%s</b><br>\n", PACKAGE_VERSION);
Printf(f,"[ <a href=\"exit.html\">Exit</a> ]");
Printf(f," [ <a href=\"index.html?node=0x%x\">Top</a> ]", tree_top);
Printf(f,"<br><hr><p>\n");
Printf(f, "<HTML><HEAD><TITLE>SWIG-%s</TITLE></HEAD><BODY BGCOLOR=\"#ffffff\">\n", PACKAGE_VERSION);
Printf(f, "<b>SWIG-%s</b><br>\n", PACKAGE_VERSION);
Printf(f, "[ <a href=\"exit.html\">Exit</a> ]");
Printf(f, " [ <a href=\"index.html?node=0x%x\">Top</a> ]", tree_top);
Printf(f, "<br><hr><p>\n");
if (n) {
raw_data(f,n);
raw_data(f, n);
}
/* Print standard footer */
Printf(f,"<br><hr></BODY></HTML>\n");
Printf(f, "<br><hr></BODY></HTML>\n");
}
void symbol_handler(FILE *f) {
Symtab *sym;
char *name = 0;
char *name = 0;
Printf(f, "<HTML><HEAD><TITLE>SWIG-%s</TITLE></HEAD><BODY BGCOLOR=\"#ffffff\">\n", PACKAGE_VERSION);
Printf(f, "<b>SWIG-%s</b><br>\n", PACKAGE_VERSION);
Printf(f, "[ <a href=\"exit.html\">Exit</a> ]");
Printf(f, " [ <a href=\"index.html?node=0x%x\">Top</a> ]", tree_top);
Printf(f, " [ <a href=\"symbol.html\">Symbols</a> ]");
Printf(f, "<br><hr><p>\n");
Printf(f,"<HTML><HEAD><TITLE>SWIG-%s</TITLE></HEAD><BODY BGCOLOR=\"#ffffff\">\n", PACKAGE_VERSION);
Printf(f,"<b>SWIG-%s</b><br>\n", PACKAGE_VERSION);
Printf(f,"[ <a href=\"exit.html\">Exit</a> ]");
Printf(f," [ <a href=\"index.html?node=0x%x\">Top</a> ]", tree_top);
Printf(f," [ <a href=\"symbol.html\">Symbols</a> ]");
Printf(f,"<br><hr><p>\n");
if (!swill_getargs("p(sym)|s(name)", &sym, &name)) {
sym = Swig_symbol_getscope("");
name = 0;
}
if (!sym) {
Printf(f,"No symbol table specified!\n");
Printf(f, "No symbol table specified!\n");
return;
}
{
String *q = Swig_symbol_qualifiedscopename(sym);
if (!Len(q)) {
Printf(f,"<b>Symbol table: :: (global)</b><br>\n");
Printf(f, "<b>Symbol table: :: (global)</b><br>\n");
} else {
Printf(f,"<b>Symbol table: %s</b><br>\n", q);
Printf(f, "<b>Symbol table: %s</b><br>\n", q);
}
Delete(q);
}
fprintf(f,"<p><form action=\"symbol.html\" method=GET>\n");
fprintf(f,"Symbol lookup: <input type=text name=name size=40></input><br>\n");
fprintf(f,"<input type=hidden name=sym value=\"0x%x\">\n", sym);
fprintf(f,"Submit : <input type=submit></input>\n");
fprintf(f,"</form>");
fprintf(f, "<p><form action=\"symbol.html\" method=GET>\n");
fprintf(f, "Symbol lookup: <input type=text name=name size=40></input><br>\n");
fprintf(f, "<input type=hidden name=sym value=\"0x%x\">\n", sym);
fprintf(f, "Submit : <input type=submit></input>\n");
fprintf(f, "</form>");
if (name) {
Node *n = Swig_symbol_clookup(name,sym);
Printf(f,"Symbol '%s':\n", name);
Printf(f,"<blockquote>\n");
Node *n = Swig_symbol_clookup(name, sym);
Printf(f, "Symbol '%s':\n", name);
Printf(f, "<blockquote>\n");
if (!n) {
Printf(f,"Not defined!\n");
Printf(f, "Not defined!\n");
} else {
raw_data(f,n);
raw_data(f, n);
}
Printf(f,"</blockquote>\n");
Printf(f, "</blockquote>\n");
}
Printf(f,"<p><b>Nested scopes</b><br>\n");
Printf(f,"<blockquote><pre>\n");
Printf(f, "<p><b>Nested scopes</b><br>\n");
Printf(f, "<blockquote><pre>\n");
{
Hash *h;
Hash *h;
h = firstChild(sym);
while (h) {
Printf(f,"<a href=\"symbol.html?sym=0x%x\">%s</a>\n", h, Getattr(h,"name"));
Printf(f, "<a href=\"symbol.html?sym=0x%x\">%s</a>\n", h, Getattr(h, "name"));
h = nextSibling(h);
}
}
Printf(f,"</pre></blockquote>\n");
Printf(f,"<p><b>Symbol table contents</b></br>\n");
raw_data(f,Getattr(sym,"symtab"));
Printf(f,"<br><hr></BODY></HTML>\n");
Printf(f, "</pre></blockquote>\n");
Printf(f, "<p><b>Symbol table contents</b></br>\n");
raw_data(f, Getattr(sym, "symtab"));
Printf(f, "<br><hr></BODY></HTML>\n");
}
#endif
void
Swig_browser(Node *top, int port) {
void Swig_browser(Node *top, int port) {
#ifdef SWIG_SWILL
int sport;
browser_exit = 0;
@ -384,37 +382,32 @@ Swig_browser(Node *top, int port) {
/* Initialize the server */
sport = swill_init(port);
if (sport < 0) {
Printf(stderr,"Couldn't open socket on port %d. Sorry.\n", port);
Printf(stderr, "Couldn't open socket on port %d. Sorry.\n", port);
return;
}
browse = new Browser();
Setmeta(top,"visible","1");
Setmeta(top, "visible", "1");
tree_top = top;
Printf(stderr,"SWIG: Tree browser listening on port %d\n", sport);
Printf(stderr, "SWIG: Tree browser listening on port %d\n", sport);
swill_handle("exit.html", exit_handler,0);
swill_handle("exit.html", exit_handler, 0);
swill_handle("index.html", node_handler, 0);
swill_handle("hide.html", hide_handler,0);
swill_handle("show.html", show_handler,0);
swill_handle("data.html", data_handler,0);
swill_handle("hide.html", hide_handler, 0);
swill_handle("show.html", show_handler, 0);
swill_handle("data.html", data_handler, 0);
swill_handle("symbol.html", symbol_handler, 0);
swill_netscape("index.html");
while (!browser_exit) {
swill_serve();
}
Printf(stderr,"Browser terminated.\n");
Printf(stderr, "Browser terminated.\n");
swill_close();
delete browse;
return;
#else
(void)top;
(void)port;
(void) top;
(void) port;
#endif
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

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