*** empty log message ***

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dave Beazley 1999-08-10 13:47:05 +00:00
commit 8801582b8e
2 changed files with 90 additions and 15 deletions

View file

@ -21,6 +21,7 @@
* Support for formatted I/O via fprintf, fscanf.
* ----------------------------------------------------------------------------- */
#define OBUFLEN 512
/* -----------------------------------------------------------------------------
* DohvPrintf(DOH *so, char *format, va_list ap)
*
@ -34,6 +35,7 @@ DohvPrintf(DOH *so, char *format, va_list ap)
int state = 0;
char *p = format;
char newformat[256];
char obuffer[OBUFLEN];
char *fmt;
char temp[64];
int widthval = 0;
@ -42,6 +44,8 @@ DohvPrintf(DOH *so, char *format, va_list ap)
char *w, *prec;
int ivalue;
int dvalue;
void *pvalue;
char *stemp;
while (*p) {
switch(state) {
@ -180,10 +184,9 @@ DohvPrintf(DOH *so, char *format, va_list ap)
if ((*p == 's') || (*p == 'S')) { /* Null-Terminated string */
DOH *doh;
DOH *Sval;
char *temps;
doh = va_arg(ap, DOH *);
if (DohCheck(doh)) {
/* Is an object at least */
/* Is a DOH object. */
if (String_check(doh)) {
Sval = doh;
} else {
@ -192,33 +195,49 @@ DohvPrintf(DOH *so, char *format, va_list ap)
maxwidth = maxwidth+strlen(newformat)+Len(Sval);
*(fmt++) = 's';
*fmt = 0;
temps = (char *) malloc(maxwidth+1);
sprintf(temps,newformat,Data(Sval));
Write(so,temps,strlen(temps));
if ((maxwidth + 1) < OBUFLEN) {
stemp = obuffer;
} else {
stemp = (char *) malloc(maxwidth+1);
}
sprintf(stemp,newformat,Data(Sval));
Write(so,stemp,strlen(stemp));
if ((DOH *) Sval != doh) {
Delete(Sval);
}
if (*p == 'S') {
Delete(doh);
}
free(temps);
if (stemp != obuffer) {
free(stemp);
}
} else {
maxwidth = maxwidth+strlen(newformat)+strlen((char *) doh);
*(fmt++) = 's';
*fmt = 0;
temps = (char *) malloc(maxwidth+1);
sprintf(temps,newformat,doh);
free(temps);
if ((maxwidth+1) < OBUFLEN) {
stemp = obuffer;
} else {
stemp = (char *) malloc(maxwidth + 1);
}
sprintf(stemp,newformat,doh);
Write(so,stemp,strlen(stemp));
if (stemp != obuffer) {
free(stemp);
}
}
} else {
int ivalue;
double dvalue;
void *pvalue;
char *stemp;
*(fmt++) = *p;
*fmt = 0;
maxwidth = maxwidth+strlen(newformat)+64;
stemp = (char *) malloc(maxwidth+1);
/* Only allocate a buffer if it is too big to fit. Shouldn't have to do
this very often */
if (maxwidth < OBUFLEN)
stemp = obuffer;
else
stemp = (char *) malloc(maxwidth+1);
switch(*p) {
case 'd':
case 'i':
@ -246,7 +265,7 @@ DohvPrintf(DOH *so, char *format, va_list ap)
break;
}
Write(so,stemp,strlen(stemp));
free(stemp);
if (stemp != obuffer) free(stemp);
}
state = 0;
break;

56
SWIG/Source/DOH/README Normal file
View file

@ -0,0 +1,56 @@
DOH (Dave's Object Hack)
Overview:
---------
DOH is a small C library that provides a number of simple yet powerful
data structures for building flexible applications. The data
structures are built around a dynamic type model in which any given
object is allowed to support one or more classes of operations.
Common Operations (for all types)
---------------------------------
Delete(obj) Decrease the reference count and destroy if zero
Copy(obj) Make a copy of an object.
Str(obj) Create a string representation of obj.
Data(obj) Return pointer to raw data in an object
Len(obj) Length of an object
Hash(obj) Hash value (used for mapping)
Cmp(obj1,obj2) Compare two objects.
Name(obj) Return the object name
First(obj) Return first object (iterator)
Next(obj) Return next object
Mapping Operations (for hash table behavior)
--------------------------------------------
Getattr(hash,key) Get an attribute
Setattr(hash,key,value) Set an attribute
Delattr(hash,key) Delete an attribute
Firstkey(hash,key) Get first key
Nextkey(hash,key) Get next key
Getattrf(hash,key,format,...) Formatted attribute get
Setattrf(hash,key,format,...) Formatted attribute set
Sequence Operations
-------------------
Getitem(list,index) Get an item
Setitem(list,index,val) Set an item
Delitem(list,index,val) Delete an item
Insert(list,index,val) Insert an item
Append(list,val) Append to end
File Operations
---------------
Read(obj,buffer,len) Read data
Write(obj,buffer,len) Write data
Getc(obj) Get a character
Putc(ch,obj) Put a character
Ungetc(ch,obj) Put character back on input stream
Seek(obj,offset,whence) Seek
Tell(obj) Return file pointer
Printf(obj,format,...) Printf
Close(obj) Close