summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Köppe <mkoeppe@mail.math.uni-magdeburg.de>2000-09-21 21:06:17 +0000
committerMatthias Köppe <mkoeppe@mail.math.uni-magdeburg.de>2000-09-21 21:06:17 +0000
commit88ffd4c6910fd9f4e83ec0147b96dd481589d320 (patch)
tree0ce0421bfcd6821e8206efad0bd36a1aa4dc9d76
parentf897860710d95c290e203f079ce9a1b039932b71 (diff)
downloadswig-88ffd4c6910fd9f4e83ec0147b96dd481589d320.tar.gz
[Guile] New typemaps for FILE *.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@875 626c5289-ae23-0410-ae9c-e8d60b6d4f22
-rw-r--r--SWIG/Lib/guile/guiledec.swg8
-rw-r--r--SWIG/Lib/guile/ports.i44
-rw-r--r--SWIG/Lib/guile/typemaps.i7
3 files changed, 58 insertions, 1 deletions
diff --git a/SWIG/Lib/guile/guiledec.swg b/SWIG/Lib/guile/guiledec.swg
index 5b9e2700a..947619c57 100644
--- a/SWIG/Lib/guile/guiledec.swg
+++ b/SWIG/Lib/guile/guiledec.swg
@@ -61,6 +61,14 @@ GSWIG_scm2char (SCM s)
scm_wrong_type_arg(NULL, 0, s);
}
+/* More 1.3.4 compatibility */
+#ifndef SCM_INPUT_PORT_P
+# define SCM_INPUT_PORT_P SCM_INPORTP
+# define SCM_OUTPUT_PORT_P SCM_OUTPORTP
+#endif
+
+/* Type system */
+
typedef struct SwigPtrType SwigPtrType;
typedef struct swig_type_info {
diff --git a/SWIG/Lib/guile/ports.i b/SWIG/Lib/guile/ports.i
new file mode 100644
index 000000000..3741070b0
--- /dev/null
+++ b/SWIG/Lib/guile/ports.i
@@ -0,0 +1,44 @@
+/* ports.i --- Guile typemaps for handling ports -*- c -*-
+ Copyright (C) 2000 Matthias Koeppe <mkoeppe@mail.math.uni-magdeburg.de>
+
+ $Header$
+*/
+
+%{
+ #ifndef _POSIX_SOURCE
+ /* This is needed on Solaris for fdopen(). */
+ # define _POSIX_SOURCE=199506L
+ #endif
+ #include <stdio.h>
+ #include <errno.h>
+%}
+
+/* Feed FILE * arguments from file ports */
+
+%typemap(guile, in) FILE *
+{
+ if(!(SCM_FPORTP($source)))
+ scm_wrong_type_arg("$name", $argnum, $source);
+ else {
+ int fd;
+ if (SCM_OUTPUT_PORT_P($source))
+ scm_force_output($source);
+ fd=dup(SCM_FPORT_FDES($source));
+ if(fd==-1)
+ scm_misc_error("$name", strerror(errno), SCM_EOL);
+ $target=fdopen(fd,
+ SCM_OUTPUT_PORT_P($source)
+ ? (SCM_INPUT_PORT_P($source)
+ ? "rw" : "w")
+ : "r");
+ if($target==NULL)
+ scm_misc_error("$name", strerror(errno), SCM_EOL);
+ }
+}
+
+%typemap(guile, indoc) FILE * "($arg <port>)";
+
+%typemap(guile, freearg) FILE* {
+ fclose($target);
+}
+
diff --git a/SWIG/Lib/guile/typemaps.i b/SWIG/Lib/guile/typemaps.i
index 418fa4de0..21d6150db 100644
--- a/SWIG/Lib/guile/typemaps.i
+++ b/SWIG/Lib/guile/typemaps.i
@@ -3,7 +3,12 @@
$Header$ */
-/* Basic types */
+/* Unlike other SWIG language modules, the Guile module handles all
+ non-pointer types uniformly via typemaps. Here are the
+ definitions.
+
+ The SIMPLE_MAP macro below defines the whole set of typemaps needed
+ for simple types. */
%define SIMPLE_MAP(C_NAME, SCM_TO_C, C_TO_SCM, SCM_NAME)
%typemap (guile, in) C_NAME "$target = SCM_TO_C($source);";