[uim-commit] r1922 - branches/r5rs/sigscheme
yamaken at freedesktop.org
yamaken at freedesktop.org
Tue Nov 1 01:21:51 PST 2005
Author: yamaken
Date: 2005-11-01 01:21:43 -0800 (Tue, 01 Nov 2005)
New Revision: 1922
Modified:
branches/r5rs/sigscheme/fileport.c
branches/r5rs/sigscheme/fileport.h
branches/r5rs/sigscheme/io.c
branches/r5rs/sigscheme/sigscheme.c
Log:
* This commit adds filename information support to ScmFilePort
* sigscheme/fileport.h
- (ScmFilePort_new): Add new arg 'aux_info'
- (ScmFilePort_open_input_file, ScmFilePort_open_output_file): New
function decl
* sigscheme/fileport.c
- (struct ScmFilePort_): Add member 'aux_info'
- (ScmFilePort_new): Add new arg 'aux_info' and handlings
- (ScmFilePort_open_input_file, ScmFilePort_open_output_file): New
function
- (fileport_close, fileport_inspect): Add aux_info handlings
* sigscheme/io.c
- (ScmOp_open_input_file, ScmOp_open_output_file): Support filename
info for SCM_USE_NEWPORT
* sigscheme/sigscheme.c
- (SigScm_Initialize_internal): Ditto
Modified: branches/r5rs/sigscheme/fileport.c
===================================================================
--- branches/r5rs/sigscheme/fileport.c 2005-11-01 08:59:55 UTC (rev 1921)
+++ branches/r5rs/sigscheme/fileport.c 2005-11-01 09:21:43 UTC (rev 1922)
@@ -67,6 +67,7 @@
const ScmBytePortVTbl *vptr;
FILE *file;
+ char *aux_info; /* human readable auxilialy information about the file */
};
/*=======================================
@@ -116,18 +117,37 @@
}
ScmBytePort *
-ScmFilePort_new(FILE *file)
-{
+ScmFilePort_new(FILE *file, const char *aux_info)
+ {
ScmFilePort *port;
SCM_PORT_ALLOC(BYTE, port, ScmFilePort);
port->vptr = ScmFilePort_vptr;
port->file = file;
+ port->aux_info = strdup(aux_info);
return (ScmBytePort *)port;
}
+ScmBytePort *
+ScmFilePort_open_input_file(const char *path)
+{
+ FILE *file;
+
+ file = fopen(path, "rb");
+ return (file) ? ScmFilePort_new(file, path) : NULL;
+}
+
+ScmBytePort *
+ScmFilePort_open_output_file(const char *path)
+{
+ FILE *file;
+
+ file = fopen(path, "wb");
+ return (file) ? ScmFilePort_new(file, path) : NULL;
+}
+
static ScmBytePort *
fileport_dyn_cast(ScmBytePort *bport, const ScmBytePortVTbl *dst_vptr)
{
@@ -143,6 +163,7 @@
int err;
err = fclose(port->file);
+ free(port->aux_info);
free(port);
return err;
@@ -151,7 +172,17 @@
static char *
fileport_inspect(ScmFilePort *port)
{
- return strdup("file");
+ char *combined;
+ size_t size;
+
+ if (port->aux_info) {
+ size = sizeof("file ") + strlen(port->aux_info);
+ combined = malloc(size);
+ snprintf(combined, size, "file %s", port->aux_info);
+ return combined;
+ } else {
+ return strdup("file");
+ }
}
static int
Modified: branches/r5rs/sigscheme/fileport.h
===================================================================
--- branches/r5rs/sigscheme/fileport.h 2005-11-01 08:59:55 UTC (rev 1921)
+++ branches/r5rs/sigscheme/fileport.h 2005-11-01 09:21:43 UTC (rev 1922)
@@ -69,8 +69,9 @@
=======================================*/
void Scm_fileport_init(void);
-/* FIXME: add a creator takes pathname */
-ScmBytePort *ScmFilePort_new(FILE *file);
+ScmBytePort *ScmFilePort_new(FILE *file, const char *aux_info);
+ScmBytePort *ScmFilePort_open_input_file(const char *path);
+ScmBytePort *ScmFilePort_open_output_file(const char *path);
#endif /* __SCM_FILEPORT_H */
Modified: branches/r5rs/sigscheme/io.c
===================================================================
--- branches/r5rs/sigscheme/io.c 2005-11-01 08:59:55 UTC (rev 1921)
+++ branches/r5rs/sigscheme/io.c 2005-11-01 09:21:43 UTC (rev 1922)
@@ -239,38 +239,52 @@
ScmObj ScmOp_open_input_file(ScmObj filepath)
{
+#if SCM_USE_NEWPORT
+ ScmBytePort *bport;
+#else
FILE *f = NULL;
+#endif
DECLARE_FUNCTION("open-input-file", ProcedureFixed1);
ASSERT_STRINGP(filepath);
+#if SCM_USE_NEWPORT
+ bport = ScmFilePort_open_input_file(SCM_STRING_STR(filepath));
+ if (!bport)
+ ERR_OBJ("cannot open file ", filepath);
+
+ return Scm_NewPort(ScmSingleByteCharPort_new(bport), SCM_PORTFLAG_INPUT);
+#else /* SCM_USE_NEWPORT */
f = fopen(SCM_STRING_STR(filepath), "r");
if (!f)
ERR_OBJ("cannot open file ", filepath);
-#if SCM_USE_NEWPORT
- return Scm_NewPort(ScmSingleByteCharPort_new(ScmFilePort_new(f)),
- SCM_PORTFLAG_INPUT);
-#else /* SCM_USE_NEWPORT */
return Scm_NewFilePort(f, SCM_STRING_STR(filepath), PORT_INPUT);
#endif /* SCM_USE_NEWPORT */
}
ScmObj ScmOp_open_output_file(ScmObj filepath)
{
+#if SCM_USE_NEWPORT
+ ScmBytePort *bport;
+#else
FILE *f = NULL;
+#endif
DECLARE_FUNCTION("open-output-file", ProcedureFixed1);
ASSERT_STRINGP(filepath);
+#if SCM_USE_NEWPORT
+ bport = ScmFilePort_open_output_file(SCM_STRING_STR(filepath));
+ if (!bport)
+ ERR_OBJ("cannot open file ", filepath);
+
+ return Scm_NewPort(ScmSingleByteCharPort_new(bport), SCM_PORTFLAG_OUTPUT);
+#else /* SCM_USE_NEWPORT */
f = fopen(SCM_STRING_STR(filepath), "w");
if (!f)
ERR_OBJ("cannot open file ", filepath);
-#if SCM_USE_NEWPORT
- return Scm_NewPort(ScmSingleByteCharPort_new(ScmFilePort_new(f)),
- SCM_PORTFLAG_OUTPUT);
-#else /* SCM_USE_NEWPORT */
return Scm_NewFilePort(f, SCM_STRING_STR(filepath), PORT_OUTPUT);
#endif /* SCM_USE_NEWPORT */
}
Modified: branches/r5rs/sigscheme/sigscheme.c
===================================================================
--- branches/r5rs/sigscheme/sigscheme.c 2005-11-01 08:59:55 UTC (rev 1921)
+++ branches/r5rs/sigscheme/sigscheme.c 2005-11-01 09:21:43 UTC (rev 1922)
@@ -128,6 +128,10 @@
static void SigScm_Initialize_internal(void)
{
+#if SCM_USE_NEWPORT
+ ScmBytePort *bport;
+#endif
+
/*=======================================================================
Core
=======================================================================*/
@@ -164,15 +168,15 @@
Scm_fileport_init();
Scm_sbcport_init();
- scm_current_input_port
- = Scm_NewPort(ScmSingleByteCharPort_new(ScmFilePort_new(stdin)),
- SCM_PORTFLAG_INPUT);
- scm_current_output_port
- = Scm_NewPort(ScmSingleByteCharPort_new(ScmFilePort_new(stdout)),
- SCM_PORTFLAG_OUTPUT);
- scm_current_error_port
- = Scm_NewPort(ScmSingleByteCharPort_new(ScmFilePort_new(stderr)),
- SCM_PORTFLAG_OUTPUT);
+ bport = ScmFilePort_new(stdin, "stdin");
+ scm_current_input_port = Scm_NewPort(ScmSingleByteCharPort_new(bport),
+ SCM_PORTFLAG_INPUT);
+ bport = ScmFilePort_new(stdout, "stdout");
+ scm_current_output_port = Scm_NewPort(ScmSingleByteCharPort_new(bport),
+ SCM_PORTFLAG_OUTPUT);
+ bport = ScmFilePort_new(stderr, "stderr");
+ scm_current_error_port = Scm_NewPort(ScmSingleByteCharPort_new(bport),
+ SCM_PORTFLAG_OUTPUT);
#else /* SCM_USE_NEWPORT */
scm_current_input_port = Scm_NewFilePort(stdin, "stdin", PORT_INPUT);
scm_current_output_port = Scm_NewFilePort(stdout, "stdout", PORT_OUTPUT);
More information about the uim-commit
mailing list