aboutsummaryrefslogtreecommitdiff
path: root/libgm2/libm2pim
diff options
context:
space:
mode:
Diffstat (limited to 'libgm2/libm2pim')
-rw-r--r--libgm2/libm2pim/Makefile.am7
-rw-r--r--libgm2/libm2pim/Makefile.in19
-rw-r--r--libgm2/libm2pim/Selective.cc77
-rw-r--r--libgm2/libm2pim/SysExceptions.cc22
-rw-r--r--libgm2/libm2pim/UnixArgs.cc30
-rw-r--r--libgm2/libm2pim/cgetopt.cc63
-rw-r--r--libgm2/libm2pim/dtoa.cc35
-rw-r--r--libgm2/libm2pim/errno.cc19
-rw-r--r--libgm2/libm2pim/ldtoa.cc36
-rw-r--r--libgm2/libm2pim/sckt.cc49
-rw-r--r--libgm2/libm2pim/termios.cc18
-rw-r--r--libgm2/libm2pim/wrapc.cc (renamed from libgm2/libm2pim/wrapc.c)92
12 files changed, 263 insertions, 204 deletions
diff --git a/libgm2/libm2pim/Makefile.am b/libgm2/libm2pim/Makefile.am
index 7bb08c0..eae14fa 100644
--- a/libgm2/libm2pim/Makefile.am
+++ b/libgm2/libm2pim/Makefile.am
@@ -161,12 +161,15 @@ libm2pim_la_SOURCES = $(M2MODS) \
errno.cc dtoa.cc \
ldtoa.cc termios.cc \
SysExceptions.cc target.c \
- wrapc.c cgetopt.cc
+ wrapc.cc cgetopt.cc
libm2pimdir = libm2pim
libm2pim_la_DEPENDENCIES = SYSTEM.def $(addsuffix .lo, $(basename $(libm2pim_la_SOURCES)))
libm2pim_la_CFLAGS = -I. -I.. -I$(GM2_SRC)/gm2-libs -I$(GM2_SRC)/gm2-libs-iso -DBUILD_GM2_LIBS -I@srcdir@/../ -I@srcdir@/../libm2iso
-libm2pim_la_M2FLAGS = -I. -I$(GM2_SRC)/gm2-libs -I$(GM2_SRC)/gm2-libs-iso -fm2-g -g -Wreturn-type -fcase
+libm2pim_la_M2FLAGS = \
+ -fm2-pathname=m2pim -I. -I$(GM2_SRC)/gm2-libs \
+ -fm2-pathname=m2iso -I$(GM2_SRC)/gm2-libs-iso \
+ -fm2-g -g -Wreturn-type -fcase -fm2-prefix=m2pim
if TARGET_DARWIN
libm2pim_la_link_flags = -Wl,-undefined,dynamic_lookup
else
diff --git a/libgm2/libm2pim/Makefile.in b/libgm2/libm2pim/Makefile.in
index 7a59893..ec81103 100644
--- a/libgm2/libm2pim/Makefile.in
+++ b/libgm2/libm2pim/Makefile.in
@@ -170,7 +170,7 @@ libm2pim_la_LIBADD =
@BUILD_PIMLIB_TRUE@ UnixArgs.lo Selective.lo sckt.lo errno.lo \
@BUILD_PIMLIB_TRUE@ dtoa.lo ldtoa.lo termios.lo \
@BUILD_PIMLIB_TRUE@ SysExceptions.lo libm2pim_la-target.lo \
-@BUILD_PIMLIB_TRUE@ libm2pim_la-wrapc.lo cgetopt.lo
+@BUILD_PIMLIB_TRUE@ wrapc.lo cgetopt.lo
libm2pim_la_OBJECTS = $(am_libm2pim_la_OBJECTS)
@BUILD_PIMLIB_TRUE@am_libm2pim_la_rpath = -rpath $(toolexeclibdir)
AM_V_P = $(am__v_P_@AM_V@)
@@ -529,12 +529,16 @@ FLAGS_TO_PASS = $(AM_MAKEFLAGS)
@BUILD_PIMLIB_TRUE@ errno.cc dtoa.cc \
@BUILD_PIMLIB_TRUE@ ldtoa.cc termios.cc \
@BUILD_PIMLIB_TRUE@ SysExceptions.cc target.c \
-@BUILD_PIMLIB_TRUE@ wrapc.c cgetopt.cc
+@BUILD_PIMLIB_TRUE@ wrapc.cc cgetopt.cc
@BUILD_PIMLIB_TRUE@libm2pimdir = libm2pim
@BUILD_PIMLIB_TRUE@libm2pim_la_DEPENDENCIES = SYSTEM.def $(addsuffix .lo, $(basename $(libm2pim_la_SOURCES)))
@BUILD_PIMLIB_TRUE@libm2pim_la_CFLAGS = -I. -I.. -I$(GM2_SRC)/gm2-libs -I$(GM2_SRC)/gm2-libs-iso -DBUILD_GM2_LIBS -I@srcdir@/../ -I@srcdir@/../libm2iso
-@BUILD_PIMLIB_TRUE@libm2pim_la_M2FLAGS = -I. -I$(GM2_SRC)/gm2-libs -I$(GM2_SRC)/gm2-libs-iso -fm2-g -g -Wreturn-type -fcase
+@BUILD_PIMLIB_TRUE@libm2pim_la_M2FLAGS = \
+@BUILD_PIMLIB_TRUE@ -fm2-pathname=m2pim -I. -I$(GM2_SRC)/gm2-libs \
+@BUILD_PIMLIB_TRUE@ -fm2-pathname=m2iso -I$(GM2_SRC)/gm2-libs-iso \
+@BUILD_PIMLIB_TRUE@ -fm2-g -g -Wreturn-type -fcase -fm2-prefix=m2pim
+
@BUILD_PIMLIB_TRUE@@TARGET_DARWIN_FALSE@libm2pim_la_link_flags =
@BUILD_PIMLIB_TRUE@@TARGET_DARWIN_TRUE@libm2pim_la_link_flags = -Wl,-undefined,dynamic_lookup
@BUILD_PIMLIB_TRUE@libm2pim_la_LINK = $(LINK) -version-info $(libtool_VERSION) $(libm2pim_la_link_flags)
@@ -628,9 +632,9 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/errno.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldtoa.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libm2pim_la-target.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libm2pim_la-wrapc.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sckt.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/termios.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wrapc.Plo@am__quote@
.c.o:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@@ -660,13 +664,6 @@ libm2pim_la-target.lo: target.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libm2pim_la_CFLAGS) $(CFLAGS) -c -o libm2pim_la-target.lo `test -f 'target.c' || echo '$(srcdir)/'`target.c
-libm2pim_la-wrapc.lo: wrapc.c
-@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libm2pim_la_CFLAGS) $(CFLAGS) -MT libm2pim_la-wrapc.lo -MD -MP -MF $(DEPDIR)/libm2pim_la-wrapc.Tpo -c -o libm2pim_la-wrapc.lo `test -f 'wrapc.c' || echo '$(srcdir)/'`wrapc.c
-@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libm2pim_la-wrapc.Tpo $(DEPDIR)/libm2pim_la-wrapc.Plo
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='wrapc.c' object='libm2pim_la-wrapc.lo' libtool=yes @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libm2pim_la_CFLAGS) $(CFLAGS) -c -o libm2pim_la-wrapc.lo `test -f 'wrapc.c' || echo '$(srcdir)/'`wrapc.c
-
.cc.o:
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
diff --git a/libgm2/libm2pim/Selective.cc b/libgm2/libm2pim/Selective.cc
index 3c6b855..09c57f2 100644
--- a/libgm2/libm2pim/Selective.cc
+++ b/libgm2/libm2pim/Selective.cc
@@ -27,6 +27,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#include <config.h>
#include <m2rts.h>
+#define EXPORT(FUNC) m2pim ## _Selective_ ## FUNC
+#define M2EXPORT(FUNC) m2pim ## _M2_Selective_ ## FUNC
+#define M2LIBNAME "m2pim"
+
#if defined(HAVE_STDDEF_H)
/* Obtain a definition for NULL. */
#include <stddef.h>
@@ -83,15 +87,15 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#if defined(HAVE_STRUCT_TIMEVAL)
extern "C" int
-Selective_Select (int nooffds, fd_set *readfds, fd_set *writefds,
- fd_set *exceptfds, struct timeval *timeout)
+EXPORT(Select) (int nooffds, fd_set *readfds, fd_set *writefds,
+ fd_set *exceptfds, struct timeval *timeout)
{
return select (nooffds, readfds, writefds, exceptfds, timeout);
}
#else
extern "C" int
-Selective_Select (int nooffds, void *readfds, void *writefds, void *exceptfds,
- void *timeout)
+EXPORT(Select) (int nooffds, void *readfds, void *writefds, void *exceptfds,
+ void *timeout)
{
return 0;
}
@@ -101,7 +105,7 @@ Selective_Select (int nooffds, void *readfds, void *writefds, void *exceptfds,
#if defined(HAVE_STRUCT_TIMEVAL)
extern "C" struct timeval *
-Selective_InitTime (unsigned int sec, unsigned int usec)
+EXPORT(InitTime) (unsigned int sec, unsigned int usec)
{
struct timeval *t = (struct timeval *)malloc (sizeof (struct timeval));
@@ -111,14 +115,14 @@ Selective_InitTime (unsigned int sec, unsigned int usec)
}
extern "C" void
-Selective_GetTime (struct timeval *t, unsigned int *sec, unsigned int *usec)
+EXPORT(GetTime) (struct timeval *t, unsigned int *sec, unsigned int *usec)
{
*sec = (unsigned int)t->tv_sec;
*usec = (unsigned int)t->tv_usec;
}
extern "C" void
-Selective_SetTime (struct timeval *t, unsigned int sec, unsigned int usec)
+EXPORT(SetTime) (struct timeval *t, unsigned int sec, unsigned int usec)
{
t->tv_sec = sec;
t->tv_usec = usec;
@@ -127,7 +131,7 @@ Selective_SetTime (struct timeval *t, unsigned int sec, unsigned int usec)
/* KillTime frees the timeval structure and returns NULL. */
extern "C" struct timeval *
-Selective_KillTime (struct timeval *t)
+EXPORT(KillTime) (struct timeval *t)
{
#if defined(HAVE_STDLIB_H)
free (t);
@@ -138,7 +142,7 @@ Selective_KillTime (struct timeval *t)
/* InitSet returns a pointer to a FD_SET. */
extern "C" FDSET_T *
-Selective_InitSet (void)
+EXPORT(InitSet) (void)
{
#if defined(HAVE_STDLIB_H)
FDSET_T *s = (FDSET_T *)malloc (sizeof (FDSET_T));
@@ -152,7 +156,7 @@ Selective_InitSet (void)
/* KillSet frees the FD_SET and returns NULL. */
extern "C" FDSET_T *
-Selective_KillSet (FDSET_T *s)
+EXPORT(KillSet) (FDSET_T *s)
{
#if defined(HAVE_STDLIB_H)
free (s);
@@ -163,7 +167,7 @@ Selective_KillSet (FDSET_T *s)
/* FdZero generate an empty set. */
extern "C" void
-Selective_FdZero (FDSET_T *s)
+EXPORT(FdZero) (FDSET_T *s)
{
FD_ZERO (s);
}
@@ -171,7 +175,7 @@ Selective_FdZero (FDSET_T *s)
/* FS_Set include an element, fd, into set, s. */
extern "C" void
-Selective_FdSet (int fd, FDSET_T *s)
+EXPORT(FdSet) (int fd, FDSET_T *s)
{
FD_SET (fd, s);
}
@@ -179,7 +183,7 @@ Selective_FdSet (int fd, FDSET_T *s)
/* FdClr exclude an element, fd, from the set, s. */
extern "C" void
-Selective_FdClr (int fd, FDSET_T *s)
+EXPORT(FdClr) (int fd, FDSET_T *s)
{
FD_CLR (fd, s);
}
@@ -187,7 +191,7 @@ Selective_FdClr (int fd, FDSET_T *s)
/* FdIsSet return TRUE if, fd, is present in set, s. */
extern "C" int
-Selective_FdIsSet (int fd, FDSET_T *s)
+EXPORT(FdIsSet) (int fd, FDSET_T *s)
{
return FD_ISSET (fd, s);
}
@@ -197,69 +201,69 @@ Selective_FdIsSet (int fd, FDSET_T *s)
It returns zero (see man 3p gettimeofday). */
extern "C" int
-Selective_GetTimeOfDay (struct timeval *t)
+EXPORT(GetTimeOfDay) (struct timeval *t)
{
return gettimeofday (t, NULL);
}
#else
extern "C" void *
-Selective_InitTime (unsigned int sec, unsigned int usec)
+EXPORT(InitTime) (unsigned int sec, unsigned int usec)
{
return NULL;
}
extern "C" void *
-Selective_KillTime (void *t)
+EXPORT(KillTime) (void *t)
{
return NULL;
}
extern "C" void
-Selective_GetTime (void *t, unsigned int *sec, unsigned int *usec)
+EXPORT(GetTime) (void *t, unsigned int *sec, unsigned int *usec)
{
}
extern "C" void
-Selective_SetTime (void *t, unsigned int sec, unsigned int usec)
+EXPORT(SetTime) (void *t, unsigned int sec, unsigned int usec)
{
}
extern "C" FDSET_T *
-Selective_InitSet (void)
+EXPORT(InitSet) (void)
{
return NULL;
}
extern "C" FDSET_T *
-Selective_KillSet (void)
+EXPORT(KillSet) (void)
{
return NULL;
}
extern "C" void
-Selective_FdZero (void *s)
+EXPORT(FdZero) (void *s)
{
}
extern "C" void
-Selective_FdSet (int fd, void *s)
+EXPORT(FdSet) (int fd, void *s)
{
}
extern "C" void
-Selective_FdClr (int fd, void *s)
+EXPORT(FdClr) (int fd, void *s)
{
}
extern "C" int
-Selective_FdIsSet (int fd, void *s)
+EXPORT(FdIsSet) (int fd, void *s)
{
return 0;
}
extern "C" int
-Selective_GetTimeOfDay (void *t)
+EXPORT(GetTimeOfDay) (void *t)
{
return -1;
}
@@ -268,7 +272,7 @@ Selective_GetTimeOfDay (void *t)
/* MaxFdsPlusOne returns max (a + 1, b + 1). */
extern "C" int
-Selective_MaxFdsPlusOne (int a, int b)
+EXPORT(MaxFdsPlusOne) (int a, int b)
{
if (a > b)
return a + 1;
@@ -279,7 +283,7 @@ Selective_MaxFdsPlusOne (int a, int b)
/* WriteCharRaw writes a single character to the file descriptor. */
extern "C" void
-Selective_WriteCharRaw (int fd, char ch)
+EXPORT(WriteCharRaw) (int fd, char ch)
{
write (fd, &ch, 1);
}
@@ -287,7 +291,7 @@ Selective_WriteCharRaw (int fd, char ch)
/* ReadCharRaw read and return a single char from file descriptor, fd. */
extern "C" char
-Selective_ReadCharRaw (int fd)
+EXPORT(ReadCharRaw) (int fd)
{
char ch;
@@ -295,24 +299,27 @@ Selective_ReadCharRaw (int fd)
return ch;
}
+/* GNU Modula-2 linking hooks. */
+
extern "C" void
-_M2_Selective_init (int argc, char *argv[], char *envp[])
+M2EXPORT(init) (int, char **, char **)
{
}
extern "C" void
-_M2_Selective_fini (int argc, char *argv[], char *envp[])
+M2EXPORT(fini) (int, char **, char **)
{
}
extern "C" void
-_M2_Selective_dep (void)
+M2EXPORT(dep) (void)
{
}
extern "C" void __attribute__((__constructor__))
-_M2_Selective_ctor (void)
+M2EXPORT(ctor) (void)
{
- M2RTS_RegisterModule ("Selective", _M2_Selective_init, _M2_Selective_fini,
- _M2_Selective_dep);
+ m2pim_M2RTS_RegisterModule ("Selective", M2LIBNAME,
+ M2EXPORT(init), M2EXPORT(fini),
+ M2EXPORT(dep));
}
diff --git a/libgm2/libm2pim/SysExceptions.cc b/libgm2/libm2pim/SysExceptions.cc
index 2c37c7a..d93e79e 100644
--- a/libgm2/libm2pim/SysExceptions.cc
+++ b/libgm2/libm2pim/SysExceptions.cc
@@ -25,6 +25,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. */
#include <config.h>
+#include "m2rts.h"
+
+#define EXPORT(FUNC) m2pim ## _SysExceptions_ ## FUNC
+#define M2EXPORT(FUNC) m2pim ## _M2_SysExceptions_ ## FUNC
+#define M2LIBNAME "m2pim"
#if defined(HAVE_SIGNAL_H)
#include <signal.h>
@@ -172,7 +177,7 @@ sigfpeDespatcher (int signum, siginfo_t *info, void *ucontext)
}
extern "C" void
-SysExceptions_InitExceptionHandlers (
+EXPORT(InitExceptionHandlers) (
void (*indexf) (void *), void (*range) (void *), void (*casef) (void *),
void (*invalidloc) (void *), void (*function) (void *),
void (*wholevalue) (void *), void (*wholediv) (void *),
@@ -223,7 +228,7 @@ SysExceptions_InitExceptionHandlers (
#else
extern "C" void
-SysExceptions_InitExceptionHandlers (void *indexf, void *range, void *casef,
+EXPORT(InitExceptionHandlers) (void *indexf, void *range, void *casef,
void *invalidloc, void *function,
void *wholevalue, void *wholediv,
void *realvalue, void *realdiv,
@@ -236,23 +241,24 @@ SysExceptions_InitExceptionHandlers (void *indexf, void *range, void *casef,
extern "C" void
-_M2_SysExceptions_init (int, char *[], char *[])
+M2EXPORT(init) (int, char **, char **)
{
}
extern "C" void
-_M2_SysExceptions_fini (int, char *[], char *[])
+M2EXPORT(fini) (int, char **, char **)
{
}
extern "C" void
-_M2_SysExceptions_dep (void)
+M2EXPORT(dep) (void)
{
}
extern "C" void __attribute__((__constructor__))
-_M2_SysExceptions_ctor (void)
+M2EXPORT(ctor) (void)
{
- M2RTS_RegisterModule ("SysExceptions", _M2_SysExceptions_init, _M2_SysExceptions_fini,
- _M2_SysExceptions_dep);
+ m2pim_M2RTS_RegisterModule ("SysExceptions", M2LIBNAME,
+ M2EXPORT(init), M2EXPORT(fini),
+ M2EXPORT(dep));
}
diff --git a/libgm2/libm2pim/UnixArgs.cc b/libgm2/libm2pim/UnixArgs.cc
index 944a3cd..803188d 100644
--- a/libgm2/libm2pim/UnixArgs.cc
+++ b/libgm2/libm2pim/UnixArgs.cc
@@ -27,10 +27,13 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#include <config.h>
#include <m2rts.h>
+#define EXPORT(FUNC) m2pim ## _UnixArgs_ ## FUNC
+#define M2EXPORT(FUNC) m2pim ## _M2_UnixArgs_ ## FUNC
+#define M2LIBNAME "m2pim"
-extern "C" int UnixArgs_GetArgC (void);
-extern "C" char **UnixArgs_GetArgV (void);
-extern "C" char **UnixArgs_GetEnvV (void);
+extern "C" int EXPORT(GetArgC) (void);
+extern "C" char **EXPORT(GetArgV) (void);
+extern "C" char **EXPORT(GetEnvV) (void);
static int UnixArgs_ArgC;
static char **UnixArgs_ArgV;
@@ -40,7 +43,7 @@ static char **UnixArgs_EnvV;
/* GetArgC returns argc. */
extern "C" int
-UnixArgs_GetArgC (void)
+EXPORT(GetArgC) (void)
{
return UnixArgs_ArgC;
}
@@ -49,7 +52,7 @@ UnixArgs_GetArgC (void)
/* GetArgV returns argv. */
extern "C" char **
-UnixArgs_GetArgV (void)
+EXPORT(GetArgV) (void)
{
return UnixArgs_ArgV;
}
@@ -58,14 +61,16 @@ UnixArgs_GetArgV (void)
/* GetEnvV returns envv. */
extern "C" char **
-UnixArgs_GetEnvV (void)
+EXPORT(GetEnvV) (void)
{
return UnixArgs_EnvV;
}
+/* GNU Modula-2 linking hooks. */
+
extern "C" void
-_M2_UnixArgs_init (int argc, char *argv[], char *envp[])
+M2EXPORT(init) (int argc, char **argv, char **envp)
{
UnixArgs_ArgC = argc;
UnixArgs_ArgV = argv;
@@ -73,18 +78,19 @@ _M2_UnixArgs_init (int argc, char *argv[], char *envp[])
}
extern "C" void
-_M2_UnixArgs_fini (int argc, char *argv[], char *envp[])
+M2EXPORT(fini) (int, char **, char **)
{
}
extern "C" void
-_M2_UnixArgs_dep (void)
+M2EXPORT(dep) (void)
{
}
extern "C" void __attribute__((__constructor__))
-_M2_UnixArgs_ctor (void)
+M2EXPORT(ctor) (void)
{
- M2RTS_RegisterModule ("UnixArgs", _M2_UnixArgs_init, _M2_UnixArgs_fini,
- _M2_UnixArgs_dep);
+ m2pim_M2RTS_RegisterModule ("UnixArgs", M2LIBNAME,
+ M2EXPORT(init), M2EXPORT(fini),
+ M2EXPORT(dep));
}
diff --git a/libgm2/libm2pim/cgetopt.cc b/libgm2/libm2pim/cgetopt.cc
index 4e8ac9e..858c775 100644
--- a/libgm2/libm2pim/cgetopt.cc
+++ b/libgm2/libm2pim/cgetopt.cc
@@ -29,20 +29,24 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#include <getopt.h>
#include <m2rts.h>
-extern "C" {char *cgetopt_optarg;}
-extern "C" {int cgetopt_optind;}
-extern "C" {int cgetopt_opterr;}
-extern "C" {int cgetopt_optopt;}
+#define EXPORT(FUNC) m2pim ## _cgetopt_ ## FUNC
+#define M2EXPORT(FUNC) m2pim ## _M2_cgetopt_ ## FUNC
+#define M2LIBNAME "m2pim"
+
+extern "C" {char *EXPORT(optarg);}
+extern "C" {int EXPORT(optind);}
+extern "C" {int EXPORT(opterr);}
+extern "C" {int EXPORT(optopt);}
extern "C" char
-cgetopt_getopt (int argc, char *argv[], char *optstring)
+EXPORT(getopt) (int argc, char *argv[], char *optstring)
{
char r = getopt (argc, argv, optstring);
- cgetopt_optarg = optarg;
- cgetopt_optind = optind;
- cgetopt_opterr = opterr;
- cgetopt_optopt = optopt;
+ EXPORT(optarg) = optarg;
+ EXPORT(optind) = optind;
+ EXPORT(opterr) = opterr;
+ EXPORT(optopt) = optopt;
if (r == (char)-1)
return (char)0;
@@ -50,29 +54,29 @@ cgetopt_getopt (int argc, char *argv[], char *optstring)
}
extern "C" int
-cgetopt_getopt_long (int argc, char *argv[], char *optstring,
+EXPORT(getopt_long) (int argc, char *argv[], char *optstring,
const struct option *longopts, int *longindex)
{
int r = getopt_long (argc, argv, optstring, longopts, longindex);
- cgetopt_optarg = optarg;
- cgetopt_optind = optind;
- cgetopt_opterr = opterr;
- cgetopt_optopt = optopt;
+ EXPORT(optarg) = optarg;
+ EXPORT(optind) = optind;
+ EXPORT(opterr) = opterr;
+ EXPORT(optopt) = optopt;
return r;
}
extern "C" int
-cgetopt_getopt_long_only (int argc, char *argv[], char *optstring,
+EXPORT(getopt_long_only) (int argc, char *argv[], char *optstring,
const struct option *longopts, int *longindex)
{
int r = getopt_long_only (argc, argv, optstring, longopts, longindex);
- cgetopt_optarg = optarg;
- cgetopt_optind = optind;
- cgetopt_opterr = opterr;
- cgetopt_optopt = optopt;
+ EXPORT(optarg) = optarg;
+ EXPORT(optind) = optind;
+ EXPORT(opterr) = opterr;
+ EXPORT(optopt) = optopt;
return r;
}
@@ -86,7 +90,7 @@ typedef struct cgetopt_Options_s
/* InitOptions a constructor for Options. */
extern "C" cgetopt_Options *
-cgetopt_InitOptions (void)
+EXPORT(InitOptions) (void)
{
cgetopt_Options *o = (cgetopt_Options *)malloc (sizeof (cgetopt_Options));
o->cinfo = (struct option *)malloc (sizeof (struct option));
@@ -98,7 +102,7 @@ cgetopt_InitOptions (void)
up all allocated memory associated with o. */
extern "C" cgetopt_Options *
-cgetopt_KillOptions (cgetopt_Options *o)
+EXPORT(KillOptions) (cgetopt_Options *o)
{
free (o->cinfo);
free (o);
@@ -108,7 +112,7 @@ cgetopt_KillOptions (cgetopt_Options *o)
/* SetOption set option[index] with {name, has_arg, flag, val}. */
extern "C" void
-cgetopt_SetOption (cgetopt_Options *o, unsigned int index, char *name,
+EXPORT(SetOption) (cgetopt_Options *o, unsigned int index, char *name,
unsigned int has_arg, int *flag, int val)
{
if (index > o->high)
@@ -127,7 +131,7 @@ cgetopt_SetOption (cgetopt_Options *o, unsigned int index, char *name,
long options. */
extern "C" struct option *
-cgetopt_GetLongOptionArray (cgetopt_Options *o)
+EXPORT(GetLongOptionArray) (cgetopt_Options *o)
{
return o->cinfo;
}
@@ -135,23 +139,24 @@ cgetopt_GetLongOptionArray (cgetopt_Options *o)
/* GNU Modula-2 linking fodder. */
extern "C" void
-_M2_cgetopt_init (int, char *argv[], char *env[])
+M2EXPORT(init) (int, char *argv[], char *env[])
{
}
extern "C" void
-_M2_cgetopt_fini (int, char *argv[], char *env[])
+M2EXPORT(fini) (int, char *argv[], char *env[])
{
}
extern "C" void
-_M2_cgetopt_dep (void)
+M2EXPORT(dep) (void)
{
}
extern "C" void __attribute__((__constructor__))
-_M2_cgetopt_ctor (void)
+M2EXPORT(ctor) (void)
{
- M2RTS_RegisterModule ("cgetopt", _M2_cgetopt_init, _M2_cgetopt_fini,
- _M2_cgetopt_dep);
+ m2pim_M2RTS_RegisterModule ("cgetopt", M2LIBNAME,
+ M2EXPORT(init), M2EXPORT(fini),
+ M2EXPORT(dep));
}
diff --git a/libgm2/libm2pim/dtoa.cc b/libgm2/libm2pim/dtoa.cc
index 95d24d4..c6b573b 100644
--- a/libgm2/libm2pim/dtoa.cc
+++ b/libgm2/libm2pim/dtoa.cc
@@ -29,6 +29,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#include <config.h>
#include <m2rts.h>
+#define EXPORT(FUNC) m2pim ## _dtoa_ ## FUNC
+#define M2EXPORT(FUNC) m2pim ## _M2_dtoa_ ## FUNC
+#define M2LIBNAME "m2pim"
+
#if defined(HAVE_STRINGS)
#include <strings.h>
#endif
@@ -106,7 +110,7 @@ typedef enum Mode { maxsignicant, decimaldigits } Mode;
contain ndigits past the decimal point (ndigits may be negative). */
extern "C" double
-dtoa_strtod (const char *s, int *error)
+EXPORT(strtod) (const char *s, int *error)
{
char *endp;
double d;
@@ -130,7 +134,7 @@ dtoa_strtod (const char *s, int *error)
it also removes the decimal point and exponent from string, p. */
extern "C" int
-dtoa_calcmaxsig (char *p, int ndigits)
+EXPORT(calcmaxsig) (char *p, int ndigits)
{
char *e;
char *o;
@@ -161,7 +165,7 @@ dtoa_calcmaxsig (char *p, int ndigits)
Ie ndigits is the number of digits after the '.'. */
extern "C" int
-dtoa_calcdecimal (char *p, int str_size, int ndigits)
+EXPORT(calcdecimal) (char *p, int str_size, int ndigits)
{
char *e;
char *o;
@@ -195,7 +199,7 @@ dtoa_calcdecimal (char *p, int str_size, int ndigits)
}
extern "C" int
-dtoa_calcsign (char *p, int str_size)
+EXPORT(calcsign) (char *p, int str_size)
{
if (p[0] == '-')
{
@@ -207,7 +211,7 @@ dtoa_calcsign (char *p, int str_size)
}
extern "C" char *
-dtoa_dtoa (double d, int mode, int ndigits, int *decpt, int *sign)
+EXPORT(dtoa) (double d, int mode, int ndigits, int *decpt, int *sign)
{
char format[50];
char *p;
@@ -220,15 +224,15 @@ dtoa_dtoa (double d, int mode, int ndigits, int *decpt, int *sign)
p = (char *) malloc (ndigits);
snprintf (format, 50, "%s%d%s", "%.", ndigits - 20, "E");
snprintf (p, ndigits, format, d);
- *sign = dtoa_calcsign (p, ndigits);
- *decpt = dtoa_calcmaxsig (p, ndigits);
+ *sign = EXPORT(calcsign) (p, ndigits);
+ *decpt = EXPORT(calcmaxsig) (p, ndigits);
return p;
case decimaldigits:
p = (char *) malloc (MAX_FP_DIGITS + 20);
snprintf (format, 50, "%s%d%s", "%.", MAX_FP_DIGITS, "E");
snprintf (p, MAX_FP_DIGITS + 20, format, d);
- *sign = dtoa_calcsign (p, MAX_FP_DIGITS + 20);
- *decpt = dtoa_calcdecimal (p, MAX_FP_DIGITS + 20, ndigits);
+ *sign = EXPORT(calcsign) (p, MAX_FP_DIGITS + 20);
+ *decpt = EXPORT(calcdecimal) (p, MAX_FP_DIGITS + 20, ndigits);
return p;
default:
abort ();
@@ -241,24 +245,25 @@ dtoa_dtoa (double d, int mode, int ndigits, int *decpt, int *sign)
/* GNU Modula-2 linking hooks. */
extern "C" void
-_M2_dtoa_init (int, char **, char **)
+M2EXPORT(init) (int, char **, char **)
{
}
extern "C" void
-_M2_dtoa_fini (int, char **, char **)
+M2EXPORT(fini) (int, char **, char **)
{
}
extern "C" void
-_M2_dtoa_dep (void)
+M2EXPORT(dep) (void)
{
}
extern "C" void __attribute__((__constructor__))
-_M2_dtoa_ctor (void)
+M2EXPORT(ctor) (void)
{
- M2RTS_RegisterModule ("dtoa", _M2_dtoa_init, _M2_dtoa_fini,
- _M2_dtoa_dep);
+ m2pim_M2RTS_RegisterModule ("dtoa", M2LIBNAME,
+ M2EXPORT(init), M2EXPORT(fini),
+ M2EXPORT(dep));
}
#endif
diff --git a/libgm2/libm2pim/errno.cc b/libgm2/libm2pim/errno.cc
index 296ab0b..db8628f 100644
--- a/libgm2/libm2pim/errno.cc
+++ b/libgm2/libm2pim/errno.cc
@@ -36,8 +36,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#include "m2rts.h"
+#define EXPORT(FUNC) m2pim ## _errno_ ## FUNC
+#define M2EXPORT(FUNC) m2pim ## _M2_errno_ ## FUNC
+#define M2LIBNAME "m2pim"
+
extern "C" int
-errno_geterrno (void)
+EXPORT(geterrno) (void)
{
#if defined(HAVE_ERRNO_H) || defined(HAVE_SYS_ERRNO_H)
return errno;
@@ -47,23 +51,24 @@ errno_geterrno (void)
}
extern "C" void
-_M2_errno_init (int, char *[], char *[])
+M2EXPORT(init) (int, char **, char **)
{
}
extern "C" void
-_M2_errno_fini (int, char *[], char *[])
+M2EXPORT(fini) (int, char **, char **)
{
}
extern "C" void
-_M2_errno_dep (void)
+M2EXPORT(dep) (void)
{
}
extern "C" void __attribute__((__constructor__))
-_M2_errno_ctor (void)
+M2EXPORT(ctor) (void)
{
- M2RTS_RegisterModule ("errno", _M2_errno_init, _M2_errno_fini,
- _M2_errno_dep);
+ m2pim_M2RTS_RegisterModule ("errno", M2LIBNAME,
+ M2EXPORT(init), M2EXPORT(fini),
+ M2EXPORT(dep));
}
diff --git a/libgm2/libm2pim/ldtoa.cc b/libgm2/libm2pim/ldtoa.cc
index 8b44983..9250ca4 100644
--- a/libgm2/libm2pim/ldtoa.cc
+++ b/libgm2/libm2pim/ldtoa.cc
@@ -29,6 +29,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#include <config.h>
#include <m2rts.h>
+#define EXPORT(FUNC) m2pim ## _ldtoa_ ## FUNC
+#define IMPORT(MODULE,FUNC) m2pim ## _ ## MODULE ## _ ## FUNC
+#define M2EXPORT(FUNC) m2pim ## _M2_ldtoa_ ## FUNC
+#define M2LIBNAME "m2pim"
+
#if defined(HAVE_STRINGS)
#include <strings.h>
#endif
@@ -97,9 +102,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
typedef enum Mode { maxsignicant, decimaldigits } Mode;
-extern "C" int dtoa_calcmaxsig (char *p, int ndigits);
-extern "C" int dtoa_calcdecimal (char *p, int str_size, int ndigits);
-extern "C" int dtoa_calcsign (char *p, int str_size);
+extern "C" int IMPORT(dtoa,calcmaxsig) (char *p, int ndigits);
+extern "C" int IMPORT(dtoa,calcdecimal) (char *p, int str_size, int ndigits);
+extern "C" int IMPORT(dtoa,calcsign) (char *p, int str_size);
/* maxsignicant return a string containing max(1,ndigits) significant
digits. The return string contains the string produced by snprintf.
@@ -108,7 +113,7 @@ extern "C" int dtoa_calcsign (char *p, int str_size);
contain ndigits past the decimal point (ndigits may be negative). */
extern "C" long double
-ldtoa_strtold (const char *s, int *error)
+EXPORT(strtold) (const char *s, int *error)
{
char *endp;
long double d;
@@ -134,7 +139,7 @@ ldtoa_strtold (const char *s, int *error)
}
extern "C" char *
-ldtoa_ldtoa (long double d, int mode, int ndigits, int *decpt, int *sign)
+EXPORT(ldtoa) (long double d, int mode, int ndigits, int *decpt, int *sign)
{
char format[50];
char *p;
@@ -147,15 +152,15 @@ ldtoa_ldtoa (long double d, int mode, int ndigits, int *decpt, int *sign)
p = (char *) malloc (ndigits);
snprintf (format, 50, "%s%d%s", "%.", ndigits - 20, "LE");
snprintf (p, ndigits, format, d);
- *sign = dtoa_calcsign (p, ndigits);
- *decpt = dtoa_calcmaxsig (p, ndigits);
+ *sign = IMPORT(dtoa,calcsign) (p, ndigits);
+ *decpt = IMPORT(dtoa,calcmaxsig) (p, ndigits);
return p;
case decimaldigits:
p = (char *) malloc (MAX_FP_DIGITS + 20);
snprintf (format, 50, "%s%d%s", "%.", MAX_FP_DIGITS, "LE");
snprintf (p, MAX_FP_DIGITS + 20, format, d);
- *sign = dtoa_calcsign (p, MAX_FP_DIGITS + 20);
- *decpt = dtoa_calcdecimal (p, MAX_FP_DIGITS + 20, ndigits);
+ *sign = IMPORT(dtoa,calcsign) (p, MAX_FP_DIGITS + 20);
+ *decpt = IMPORT(dtoa,calcdecimal) (p, MAX_FP_DIGITS + 20, ndigits);
return p;
default:
abort ();
@@ -166,24 +171,25 @@ ldtoa_ldtoa (long double d, int mode, int ndigits, int *decpt, int *sign)
/* GNU Modula-2 linking hooks. */
extern "C" void
-_M2_ldtoa_init (int, char **, char **)
+M2EXPORT(init) (int, char **, char **)
{
}
extern "C" void
-_M2_ldtoa_fini (int, char **, char **)
+M2EXPORT(fini) (int, char **, char **)
{
}
extern "C" void
-_M2_ldtoa_dep (void)
+M2EXPORT(dep) (void)
{
}
extern "C" void __attribute__((__constructor__))
-_M2_ldtoa_ctor (void)
+M2EXPORT(ctor) (void)
{
- M2RTS_RegisterModule ("ldtoa", _M2_ldtoa_init, _M2_ldtoa_fini,
- _M2_ldtoa_dep);
+ m2pim_M2RTS_RegisterModule ("ldtoa", M2LIBNAME,
+ M2EXPORT(init), M2EXPORT(fini),
+ M2EXPORT(dep));
}
#endif
diff --git a/libgm2/libm2pim/sckt.cc b/libgm2/libm2pim/sckt.cc
index 585ed14..ee579c2 100644
--- a/libgm2/libm2pim/sckt.cc
+++ b/libgm2/libm2pim/sckt.cc
@@ -27,6 +27,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#include <config.h>
#include <m2rts.h>
+#define EXPORT(FUNC) m2pim ## _sckt_ ## FUNC
+#define M2EXPORT(FUNC) m2pim ## _M2_sckt_ ## FUNC
+#define M2LIBNAME "m2pim"
+
#if defined(HAVE_SYS_TYPES_H)
#include <sys/types.h>
#endif
@@ -125,7 +129,7 @@ localExit (int i)
This method attempts to use the port specified by the parameter. */
extern "C" tcpServerState *
-tcpServerEstablishPort (int portNo)
+EXPORT(tcpServerEstablishPort) (int portNo)
{
tcpServerState *s = (tcpServerState *)malloc (sizeof (tcpServerState));
int b, p, n;
@@ -180,16 +184,16 @@ tcpServerEstablishPort (int portNo)
information about a socket declared to receive tcp connections. */
extern "C" tcpServerState *
-tcpServerEstablish (void)
+EXPORT(tcpServerEstablish) (void)
{
- return tcpServerEstablishPort (PORTSTART);
+ return EXPORT(tcpServerEstablishPort) (PORTSTART);
}
/* tcpServerAccept returns a file descriptor once a client has connected and
been accepted. */
extern "C" int
-tcpServerAccept (tcpServerState *s)
+EXPORT(tcpServerAccept) (tcpServerState *s)
{
socklen_t i = sizeof (s->isa);
int t;
@@ -204,7 +208,7 @@ tcpServerAccept (tcpServerState *s)
/* tcpServerPortNo returns the portNo from structure, s. */
extern "C" int
-tcpServerPortNo (tcpServerState *s)
+EXPORT(tcpServerPortNo) (tcpServerState *s)
{
return s->portNo;
}
@@ -212,7 +216,7 @@ tcpServerPortNo (tcpServerState *s)
/* tcpServerSocketFd returns the sockFd from structure, s. */
extern "C" int
-tcpServerSocketFd (tcpServerState *s)
+EXPORT(tcpServerSocketFd) (tcpServerState *s)
{
return s->sockFd;
}
@@ -220,7 +224,7 @@ tcpServerSocketFd (tcpServerState *s)
/* getLocalIP returns the IP address of this machine. */
extern "C" unsigned int
-getLocalIP (tcpServerState *s)
+EXPORT(getLocalIP) (tcpServerState *s)
{
char hostname[1024];
struct hostent *hp;
@@ -262,7 +266,7 @@ getLocalIP (tcpServerState *s)
/* tcpServerIP returns the IP address from structure s. */
extern "C" int
-tcpServerIP (tcpServerState *s)
+EXPORT(tcpServerIP) (tcpServerState *s)
{
return *((int *)s->hp->h_addr_list[0]);
}
@@ -271,7 +275,7 @@ tcpServerIP (tcpServerState *s)
has connected to server s. */
extern "C" unsigned int
-tcpServerClientIP (tcpServerState *s)
+EXPORT(tcpServerClientIP) (tcpServerState *s)
{
unsigned int ip;
@@ -285,7 +289,7 @@ tcpServerClientIP (tcpServerState *s)
has connected to server s. */
extern "C" unsigned int
-tcpServerClientPortNo (tcpServerState *s)
+EXPORT(tcpServerClientPortNo) (tcpServerState *s)
{
return s->isa.sin_port;
}
@@ -309,7 +313,7 @@ typedef struct
connected to, serverName:portNo. */
extern "C" tcpClientState *
-tcpClientSocket (char *serverName, int portNo)
+EXPORT(tcpClientSocket) (char *serverName, int portNo)
{
tcpClientState *s = (tcpClientState *)malloc (sizeof (tcpClientState));
@@ -342,7 +346,7 @@ tcpClientSocket (char *serverName, int portNo)
connected to, ip:portNo. */
extern "C" tcpClientState *
-tcpClientSocketIP (unsigned int ip, int portNo)
+EXPORT(tcpClientSocketIP) (unsigned int ip, int portNo)
{
tcpClientState *s = (tcpClientState *)malloc (sizeof (tcpClientState));
@@ -368,7 +372,7 @@ tcpClientSocketIP (unsigned int ip, int portNo)
once a connect has been performed. */
extern "C" int
-tcpClientConnect (tcpClientState *s)
+EXPORT(tcpClientConnect) (tcpClientState *s)
{
if (connect (s->sockFd, (struct sockaddr *)&s->sa, sizeof (s->sa)) < 0)
ERROR ("failed to connect to the TCP server");
@@ -379,7 +383,7 @@ tcpClientConnect (tcpClientState *s)
/* tcpClientPortNo returns the portNo from structure s. */
extern "C" int
-tcpClientPortNo (tcpClientState *s)
+EXPORT(tcpClientPortNo) (tcpClientState *s)
{
return s->portNo;
}
@@ -387,7 +391,7 @@ tcpClientPortNo (tcpClientState *s)
/* tcpClientSocketFd returns the sockFd from structure s. */
extern "C" int
-tcpClientSocketFd (tcpClientState *s)
+EXPORT(tcpClientSocketFd) (tcpClientState *s)
{
return s->sockFd;
}
@@ -395,7 +399,7 @@ tcpClientSocketFd (tcpClientState *s)
/* tcpClientIP returns the sockFd from structure s. */
extern "C" int
-tcpClientIP (tcpClientState *s)
+EXPORT(tcpClientIP) (tcpClientState *s)
{
#if defined(DEBUGGING)
printf ("client ip = %s\n", inet_ntoa (s->sa.sin_addr.s_addr));
@@ -407,23 +411,24 @@ tcpClientIP (tcpClientState *s)
/* GNU Modula-2 link fodder. */
extern "C" void
-_M2_sckt_init (int, char *[], char *[])
+M2EXPORT(init) (int, char *[], char *[])
{
}
extern "C" void
-_M2_sckt_finish (int, char *[], char *[])
+M2EXPORT(finish) (int, char *[], char *[])
{
}
extern "C" void
-_M2_sckt_dep (void)
+M2EXPORT(dep) (void)
{
}
extern "C" void __attribute__((__constructor__))
-_M2_sckt_ctor (void)
+M2EXPORT(ctor) (void)
{
- M2RTS_RegisterModule ("sckt", _M2_sckt_init, _M2_sckt_finish,
- _M2_sckt_dep);
+ m2pim_M2RTS_RegisterModule ("sckt", M2LIBNAME,
+ M2EXPORT(init), M2EXPORT(finish),
+ M2EXPORT(dep));
}
diff --git a/libgm2/libm2pim/termios.cc b/libgm2/libm2pim/termios.cc
index 55818d2..5812837 100644
--- a/libgm2/libm2pim/termios.cc
+++ b/libgm2/libm2pim/termios.cc
@@ -27,6 +27,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#include <config.h>
#include <m2rts.h>
+#define EXPORT(FUNC) m2pim ## _termios_ ## FUNC
+#define M2EXPORT(FUNC) m2pim ## _M2_termios_ ## FUNC
+#define M2LIBNAME "m2pim"
+
#if defined(HAVE_STDIO_H)
#include <stdio.h>
#endif
@@ -60,8 +64,6 @@ void _M2_termios_finish (void);
#if defined(HAVE_TERMIOS_H)
-#define EXPORT(X) termios##_##X
-
typedef enum {
vintr,
vquit,
@@ -1964,23 +1966,23 @@ EXPORT (SetChar) (struct termios *t, ControlChar c, char ch)
#endif
extern "C" void
-_M2_termios_init (int, char *[], char *[])
+M2EXPORT(init) (int, char *argv[], char *env[])
{
}
extern "C" void
-_M2_termios_fini (int, char *[], char *[])
+M2EXPORT(fini) (int, char *argv[], char *env[])
{
}
extern "C" void
-_M2_termios_dep (void)
+M2EXPORT(dep) (void)
{
}
extern "C" void __attribute__((__constructor__))
-_M2_termios_ctor (void)
+M2EXPORT(ctor) (void)
{
- M2RTS_RegisterModule ("termios", _M2_termios_init, _M2_termios_fini,
- _M2_termios_dep);
+ m2pim_M2RTS_RegisterModule ("termios", M2LIBNAME,
+ M2EXPORT(init), M2EXPORT(fini), M2EXPORT(dep));
}
diff --git a/libgm2/libm2pim/wrapc.c b/libgm2/libm2pim/wrapc.cc
index 8e35949..0412ccc 100644
--- a/libgm2/libm2pim/wrapc.c
+++ b/libgm2/libm2pim/wrapc.cc
@@ -25,6 +25,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. */
#include <config.h>
+#include <m2rts.h>
+
+#define EXPORT(FUNC) m2pim ## _wrapc_ ## FUNC
+#define M2EXPORT(FUNC) m2pim ## _M2_wrapc_ ## FUNC
+#define M2LIBNAME "m2pim"
#if defined(HAVE_MATH_H)
#include <math.h>
@@ -69,11 +74,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
/* strtime returns the address of a string which describes the
local time. */
-char *
-wrapc_strtime (void)
+extern "C" char *
+EXPORT(strtime) (void)
{
#if defined(HAVE_CTIME)
- time_t clock = time ((void *)0);
+ time_t clock = time (NULL);
char *string = ctime (&clock);
string[24] = (char)0;
@@ -84,8 +89,8 @@ wrapc_strtime (void)
#endif
}
-int
-wrapc_filesize (int f, unsigned int *low, unsigned int *high)
+extern "C" int
+EXPORT(filesize) (int f, unsigned int *low, unsigned int *high)
{
#if defined(HAVE_SYS_STAT_H) && defined(HAVE_STRUCT_STAT)
struct stat s;
@@ -104,8 +109,8 @@ wrapc_filesize (int f, unsigned int *low, unsigned int *high)
/* filemtime returns the mtime of a file, f. */
-int
-wrapc_filemtime (int f)
+extern "C" int
+EXPORT(filemtime) (int f)
{
#if defined(HAVE_SYS_STAT_H) && defined(HAVE_STRUCT_STAT)
struct stat s;
@@ -122,8 +127,8 @@ wrapc_filemtime (int f)
/* fileinode returns the inode associated with a file, f. */
#if defined(HAVE_SYS_STAT_H) && defined(HAVE_STRUCT_STAT)
-ino_t
-wrapc_fileinode (int f, unsigned int *low, unsigned int *high)
+extern "C" ino_t
+EXPORT(fileinode) (int f, unsigned int *low, unsigned int *high)
{
struct stat s;
@@ -140,8 +145,8 @@ wrapc_fileinode (int f, unsigned int *low, unsigned int *high)
return -1;
}
#else
-int
-wrapc_fileinode (int f, unsigned int *low, unsigned int *high)
+extern "C" int
+EXPORT(fileinode) (int f, unsigned int *low, unsigned int *high)
{
*low = 0;
*high = 0;
@@ -151,8 +156,8 @@ wrapc_fileinode (int f, unsigned int *low, unsigned int *high)
/* getrand returns a random number between 0..n-1. */
-int
-wrapc_getrand (int n)
+extern "C" int
+EXPORT(getrand) (int n)
{
return rand () % n;
}
@@ -160,8 +165,8 @@ wrapc_getrand (int n)
#if defined(HAVE_PWD_H)
#include <pwd.h>
-char *
-wrapc_getusername (void)
+extern "C" char *
+EXPORT(getusername) (void)
{
return getpwuid (getuid ())->pw_gecos;
}
@@ -169,8 +174,8 @@ wrapc_getusername (void)
/* getnameuidgid fills in the, uid, and, gid, which represents
user, name. */
-void
-wrapc_getnameuidgid (char *name, int *uid, int *gid)
+extern "C" void
+EXPORT(getnameuidgid) (char *name, int *uid, int *gid)
{
struct passwd *p = getpwnam (name);
@@ -186,22 +191,22 @@ wrapc_getnameuidgid (char *name, int *uid, int *gid)
}
}
#else
-char *
-wrapc_getusername (void)
+extern "C" char *
+EXPORT(getusername) (void)
{
return "unknown";
}
-void
-wrapc_getnameuidgid (char *name, int *uid, int *gid)
+extern "C" void
+EXPORT(getnameuidgid) (char *name, int *uid, int *gid)
{
*uid = -1;
*gid = -1;
}
#endif
-int
-wrapc_signbit (double r)
+extern "C" int
+EXPORT(signbit) (double r)
{
#if defined(HAVE_SIGNBIT)
@@ -213,8 +218,8 @@ wrapc_signbit (double r)
#endif
}
-int
-wrapc_signbitl (long double r)
+extern "C" int
+EXPORT(signbitl) (long double r)
{
#if defined(HAVE_SIGNBITL)
@@ -226,8 +231,8 @@ wrapc_signbitl (long double r)
#endif
}
-int
-wrapc_signbitf (float r)
+extern "C" int
+EXPORT(signbitf) (float r)
{
#if defined(HAVE_SIGNBITF)
@@ -242,8 +247,8 @@ wrapc_signbitf (float r)
/* isfinite provide non builtin alternative to the gcc builtin
isfinite. Returns 1 if x is finite and 0 if it is not. */
-int
-wrapc_isfinite (double x)
+extern "C" int
+EXPORT(isfinite) (double x)
{
#if defined(FP_NAN) && defined(FP_INFINITE)
return (fpclassify (x) != FP_NAN && fpclassify (x) != FP_INFINITE);
@@ -255,8 +260,8 @@ wrapc_isfinite (double x)
/* isfinitel provide non builtin alternative to the gcc builtin
isfinite. Returns 1 if x is finite and 0 if it is not. */
-int
-wrapc_isfinitel (long double x)
+extern "C" int
+EXPORT(isfinitel) (long double x)
{
#if defined(FP_NAN) && defined(FP_INFINITE)
return (fpclassify (x) != FP_NAN && fpclassify (x) != FP_INFINITE);
@@ -268,8 +273,8 @@ wrapc_isfinitel (long double x)
/* isfinitef provide non builtin alternative to the gcc builtin
isfinite. Returns 1 if x is finite and 0 if it is not. */
-int
-wrapc_isfinitef (float x)
+extern "C" int
+EXPORT(isfinitef) (float x)
{
#if defined(FP_NAN) && defined(FP_INFINITE)
return (fpclassify (x) != FP_NAN && fpclassify (x) != FP_INFINITE);
@@ -278,20 +283,27 @@ wrapc_isfinitef (float x)
#endif
}
-/* init/finish are GNU Modula-2 linking fodder. */
+/* GNU Modula-2 linking hooks. */
-void
-_M2_wrapc_init ()
+extern "C" void
+M2EXPORT(init) (int, char **, char **)
{
}
-void
-_M2_wrapc_fini ()
+extern "C" void
+M2EXPORT(fini) (int, char **, char **)
{
}
-void
-_M2_wrapc_ctor ()
+extern "C" void
+M2EXPORT(dep) (void)
{
}
+extern "C" void __attribute__((__constructor__))
+M2EXPORT(ctor) (void)
+{
+ m2pim_M2RTS_RegisterModule ("wrapc", M2LIBNAME,
+ M2EXPORT(init), M2EXPORT(fini),
+ M2EXPORT(dep));
+}