summaryrefslogtreecommitdiff
path: root/gutils
diff options
context:
space:
mode:
authorpfaedit <pfaedit>2007-12-09 20:44:15 +0000
committerpfaedit <pfaedit>2007-12-09 20:44:15 +0000
commit46f170ba7d759508b9ad886bfa319fb554c5dbb0 (patch)
tree008094d788adcbb418b2dbc51aa86f5d1d738206 /gutils
parent9127cc4509632f235bbddfcdfdb51a0a004fbb1b (diff)
Move some files from gunicode to gutils (files which used to be in gdraw).
Couple of library files didn't compile with the config.h based system, so fix that.
Diffstat (limited to 'gutils')
-rw-r--r--gutils/Makefile.dynamic.in3
-rw-r--r--gutils/Makefile.static.in3
-rw-r--r--gutils/dynamic.c173
-rw-r--r--gutils/gimagereadgif.c1
-rw-r--r--gutils/gimagereadjpeg.c1
-rw-r--r--gutils/gimagereadpng.c4
-rw-r--r--gutils/gimagereadtiff.c3
-rw-r--r--gutils/gimagewritejpeg.c3
-rw-r--r--gutils/gimagewritepng.c3
-rw-r--r--gutils/gwwintl.c136
10 files changed, 328 insertions, 2 deletions
diff --git a/gutils/Makefile.dynamic.in b/gutils/Makefile.dynamic.in
index ea2ecb05..0655941f 100644
--- a/gutils/Makefile.dynamic.in
+++ b/gutils/Makefile.dynamic.in
@@ -26,7 +26,8 @@ libgutils_OBJECTS = divisors.lo fsys.lo gimage.lo gimagereadbmp.lo \
gimageread.lo gimagereadgif.lo gimagereadjpeg.lo gimagereadpng.lo \
gimagereadras.lo gimagereadrgb.lo gimagereadtiff.lo gimagereadxbm.lo \
gimagereadxpm.lo gimagewritebmp.lo gimagewritegimage.lo \
- gimagewritejpeg.lo gimagewritepng.lo gimagewritexbm.lo gimagewritexpm.lo
+ gimagewritejpeg.lo gimagewritepng.lo gimagewritexbm.lo gimagewritexpm.lo \
+ gwwintl.lo dynamic.lo
Incs = -I$(top_srcdir)/inc -I/usr/pkg/include -I/usr/pkg/include/giflib
CFLAGS = @CFLAGS@ @CPPFLAGS@ $(Incs) @WFLAGS@ $(X_CFLAGS) -DNOTHREADS @DEFS@ -DLIBDIR='"$(libdir)"'
diff --git a/gutils/Makefile.static.in b/gutils/Makefile.static.in
index 54313559..89433db2 100644
--- a/gutils/Makefile.static.in
+++ b/gutils/Makefile.static.in
@@ -16,7 +16,8 @@ libgutils_OBJECTS = divisors.o fsys.o gimage.o gimagereadbmp.o \
gimageread.o gimagereadgif.o gimagereadjpeg.o gimagereadpng.o \
gimagereadras.o gimagereadrgb.o gimagereadtiff.o gimagereadxbm.o \
gimagereadxpm.o gimagewritebmp.o gimagewritegimage.o \
- gimagewritejpeg.o gimagewritepng.o gimagewritexbm.o gimagewritexpm.o
+ gimagewritejpeg.o gimagewritepng.o gimagewritexbm.o gimagewritexpm.o \
+ gwwintl.o dynamic.o
Incs = -I$(top_srcdir)/inc -I/usr/pkg/include -I/usr/pkg/include/giflib
CFLAGS = @CFLAGS@ @CPPFLAGS@ $(Incs) @WFLAGS@ $(X_CFLAGS) -DNOTHREADS @DEFS@ -DLIBDIR='"$(libdir)"'
diff --git a/gutils/dynamic.c b/gutils/dynamic.c
new file mode 100644
index 00000000..d4384172
--- /dev/null
+++ b/gutils/dynamic.c
@@ -0,0 +1,173 @@
+/* Copyright (C) 2005-2007 by George Williams */
+/*
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+
+ * The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <basics.h>
+
+/* Parse GNU .la "library" files. They give us the name to use with dlopen */
+/* Currently only important on _Cygwin */
+#if defined(__CygWin) && !defined(NODYNAMIC)
+# include <dynamic.h>
+# include <stdio.h>
+# include <string.h>
+# include <stdlib.h>
+
+static char *LaInDir(char *dir,const char *filename,char *buffer, int buflen) {
+ char *pt, *dpt;
+ FILE *test;
+ char dllname[1025];
+
+ if ( dir==NULL ) {
+ strncpy(buffer,filename,buflen-3);
+ buffer[buflen-3] = '\0';
+ } else
+ snprintf(buffer,buflen-3,"%s/%s", dir,filename);
+ dpt = strrchr(buffer,'/');
+ if ( dpt==NULL )
+ pt = strrchr(buffer,'.');
+ else
+ pt = strrchr(dpt+1,'.');
+ if ( pt==NULL )
+ strcat(buffer,".la");
+ else
+ strcpy(pt,".la");
+
+ test = fopen(buffer,"r");
+ if ( test==NULL )
+return( NULL );
+ while ( fgets(buffer,buflen,test)!=NULL ) {
+ if ( strncmp(buffer,"dlname='",8)==0 ) {
+ pt = strrchr(buffer+8,'\'');
+ if ( pt!=NULL ) {
+ *pt = '\0';
+ fclose(test);
+ if ( buffer[8]=='\0' )
+return( NULL ); /* No dlopenable version */
+ if ( buffer[8]=='/' )
+return( buffer+8 );
+ strcpy(dllname,buffer+8);
+ if ( dir==NULL ) {
+ pt = strrchr(filename,'/');
+ if ( pt==NULL )
+return( buffer+8 );
+ snprintf(buffer,buflen,"%.*s/%s", pt-filename, filename, dllname );
+ } else
+ snprintf(buffer,buflen,"%s/%s", dir,dllname);
+return( buffer );
+ }
+ }
+ }
+ fclose(test);
+return( NULL );
+}
+
+#ifdef dlopen
+# undef dlopen
+#endif
+
+void *libtool_laopen(const char *filename, int flags) {
+ char *ret;
+ char buffer[1025];
+ char dirbuf[1025];
+ char *path, *pt;
+
+ if ( filename==NULL )
+return( dlopen(NULL,flags)); /* Return magic handle to main program */
+
+ if ( strchr(filename,'/')!=NULL )
+ ret = LaInDir(NULL,filename,buffer,sizeof(buffer));
+ else {
+ ret = NULL;
+ path = getenv("LD_LIBRARY_PATH");
+ if ( path!=NULL ) {
+ while ( (pt=strchr(path,':'))!=NULL ) {
+ strncpy(dirbuf,path,pt-path);
+ dirbuf[pt-path] = '\0';
+ ret = LaInDir(dirbuf,filename,buffer,sizeof(buffer));
+ if ( ret!=NULL )
+ break;
+ path = pt+1;
+ }
+ if ( ret==NULL )
+ ret = LaInDir(path,filename,buffer,sizeof(buffer));
+ }
+ /* I should search /etc/ld.so.cache here, but I can't parse it */
+ if ( ret==NULL )
+ ret = LaInDir("/lib",filename,buffer,sizeof(buffer));
+ if ( ret==NULL )
+ ret = LaInDir("/usr/lib",filename,buffer,sizeof(buffer));
+ if ( ret==NULL )
+ ret = LaInDir("/usr/X11R6/lib",filename,buffer,sizeof(buffer));
+ if ( ret==NULL )
+ ret = LaInDir("/usr/local/lib",filename,buffer,sizeof(buffer));
+ }
+ if ( ret!=NULL )
+return( dlopen( ret,flags ));
+
+return( dlopen(filename,flags) ); /* This will almost certainly fail, but it will provide an error for dlerror() */
+}
+#elif defined( __Mac )
+# include <dynamic.h>
+# include <stdio.h>
+# include <string.h>
+ /* The mac now has normal dlopen routines */
+
+void *gwwv_dlopen(char *name,int flags) {
+#undef dlopen
+ void *lib = dlopen(name,flags);
+ char *temp;
+
+ if (( lib!=NULL && lib!=(void *) -1) || name==NULL || *name=='/' )
+return( lib );
+
+ temp = galloc( strlen("/sw/lib/") + strlen(name) +1 );
+ strcpy(temp,"/sw/lib/");
+ strcat(temp,name);
+ lib = dlopen(temp,flags);
+ free(temp);
+return( lib );
+}
+#elif defined( __Mac )
+# include <basics.h>
+# include <dynamic.h>
+# include <stdio.h>
+# include <string.h>
+
+const void *gwwv_NSAddImage(char *name,uint32_t options) {
+ const void *lib = NSAddImage(name,options);
+ char *temp;
+
+ if (( lib!=NULL && lib!=(void *) -1) || name==NULL || *name=='/' )
+return( lib );
+
+ temp = galloc( strlen("/sw/lib/") + strlen(name) +1 );
+ strcpy(temp,"/sw/lib/");
+ strcat(temp,name);
+ lib = NSAddImage(temp,options);
+ free(temp);
+return( lib );
+}
+#endif
diff --git a/gutils/gimagereadgif.c b/gutils/gimagereadgif.c
index d7f9a516..ea98064b 100644
--- a/gutils/gimagereadgif.c
+++ b/gutils/gimagereadgif.c
@@ -24,6 +24,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <basics.h>
/* There doesn't seem to be any difference between libgif and libungif (on my
* system they are symbolic linked together). Either libungif doesn't support
diff --git a/gutils/gimagereadjpeg.c b/gutils/gimagereadjpeg.c
index c8f5584b..8c703816 100644
--- a/gutils/gimagereadjpeg.c
+++ b/gutils/gimagereadjpeg.c
@@ -24,6 +24,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <basics.h>
#ifdef _NO_LIBJPEG
static int a_file_must_define_something=0; /* ANSI says so */
diff --git a/gutils/gimagereadpng.c b/gutils/gimagereadpng.c
index 224810d5..355df1c6 100644
--- a/gutils/gimagereadpng.c
+++ b/gutils/gimagereadpng.c
@@ -24,6 +24,10 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#ifdef _NO_LIBPNG
static void *a_file_must_define_something=(void *) &a_file_must_define_something;
diff --git a/gutils/gimagereadtiff.c b/gutils/gimagereadtiff.c
index f7462925..c3685f98 100644
--- a/gutils/gimagereadtiff.c
+++ b/gutils/gimagereadtiff.c
@@ -24,6 +24,9 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
#ifdef _NO_LIBTIFF
static int a_file_must_define_something=0; /* ANSI says so */
diff --git a/gutils/gimagewritejpeg.c b/gutils/gimagewritejpeg.c
index 8d4a4b73..46753582 100644
--- a/gutils/gimagewritejpeg.c
+++ b/gutils/gimagewritejpeg.c
@@ -24,6 +24,9 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
#ifdef _NO_LIBJPEG
static int a_file_must_define_something=0; /* ANSI says so */
diff --git a/gutils/gimagewritepng.c b/gutils/gimagewritepng.c
index 37dd8d81..7b58c02b 100644
--- a/gutils/gimagewritepng.c
+++ b/gutils/gimagewritepng.c
@@ -24,6 +24,9 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
#ifdef _NO_LIBPNG
static int a_file_must_define_something=0; /* ANSI says so */
diff --git a/gutils/gwwintl.c b/gutils/gwwintl.c
new file mode 100644
index 00000000..381e1675
--- /dev/null
+++ b/gutils/gwwintl.c
@@ -0,0 +1,136 @@
+/* Copyright (C) 2000-2007 by George Williams */
+/*
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+
+ * The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+ * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <basics.h>
+#include <intl.h>
+
+char *sgettext(const char *msgid) {
+ const char *msgval = _(msgid);
+ char *found;
+ if (msgval == msgid)
+ if ( (found = strrchr (msgid, '|'))!=NULL )
+ msgval = found+1;
+return (char *) msgval;
+}
+
+#if defined( HAVE_LIBINTL_H ) && !defined( NODYNAMIC ) && !defined ( _STATIC_LIBINTL )
+# include <dynamic.h>
+
+static DL_CONST void *libintl = NULL;
+
+static char *(*_bind_textdomain_codeset)(const char *, const char *);
+static char *(*_bindtextdomain)(const char *, const char *);
+static char *(*_textdomain)(const char *);
+static char *(*_gettext)(const char *);
+static char *(*_ngettext)(const char *, const char *, unsigned long int);
+static char *(*_dgettext)(const char *, const char *);
+
+static int init_gettext(void) {
+
+ if ( libintl == (void *) -1 )
+return( false );
+ else if ( libintl !=NULL )
+return( true );
+
+ libintl = dlopen("libintl" SO_EXT,RTLD_LAZY);
+ if ( libintl==NULL ) {
+ libintl = (void *) -1;
+return( false );
+ }
+
+ _bind_textdomain_codeset = (char *(*)(const char *, const char *)) dlsym(libintl,"bind_textdomain_codeset");
+ _bindtextdomain = (char *(*)(const char *, const char *)) dlsym(libintl,"bindtextdomain");
+ _textdomain = (char *(*)(const char *)) dlsym(libintl,"textdomain");
+ _gettext = (char *(*)(const char *)) dlsym(libintl,"gettext");
+ _ngettext = (char *(*)(const char *, const char *, unsigned long int)) dlsym(libintl,"ngettext");
+ _dgettext = (char *(*)(const char *, const char *)) dlsym(libintl,"dgettext");
+
+ if ( _bind_textdomain_codeset==NULL || _bindtextdomain==NULL ||
+ _textdomain==NULL || _gettext==NULL || _ngettext==NULL ) {
+ libintl = (void *) -1;
+ fprintf( stderr, "Found a copy of libintl but could not use it.\n" );
+return( false );
+ }
+return( true );
+}
+
+char *gwwv_bind_textdomain_codeset(const char *domain, const char *dir) {
+ if ( libintl==NULL )
+ init_gettext();
+ if ( libintl!=(void *) -1 )
+return( (_bind_textdomain_codeset)(domain,dir));
+
+return( NULL );
+}
+
+char *gwwv_bindtextdomain(const char *domain, const char *dir) {
+ if ( libintl==NULL )
+ init_gettext();
+ if ( libintl!=(void *) -1 )
+return( (_bindtextdomain)(domain,dir));
+
+return( NULL );
+}
+
+char *gwwv_textdomain(const char *domain) {
+ if ( libintl==NULL )
+ init_gettext();
+ if ( libintl!=(void *) -1 )
+return( (_textdomain)(domain));
+
+return( NULL );
+}
+
+char *gwwv_gettext(const char *msg) {
+ if ( libintl==NULL )
+ init_gettext();
+ if ( libintl!=(void *) -1 )
+return( (_gettext)(msg));
+
+return( (char *) msg );
+}
+
+char *gwwv_ngettext(const char *msg, const char *pmsg,unsigned long int n) {
+ if ( libintl==NULL )
+ init_gettext();
+ if ( libintl!=(void *) -1 )
+return( (_ngettext)(msg,pmsg,n));
+
+return( (char *) (n==1?msg:pmsg) );
+}
+
+char *gwwv_dgettext(const char *domain, const char *msg) {
+ if ( libintl==NULL )
+ init_gettext();
+ if ( libintl!=(void *) -1 && _dgettext!=NULL )
+return( (_dgettext)(domain,msg));
+
+return( (char *) msg );
+}
+#endif