summaryrefslogtreecommitdiff
path: root/Unicode
diff options
context:
space:
mode:
authorpfaedit <pfaedit>2007-11-16 05:27:19 +0000
committerpfaedit <pfaedit>2007-11-16 05:27:19 +0000
commit84f9b79b12710df99db106ffc262298dc0c76e4d (patch)
tree91605d904e3648e49580d1020a06ec50162777d9 /Unicode
parent966d49264482f42c0112042dc5dab3ba459e81c5 (diff)
Try to encapsulate some of fontforge's dependency on gdraw in such a way that it can be replaced easily. Well... more easily.
Diffstat (limited to 'Unicode')
-rw-r--r--Unicode/Makefile.dynamic.in2
-rw-r--r--Unicode/Makefile.static.in3
-rw-r--r--Unicode/dynamic.c172
-rw-r--r--Unicode/gwwintl.c133
4 files changed, 308 insertions, 2 deletions
diff --git a/Unicode/Makefile.dynamic.in b/Unicode/Makefile.dynamic.in
index ec2966c3..226d0981 100644
--- a/Unicode/Makefile.dynamic.in
+++ b/Unicode/Makefile.dynamic.in
@@ -16,7 +16,7 @@ CC = @CC@
libgunicode_OBJECTS = ArabicForms.lo alphabet.lo backtrns.lo char.lo \
cjk.lo memory.lo ucharmap.lo unialt.lo ustring.lo utype.lo \
- usprintf.lo gwwiconv.lo
+ usprintf.lo gwwiconv.lo gwwintl.lo dynamic.lo
Incs = -I$(top_srcdir)/inc -I/usr/pkg/include -I/usr/pkg/include/giflib
CFLAGS = @CFLAGS@ @CPPFLAGS@ $(Incs) @WFLAGS@ @DEFS@
diff --git a/Unicode/Makefile.static.in b/Unicode/Makefile.static.in
index 16cfbfb7..5e4e38a2 100644
--- a/Unicode/Makefile.static.in
+++ b/Unicode/Makefile.static.in
@@ -10,7 +10,8 @@ CC = @CC@
RANLIB = @RANLIB@
libgunicode_OBJECTS = ArabicForms.o alphabet.o backtrns.o char.o \
- cjk.o memory.o ucharmap.o unialt.o ustring.o utype.o usprintf.o gwwiconv.o
+ cjk.o memory.o ucharmap.o unialt.o ustring.o utype.o usprintf.o gwwiconv.o \
+ gwwintl.o dynamic.o
Incs = -I$(top_srcdir)/inc -I/usr/pkg/include -I/usr/pkg/include/giflib
CFLAGS = @CFLAGS@ @CPPFLAGS@ $(Incs) @WFLAGS@ @DEFS@
diff --git a/Unicode/dynamic.c b/Unicode/dynamic.c
new file mode 100644
index 00000000..bc46a1d6
--- /dev/null
+++ b/Unicode/dynamic.c
@@ -0,0 +1,172 @@
+/* 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.
+ */
+
+/* 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 <basics.h>
+# 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/Unicode/gwwintl.c b/Unicode/gwwintl.c
new file mode 100644
index 00000000..0617a0ac
--- /dev/null
+++ b/Unicode/gwwintl.c
@@ -0,0 +1,133 @@
+/* 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 <stdlib.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