diff --git a/SWIG/Source/DOH/Doh/base.c b/SWIG/Source/DOH/Doh/base.c index 804099c57..d08f5a030 100644 --- a/SWIG/Source/DOH/Doh/base.c +++ b/SWIG/Source/DOH/Doh/base.c @@ -13,12 +13,13 @@ * can be used and distributed. ****************************************************************************/ +static char cvsroot[] = "$Header$"; + /******************************************************************************* - * $Header$ - * * File : base.c * - * Methods for base objects + * This file contains all of the basic DOH methods. These functions really + * just dispatch to the methods for each object. *******************************************************************************/ #include "dohint.h" diff --git a/SWIG/Source/DOH/Doh/callable.c b/SWIG/Source/DOH/Doh/callable.c index 556941543..b8d5dee68 100644 --- a/SWIG/Source/DOH/Doh/callable.c +++ b/SWIG/Source/DOH/Doh/callable.c @@ -13,22 +13,37 @@ * can be used and distributed. ****************************************************************************/ -#include "dohint.h" +static char cvsroot[] = "$Header$"; /* ----------------------------------------------------------------------------- * callable.c * - * Callable object. + * Implements a callable function-like object. * ----------------------------------------------------------------------------- */ +#include "dohint.h" + typedef struct { DOHCOMMON; DOH *(*func)(DOH *, DOH *); } CallableObj; -void Callable_delete(DOH *); -DOH *Callable_copy(DOH *); -DOH *Callable_call(DOH *, DOH *); +static void +Callable_delete(DOH *co) { + DohObjFree(co); +} + +static DOH * +Callable_copy(DOH *co) { + CallableObj *c = (CallableObj *) co; + return NewCallable(c->func); +} + +static DOH * +Callable_call(DOH *co, DOH *args) { + CallableObj *c = (CallableObj *) co; + return (*c->func)(c,args); +} static DohCallableMethods doh_callable_methods = { Callable_call @@ -39,48 +54,34 @@ static DohObjInfo DohCallableType = { sizeof(CallableObj), /* objsize */ Callable_delete, /* doh_del */ Callable_copy, /* doh_copy */ - 0, /* doh_clear */ - 0, /* doh_scope */ - 0, /* doh_str */ - 0, /* doh_data */ - 0, /* doh_dump */ - 0, /* doh_load */ - 0, /* doh_len */ - 0, /* doh_hash */ - 0, /* doh_cmp */ - 0, /* doh_mapping */ - 0, /* doh_sequence */ - 0, /* doh_file */ - 0, /* doh_string */ + 0, /* doh_clear */ + 0, /* doh_scope */ + 0, /* doh_str */ + 0, /* doh_data */ + 0, /* doh_dump */ + 0, /* doh_load */ + 0, /* doh_len */ + 0, /* doh_hash */ + 0, /* doh_cmp */ + 0, /* doh_mapping */ + 0, /* doh_sequence */ + 0, /* doh_file */ + 0, /* doh_string */ &doh_callable_methods, /* doh_callable */ - 0, /* doh_position */ - 0, /* reserved5 */ - 0, /* reserved6 */ - 0, /* user1 */ - 0, /* user2 */ - 0, /* user3 */ - 0, /* user4 */ + 0, /* doh_position */ + 0, /* reserved5 */ + 0, /* reserved6 */ + 0, /* user1 */ + 0, /* user2 */ + 0, /* user3 */ + 0, /* user4 */ }; -DOH *NewCallable(DOH *(*func)(DOH *, DOH *)) { +DOH * +NewCallable(DOH *(*func)(DOH *, DOH *)) { CallableObj *c; c = (CallableObj *) DohObjMalloc(sizeof(CallableObj)); c->objinfo = &DohCallableType; c->func = func; return (DOH *) c; } - -void Callable_delete(DOH *co) { - DohObjFree(co); -} - -DOH *Callable_copy(DOH *co) { - CallableObj *c = (CallableObj *) co; - return NewCallable(c->func); -} - -DOH *Callable_call(DOH *co, DOH *args) { - CallableObj *c = (CallableObj *) co; - return (*c->func)(c,args); -} - diff --git a/SWIG/Source/DOH/Doh/file.c b/SWIG/Source/DOH/Doh/file.c index df1ccd39f..29bde8f68 100644 --- a/SWIG/Source/DOH/Doh/file.c +++ b/SWIG/Source/DOH/Doh/file.c @@ -13,34 +13,135 @@ * can be used and distributed. ****************************************************************************/ +static char cvsroot[] = "$Header$"; + +/* --------------------------------------------------------------------------- + * file.c + * + * This file implements a DOH file-like object. + * --------------------------------------------------------------------------- */ + #include "dohint.h" #include -/* --------------------------------------------------------------------------- - * $Header$ - * string.c +typedef struct { + DOHCOMMON; + FILE *filep; + int fd; + int closeondel; +} DohFile; + +/* ----------------------------------------------------------------------------- + * DelFile(DOH *s) - Delete a file + * ----------------------------------------------------------------------------- */ + +static void +DelFile(DOH *so) { + DohFile *f = (DohFile *) so; + assert(f->refcount <= 0); + if (f->closeondel) + fclose(f->filep); + DohObjFree(f); +} + +/* ----------------------------------------------------------------------------- + * int File_read(DOH *so, void *buffer, int len) + * + * Read data from the File + * ----------------------------------------------------------------------------- */ + +static int +File_read(DOH *so, void *buffer, int len) { + DohFile *s = (DohFile *) so; + if (s->filep) + return fread(buffer,1,len,s->filep); + else + return read(s->fd,buffer,len); +} + +/* ----------------------------------------------------------------------------- + * int File_write(DOH *so, void *buffer, int len) + * + * Write data to the File + * ----------------------------------------------------------------------------- */ +static int +File_write(DOH *so, void *buffer, int len) { + DohFile *s = (DohFile *) so; + if (s->filep) + return fwrite(buffer,1,len,s->filep); + else + return write(s->fd, buffer, len); +} + +/* ----------------------------------------------------------------------------- + * int File_seek(DOH *so, long offset, int whence) + * + * Seek to a new position + * ----------------------------------------------------------------------------- */ +static int +File_seek(DOH *so, long offset, int whence) { + DohFile *s = (DohFile *) so; + if (s->filep) + return fseek(s->filep,offset,whence); + else + return lseek(s->fd,offset,whence); +} + +/* ----------------------------------------------------------------------------- + * long File_tell(DOH *so) + * + * Return current position + * ----------------------------------------------------------------------------- */ +static long +File_tell(DOH *so) { + DohFile *s = (DohFile *) so; + if (s->filep) + return ftell(s->filep); + else + return lseek(s->fd,0,SEEK_CUR); +} + +/* ----------------------------------------------------------------------------- + * int File_putc(DOH *obj, int ch) * - * String support. - * --------------------------------------------------------------------------- */ + * Put a character on the output + * ----------------------------------------------------------------------------- */ -typedef struct File { - DOHCOMMON; - FILE *filep; - int fd; - int closeondel; -} File; +static int +File_putc(DOH *obj, int ch) { + DohFile *s = (DohFile *) obj; + if (s->filep) + return fputc(ch,s->filep); + return EOF; +} -/* Forward references */ +/* ----------------------------------------------------------------------------- + * int File_getc(DOH *obj) + * + * Get a character + * ----------------------------------------------------------------------------- */ -void DelFile(DOH *s); -int File_read(DOH *s, void *buffer, int length); -int File_write(DOH *s, void *buffer, int length); -int File_putc(DOH *s, int ch); -int File_getc(DOH *s); -int File_ungetc(DOH *s, int ch); -int File_seek(DOH *s, long offset, int whence); -long File_tell(DOH *s); +static int +File_getc(DOH *obj) { + DohFile *s = (DohFile *) obj; + if (s->filep) + return fgetc(s->filep); + return EOF; +} +/* ----------------------------------------------------------------------------- + * int File_ungetc(DOH *obj, int ch) + * + * Put a character back onto the input + * ----------------------------------------------------------------------------- */ + +static int +File_ungetc(DOH *obj, int ch) { + DohFile *s = (DohFile *) obj; + if (s->filep) + return ungetc(ch, s->filep); + return EOF; +} static DohFileMethods FileFileMethods = { File_read, @@ -53,9 +154,9 @@ static DohFileMethods FileFileMethods = { 0, /* close */ }; -static DohObjInfo FileType = { - "File", /* objname */ - sizeof(File), /* objsize */ +static DohObjInfo DohFileType = { + "DohFile", /* objname */ + sizeof(DohFile), /* objsize */ DelFile, /* doh_del */ 0, /* doh_copy */ 0, /* doh_clear */ @@ -75,17 +176,13 @@ static DohObjInfo FileType = { 0, /* doh_position */ }; -DohObjInfo *File_type() { - return &FileType; -} - /* ----------------------------------------------------------------------------- * NewFile(DOH *filename, char *mode) * ----------------------------------------------------------------------------- */ DOH * NewFile(DOH *fn, char *mode) { - File *f; + DohFile *f; FILE *file; char *filename; @@ -93,12 +190,12 @@ NewFile(DOH *fn, char *mode) file = fopen(filename,mode); if (!file) return 0; - f = (File *) DohObjMalloc(sizeof(File)); + f = (DohFile *) DohObjMalloc(sizeof(DohFile)); if (!f) { fclose(file); return 0; } - f->objinfo = &FileType; + f->objinfo = &DohFileType; f->filep = file; f->fd = fileno(file); f->closeondel = 1; @@ -112,10 +209,10 @@ NewFile(DOH *fn, char *mode) DOH * NewFileFromFile(FILE *file) { - File *f; - f = (File *) DohObjMalloc(sizeof(File)); + DohFile *f; + f = (DohFile *) DohObjMalloc(sizeof(DohFile)); if (!f) return 0; - f->objinfo = &FileType; + f->objinfo = &DohFileType; f->filep = file; f->fd = fileno(file); f->closeondel = 0; @@ -129,27 +226,16 @@ NewFileFromFile(FILE *file) DOH * NewFileFromFd(int fd) { - File *f; - f = (File *) DohObjMalloc(sizeof(File)); + DohFile *f; + f = (DohFile *) DohObjMalloc(sizeof(DohFile)); if (!f) return 0; - f->objinfo = &FileType; + f->objinfo = &DohFileType; f->filep = 0; f->fd = fd; f->closeondel = 0; return (DOH *) f; } - -/* ----------------------------------------------------------------------------- - * DelFile(DOH *s) - Delete a file - * ----------------------------------------------------------------------------- */ -void -DelFile(DOH *so) { - File *f = (File *) so; - assert(f->refcount <= 0); - if (f->closeondel) - fclose(f->filep); - DohObjFree(f); -} + /* ----------------------------------------------------------------------------- * int File_check(DOH *f) - Check if f is a file @@ -157,111 +243,13 @@ DelFile(DOH *so) { int File_check(DOH *f) { - File *df; + DohFile *df; if (!DohCheck(f)) return 0; - - df = (File *) f; - if (df->objinfo == &FileType) return 1; + df = (DohFile *) f; + if (df->objinfo == &DohFileType) return 1; return 0; } -/* ----------------------------------------------------------------------------- - * int File_read(DOH *so, void *buffer, int len) - * - * Read data from the File - * ----------------------------------------------------------------------------- */ -int -File_read(DOH *so, void *buffer, int len) { - File *s = (File *) so; - if (s->filep) - return fread(buffer,1,len,s->filep); - else - return read(s->fd,buffer,len); -} - -/* ----------------------------------------------------------------------------- - * int File_write(DOH *so, void *buffer, int len) - * - * Write data to the File - * ----------------------------------------------------------------------------- */ -int -File_write(DOH *so, void *buffer, int len) { - File *s = (File *) so; - if (s->filep) - return fwrite(buffer,1,len,s->filep); - else - return write(s->fd, buffer, len); -} - -/* ----------------------------------------------------------------------------- - * int File_seek(DOH *so, long offset, int whence) - * - * Seek to a new position - * ----------------------------------------------------------------------------- */ -int -File_seek(DOH *so, long offset, int whence) { - File *s = (File *) so; - if (s->filep) - return fseek(s->filep,offset,whence); - else - return lseek(s->fd,offset,whence); -} - -/* ----------------------------------------------------------------------------- - * long File_tell(DOH *so) - * - * Return current position - * ----------------------------------------------------------------------------- */ -long -File_tell(DOH *so) { - File *s = (File *) so; - if (s->filep) - return ftell(s->filep); - else - return lseek(s->fd,0,SEEK_CUR); -} - -/* ----------------------------------------------------------------------------- - * int File_putc(DOH *obj, int ch) - * - * Put a character on the output - * ----------------------------------------------------------------------------- */ - -int File_putc(DOH *obj, int ch) { - File *s = (File *) obj; - if (s->filep) - return fputc(ch,s->filep); - return EOF; -} - -/* ----------------------------------------------------------------------------- - * int File_getc(DOH *obj) - * - * Get a character - * ----------------------------------------------------------------------------- */ - -int File_getc(DOH *obj) { - File *s = (File *) obj; - if (s->filep) - return fgetc(s->filep); - return EOF; -} - -/* ----------------------------------------------------------------------------- - * int File_ungetc(DOH *obj, int ch) - * - * Put a character back onto the input - * ----------------------------------------------------------------------------- */ - -int File_ungetc(DOH *obj, int ch) { - File *s = (File *) obj; - if (s->filep) - return ungetc(ch, s->filep); - return EOF; -} - - - diff --git a/SWIG/Source/DOH/Doh/fio.c b/SWIG/Source/DOH/Doh/fio.c index c462b3c21..13b042ca3 100644 --- a/SWIG/Source/DOH/Doh/fio.c +++ b/SWIG/Source/DOH/Doh/fio.c @@ -13,14 +13,17 @@ * can be used and distributed. ****************************************************************************/ -#include "dohint.h" +static char cvsroot[] = "$Header:"; /* ----------------------------------------------------------------------------- * fio.c * - * Support for formatted I/O via fprintf, fscanf. + * This file provides support for formatted I/O via fprint style + * functions. * ----------------------------------------------------------------------------- */ +#include "dohint.h" + #define OBUFLEN 512 static int Writen(DOH *out, void *buffer, int len) { @@ -38,7 +41,7 @@ static int Writen(DOH *out, void *buffer, int len) { /* ----------------------------------------------------------------------------- * void DohEncoding(char *name, DOH *(*fn)(DOH *s)) * - * Register a printf encoding method. + * Register a printf named encoding method. * ----------------------------------------------------------------------------- */ static DOH *encodings = 0; diff --git a/SWIG/Source/DOH/Doh/main.c b/SWIG/Source/DOH/Doh/main.c deleted file mode 100644 index 35c08baa9..000000000 --- a/SWIG/Source/DOH/Doh/main.c +++ /dev/null @@ -1,30 +0,0 @@ -#include "doh.h" - -int main() { - DOH *d1, *d2, *d3; - DOH *f; - DOH *l; - DOH *h; - - printf("starting...\n"); - f = NewFile("foo","w"); - printf("%x\n",f); - d1 = NewString("Hello"); - d2 = NewString("World"); - Append(d1,d2); - Printf(d1,"This is a test %d", 42); - Setattr(d1,"foo",d2); - Printf(f,"Hello World\n"); - Printf(f,"%s\n",d1); - l = NewList(); - Append(l,d1); - Append(l,d2); - Append(l,f); - h = NewHash(); - Setattr(h,"foo",d1); - Setattr(h,"bar",l); - Printf(f,"%o\n",l); - Printf(f,"%o\n",h); - Printf(f,"%o\n", Getattr(h,"bar")); -} - diff --git a/SWIG/Source/DOH/Doh/memory.c b/SWIG/Source/DOH/Doh/memory.c index 9e2f502ae..67956bf9a 100644 --- a/SWIG/Source/DOH/Doh/memory.c +++ b/SWIG/Source/DOH/Doh/memory.c @@ -13,6 +13,8 @@ * can be used and distributed. ****************************************************************************/ +static char cvsroot[] = "$Header$"; + #include "dohint.h" #ifndef DOH_POOL_SIZE diff --git a/SWIG/Source/DOH/Doh/string.c b/SWIG/Source/DOH/Doh/string.c index 1ca6cbcf9..926e12ce6 100644 --- a/SWIG/Source/DOH/Doh/string.c +++ b/SWIG/Source/DOH/Doh/string.c @@ -13,15 +13,16 @@ * can be used and distributed. ****************************************************************************/ -#include "dohint.h" +static char cvsroot[] = "$Header$"; /* --------------------------------------------------------------------------- - * $Header$ * string.c * - * String support. + * String object. * --------------------------------------------------------------------------- */ +#include "dohint.h" + typedef struct String { DOHXCOMMON; int maxsize; /* Max size allocated */ diff --git a/SWIG/Source/DOH/Doh/void.c b/SWIG/Source/DOH/Doh/void.c index a9bdfaf90..fe6b6c63d 100644 --- a/SWIG/Source/DOH/Doh/void.c +++ b/SWIG/Source/DOH/Doh/void.c @@ -13,7 +13,8 @@ * can be used and distributed. ****************************************************************************/ -#include "dohint.h" + +static char cvsroot[] = "$Header$"; /* ----------------------------------------------------------------------------- * void.c @@ -21,6 +22,8 @@ * Void Object * ----------------------------------------------------------------------------- */ +#include "dohint.h" + typedef struct { DOHCOMMON; void *ptr;