From df7ba1da836ebfb59b22ad2ee93d10e76f025903 Mon Sep 17 00:00:00 2001 From: Dave Beazley Date: Wed, 19 Jan 2000 23:35:55 +0000 Subject: [PATCH] A bunch of cleanup git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@126 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/DOH/Doh/base.c | 1190 ++++++++++++++++++++++--------------- Source/DOH/Doh/callable.c | 45 +- Source/DOH/Doh/file.c | 18 +- Source/DOH/Doh/list.c | 54 +- Source/DOH/Doh/memory.c | 10 +- Source/DOH/Doh/string.c | 13 +- Source/DOH/Include/doh.h | 34 +- Source/LParse/cscanner.c | 8 +- Source/LParse/parser.y | 2 + Source/LParse/type.c | 1 - 10 files changed, 839 insertions(+), 536 deletions(-) diff --git a/Source/DOH/Doh/base.c b/Source/DOH/Doh/base.c index d08f5a030..58f8fda44 100644 --- a/Source/DOH/Doh/base.c +++ b/Source/DOH/Doh/base.c @@ -1,45 +1,23 @@ -/**************************************************************************** - * DOH (Dynamic Object Hack) +/****************************************************************************** + * DOH * - * Author : David Beazley + * Author(s) : David Beazley (beazley@cs.uchicago.edu) * - * Department of Computer Science - * University of Chicago - * 1100 E 58th Street - * Chicago, IL 60637 - * beazley@cs.uchicago.edu - * - * Please read the file LICENSE for the copyright and terms by which DOH - * can be used and distributed. - ****************************************************************************/ + * Copyright (C) 1999-2000. The University of Chicago + * See the file LICENSE for information on usage and redistribution. + ******************************************************************************/ static char cvsroot[] = "$Header$"; /******************************************************************************* - * File : base.c + * base.c * - * This file contains all of the basic DOH methods. These functions really - * just dispatch to the methods for each object. + * This file contains the function entry points for dispatching methods on DOH + * objects. *******************************************************************************/ #include "dohint.h" -int doh_debug_level = 0; - -void DohError(int level, char *fmt, ...) { - va_list ap; - va_start(ap,fmt); - if (level <= doh_debug_level) { - printf("DOH %d:",level); - vprintf(fmt,ap); - } - va_end(ap); -} - -void DohDebug(int d) { - doh_debug_level = d; -} - static DohObjInfo DohBaseType = { "Base", /* objname */ sizeof(DohBase), /* objsize */ @@ -68,313 +46,428 @@ static DohObjInfo DohBaseType = { 0, /* user4 */ }; +static int doh_debug_level = 0; + /* ----------------------------------------------------------------------------- - String interning. This is used for getattr,setattr functions. + * DohTrace() + * + * This function is used to print tracing information during debugging. + * ----------------------------------------------------------------------------- */ - The following structure maps raw char * entries to string objects. - ----------------------------------------------------------------------------- */ - -typedef struct StringNode { - char *cstr; - DOH *sstr; - struct StringNode *left; - struct StringNode *right; -} StringNode; - -static StringNode *root = 0; - -static DOH *find_internal(DOH *co) { - StringNode *r, *s; - int d; - char *c; - DOH *n; - if (DohCheck(co)) return co; - c = (char *) co; - n = NewString(c); - return n; +void +DohTrace(int level, char *fmt, ...) { + va_list ap; + va_start(ap,fmt); + if (level & doh_debug_level) { + printf("DOH %x:", level); + vprintf(fmt,ap); + } + va_end(ap); } -/* Destroy an object */ -void DohDelete(DOH *obj) { - DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohDestroy %x\n",obj); - if (!DohCheck(b)) return; - if (b->flags & DOH_FLAG_INTERN) return; - b->refcount--; - if (b->refcount == 0) { - if (b->objinfo->doh_del) { - (b->objinfo->doh_del)(obj); - } - return; - } +/* ----------------------------------------------------------------------------- + * DohDebug() + * + * Set the DOH tracing level. + * ----------------------------------------------------------------------------- */ + +void +DohDebug(int d) { + doh_debug_level = d; } -void DohIntern(DOH *obj) { +/* ----------------------------------------------------------------------------- + * DohDelete() + * + * Delete an object by decreasing its reference count. Calls the object + * destructor if the reference count is zero after the decrement. + * ----------------------------------------------------------------------------- */ + +void +DohDelete(DOH *obj) { DohBase *b = (DohBase *) obj; + DohTrace(DOH_CALLS,"DohDelete %x\n",obj); + if (!DohCheck(b)) return; + if (b->flags & DOH_FLAG_INTERN) return; + b->refcount--; + if (b->refcount == 0) { + if (b->objinfo->doh_del) (b->objinfo->doh_del)(obj); + } +} + +/* ----------------------------------------------------------------------------- + * DohIntern() + * + * Flips the intern bit on an object forcing it to be never be garbage collected. + * ----------------------------------------------------------------------------- */ + +void +DohIntern(DOH *obj) { + DohBase *b = (DohBase *) obj; + DohTrace(DOH_CALLS,"DohIntern %x\n", obj); if (!DohCheck(b)) return; b->flags = b->flags | DOH_FLAG_INTERN; } -/* Copy an object */ -DOH *DohCopy(DOH *obj) { - DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohCopy %x\n",obj); - if (!DohCheck(b)) { - DohError(DOH_UNKNOWN,"Unknown object %x passed to Copy.\n", obj); - return 0; - } - if (b->objinfo->doh_copy) { - return (b->objinfo->doh_copy)(obj); - } - DohError(DOH_UNSUPPORTED,"No copy method defined for type '%s'\n", b->objinfo->objname); - return 0; -} +/* ----------------------------------------------------------------------------- + * DohCopy() + * + * Make a copy of an object. + * ----------------------------------------------------------------------------- */ -void DohClear(DOH *obj) { - DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohClear %x\n",obj); - if (!DohCheck(b)) { - DohError(DOH_UNKNOWN,"Unknown object %x passed to Clear.\n",obj); - return; - } - if (b->objinfo->doh_clear) { - (b->objinfo->doh_clear)(obj); - return; - } - DohError(DOH_UNSUPPORTED, "No clear method defined for type '%s'\n", b->objinfo->objname); -} - -void DohSetScope(DOH *obj, int s) { - DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohScope %x\n",obj); - if (!DohCheck(b)) { - DohError(DOH_UNKNOWN,"Unknown object %x passed to Scope.\n",obj); - return; - } - if (b->objinfo->doh_scope) { - (b->objinfo->doh_scope)(obj,s); - return; - } - if (s < b->scope) b->scope = s; -} - -/* Turn an object into a string */ -DOH *DohStr(DOH *obj) { - DOH *s; - DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohStr %x\n",obj); - if (DohCheck(b)) { - if (b->objinfo->doh_str) { - return (b->objinfo->doh_str)(b); - } - s = NewString("", b->objinfo->objname, b); - return s; - } else { - DohError(DOH_CONVERSION, "Creating new string from unknown object %x (assuming char *).\n", obj); - return NewString(obj); - } -} - -/* Serialize an object */ -int DohDump(DOH *obj, DOH *out) { +DOH * +DohCopy(DOH *obj) { DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohDump %x, %x\n",obj,out); + DohTrace(DOH_CALLS,"DohCopy %x\n",obj); + if (!DohCheck(b)) { + DohTrace(DOH_UNKNOWN,"Unknown object %x passed to Copy.\n", obj); + return 0; + } + if (b->objinfo->doh_copy) return (b->objinfo->doh_copy)(obj); + DohTrace(DOH_UNSUPPORTED,"No copy method defined for type '%s'\n", b->objinfo->objname); + return 0; +} + +/* ----------------------------------------------------------------------------- + * DohClear() + * + * Clear the contents of an object. + * ----------------------------------------------------------------------------- */ + +void +DohClear(DOH *obj) { + DohBase *b = (DohBase *) obj; + DohTrace(DOH_CALLS,"DohClear %x\n",obj); + if (!DohCheck(b)) { + DohTrace(DOH_UNKNOWN,"Unknown object %x passed to Clear.\n",obj); + return; + } + if (b->objinfo->doh_clear) { + (b->objinfo->doh_clear)(obj); + return; + } + DohTrace(DOH_UNSUPPORTED, "No clear method defined for type '%s'\n", b->objinfo->objname); +} + +/* ----------------------------------------------------------------------------- + * DohSetScope() + * + * Manually change the scope level of an object. + * ----------------------------------------------------------------------------- */ + +void +DohSetScope(DOH *obj, int s) { + DohBase *b = (DohBase *) obj; + DohTrace(DOH_CALLS,"DohScope %x\n",obj); + if (!DohCheck(b)) { + DohTrace(DOH_UNKNOWN,"Unknown object %x passed to Scope.\n",obj); + return; + } + if (b->objinfo->doh_scope) { + (b->objinfo->doh_scope)(obj,s); + return; + } + if (s < b->scope) b->scope = s; +} + +/* ----------------------------------------------------------------------------- + * DohStr() + * + * Create a string representation of an object. If the object has no str method + * a generic representation of the form is created. + * Non-DOH objects are assumed to + * ----------------------------------------------------------------------------- */ + +DOH * +DohStr(DOH *obj) { + DOH *s; + DohBase *b = (DohBase *) obj; + DohTrace(DOH_CALLS,"DohStr %x\n",obj); + if (DohCheck(b)) { + if (b->objinfo->doh_str) { + return (b->objinfo->doh_str)(b); + } + s = NewString("", b->objinfo->objname, b); + Seek(s,0,SEEK_SET); + return s; + } else { + DohTrace(DOH_CONVERSION, "Creating new string from unknown object %x (assuming char *).\n", obj); + return NewString(obj); + } +} + +/* ----------------------------------------------------------------------------- + * DohDump() + * + * Serialize an object onto an output stream. + * ----------------------------------------------------------------------------- */ + +int +DohDump(DOH *obj, DOH *out) { + DohBase *b = (DohBase *) obj; + DohTrace(DOH_CALLS,"DohDump %x, %x\n",obj,out); if (DohCheck(obj)) { if (b->objinfo->doh_dump) { return (b->objinfo->doh_dump)(b,out); } - DohError(DOH_UNSUPPORTED,"No dump method defined for type '%s'\n", b->objinfo->objname); + DohTrace(DOH_UNSUPPORTED,"No dump method defined for type '%s'\n", b->objinfo->objname); } else { - DohError(DOH_UNKNOWN, "Unknown object %x passed to Dump.\n",obj); + DohTrace(DOH_UNKNOWN, "Unknown object %x passed to Dump.\n",obj); } return 0; } -/* Get the length */ -int DohLen(DOH *obj) { - DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohLen %x\n",obj); - if (!b) return 0; - if (DohCheck(b)) { - if (b->objinfo->doh_len) { - return (b->objinfo->doh_len)(obj); - } - DohError(DOH_UNSUPPORTED, "No len method defined for type '%s'\n", b->objinfo->objname); - } else { - DohError(DOH_CONVERSION, "Using strlen() on unknown object %x.\n", obj); - return strlen((char *) obj); - } - return 0; -} - -/* Get the hash value */ -int DohHashval(DOH *obj) { - DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohHashval %x\n",obj); - if (DohCheck(b)) { - if (b->objinfo->doh_hash) { - return (b->objinfo->doh_hash)(obj); - } - DohError(DOH_UNSUPPORTED,"No hash method defined for type '%s'\n", b->objinfo->objname); - } else { - DohError(DOH_UNKNOWN,"Unknown object %x passed to Hashval.\n", obj); - } - return 0; -} - -/* Get raw data */ -void *DohData(DOH *obj) { - char *c; - DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohData %x\n",obj); - c = (char *) obj; - if (DohCheck(c)) { - if (b->objinfo) { - if (b->objinfo->doh_data) { - return (b->objinfo->doh_data)(obj); - } - } - DohError(DOH_UNSUPPORTED,"No data method defined for type '%s'\n", b->objinfo->objname); - return 0; - } else { - DohError(DOH_CONVERSION, "Unknown object %x passed to Data being returned as-is.\n", obj); - } - return c; -} - -/* Get the line number */ -int DohGetline(DOH *obj) { +/* ----------------------------------------------------------------------------- + * DohLen() + * + * Return the length of an object. If a non-DOH object is passed, strlen() + * is invoked on it. + * ----------------------------------------------------------------------------- */ +int +DohLen(DOH *obj) { DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohGetline %x\n",obj); + DohTrace(DOH_CALLS,"DohLen %x\n",obj); + if (!b) return 0; + if (DohCheck(b)) { + if (b->objinfo->doh_len) { + return (b->objinfo->doh_len)(obj); + } + DohTrace(DOH_UNSUPPORTED, "No len method defined for type '%s'\n", b->objinfo->objname); + } else { + DohTrace(DOH_CONVERSION, "Using strlen() on unknown object %x.\n", obj); + return strlen((char *) obj); + } + return 0; +} + +/* ----------------------------------------------------------------------------- + * DohHashVal() + * + * Compute the integer hash value of an object. Only needed for objects that + * need to serve as a keys. + * ----------------------------------------------------------------------------- */ + +int +DohHashval(DOH *obj) { + DohBase *b = (DohBase *) obj; + DohTrace(DOH_CALLS,"DohHashval %x\n",obj); + if (DohCheck(b)) { + if (b->objinfo->doh_hash) { + return (b->objinfo->doh_hash)(obj); + } + DohTrace(DOH_UNSUPPORTED,"No hash method defined for type '%s'\n", b->objinfo->objname); + } else { + DohTrace(DOH_UNKNOWN,"Unknown object %x passed to Hashval.\n", obj); + } + return 0; +} + +/* ----------------------------------------------------------------------------- + * DohData() + * + * Return pointer to the raw data stored inside an object (when applicable). + * ----------------------------------------------------------------------------- */ + +void * +DohData(DOH *obj) { + DohBase *b = (DohBase *) obj; + DohTrace(DOH_CALLS,"DohData %x\n",obj); + if (DohCheck(obj)) { + if (b->objinfo) { + if (b->objinfo->doh_data) { + return (b->objinfo->doh_data)(obj); + } + } + DohTrace(DOH_UNSUPPORTED,"No data method defined for type '%s'\n", b->objinfo->objname); + return 0; + } + DohTrace(DOH_CONVERSION, "Unknown object %x passed to Data being returned as-is.\n", obj); + return (char *) obj; +} + +/* ----------------------------------------------------------------------------- + * DohGetLine() + * + * Return the line number associated with an object or -1 if unspecified. + * ----------------------------------------------------------------------------- */ + +int +DohGetline(DOH *obj) { + DohBase *b = (DohBase *) obj; + DohTrace(DOH_CALLS,"DohGetline %x\n",obj); if (DohCheck(obj)) { if (b->objinfo->doh_position && b->objinfo->doh_position->doh_getline) { return (b->objinfo->doh_position->doh_getline)(obj); + } else { + DohTrace(DOH_UNSUPPORTED,"No getline method defined for type '%s'\n", b->objinfo->objname); + return -1; } - } else { - DohError(DOH_UNKNOWN, "Unknown object %x passed to Getline.\n", obj); } - return 0; + DohTrace(DOH_UNKNOWN, "Unknown object %x passed to Getline.\n", obj); + return -1; } -/* Set the line number */ -void DohSetline(DOH *obj, int line) { +/* ----------------------------------------------------------------------------- + * DohSetLine() + * + * Set the line number associated with an object. + * ----------------------------------------------------------------------------- */ + +void +DohSetline(DOH *obj, int line) { DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohSetline %x, %d\n",obj, line); + DohTrace(DOH_CALLS,"DohSetline %x, %d\n",obj, line); if (DohCheck(obj)) { if (b->objinfo->doh_position && b->objinfo->doh_position->doh_setline) { (b->objinfo->doh_position->doh_setline)(obj, line); return; } + DohTrace(DOH_UNSUPPORTED,"No setline method defined for type '%s'\n", b->objinfo->objname); } else { - DohError(DOH_UNKNOWN, "Unknown object %x passed to Setline.\n", obj); + DohTrace(DOH_UNKNOWN, "Unknown object %x passed to Setline.\n", obj); } } -/* Get the file name */ -DOH *DohGetfile(DOH *obj) { +/* ----------------------------------------------------------------------------- + * DohGetfile() + * + * Get the file associated with an object. + * ----------------------------------------------------------------------------- */ + +DOH * +DohGetfile(DOH *obj) { DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohGetfile %x\n",obj); + DohTrace(DOH_CALLS,"DohGetfile %x\n",obj); if (DohCheck(obj)) { if (b->objinfo->doh_position && b->objinfo->doh_position->doh_getfile) { return (b->objinfo->doh_position->doh_getfile)(obj); } + DohTrace(DOH_UNSUPPORTED,"No getfile method defined for type '%s'\n", b->objinfo->objname); } else { - DohError(DOH_UNKNOWN, "Unknown object %x passed to Getfile.\n", obj); + DohTrace(DOH_UNKNOWN, "Unknown object %x passed to Getfile.\n", obj); } return 0; } -/* Set the file */ -void DohSetfile(DOH *obj, DOH *file) { - DOH *nf = 0; +/* ----------------------------------------------------------------------------- + * DohSetfile() + * + * Set the file associated with an object. + * ----------------------------------------------------------------------------- */ + +void +DohSetfile(DOH *obj, DOH *file) { DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohSetfile %x, %x\n",obj,file); + DohTrace(DOH_CALLS,"DohSetfile %x, %x\n",obj,file); if (DohCheck(obj)) { if (b->objinfo->doh_position && b->objinfo->doh_position->doh_setfile) { (b->objinfo->doh_position->doh_setfile)(obj,file); return; } + DohTrace(DOH_UNSUPPORTED,"No setfile method defined for type '%s'\n", b->objinfo->objname); } else { - DohError(DOH_UNKNOWN, "Unknown object %x passed to Setfile.\n", obj); + DohTrace(DOH_UNKNOWN, "Unknown object %x passed to Setfile.\n", obj); } } -/* Get an attribute from an object */ -int DohCmp(DOH *obj1, DOH *obj2) { - DohBase *b1, *b2; - DohError(DOH_CALLS,"DohCmp %x, %x\n",obj1,obj2); - b1 = (DohBase *) obj1; - b2 = (DohBase *) obj2; - if (!DohCheck(b1)) { - b1 = find_internal(b1); - } - if (!DohCheck(b2)) { - b2 = find_internal(b2); - } - if (b1->objinfo == b2->objinfo) { - if (b1->objinfo->doh_cmp) { - return (b1->objinfo->doh_cmp)(b1,b2); - } - DohError(DOH_UNSUPPORTED,"No cmp method defined for type '%s'\n", b1->objinfo->objname); - return 1; - } - DohError(DOH_UNSUPPORTED,"Can't compare type '%s' with type '%s'\n", b1->objinfo->objname, b2->objinfo->objname); - return 1; +/* ----------------------------------------------------------------------------- + * DohCmp() + * + * Compare two objects. If either of the objects are non-DOH objects, the + * objects are compared using strcmp(). + * ----------------------------------------------------------------------------- */ + +int +DohCmp(DOH *obj1, DOH *obj2) { + DohBase *b1, *b2; + DohTrace(DOH_CALLS,"DohCmp %x, %x\n",obj1,obj2); + b1 = (DohBase *) obj1; + b2 = (DohBase *) obj2; + if ((!DohCheck(b1)) || (!DohCheck(b2))) { + return strcmp((char *) DohData(b1),(char *) DohData(b2)); + } + if (b1->objinfo->doh_cmp) { + return (b1->objinfo->doh_cmp)(b1,b2); + } + DohTrace(DOH_UNSUPPORTED,"No cmp method defined for type '%s'\n", b1->objinfo->objname); + return 1; } /* ---------------------------------------------------------------------- * Mapping Interface * ---------------------------------------------------------------------- */ -int DohIsMapping(DOH *obj) { +/* ----------------------------------------------------------------------------- + * DohIsMapping() + * + * Return 1 if an object defines a mapping interface. + * ----------------------------------------------------------------------------- */ + +int +DohIsMapping(DOH *obj) { DohBase *b = (DohBase *) obj; if (!DohCheck(b)) return 0; if (b->objinfo->doh_mapping) return 1; else return 0; } -/* Get an attribute from an object */ -DOH *DohGetattr(DOH *obj, DOH *name) { +/* ----------------------------------------------------------------------------- + * DohGetattr() + * + * Get an attribute from a mapping object. + * ----------------------------------------------------------------------------- */ + +DOH * +DohGetattr(DOH *obj, DOH *name) { DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohGetattr %x, %x\n",obj,name); - if (!name) return 0; + DohTrace(DOH_CALLS,"DohGetattr %x, %x\n",obj,name); if (DohIsMapping(b)) { if (b->objinfo->doh_mapping->doh_getattr) { return (b->objinfo->doh_mapping->doh_getattr)(obj,name); } } if (DohCheck(b)) { - DohError(DOH_UNSUPPORTED,"No getattr method defined for type '%s'\n", b->objinfo->objname); + DohTrace(DOH_UNSUPPORTED,"No getattr method defined for type '%s'\n", b->objinfo->objname); } else { - DohError(DOH_UNKNOWN,"Unknown object %x passed to Getattr.\n", obj); + DohTrace(DOH_UNKNOWN,"Unknown object %x passed to Getattr.\n", obj); } return 0; } -/* Set an attribute in an object */ -int DohSetattr(DOH *obj, DOH *name, DOH *value) { - DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohSetattr %x, %x, %x\n",obj,name, value); - if ((!name) || (!value)) return 0; - if (DohIsMapping(b)) { - if (b->objinfo->doh_mapping->doh_setattr) { - return (b->objinfo->doh_mapping->doh_setattr)(obj,name,value); - } +/* ----------------------------------------------------------------------------- + * DohSetattr() + * + * Set an attribute in a mapping object. + * ----------------------------------------------------------------------------- */ + +int +DohSetattr(DOH *obj, DOH *name, DOH *value) { + DohBase *b = (DohBase *) obj; + DohTrace(DOH_CALLS,"DohSetattr %x, %x, %x\n",obj,name, value); + if (DohIsMapping(b)) { + if (b->objinfo->doh_mapping->doh_setattr) { + return (b->objinfo->doh_mapping->doh_setattr)(obj,name,value); } - if (DohCheck(b)) { - DohError(DOH_UNSUPPORTED, "No setattr method defined for type '%s'\n", b->objinfo->objname); - } else { - DohError(DOH_UNKNOWN,"Unknown object %x passed to Setattr\n", obj); - } - return 0; + } + if (DohCheck(b)) { + DohTrace(DOH_UNSUPPORTED, "No setattr method defined for type '%s'\n", b->objinfo->objname); + } else { + DohTrace(DOH_UNKNOWN,"Unknown object %x passed to Setattr\n", obj); + } + return 0; } -/* Delete an attribute from an object */ -void DohDelattr(DOH *obj, DOH *name) { +/* ----------------------------------------------------------------------------- + * DohDelattr() + * + * Delete an attribute in a mapping object. + * ----------------------------------------------------------------------------- */ + +void +DohDelattr(DOH *obj, DOH *name) { DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohDelattr %x, %x\n",obj,name); - if (!name) return; + DohTrace(DOH_CALLS,"DohDelattr %x, %x\n",obj,name); if (DohIsMapping(obj)) { if (b->objinfo->doh_mapping->doh_delattr) { (b->objinfo->doh_mapping->doh_delattr)(obj,name); @@ -382,260 +475,306 @@ void DohDelattr(DOH *obj, DOH *name) { } } if (DohCheck(obj)) { - DohError(DOH_UNSUPPORTED, "No delattr method defined for type '%s'\n", b->objinfo->objname); + DohTrace(DOH_UNSUPPORTED, "No delattr method defined for type '%s'\n", b->objinfo->objname); } else { - DohError(DOH_UNKNOWN,"Unknown object %x passed to Delattr\n",obj); + DohTrace(DOH_UNKNOWN,"Unknown object %x passed to Delattr\n",obj); } } +/* ----------------------------------------------------------------------------- + * DohFirstkey() + * + * Return the first key value in a mapping object. + * ----------------------------------------------------------------------------- */ -/* Get first item in an object */ -DOH *DohFirst(DOH *obj) { - DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohFirst %x\n",obj); - if (DohIsMapping(obj)) { - if (b->objinfo->doh_mapping->doh_firstkey) { - return DohGetattr(obj,(b->objinfo->doh_mapping->doh_firstkey)(obj)); - } - } - if (DohCheck(obj)) { - DohError(DOH_UNSUPPORTED,"No firstkey method defined for type '%s'\n", b->objinfo->objname); - } else { - DohError(DOH_UNKNOWN,"Unknown object %x passed to DohFirst\n",obj); +DOH * +DohFirstkey(DOH *obj) { + DohBase *b = (DohBase *) obj; + DohTrace(DOH_CALLS,"DohFirstkey %x\n",obj); + if (DohIsMapping(obj)) { + if (b->objinfo->doh_mapping->doh_firstkey) { + return (b->objinfo->doh_mapping->doh_firstkey)(obj); } - return 0; + } + if (DohCheck(obj)) { + DohTrace(DOH_UNSUPPORTED,"No firstkey method defined for type '%s'\n", b->objinfo->objname); + } else { + DohTrace(DOH_UNKNOWN,"Unknown object %x passed to DohFirstkey\n",obj); + } + return 0; } -/* Get next item in an object */ -DOH *DohNext(DOH *obj) { - DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohNext %x\n",obj); - if (DohIsMapping(obj)) { - if (b->objinfo->doh_mapping->doh_nextkey) { - return DohGetattr(obj,(b->objinfo->doh_mapping->doh_nextkey)(obj)); - } +/* ----------------------------------------------------------------------------- + * DohNextkey() + * + * Return the next key in a mapping object. + * ----------------------------------------------------------------------------- */ + +DOH * +DohNextkey(DOH *obj) { + DohBase *b = (DohBase *) obj; + DohTrace(DOH_CALLS,"DohNextkey %x\n",obj); + if (DohIsMapping(obj)) { + if (b->objinfo->doh_mapping->doh_nextkey) { + return (b->objinfo->doh_mapping->doh_nextkey)(obj); } - if (DohCheck(obj)) { - DohError(DOH_UNSUPPORTED,"No nextkey method defined for type '%s'\n", b->objinfo->objname); + } + if (DohCheck(obj)) { + DohTrace(DOH_UNSUPPORTED,"No nextkey method defined for type '%s'\n", b->objinfo->objname); } else { - DohError(DOH_UNKNOWN,"Unknown object %x passed to DohNext\n",obj); + DohTrace(DOH_UNKNOWN,"Unknown object %x passed to DohNextkey\n",obj); } - return 0; + return 0; } +/* ----------------------------------------------------------------------------- + * DohGetInt() + * + * Return an element as an integer. + * ----------------------------------------------------------------------------- */ -/* Get first item in an object */ -DOH *DohFirstkey(DOH *obj) { - DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohFirstkey %x\n",obj); - if (DohIsMapping(obj)) { - if (b->objinfo->doh_mapping->doh_firstkey) { - return (b->objinfo->doh_mapping->doh_firstkey)(obj); - } - } - if (DohCheck(obj)) { - DohError(DOH_UNSUPPORTED,"No firstkey method defined for type '%s'\n", b->objinfo->objname); - } else { - DohError(DOH_UNKNOWN,"Unknown object %x passed to DohFirstkey\n",obj); - } - return 0; -} - -/* Get next item in an object */ -DOH *DohNextkey(DOH *obj) { - DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohNextkey %x\n",obj); - if (DohIsMapping(obj)) { - if (b->objinfo->doh_mapping->doh_nextkey) { - return (b->objinfo->doh_mapping->doh_nextkey)(obj); - } - } - if (DohCheck(obj)) { - DohError(DOH_UNSUPPORTED,"No nextkey method defined for type '%s'\n", b->objinfo->objname); - } else { - DohError(DOH_UNKNOWN,"Unknown object %x passed to DohNextkey\n",obj); - } - return 0; -} - -int DohGetInt(DOH *obj, DOH *name) { +int +DohGetInt(DOH *obj, DOH *name) { DOH *val; - DohError(DOH_CALLS,"DohGetInt %x, %x\n",obj,name); + DohTrace(DOH_CALLS,"DohGetInt %x, %x\n",obj,name); val = Getattr(obj,name); if (!val) return 0; - if (String_check(val)) { + if (DohIsString(val)) { return atoi(Data(val)); } return 0; } -double DohGetDouble(DOH *obj, DOH *name) { +/* ----------------------------------------------------------------------------- + * DohGetDouble() + * + * Return an element as a double. + * ----------------------------------------------------------------------------- */ + +double +DohGetDouble(DOH *obj, DOH *name) { DOH *val; - DohError(DOH_CALLS,"DohGetDouble %x, %x\n",obj,name); + DohTrace(DOH_CALLS,"DohGetDouble %x, %x\n",obj,name); val = Getattr(obj,name); if (!val) return 0; - if (String_check(val)) { + if (DohIsString(val)) { return atof(Data(val)); } return 0; } -char *DohGetChar(DOH *obj, DOH *name) { +/* ----------------------------------------------------------------------------- + * DohGetChar() + * + * Return an element as a char * + * ----------------------------------------------------------------------------- */ + +char * +DohGetChar(DOH *obj, DOH *name) { DOH *val; - DohError(DOH_CALLS,"DohGetChar %x, %x\n",obj,name); + DohTrace(DOH_CALLS,"DohGetChar %x, %x\n",obj,name); val = Getattr(obj,name); if (!val) return 0; - if (String_check(val)) { + if (DohIsString(val)) { return (char *) Data(val); } return 0; } -void DohSetInt(DOH *obj, DOH *name, int value) { +/* ----------------------------------------------------------------------------- + * DohSetInt() + * + * Set an attribute as an integer + * ----------------------------------------------------------------------------- */ + +void +DohSetInt(DOH *obj, DOH *name, int value) { DOH *temp; - DohError(DOH_CALLS,"DohSetInt %x, %x, %d\n", obj, name, value); + DohTrace(DOH_CALLS,"DohSetInt %x, %x, %d\n", obj, name, value); temp = NewString(""); Printf(temp,"%d",value); Setattr(obj,name,temp); } -void DohSetDouble(DOH *obj, DOH *name, double value) { +/* ----------------------------------------------------------------------------- + * DohSetDouble() + * + * Set an attribute as a double + * ----------------------------------------------------------------------------- */ + +void +DohSetDouble(DOH *obj, DOH *name, double value) { DOH *temp; - DohError(DOH_CALLS,"DohSetInt %x, %x, %g\n", obj, name, value); + DohTrace(DOH_CALLS,"DohSetDouble %x, %x, %g\n", obj, name, value); temp = NewString(""); - Printf(temp,"%g",value); + Printf(temp,"%0.17f",value); Setattr(obj,name,temp); } +/* ----------------------------------------------------------------------------- + * DohSetChar() + * + * Set an attribute as a string. + * ----------------------------------------------------------------------------- */ + +void +DohSetChar(DOH *obj, DOH *name, char *value) { + DOH *temp; + DohTrace(DOH_CALLS,"DohSetChar %x, %x, %g\n", obj, name, value); + temp = NewString(value); + Setattr(obj,name,temp); +} /* ---------------------------------------------------------------------- * Sequence Interface * ---------------------------------------------------------------------- */ -int DohIsSequence(DOH *obj) { +/* ----------------------------------------------------------------------------- + * DohIsSequence() + * + * Return 1 if an object supports sequence methods. + * ----------------------------------------------------------------------------- */ + +int +DohIsSequence(DOH *obj) { DohBase *b = (DohBase *) obj; if (!DohCheck(b)) return 0; if (b->objinfo->doh_sequence) return 1; else return 0; } -/* Get an item from an object */ -DOH *DohGetitem(DOH *obj, int index) { - DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohGetitem %x, %d\n",obj,index); - if (DohIsSequence(obj)) { - if (b->objinfo->doh_sequence->doh_getitem) { - return (b->objinfo->doh_sequence->doh_getitem)(obj,index); - } - } - if (DohCheck(obj)) { - DohError(DOH_UNSUPPORTED,"No getitem method defined for type '%s'\n", b->objinfo->objname); - } else { - DohError(DOH_UNKNOWN,"Unknown object %x passed to DohGetitem\n",obj); - } - return 0; -} +/* ----------------------------------------------------------------------------- + * DohGetitem() + * + * Return an item from a sequence. + * ----------------------------------------------------------------------------- */ -/* Set an item in an object */ -void DohSetitem(DOH *obj, int index, DOH *value) { - DOH *value_obj; +DOH * +DohGetitem(DOH *obj, int index) { DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohSetitem %x, %d, %x\n",obj,index, value); + DohTrace(DOH_CALLS,"DohGetitem %x, %d\n",obj,index); if (DohIsSequence(obj)) { - if (!DohCheck(value)) { - DohError(DOH_CONVERSION,"Unknown object %x being converted to a string in Setitem.\n", value); - value_obj = NewString(value); - } else { - value_obj = value; - } - if (b->objinfo->doh_sequence->doh_setitem) { - (b->objinfo->doh_sequence->doh_setitem)(obj,index,value_obj); - return; + if (b->objinfo->doh_sequence->doh_getitem) { + return (b->objinfo->doh_sequence->doh_getitem)(obj,index); } } if (DohCheck(obj)) { - DohError(DOH_UNSUPPORTED,"No setitem method defined for type '%s'\n", b->objinfo->objname); + DohTrace(DOH_UNSUPPORTED,"No getitem method defined for type '%s'\n", b->objinfo->objname); } else { - DohError(DOH_UNKNOWN,"Unknown object %x passed to DohSetitem\n",obj); + DohTrace(DOH_UNKNOWN,"Unknown object %x passed to DohGetitem\n",obj); + } + return 0; +} + +/* ----------------------------------------------------------------------------- + * DohSetitem() + * + * Set an item in a sequence. + * ----------------------------------------------------------------------------- */ + +int +DohSetitem(DOH *obj, int index, DOH *value) { + DohBase *b = (DohBase *) obj; + DohTrace(DOH_CALLS,"DohSetitem %x, %d, %x\n",obj,index, value); + if (DohIsSequence(obj)) { + if (b->objinfo->doh_sequence->doh_setitem) { + return (b->objinfo->doh_sequence->doh_setitem)(obj,index,value); + } + } + if (DohCheck(obj)) { + DohTrace(DOH_UNSUPPORTED,"No setitem method defined for type '%s'\n", b->objinfo->objname); + } else { + DohTrace(DOH_UNKNOWN,"Unknown object %x passed to DohSetitem\n",obj); } } -/* Delete an item from an object */ -void DohDelitem(DOH *obj, int index) { +/* ----------------------------------------------------------------------------- + * DohDelitem() + * + * Delete an item in a sequence. + * ----------------------------------------------------------------------------- */ + +int +DohDelitem(DOH *obj, int index) { DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohDelitem %x, %d\n",obj,index); + DohTrace(DOH_CALLS,"DohDelitem %x, %d\n",obj,index); if (DohIsSequence(obj)) { if (b->objinfo->doh_sequence->doh_delitem) { - (b->objinfo->doh_sequence->doh_delitem)(obj,index); - return; + return (b->objinfo->doh_sequence->doh_delitem)(obj,index); } } if (DohCheck(obj)) { - DohError(DOH_UNSUPPORTED,"No delitem method defined for type '%s'\n", b->objinfo->objname); + DohTrace(DOH_UNSUPPORTED,"No delitem method defined for type '%s'\n", b->objinfo->objname); } else { - DohError(DOH_UNKNOWN,"Unknown object %x passed to DohDelitem\n",obj); + DohTrace(DOH_UNKNOWN,"Unknown object %x passed to DohDelitem\n",obj); } } -/* Set an item in an object */ -void DohInsertitem(DOH *obj, int index, DOH *value) { - DOH *value_obj; +/* ----------------------------------------------------------------------------- + * DohInsertitem() + * + * Insert an item into a sequence. + * ----------------------------------------------------------------------------- */ + +int +DohInsertitem(DOH *obj, int index, DOH *value) { int no = 0; DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohInsertitem %x, %d, %x\n",obj,index, value); + DohTrace(DOH_CALLS,"DohInsertitem %x, %d, %x\n",obj,index, value); if (DohIsSequence(obj)) { - if (!DohCheck(value)) { - DohError(DOH_CONVERSION,"Unknown object %x being converted to a string in Insertitem.\n", value); - value_obj = NewString(value); - no = 1; - } else { - value_obj = value; - } if (b->objinfo->doh_sequence->doh_insitem) { - (b->objinfo->doh_sequence->doh_insitem)(obj,index,value_obj); + return (b->objinfo->doh_sequence->doh_insitem)(obj,index,value); } - if (no) { - Delete(value_obj); - } - return; } if (DohCheck(obj)) { - DohError(DOH_UNSUPPORTED,"No insitem method defined for type '%s'\n", b->objinfo->objname); + DohTrace(DOH_UNSUPPORTED,"No insitem method defined for type '%s'\n", b->objinfo->objname); } else { - DohError(DOH_UNKNOWN,"Unknown object %x passed to DohInsertitem\n",obj); + DohTrace(DOH_UNKNOWN,"Unknown object %x passed to DohInsertitem\n",obj); } } -/* Delete an item from an object */ -DOH *DohFirstitem(DOH *obj) { +/* ----------------------------------------------------------------------------- + * DohFirstitem() + * + * Get the first item in a sequence + * ----------------------------------------------------------------------------- */ + +DOH * +DohFirstitem(DOH *obj) { DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohFirstitem %x\n"); + DohTrace(DOH_CALLS,"DohFirstitem %x\n"); if (DohIsSequence(obj)) { if (b->objinfo->doh_sequence->doh_firstitem) { return (b->objinfo->doh_sequence->doh_firstitem)(obj); } } if (DohCheck(obj)) { - DohError(DOH_UNSUPPORTED,"No firstitem method defined for type '%s'\n", b->objinfo->objname); + DohTrace(DOH_UNSUPPORTED,"No firstitem method defined for type '%s'\n", b->objinfo->objname); } else { - DohError(DOH_UNKNOWN,"Unknown object %x passed to DohFirstitem\n",obj); + DohTrace(DOH_UNKNOWN,"Unknown object %x passed to DohFirstitem\n",obj); } return 0; } -/* Delete an item from an object */ -DOH *DohNextitem(DOH *obj) { +/* ----------------------------------------------------------------------------- + * DohNextitem() + * + * Get the next item in a sequence. + * ----------------------------------------------------------------------------- */ + +DOH * +DohNextitem(DOH *obj) { DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohNextitem %x\n"); + DohTrace(DOH_CALLS,"DohNextitem %x\n"); if (DohIsSequence(obj)) { if (b->objinfo->doh_sequence->doh_nextitem) { return (b->objinfo->doh_sequence->doh_nextitem)(obj); } } if (DohCheck(obj)) { - DohError(DOH_UNSUPPORTED,"No nextitem method defined for type '%s'\n", b->objinfo->objname); + DohTrace(DOH_UNSUPPORTED,"No nextitem method defined for type '%s'\n", b->objinfo->objname); } else { - DohError(DOH_UNKNOWN,"Unknown object %x passed to DohNextitem\n",obj); + DohTrace(DOH_UNKNOWN,"Unknown object %x passed to DohNextitem\n",obj); } return 0; } @@ -644,34 +783,53 @@ DOH *DohNextitem(DOH *obj) { * File methods * ----------------------------------------------------------------------------- */ -int DohIsFile(DOH *obj) { +/* ----------------------------------------------------------------------------- + * DohIsFile() + * + * Return 1 if an object supports file methods. + * ----------------------------------------------------------------------------- */ + +int +DohIsFile(DOH *obj) { DohBase *b = (DohBase *) obj; if (!DohCheck(b)) return 0; if (b->objinfo->doh_file) return 1; else return 0; } -/* Read */ -int DohRead(DOH *obj, void *buffer, int length) { +/* ----------------------------------------------------------------------------- + * DohRead() + * + * Read bytes from an object. Implicitly converts to a FILE *. + * ----------------------------------------------------------------------------- */ + +int +DohRead(DOH *obj, void *buffer, int length) { DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohRead %x, %x, %d\n",obj,buffer,length); + DohTrace(DOH_CALLS,"DohRead %x, %x, %d\n",obj,buffer,length); if (DohIsFile(obj)) { if (b->objinfo->doh_file->doh_read) { return (b->objinfo->doh_file->doh_read)(obj,buffer,length); } } else if (!DohCheck(b)) { /* Hmmm. Not a file. Maybe it's a real FILE */ - DohError(DOH_CONVERSION,"Unknown object %x converted to FILE * in DohRead\n",b); + DohTrace(DOH_CONVERSION,"Unknown object %x converted to FILE * in DohRead\n",b); return fread(buffer,1,length,(FILE *) b); } - DohError(DOH_UNSUPPORTED,"No read method defined for type '%s'\n", b->objinfo->objname); + DohTrace(DOH_UNSUPPORTED,"No read method defined for type '%s'\n", b->objinfo->objname); return -1; } -/* Write */ -int DohWrite(DOH *obj, void *buffer, int length) { +/* ----------------------------------------------------------------------------- + * DohWrite() + * + * Write bytes to an object. Implicitly converts to a FILE * + * ----------------------------------------------------------------------------- */ + +int +DohWrite(DOH *obj, void *buffer, int length) { DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohWrite %x, %x, %d\n",obj,buffer,length); + DohTrace(DOH_CALLS,"DohWrite %x, %x, %d\n",obj,buffer,length); if (DohIsFile(obj)) { if (b->objinfo->doh_file->doh_write) { return (b->objinfo->doh_file->doh_write)(obj,buffer,length); @@ -679,117 +837,148 @@ int DohWrite(DOH *obj, void *buffer, int length) { } if (!DohCheck(b)) { /* Hmmm. Not a file. Maybe it's a real FILE */ - DohError(DOH_CONVERSION,"Unknown object %x converted to FILE * in DohWrite\n",b); + DohTrace(DOH_CONVERSION,"Unknown object %x converted to FILE * in DohWrite\n",b); return fwrite(buffer,1,length,(FILE *) b); } - DohError(DOH_UNSUPPORTED,"No write method defined for type '%s'\n", b->objinfo->objname); + DohTrace(DOH_UNSUPPORTED,"No write method defined for type '%s'\n", b->objinfo->objname); return -1; } -/* Seek */ -int DohSeek(DOH *obj, long offset, int whence) { +/* ----------------------------------------------------------------------------- + * DohSeek() + * + * Seek to a new position. + * ----------------------------------------------------------------------------- */ + +int +DohSeek(DOH *obj, long offset, int whence) { DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohSeek %x, %d, %d\n",obj,offset,whence); + DohTrace(DOH_CALLS,"DohSeek %x, %d, %d\n",obj,offset,whence); if (DohIsFile(obj)) { if (b->objinfo->doh_file->doh_seek) { return (b->objinfo->doh_file->doh_seek)(obj,offset,whence); } } if (!DohCheck(b)) { - /* Hmmm. Not a file. Maybe it's a real FILE */ - DohError(DOH_CONVERSION,"Unknown object %x converted to FILE * in DohSeek\n",b); + DohTrace(DOH_CONVERSION,"Unknown object %x converted to FILE * in DohSeek\n",b); return fseek((FILE *) b, offset, whence); } - DohError(DOH_UNSUPPORTED,"No seek method defined for type '%s'\n", b->objinfo->objname); + DohTrace(DOH_UNSUPPORTED,"No seek method defined for type '%s'\n", b->objinfo->objname); return -1; } -/* Tell */ -long DohTell(DOH *obj) { +/* ----------------------------------------------------------------------------- + * DohTell() + * + * Return current file pointer. + * ----------------------------------------------------------------------------- */ + +long +DohTell(DOH *obj) { DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohTell %x\n",obj); + DohTrace(DOH_CALLS,"DohTell %x\n",obj); if (DohIsFile(obj)) { if (b->objinfo->doh_file->doh_tell) { return (b->objinfo->doh_file->doh_tell)(obj); } } if (!DohCheck(b)) { - /* Hmmm. Not a file. Maybe it's a real FILE */ - DohError(DOH_CONVERSION,"Unknown object %x converted to FILE * in DohTell\n",b); + DohTrace(DOH_CONVERSION,"Unknown object %x converted to FILE * in DohTell\n",b); return ftell((FILE *) b); } - DohError(DOH_UNSUPPORTED,"No tell method defined for type '%s'\n", b->objinfo->objname); + DohTrace(DOH_UNSUPPORTED,"No tell method defined for type '%s'\n", b->objinfo->objname); return -1; } -/* Getc */ -int DohGetc(DOH *obj) { +/* ----------------------------------------------------------------------------- + * DohGetc() + * + * Return a character + * ----------------------------------------------------------------------------- */ + +int +DohGetc(DOH *obj) { DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohGetc %x\n",obj); + DohTrace(DOH_CALLS,"DohGetc %x\n",obj); if (DohIsFile(obj)) { if (b->objinfo->doh_file->doh_getc) { return (b->objinfo->doh_file->doh_getc)(obj); } } if (!DohCheck(b)) { - /* Hmmm. Not a file. Maybe it's a real FILE */ - DohError(DOH_CONVERSION,"Unknown object %x converted to FILE * in DohGetc\n",b); + DohTrace(DOH_CONVERSION,"Unknown object %x converted to FILE * in DohGetc\n",b); return fgetc((FILE *) b); } - DohError(DOH_UNSUPPORTED,"No getc method defined for type '%s'\n", b->objinfo->objname); + DohTrace(DOH_UNSUPPORTED,"No getc method defined for type '%s'\n", b->objinfo->objname); return EOF; } -/* Putc */ -int DohPutc(int ch, DOH *obj) { +/* ----------------------------------------------------------------------------- + * DohPutc() + * + * Put a character. + * ----------------------------------------------------------------------------- */ + +int +DohPutc(int ch, DOH *obj) { DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohPutc '%c',%x\n",ch,obj); + DohTrace(DOH_CALLS,"DohPutc '%c',%x\n",ch,obj); if (DohIsFile(obj)) { if (b->objinfo->doh_file->doh_putc) { return (b->objinfo->doh_file->doh_putc)(obj,ch); } } if (!DohCheck(b)) { - /* Hmmm. Not a file. Maybe it's a real FILE */ - DohError(DOH_CONVERSION,"Unknown object %x converted to FILE * in DohPutc\n",b); + DohTrace(DOH_CONVERSION,"Unknown object %x converted to FILE * in DohPutc\n",b); return fputc(ch,(FILE *) b); } - DohError(DOH_UNSUPPORTED,"No putc method defined for type '%s'\n", b->objinfo->objname); + DohTrace(DOH_UNSUPPORTED,"No putc method defined for type '%s'\n", b->objinfo->objname); return EOF; } -/* ungetc */ -int DohUngetc(int ch, DOH *obj) { +/* ----------------------------------------------------------------------------- + * DohUngetc() + * + * Put a character back on the input stream. + * ----------------------------------------------------------------------------- */ + +int +DohUngetc(int ch, DOH *obj) { DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohUngetc '%c',%x\n",ch,obj); + DohTrace(DOH_CALLS,"DohUngetc '%c',%x\n",ch,obj); if (DohIsFile(obj)) { if (b->objinfo->doh_file->doh_ungetc) { return (b->objinfo->doh_file->doh_ungetc)(obj,ch); } } if (!DohCheck(b)) { - /* Hmmm. Not a file. Maybe it's a real FILE */ - DohError(DOH_CONVERSION,"Unknown object %x converted to FILE * in DohUngetc\n",b); + DohTrace(DOH_CONVERSION,"Unknown object %x converted to FILE * in DohUngetc\n",b); return ungetc(ch,(FILE *) b); } - DohError(DOH_UNSUPPORTED,"No ungetc method defined for type '%s'\n", b->objinfo->objname); + DohTrace(DOH_UNSUPPORTED,"No ungetc method defined for type '%s'\n", b->objinfo->objname); return EOF; } -int DohClose(DOH *obj) { +/* ----------------------------------------------------------------------------- + * DohClose() + * + * Close a file object. + * ----------------------------------------------------------------------------- */ + +int +DohClose(DOH *obj) { DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohClose %x\n",obj); + DohTrace(DOH_CALLS,"DohClose %x\n",obj); if (DohIsFile(obj)) { if (b->objinfo->doh_file->doh_close) { return (b->objinfo->doh_file->doh_close)(obj); } } if (!DohCheck(b)) { - /* Hmmm. Not a file. Maybe it's a real FILE */ - DohError(DOH_CONVERSION,"Unknown object %x converted to FILE * in DohClose\n",b); + DohTrace(DOH_CONVERSION,"Unknown object %x converted to FILE * in DohClose\n",b); return fclose((FILE *) obj); } - DohError(DOH_UNSUPPORTED,"No close method defined for type '%s'\n", b->objinfo->objname); + DohTrace(DOH_UNSUPPORTED,"No close method defined for type '%s'\n", b->objinfo->objname); return 0; } @@ -797,41 +986,62 @@ int DohClose(DOH *obj) { * String methods * ----------------------------------------------------------------------------- */ -int DohIsString(DOH *obj) { +/* ----------------------------------------------------------------------------- + * DohIsString() + * + * Return 1 if an object supports string methods. + * ----------------------------------------------------------------------------- */ + +int +DohIsString(DOH *obj) { DohBase *b = (DohBase *) obj; if (!DohCheck(b)) return 0; if (b->objinfo->doh_string) return 1; else return 0; } -int DohReplace(DOH *src, DOH *token, DOH *rep, int flags) { +/* ----------------------------------------------------------------------------- + * DohReplace() + * + * Perform string replacement. + * ----------------------------------------------------------------------------- */ + +int +DohReplace(DOH *src, DOH *token, DOH *rep, int flags) { DohBase *b = (DohBase *) src; - DohError(DOH_CALLS, "DohReplace %x\n", src); + DohTrace(DOH_CALLS, "DohReplace %x\n", src); if (DohIsString(src)) { if (b->objinfo->doh_string->doh_replace) { return (b->objinfo->doh_string->doh_replace)(src,token,rep,flags); } } if (DohCheck(b)) { - DohError(DOH_UNSUPPORTED, "No replace method defined for type '%s'\n", b->objinfo->objname); + DohTrace(DOH_UNSUPPORTED, "No replace method defined for type '%s'\n", b->objinfo->objname); } else { - DohError(DOH_UNKNOWN,"Unknown object %x passed to Replace\n", b); + DohTrace(DOH_UNKNOWN,"Unknown object %x passed to Replace\n", b); } return 0; } -void DohChop(DOH *src) { +/* ----------------------------------------------------------------------------- + * DohChop() + * + * Chop whitespace at the end of a string. + * ----------------------------------------------------------------------------- */ + +void +DohChop(DOH *src) { DohBase *b = (DohBase *) src; - DohError(DOH_CALLS, "DohChop %x\n", src); + DohTrace(DOH_CALLS, "DohChop %x\n", src); if (DohIsString(src)) { if (b->objinfo->doh_string->doh_chop) { (b->objinfo->doh_string->doh_chop)(src); } } if (DohCheck(b)) { - DohError(DOH_UNSUPPORTED, "No chop method defined for type '%s'\n", b->objinfo->objname); + DohTrace(DOH_UNSUPPORTED, "No chop method defined for type '%s'\n", b->objinfo->objname); } else { - DohError(DOH_UNKNOWN,"Unknown object %x passed to Chop\n", b); + DohTrace(DOH_UNKNOWN,"Unknown object %x passed to Chop\n", b); } } @@ -839,9 +1049,31 @@ void DohChop(DOH *src) { * Callable methods * ----------------------------------------------------------------------------- */ -DOH *DohCall(DOH *obj, DOH *args) { +/* ----------------------------------------------------------------------------- + * DohIsCallable() + * + * Return 1 if an object supports callable methods. + * ----------------------------------------------------------------------------- */ + +int +DohIsCallable(DOH *obj) { + DohBase *b = (DohBase *) obj; + if (!DohCheck(b)) return 0; + if (b->objinfo->doh_callable) return 1; + else return 0; +} + + +/* ----------------------------------------------------------------------------- + * DohCall() + * + * Perform a function call on an object. + * ----------------------------------------------------------------------------- */ + +DOH * +DohCall(DOH *obj, DOH *args) { DohBase *b = (DohBase *) obj; - DohError(DOH_CALLS,"DohCall %x\n",obj); + DohTrace(DOH_CALLS,"DohCall %x\n",obj); if (DohCheck(b)) { if ((b->objinfo->doh_callable) && (b->objinfo->doh_callable->doh_call)) { return (b->objinfo->doh_callable->doh_call)(b,args); @@ -850,23 +1082,39 @@ DOH *DohCall(DOH *obj, DOH *args) { return 0; } -void DohInit(DOH *b) { - DohBase *bs = (DohBase *) b; - bs->refcount = 1; - bs->objinfo = &DohBaseType; - bs->flags = 0; -} +/* ----------------------------------------------------------------------------- + * DohInit() + * + * Initialize an object. + * ----------------------------------------------------------------------------- */ -void DohXInit(DOH *b) { - DohXBase *bs = (DohXBase *) b; - bs->file = 0; - bs->line = 0; +void +DohInit(DOH *b) { + DohBase *bs = (DohBase *) b; + bs->refcount = 1; + bs->objinfo = &DohBaseType; + bs->flags = 0; } /* ----------------------------------------------------------------------------- - * XBase_setfile(DOH *ho, DOH *file) + * DohXInit() + * + * Initialize an extended object. * ----------------------------------------------------------------------------- */ -void XBase_setfile(DOH *ho, DOH *file) { +void +DohXInit(DOH *b) { + DohXBase *bs = (DohXBase *) b; + bs->file = 0; + bs->line = 0; +} + +/* ----------------------------------------------------------------------------- + * XBase_setfile() + * + * Set file location (default method). + * ----------------------------------------------------------------------------- */ +void +XBase_setfile(DOH *ho, DOH *file) { DohXBase *h = (DohXBase *) ho; if (!DohCheck(file)) file = NewString(file); h->file = file; @@ -874,25 +1122,31 @@ void XBase_setfile(DOH *ho, DOH *file) { } /* ----------------------------------------------------------------------------- - * DOH *XBase_getfile(DOH *ho) + * XBase_getfile() * ----------------------------------------------------------------------------- */ -DOH *XBase_getfile(DOH *ho) { + +DOH * +XBase_getfile(DOH *ho) { DohXBase *h = (DohXBase *) ho; return h->file; } /* ----------------------------------------------------------------------------- - * void XBase_setline(DOH *ho, int l) + * XBase_setline() * ----------------------------------------------------------------------------- */ -void XBase_setline(DOH *ho, int l) { +void +XBase_setline(DOH *ho, int l) { DohXBase *h = (DohXBase *) ho; h->line = l; } /* ----------------------------------------------------------------------------- - * int XBase_getline(DOH *ho) + * XBase_getline() * ----------------------------------------------------------------------------- */ -int XBase_getline(DOH *ho) { +int +XBase_getline(DOH *ho) { DohXBase *h = (DohXBase *) ho; return h->line; } + + diff --git a/Source/DOH/Doh/callable.c b/Source/DOH/Doh/callable.c index b8d5dee68..b83bec6a8 100644 --- a/Source/DOH/Doh/callable.c +++ b/Source/DOH/Doh/callable.c @@ -1,17 +1,11 @@ -/**************************************************************************** - * DOH (Dynamic Object Hack) +/****************************************************************************** + * DOH * - * Author : David Beazley + * Author(s) : David Beazley (beazley@cs.uchicago.edu) * - * Department of Computer Science - * University of Chicago - * 1100 E 58th Street - * Chicago, IL 60637 - * beazley@cs.uchicago.edu - * - * Please read the file LICENSE for the copyright and terms by which SWIG - * can be used and distributed. - ****************************************************************************/ + * Copyright (C) 1999-2000. The University of Chicago + * See the file LICENSE for information on usage and redistribution. + ******************************************************************************/ static char cvsroot[] = "$Header$"; @@ -28,23 +22,44 @@ typedef struct { DOH *(*func)(DOH *, DOH *); } CallableObj; +/* ----------------------------------------------------------------------------- + * Callable_delete() + * + * Destroy a callable object. + * ----------------------------------------------------------------------------- */ + static void Callable_delete(DOH *co) { DohObjFree(co); } +/* ----------------------------------------------------------------------------- + * Callable_copy() + * + * Copy a callable object. + * ----------------------------------------------------------------------------- */ + static DOH * Callable_copy(DOH *co) { CallableObj *c = (CallableObj *) co; return NewCallable(c->func); } +/* ----------------------------------------------------------------------------- + * Callable_call() + * + * Call an object. The object itself is passed as the first argument and remaining + * arguments are passed as a second argument. + * ----------------------------------------------------------------------------- */ + static DOH * Callable_call(DOH *co, DOH *args) { CallableObj *c = (CallableObj *) co; return (*c->func)(c,args); } +/* Method tables */ + static DohCallableMethods doh_callable_methods = { Callable_call }; @@ -77,6 +92,12 @@ static DohObjInfo DohCallableType = { 0, /* user4 */ }; +/* ----------------------------------------------------------------------------- + * NewCallable() + * + * Create a new callable object. + * ----------------------------------------------------------------------------- */ + DOH * NewCallable(DOH *(*func)(DOH *, DOH *)) { CallableObj *c; diff --git a/Source/DOH/Doh/file.c b/Source/DOH/Doh/file.c index 29bde8f68..c9abb7259 100644 --- a/Source/DOH/Doh/file.c +++ b/Source/DOH/Doh/file.c @@ -1,17 +1,11 @@ -/**************************************************************************** - * DOH (Dynamic Object Hack) +/****************************************************************************** + * DOH * - * Author : David Beazley + * Author(s) : David Beazley (beazley@cs.uchicago.edu) * - * Department of Computer Science - * University of Chicago - * 1100 E 58th Street - * Chicago, IL 60637 - * beazley@cs.uchicago.edu - * - * Please read the file LICENSE for the copyright and terms by which DOH - * can be used and distributed. - ****************************************************************************/ + * Copyright (C) 1999-2000. The University of Chicago + * See the file LICENSE for information on usage and redistribution. + ******************************************************************************/ static char cvsroot[] = "$Header$"; diff --git a/Source/DOH/Doh/list.c b/Source/DOH/Doh/list.c index a643d45a6..2b30d6260 100644 --- a/Source/DOH/Doh/list.c +++ b/Source/DOH/Doh/list.c @@ -138,26 +138,33 @@ List_scope(DOH *lo, int s) { static int List_insert(DOH *lo, int pos, DOH *item) { - List *l; - DohBase *b; - int i; + List *l; + DohBase *b; + int i, no = 0; + + if (!item) return -1; + + l = (List *) lo; - if (!item) return -1; - b = (DohBase *) item; - l = (List *) lo; - - 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[pos] = item; - b->refcount++; - Setscope(b,l->scope); - l->nitems++; - return 0; + if (!DohCheck(item)) { + DohTrace(DOH_CONVERSION,"Unknown object %x being converted to a string in List_insert.\n", item); + item = NewString(item); + no = 1; + } + b = (DohBase *) 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); + for (i = l->nitems; i > pos; i--) { + l->items[i] = l->items[i-1]; + } + l->items[pos] = item; + b->refcount++; + Setscope(b,l->scope); + l->nitems++; + if (no) Delete(item); + return 0; } /* ----------------------------------------------------------------------------- @@ -219,15 +226,22 @@ static int List_set(DOH *lo, int n, DOH *val) { List *l; - + int no = 0; l = (List *) lo; if ((n < 0) || (n >= l->nitems)) { printf("List_set : Invalid list index %d\n", n); + return -1; + } + if (!DohCheck(val)) { + DohTrace(DOH_CONVERSION,"Unknown object %x being converted to a string in List_setitem.\n", val); + val = NewString(val); + no = 1; } Delete(l->items[n]); l->items[n] = val; Incref(val); Setscope(val,l->scope); + Delete(val); return 0; } diff --git a/Source/DOH/Doh/memory.c b/Source/DOH/Doh/memory.c index 67956bf9a..39398d837 100644 --- a/Source/DOH/Doh/memory.c +++ b/Source/DOH/Doh/memory.c @@ -201,7 +201,7 @@ static void real_objfree(DOH *ptr) { b = (DohBase *) ptr; if (!b->objinfo) { - DohError(DOH_MEMORY,"DohObjFree. %x not properly defined. No objinfo structure.\n", ptr); + DohTrace(DOH_MEMORY,"DohObjFree. %x not properly defined. No objinfo structure.\n", ptr); return; /* Improperly initialized object. leak some more */ } f = (Fragment *) DohMalloc(sizeof(Fragment)); @@ -227,7 +227,7 @@ DohGarbageCollect() { DohBase *b, *b1; int ndeleted = 1; - DohError(DOH_MEMORY,"Garbage collecting.\n"); + DohTrace(DOH_MEMORY,"Garbage collecting.\n"); while (ndeleted) { ndeleted = 0; s = nscopes - 1; @@ -255,7 +255,7 @@ DohGarbageCollect() { s--; } } - DohError(DOH_MEMORY,"Done garbage collecting.\n"); + DohTrace(DOH_MEMORY,"Done garbage collecting.\n"); } /* ---------------------------------------------------------------------- @@ -338,12 +338,12 @@ void DohObjFree(DOH *ptr) { DohBase *b; if (!DohCheck(ptr)) { - DohError(DOH_MEMORY,"DohObjFree. %x not a DOH object!\n", ptr); + DohTrace(DOH_MEMORY,"DohObjFree. %x not a DOH object!\n", ptr); return; /* Oh well. Guess we're leaky */ } b = (DohBase *) ptr; if (!b->objinfo) { - DohError(DOH_MEMORY,"DohObjFree. %x not properly defined. No objinfo structure.\n", ptr); + DohTrace(DOH_MEMORY,"DohObjFree. %x not properly defined. No objinfo structure.\n", ptr); return; /* Improperly initialized object. leak some more */ } } diff --git a/Source/DOH/Doh/string.c b/Source/DOH/Doh/string.c index 926e12ce6..bf1f7e235 100644 --- a/Source/DOH/Doh/string.c +++ b/Source/DOH/Doh/string.c @@ -425,10 +425,15 @@ String_insert(DOH *so, int pos, DOH *str) char *c; int len; s = (String *) so; - /* assert(s->refcount <= 1); */ - s1 = (String *) str; - len = s1->len; - c = s1->str; + if (!DohCheck(str)) { + DohTrace(DOH_CONVERSION,"Unknown object %x being inserted as char * in String_insert.\n", str); + c = (char *) str; + len = strlen(c); + } else { + s1 = (String *) str; + len = s1->len; + c = s1->str; + } raw_insert(s,pos,c,len); return 0; } diff --git a/Source/DOH/Include/doh.h b/Source/DOH/Include/doh.h index 7db6bc6ca..405a239b8 100644 --- a/Source/DOH/Include/doh.h +++ b/Source/DOH/Include/doh.h @@ -181,8 +181,6 @@ typedef struct DohObjInfo { extern void DohDelattr(DOH *obj, DOH *name); extern DOH *DohFirstkey(DOH *obj); extern DOH *DohNextkey(DOH *obj); - extern DOH *DohFirst(DOH *obj); - extern DOH *DohNext(DOH *obj); extern int DohGetInt(DOH *obj, DOH *name); extern double DohGetDouble(DOH *obj, DOH *name); extern char *DohGetChar(DOH *obj, DOH *name); @@ -192,9 +190,9 @@ typedef struct DohObjInfo { /* Sequence methods */ extern DOH *DohGetitem(DOH *obj, int index); - extern void DohSetitem(DOH *obj, int index, DOH *value); - extern void DohDelitem(DOH *obj, int index); - extern void DohInsertitem(DOH *obj, int index, DOH *value); + extern int DohSetitem(DOH *obj, int index, DOH *value); + extern int DohDelitem(DOH *obj, int index); + extern int DohInsertitem(DOH *obj, int index, DOH *value); extern DOH *DohFirstitem(DOH *obj); extern DOH *DohNextitem(DOH *obj); @@ -230,9 +228,15 @@ typedef struct DohObjInfo { /* Miscellaneous */ - extern void DohError(int level, char *fmt,...); + extern void DohTrace(int level, char *fmt,...); extern void DohDebug(int d); + extern int DohIsMapping(DOH *obj); + extern int DohIsSequence(DOH *obj); + extern int DohIsString(DOH *obj); + extern int DohIsFile(DOH *obj); + extern int DohIsCallable(DOH *obj); + #ifndef DOH_LONG_NAMES /* Macros to invoke the above functions. Includes the location of the caller to simplify debugging if something goes wrong */ @@ -254,8 +258,6 @@ typedef struct DohObjInfo { #define Append(s,x) DohInsertitem(s,DOH_END,x) #define Push(s,x) DohInsertitem(s,DOH_BEGIN,x) #define Len DohLen -#define First DohFirst -#define Next DohNext #define Firstkey DohFirstkey #define Nextkey DohNextkey #define Data DohData @@ -384,15 +386,21 @@ extern DOH *DohSplit(DOH *input, char *chs, int nsplits); extern DOH *DohNone; +/* ----------------------------------------------------------------------------- + * Callable + * ----------------------------------------------------------------------------- */ + +extern DOH *NewCallable(DOH *(*func)(DOH *, DOH *)); + /* ----------------------------------------------------------------------------- * Error handling levels. * ----------------------------------------------------------------------------- */ -#define DOH_UNSUPPORTED 1 -#define DOH_UNKNOWN 2 -#define DOH_MEMORY 3 -#define DOH_CONVERSION 5 -#define DOH_CALLS 10 +#define DOH_UNSUPPORTED 0x01 +#define DOH_UNKNOWN 0x02 +#define DOH_MEMORY 0x04 +#define DOH_CONVERSION 0x08 +#define DOH_CALLS 0x10 #ifdef __cplusplus } diff --git a/Source/LParse/cscanner.c b/Source/LParse/cscanner.c index 73bfaca2e..9cb862dc7 100644 --- a/Source/LParse/cscanner.c +++ b/Source/LParse/cscanner.c @@ -83,6 +83,8 @@ static int remap[SWIG_MAXTOKENS]; static int cscan_init = 0; static int cplusplus_mode = 0; static int objc_mode = 0; +static int strict_type = 1; + static SwigScanner *cscanner = 0; /* ----------------------------------------------------------------------------- @@ -125,6 +127,10 @@ void LParse_set_location(DOH *file, int line) { SwigScanner_set_location(cscanner,file,line); } +void LParse_strict_type(int i) { + strict_type = i; +} + /* ----------------------------------------------------------------------------- * LParse_cplusplus(int i) - Enable C++ scanning * ----------------------------------------------------------------------------- */ @@ -371,7 +377,7 @@ yylex1(void) { /* Have an unknown identifier, as a last step, we'll */ /* do a typedef lookup on it. */ yylval.tok.text = NewString(yytext); - if (LParse_typedef_check(yylval.tok.text)) { + if (strict_type && LParse_typedef_check(yylval.tok.text)) { return TYPE_TYPEDEF; } return(ID); diff --git a/Source/LParse/parser.y b/Source/LParse/parser.y index f34e01142..de20fbfad 100644 --- a/Source/LParse/parser.y +++ b/Source/LParse/parser.y @@ -29,6 +29,8 @@ #define yynerrs lparse_yynerrs extern int lparse_yylex(); +extern void LParse_strict_type(int); + void yyerror (char *s); #include "lparse.h" diff --git a/Source/LParse/type.c b/Source/LParse/type.c index 25319f39d..c1c0b9abd 100644 --- a/Source/LParse/type.c +++ b/Source/LParse/type.c @@ -150,7 +150,6 @@ LParseTypeStr(DOH *to) { int i; LParseType *t = (LParseType *) to; s = NewString(""); - Printf(s,"(%d) - ", t->type); if (t->qualifier) Printf(s,"%s ",t->qualifier); Printf(s,"%s ",t->name);