Update for SWILL

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@1068 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dave Beazley 2001-03-27 03:49:37 +00:00
commit 1da7189dba
4 changed files with 109 additions and 11 deletions

View file

@ -18,6 +18,8 @@ prefix = @prefix@
RANLIB = @RANLIB@
AR = @AR@
DOHOPT =
########################################################################
# Normally, you shouldn't have to change anything below this point #
########################################################################
@ -36,7 +38,7 @@ SHELL = /bin/sh
# Rules for creation of a .o file from .c
.SUFFIXES: .c
.c.o:
$(CC) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
$(CC) $(DOHOPT) $(INCLUDE) $(CFLAGS) -c -o $*.o $<
all: $(LIB)

View file

@ -14,8 +14,13 @@ static char cvsroot[] = "$Header$";
#include "dohint.h"
#ifdef DOH_INTFILE
#include <unistd.h>
#endif
typedef struct {
FILE *filep;
int fd;
int closeondel;
} DohFile;
@ -26,8 +31,16 @@ typedef struct {
static void
DelFile(DOH *fo) {
DohFile *f = (DohFile *) ObjData(fo);
if (f->closeondel)
fclose(f->filep);
if (f->closeondel) {
if (f->filep) {
fclose(f->filep);
}
#ifdef DOH_INTFILE
if (f->fd) {
close(f->fd);
}
#endif
}
}
/* -----------------------------------------------------------------------------
@ -37,7 +50,15 @@ DelFile(DOH *fo) {
static int
File_read(DOH *fo, void *buffer, int len) {
DohFile *f = (DohFile *) ObjData(fo);
return fread(buffer,1,len,f->filep);
if (f->filep) {
return fread(buffer,1,len,f->filep);
} else if (f->fd) {
#ifdef DOH_INTFILE
return read(f->fd,buffer,len);
#endif
}
return -1;
}
/* -----------------------------------------------------------------------------
@ -47,7 +68,14 @@ File_read(DOH *fo, void *buffer, int len) {
static int
File_write(DOH *fo, void *buffer, int len) {
DohFile *f = (DohFile *) ObjData(fo);
return fwrite(buffer,1,len,f->filep);
if (f->filep) {
return fwrite(buffer,1,len,f->filep);
} else if (f->fd) {
#ifdef DOH_INTFILE
return write(f->fd,buffer,len);
#endif
}
return -1;
}
/* -----------------------------------------------------------------------------
@ -57,7 +85,14 @@ File_write(DOH *fo, void *buffer, int len) {
static int
File_seek(DOH *fo, long offset, int whence) {
DohFile *f = (DohFile *) ObjData(fo);
return fseek(f->filep,offset,whence);
if (f->filep) {
return fseek(f->filep,offset,whence);
} else if (f->fd) {
#ifdef DOH_INTFILE
return lseek(f->fd, offset, whence);
#endif
}
return -1;
}
/* -----------------------------------------------------------------------------
@ -67,7 +102,14 @@ File_seek(DOH *fo, long offset, int whence) {
static long
File_tell(DOH *fo) {
DohFile *f = (DohFile *) ObjData(fo);
return ftell(f->filep);
if (f->filep) {
return ftell(f->filep);
} else if (f->fd) {
#ifdef DOH_INTFILE
return tell(f->fd);
#endif
}
return -1;
}
/* -----------------------------------------------------------------------------
@ -76,8 +118,17 @@ File_tell(DOH *fo) {
static int
File_putc(DOH *fo, int ch) {
char c;
DohFile *f = (DohFile *) ObjData(fo);
return fputc(ch,f->filep);
if (f->filep) {
return fputc(ch,f->filep);
} else if (f->fd) {
#ifdef DOH_INTFILE
c = (char) ch;
return write(f->fd,&c,1);
#endif
}
return -1;
}
/* -----------------------------------------------------------------------------
@ -86,8 +137,17 @@ File_putc(DOH *fo, int ch) {
static int
File_getc(DOH *fo) {
char c;
DohFile *f = (DohFile *) ObjData(fo);
return fgetc(f->filep);
if (f->filep) {
return fgetc(f->filep);
} else if (f->fd) {
#ifdef DOH_INTFILE
if (read(f->fd,&c,1) < 0) return EOF;
return c;
#endif
}
return EOF;
}
/* -----------------------------------------------------------------------------
@ -99,7 +159,14 @@ File_getc(DOH *fo) {
static int
File_ungetc(DOH *fo, int ch) {
DohFile *f = (DohFile *) ObjData(fo);
return ungetc(ch, f->filep);
if (f->filep) {
return ungetc(ch, f->filep);
} else if (f->fd) {
#ifdef DOH_INTFILE
/* Not implemented yet */
#endif
}
return -1;
}
static DohFileMethods FileFileMethods = {
@ -165,6 +232,7 @@ NewFile(DOH *fn, char *mode)
return 0;
}
f->filep = file;
f->fd = 0;
f->closeondel = 1;
return DohObjMalloc(DOHTYPE_FILE,f);
}
@ -187,6 +255,30 @@ NewFileFromFile(FILE *file)
f = (DohFile *) DohMalloc(sizeof(DohFile));
if (!f) return 0;
f->filep = file;
f->fd = 0;
f->closeondel = 0;
return DohObjMalloc(DOHTYPE_FILE,f);
}
/* -----------------------------------------------------------------------------
* NewFileFromFd()
*
* Create a file object from an already open FILE *.
* ----------------------------------------------------------------------------- */
DOH *
NewFileFromFd(int fd)
{
DohFile *f;
static int init = 0;
if (!init) {
DohRegisterType(DOHTYPE_FILE, &DohFileType);
init = 1;
}
f = (DohFile *) DohMalloc(sizeof(DohFile));
if (!f) return 0;
f->filep = 0;
f->fd = fd;
f->closeondel = 0;
return DohObjMalloc(DOHTYPE_FILE,f);
}

View file

@ -204,6 +204,8 @@ extern DOHString *NewStringf(const DOH *fmt, ...);
extern DOHFile *NewFile(DOH *file, char *mode);
extern DOHFile *NewFileFromFile(FILE *f);
extern DOHFile *NewFileFromFd(int fd);
extern int DohCopyto(DOHFile *input, DOHFile *output);
#define Copyto DohCopyto

View file

@ -10,6 +10,8 @@ exec_prefix= @exec_prefix@
INCLUDE_DIR = $(prefix)/include
LIB_DIR = $(exec_prefix)/lib
DOHOPT =
# Installer
INSTALL = ./install-sh -c
@ -17,7 +19,7 @@ INSTALL_DATA = ${INSTALL} -m 644
INSTALL_PROGRAM= ${INSTALL} -m 755
all:
cd Doh; $(MAKE)
cd Doh; $(MAKE) DOHOPT='$(DOHOPT)'
install:
@echo "Installing $(LIB_DIR)/libdoh.a..."