*** empty log message ***
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
8801582b8e
commit
de4fd916ec
5 changed files with 132 additions and 130 deletions
|
|
@ -24,9 +24,9 @@ AR = ar
|
|||
# Normally, you shouldn't have to change anything below this point #
|
||||
########################################################################
|
||||
|
||||
LIBOBJS = fio.o memory.o base.o file.o list.o hash.o string.o
|
||||
LIBOBJS = void.o fio.o memory.o base.o file.o list.o hash.o string.o
|
||||
|
||||
LIBSRCS = fio.c memory.c base.c file.c list.c hash.c string.c
|
||||
LIBSRCS = void.c fio.c memory.c base.c file.c list.c hash.c string.c
|
||||
|
||||
LIBHEADERS = ../Include/doh.h
|
||||
LIB = ../libdoh.a
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
typedef struct File {
|
||||
DOHCOMMON;
|
||||
FILE *filep;
|
||||
int fd;
|
||||
int closeondel;
|
||||
} File;
|
||||
|
||||
|
|
@ -95,6 +96,7 @@ NewFile(char *filename, char *mode)
|
|||
DohInit(f);
|
||||
f->objinfo = &FileType;
|
||||
f->filep = file;
|
||||
f->fd = fileno(file);
|
||||
f->closeondel = 1;
|
||||
return (DOH *) f;
|
||||
}
|
||||
|
|
@ -112,6 +114,25 @@ NewFileFromFile(FILE *file)
|
|||
DohInit(f);
|
||||
f->objinfo = &FileType;
|
||||
f->filep = file;
|
||||
f->fd = fileno(file);
|
||||
f->closeondel = 0;
|
||||
return (DOH *) f;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* NewFileFromFd(int fd)
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
DOH *
|
||||
NewFileFromFd(int fd)
|
||||
{
|
||||
File *f;
|
||||
f = (File *) DohMalloc(sizeof(File));
|
||||
if (!f) return 0;
|
||||
DohInit(f);
|
||||
f->objinfo = &FileType;
|
||||
f->filep = 0;
|
||||
f->fd = fd;
|
||||
f->closeondel = 0;
|
||||
return (DOH *) f;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
int
|
||||
DohvPrintf(DOH *so, char *format, va_list ap)
|
||||
{
|
||||
static char *fmt_codes = "dioxXucsSfeEgGpnbB";
|
||||
static char *fmt_codes = "dioxXucsSfeEgGpn";
|
||||
int state = 0;
|
||||
char *p = format;
|
||||
char newformat[256];
|
||||
|
|
@ -46,12 +46,14 @@ DohvPrintf(DOH *so, char *format, va_list ap)
|
|||
int dvalue;
|
||||
void *pvalue;
|
||||
char *stemp;
|
||||
int nbytes = 0;
|
||||
|
||||
while (*p) {
|
||||
switch(state) {
|
||||
case 0: /* Ordinary text */
|
||||
if (*p != '%') {
|
||||
Putc(*p,so);
|
||||
nbytes++;
|
||||
} else{
|
||||
fmt = newformat;
|
||||
widthval = 0;
|
||||
|
|
@ -81,6 +83,7 @@ DohvPrintf(DOH *so, char *format, va_list ap)
|
|||
} else if (*p == '%') {
|
||||
Putc(*p,so);
|
||||
fmt = newformat;
|
||||
nbytes++;
|
||||
state = 0;
|
||||
} else {
|
||||
*(fmt++) = *p;
|
||||
|
|
@ -200,7 +203,7 @@ DohvPrintf(DOH *so, char *format, va_list ap)
|
|||
} else {
|
||||
stemp = (char *) malloc(maxwidth+1);
|
||||
}
|
||||
sprintf(stemp,newformat,Data(Sval));
|
||||
nbytes+=sprintf(stemp,newformat,Data(Sval));
|
||||
Write(so,stemp,strlen(stemp));
|
||||
if ((DOH *) Sval != doh) {
|
||||
Delete(Sval);
|
||||
|
|
@ -220,7 +223,7 @@ DohvPrintf(DOH *so, char *format, va_list ap)
|
|||
} else {
|
||||
stemp = (char *) malloc(maxwidth + 1);
|
||||
}
|
||||
sprintf(stemp,newformat,doh);
|
||||
nbytes+=sprintf(stemp,newformat,doh);
|
||||
Write(so,stemp,strlen(stemp));
|
||||
if (stemp != obuffer) {
|
||||
free(stemp);
|
||||
|
|
@ -247,7 +250,7 @@ DohvPrintf(DOH *so, char *format, va_list ap)
|
|||
case 'X':
|
||||
case 'c':
|
||||
ivalue = va_arg(ap,int);
|
||||
sprintf(stemp,newformat,ivalue);
|
||||
nbytes+=sprintf(stemp,newformat,ivalue);
|
||||
break;
|
||||
case 'f':
|
||||
case 'g':
|
||||
|
|
@ -255,11 +258,11 @@ DohvPrintf(DOH *so, char *format, va_list ap)
|
|||
case 'E':
|
||||
case 'G':
|
||||
dvalue = va_arg(ap,double);
|
||||
sprintf(stemp,newformat,dvalue);
|
||||
nbytes+=sprintf(stemp,newformat,dvalue);
|
||||
break;
|
||||
case 'p':
|
||||
pvalue = va_arg(ap,void *);
|
||||
sprintf(stemp,newformat,pvalue);
|
||||
nbytes+=sprintf(stemp,newformat,pvalue);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
@ -274,9 +277,9 @@ DohvPrintf(DOH *so, char *format, va_list ap)
|
|||
}
|
||||
if (state) {
|
||||
*fmt = 0;
|
||||
Write(so,fmt,strlen(fmt));
|
||||
nbytes += Write(so,fmt,strlen(fmt));
|
||||
}
|
||||
return 1;
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
/* Printf */
|
||||
|
|
@ -288,117 +291,3 @@ int DohPrintf(DOH *obj, char *format, ...) {
|
|||
va_end(ap);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef OLD
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* int String_scanfv(DOH *doh, char *format, va_list ap)
|
||||
*
|
||||
* Do a string scanf. Somewhat broken compared to C scanf.
|
||||
* ---------------------------------------------------------------------- */
|
||||
|
||||
int String_scanfv(DOH *doh, char *format, va_list ap) {
|
||||
static char *fmt_chars = "diouxcsefgp";
|
||||
String *s;
|
||||
char newformat[256];
|
||||
char *fmt;
|
||||
char *p;
|
||||
int state;
|
||||
void *ptr;
|
||||
int total = 0;
|
||||
int i;
|
||||
|
||||
s = (String *) doh;
|
||||
state = 0;
|
||||
p = format;
|
||||
while (*p) {
|
||||
switch(state) {
|
||||
case 0:
|
||||
if (*p == '%') {
|
||||
fmt = newformat;
|
||||
*(fmt++) = *p;
|
||||
state = 10;
|
||||
}
|
||||
break;
|
||||
case 10:
|
||||
if (strchr(fmt_chars,*p)) {
|
||||
int len;
|
||||
*(fmt++) = *p;
|
||||
*fmt = 0;
|
||||
ptr = va_arg(ap, void *);
|
||||
len = sscanf(s->str+s->sp,newformat,ptr);
|
||||
for (i = 0; i < len; i++) {
|
||||
while (s->sp < s->len) {
|
||||
if (!isspace(s->str[s->sp])) break;
|
||||
s->sp++;
|
||||
}
|
||||
while (s->sp < s->len) {
|
||||
if (isspace(s->str[s->sp])) break;
|
||||
s->sp++;
|
||||
}
|
||||
}
|
||||
total += len;
|
||||
state = 0;
|
||||
fmt = newformat;
|
||||
} else {
|
||||
*(fmt++) = *p;
|
||||
}
|
||||
break;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
/* vPrintf */
|
||||
int DohvPrintf(DOH *obj, char *format, va_list ap) {
|
||||
int ret;
|
||||
DohBase *b = (DohBase *) obj;
|
||||
if (DohIsFile(obj)) {
|
||||
if (b->objinfo->doh_file->doh_printf) {
|
||||
return (b->objinfo->doh_file->doh_printf)(obj,format,ap);
|
||||
}
|
||||
printf("No printf method defined for type '%s'\n", b->objinfo->objname);
|
||||
} else {
|
||||
if (!DohCheck(obj)) {
|
||||
DOH *str;
|
||||
str = NewString("");
|
||||
DohvAppendf(str,format,ap);
|
||||
ret = fprintf((FILE *) obj, "%s", Data(str));
|
||||
Delete(str);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Printf */
|
||||
int DohScanf(DOH *obj, char *format, ...) {
|
||||
va_list ap;
|
||||
int ret;
|
||||
DohBase *b = (DohBase *) obj;
|
||||
if (DohIsFile(obj)) {
|
||||
if (b->objinfo->doh_file->doh_scanf) {
|
||||
va_start(ap,format);
|
||||
ret = (b->objinfo->doh_file->doh_scanf)(obj,format,ap);
|
||||
va_end(ap);
|
||||
return ret;
|
||||
}
|
||||
printf("No scanf method defined for type '%s'\n", b->objinfo->objname);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* vPrintf */
|
||||
int DohvScanf(DOH *obj, char *format, va_list ap) {
|
||||
DohBase *b = (DohBase *) obj;
|
||||
if (DohIsFile(obj)) {
|
||||
if (b->objinfo->doh_file->doh_scanf) {
|
||||
return (b->objinfo->doh_file->doh_scanf)(obj,format,ap);
|
||||
}
|
||||
printf("No scanf method defined for type '%s'\n", b->objinfo->objname);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
88
SWIG/Source/DOH/Doh/void.c
Normal file
88
SWIG/Source/DOH/Doh/void.c
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
/****************************************************************************
|
||||
* DOH (Dynamic Object Hack)
|
||||
*
|
||||
* Author : David Beazley
|
||||
*
|
||||
* 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.
|
||||
****************************************************************************/
|
||||
|
||||
#include "doh.h"
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* void.c
|
||||
*
|
||||
* Void Object
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
typedef struct {
|
||||
DOHCOMMON;
|
||||
void *ptr;
|
||||
void (*del)(void *);
|
||||
} VoidObj;
|
||||
|
||||
void Void_delete(DOH *);
|
||||
DOH *Void_copy(DOH *);
|
||||
void *Void_data(DOH *);
|
||||
|
||||
static DohObjInfo DohVoidType = {
|
||||
"VoidObj", /* objname */
|
||||
sizeof(VoidObj), /* objsize */
|
||||
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_mapping */
|
||||
0, /* doh_sequence */
|
||||
0, /* doh_file */
|
||||
0, /* reserved2 */
|
||||
0, /* reserved3 */
|
||||
0, /* reserved4 */
|
||||
0, /* reserved5 */
|
||||
0, /* reserved6 */
|
||||
0, /* user1 */
|
||||
0, /* user2 */
|
||||
0, /* user3 */
|
||||
0, /* user4 */
|
||||
};
|
||||
|
||||
|
||||
DOH *NewVoid(void *obj, void (*del)(void *)) {
|
||||
VoidObj *v;
|
||||
v = (VoidObj *) malloc(sizeof(VoidObj));
|
||||
DohInit(v);
|
||||
v->objinfo = &DohVoidType;
|
||||
v->ptr = obj;
|
||||
v->del = del;
|
||||
return (DOH *) v;
|
||||
}
|
||||
|
||||
void Void_delete(DOH *vo) {
|
||||
VoidObj *v = (VoidObj *) vo;
|
||||
if (v->del) {
|
||||
(*v->del)(v->ptr);
|
||||
}
|
||||
free(v);
|
||||
}
|
||||
|
||||
DOH *Void_copy(DOH *vo) {
|
||||
VoidObj *v = (VoidObj *) vo;
|
||||
return NewVoid(v->ptr,0);
|
||||
}
|
||||
|
||||
void *Void_data(DOH *vo) {
|
||||
VoidObj *v = (VoidObj *) vo;
|
||||
return v->ptr;
|
||||
}
|
||||
|
||||
|
|
@ -156,8 +156,8 @@ extern int DohUngetc(int ch, DOH *obj);
|
|||
|
||||
extern int DohPrintf(DOH *obj, char *format, ...);
|
||||
extern int DohvPrintf(DOH *obj, char *format, va_list ap);
|
||||
extern int DohScanf(DOH *obj, char *format, ...);
|
||||
extern int DohvScanf(DOH *obj, char *format, va_list ap);
|
||||
/* extern int DohScanf(DOH *obj, char *format, ...);
|
||||
extern int DohvScanf(DOH *obj, char *format, va_list ap); */
|
||||
|
||||
/* Macros to invoke the above functions. Includes the location of
|
||||
the caller to simplify debugging if something goes wrong */
|
||||
|
|
@ -201,8 +201,9 @@ extern int DohvScanf(DOH *obj, char *format, va_list ap);
|
|||
#define Putc DohPutc
|
||||
#define Ungetc DohUngetc
|
||||
#define vPrintf DohvPrintf
|
||||
#define Scanf DohScanf
|
||||
#define vScanf DohvScanf
|
||||
|
||||
/* #define Scanf DohScanf
|
||||
#define vScanf DohvScanf*/
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* DohBase
|
||||
|
|
@ -263,8 +264,11 @@ extern DOH *NewHash();
|
|||
extern int Hash_check(DOH *h);
|
||||
extern DOH *Hash_keys(DOH *);
|
||||
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Void
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
extern DOH *NewVoid(void *ptr, void (*del)(void *));
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue