diff options
author | Bruno Haible <bruno@clisp.org> | 2001-12-17 17:37:33 +0000 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2009-06-21 23:47:48 +0200 |
commit | 24f95f724fde0ababcae02d1094940c953156afd (patch) | |
tree | bc0c64b4edb83cd9ae19c9bf8353e8a4c1e62881 /os2 | |
parent | 036f69999b9510f137d7a3a59b5ba8e690e0807b (diff) | |
download | external_gettext-24f95f724fde0ababcae02d1094940c953156afd.zip external_gettext-24f95f724fde0ababcae02d1094940c953156afd.tar.gz external_gettext-24f95f724fde0ababcae02d1094940c953156afd.tar.bz2 |
New OS/2 support.
Diffstat (limited to 'os2')
-rw-r--r-- | os2/Makefile | 268 | ||||
-rw-r--r-- | os2/README.OS2 | 161 | ||||
-rw-r--r-- | os2/backward.def | 13 | ||||
-rw-r--r-- | os2/iconv/README | 2 | ||||
-rw-r--r-- | os2/iconv/iconv.c | 148 | ||||
-rw-r--r-- | os2/iconv/iconv.h | 43 | ||||
-rw-r--r-- | os2/os2compat.h | 77 |
7 files changed, 712 insertions, 0 deletions
diff --git a/os2/Makefile b/os2/Makefile new file mode 100644 index 0000000..5c3d108 --- /dev/null +++ b/os2/Makefile @@ -0,0 +1,268 @@ +# OS/2 GNU Makefile for building gettext with GNU Make and GNU C compiler +# +# OS/2 still supports the regular configure/make building mechanism, but its +# way more clumsy, complicated and error prone. It is highly recommended to +# use this makefile instead, because : +# - this makefile builds an optimized static and dynamic version of the +# library +# - it is able to build both optimized and debug versions of the library +# without any reconfiguring +# - it is able to generate a complete OS/2 binary distribution (make distr) +# - besides its simply alot faster than configure generated makefiles +# +# The makefile is designed to be more or less gettext version independent, +# so it is likely to work with future versions of gettext as well. However, +# please inspect the pre-built config.h file (if you haven't built one with +# configure) so that VERSION macro contains the correct value. +# + +# Use CMD.EXE as shell since its way faster +SHELL = $(COMSPEC) +# An Unix-like shell (needed for running config.charset) +UNIXSHELL = sh.exe + +# Debug mode (1) or optimize mode (0) +DEBUG = 0 + +# The version of INTL.DLL (the name suffix) +INTLDLLVER = + +# Pack the DLL and executables with lxlite +LXLITE = 1 + +# Output directory +OUT = out/$(OUT.SUFFIX)/ +# Root package directory +ROOT = ../ +# The base directory for distribution archive (emx/ or usr/) +INST = emx/ +# A shortcut for emx/src/gettext-version/ +INSTSRC = $(INST)src/gettext-$(VERSION)/ + +# Tools +CC = gcc -c +CFLAGS = -Wall -Zmt $(INCLUDE) $(DEFS) +INCLUDE = -I. -I$(ROOT) -I$(ROOT)intl -I$(ROOT)src -I$(ROOT)lib +DEFS = -DHAVE_CONFIG_H -DLIBDIR=\"/usr/lib\" \ + -DLOCALEDIR=\"/usr/share/locale\" -DLOCALE_ALIAS_PATH=\"/usr/share/locale\" + +LD = gcc +LDFLAGS = -Zmt -Zcrtdll +LDFLAGS.SHARED = -Zmt -Zcrtdll -Zdll +LIBS = -liberty -lgcc + +AR = ar +ARFLAGS = crs + +MKDIR = mkdir.exe -p +COPY = cp -p + +LINKINTL = $(OUT)intl.a + +ifeq ($(DEBUG),0) + CFLAGS += -s -O2 + LDFLAGS += -s -Zexe + LDFLAGS.SHARED += -s + OUT.SUFFIX = release +else + CFLAGS += -g -Zomf + LDFLAGS += -g -Zexe -Zomf + LDFLAGS.SHARED += -g -Zomf + OUT.SUFFIX = debug + LXLITE := 0 + LINKINTL = $(OUT)intl_s.a +endif + +# The list of languages to be included in binary distribution +LINGUAS = cs da de el es fr gl id it nl nn no pl pt pt_BR ru sl sv tr +# The following languages don't work with OS/2 iconv: +#en@boldquot en@quot et ja ko zh + +VERSION = $(shell sed config.h -ne "/VERSION/{" -e "s/.*VERSION[ ]*//" -e 's/"//g' -e "p" -e "}") + +# Fetch the list of source files for libintl from intl/Makefile.in +INTL.SOURCES = $(addprefix $(ROOT)intl/,\ + $(subst $$lo,c,\ + $(subst @INTLOS2OBJS@,os2compat.c,\ + $(subst @INTLOBJS@,intl-compat.c,\ + $(subst OBJECTS = ,,\ + $(subst \,,\ + $(shell sed $(ROOT)intl/Makefile.in -ne "/^OBJECTS =/,/[^\]$$/p"))))))) +INTL.OBJECTS = $(addprefix $(OUT),$(subst $(ROOT),,$(INTL.SOURCES:.c=.o))) + +PROGRAMS = gettext ngettext msgcmp msgfmt msgmerge msgunfmt xgettext msgcomm +PROGRAMS.EXE = $(addprefix $(OUT),$(addsuffix .exe,$(PROGRAMS))) +SRC.SOURCES = $(filter-out $(addprefix $(ROOT)src/,$(addsuffix .c,$(PROGRAMS))),\ + $(wildcard $(ROOT)src/*.c)) +SRC.OBJECTS = $(addprefix $(OUT),$(subst $(ROOT),,$(SRC.SOURCES:.c=.o))) +LIB.SOURCES = $(addprefix $(ROOT)lib/,basename.c error.c stpcpy.c stpncpy.c \ + concatpath.c mbswidth.c fstrcmp.c hash.c printf-prs.c c-ctype.c linebreak.c \ + getline.c) +LIB.OBJECTS = $(addprefix $(OUT),$(subst $(ROOT),,$(LIB.SOURCES:.c=.o))) + +OUTDIRS = $(OUT) $(sort $(dir $(INTL.OBJECTS) $(SRC.OBJECTS) $(LIB.OBJECTS) $(INSTALL.FILES))) + +INSTALL.FILES = $(addprefix $(INST)bin/,$(addsuffix .exe,$(PROGRAMS))) \ + $(INST)lib/intl.a $(INST)lib/intl_s.a $(INST)dll/intl.dll $(INST)include/libintl.h \ + $(INST)share/locale/charset.alias $(INST)share/locale/locale.alias \ + $(INST)doc/gettext-$(VERSION)/README.OS2 \ + $(INST)doc/gettext-$(VERSION)/COPYING $(INST)doc/gettext-$(VERSION)/README \ + $(INST)include/iconv.h $(INST)include/langinfo.h \ + $(addsuffix /LC_MESSAGES/gettext.mo,$(addprefix $(INST)share/locale/,$(LINGUAS))) \ + $(INSTALL.DIFF) + +# The diff and source files which we want in binary distribution (do we?) +INSTALL.DIFF = $(INSTSRC)gettext-$(VERSION).diff \ + $(addprefix $(INSTSRC)os2/,$(wildcard *.c *.h *.def) Makefile README.OS2) \ + $(INSTSRC)intl/os2compat.c + +.SUFFIXES: +.SUFFIXES: .o .a .def .exe .dll .po .mo +.PRECIOUS: $(OUT)%.o + +.PHONY: all depend clean distr rmzip + +$(OUT)%.o: $(ROOT)%.c + $(CC) $(CFLAGS) -o $@ $< + +# To avoid playing with object file lists for every program we will build +# instead a library containing all the object files from src directory, and +# then link the library against the main program module, so that linker can +# pull all the required functions from there +$(OUT)%.exe: $(OUT)src/%.o $(OUT)util.a $(LINKINTL) + $(LD) $(LDFLAGS) -o $@ $^ $(LIBS) +ifeq ($(LXLITE),1) + lxlite $@ +endif + +all: $(OUTDIRS) $(ROOT)src/po-gram-gen2.h $(ROOT)intl/libintl.h \ + $(OUT)intl.a $(OUT)intl_s.a $(OUT)intl$(INTLDLLVER).dll $(PROGRAMS.EXE) + +depend: $(INTL.SOURCES) $(SRC.SOURCES) + makedep $(INCLUDE) $(DEFS) -p $$(OUT) -r $^ + +clean: + rm -rf out emx + +distr: all rmzip gettext-os2-$(VERSION)-bin.zip + +rmzip: + rm -f gettext-os2-$(VERSION)-bin.zip + +$(OUTDIRS): + $(MKDIR) $(@:/=) + +$(OUT)intl_s.a: $(INTL.OBJECTS) + $(AR) $(ARFLAGS) $@ $^ + +$(OUT)intl.def: $(INTL.OBJECTS) + @echo LIBRARY INTL$(INTLDLLVER) INITINSTANCE TERMINSTANCE>$@ + @echo DESCRIPTION "GNU gettext internationalization library version $(VERSION)">>$@ + @echo DATA MULTIPLE NONSHARED>>$@ + @echo EXPORTS>>$@ + type backward.def>>$@ + emxexp $^ >>$@ + +$(OUT)intl$(INTLDLLVER).dll: $(INTL.OBJECTS) $(OUT)intl.def + @echo ********************************************************* + @echo *** YOU CAN SAFELY IGNORE WARNINGS FROM EMXBIND BELOW *** + @echo ********************************************************* + $(LD) $(LDFLAGS.SHARED) -o $@ $^ $(LIBS) +ifeq ($(LXLITE),1) + lxlite $@ +endif + +# Remove the ordinals from exports so that newer programs import by name +$(OUT)intl.a: $(OUT)intl.def + emximp -o $@ $< + +$(OUT)util.a: $(SRC.OBJECTS) $(LIB.OBJECTS) + $(AR) $(ARFLAGS) $@ $^ + +$(ROOT)src/po-gram-gen2.h: $(ROOT)src/po-gram-gen.h + sed -e "s/[yY][yY]/po_gram_/g" $< > $@ + +$(ROOT)intl/libintl.h: $(ROOT)intl/libgnuintl.h + $(COPY) $< $@ + +gettext-os2-$(VERSION)-bin.zip: $(INSTALL.FILES) + @rm -f $@ + zip -9XD $@ $^ + +# The following rules are for `make distr' target only + +$(INST)share/locale/charset.alias: $(ROOT)lib/config.charset + $(UNIXSHELL) $< i386-pc-os2-emx >$@ +$(INST)share/locale/locale.alias: $(ROOT)intl/locale.alias + $(COPY) $< $@ +$(INST)bin/% $(INST)lib/% $(INST)dll/%: $(OUT)% + $(COPY) $< $@ +$(INST)include/%: $(ROOT)intl/% + $(COPY) $< $@ +$(INST)doc/gettext-$(VERSION)/%: $(ROOT)% + $(COPY) $< $@ +$(INST)doc/gettext-$(VERSION)/% $(INSTSRC)% $(INSTSRC)os2/% $(INST)include/%: % + $(COPY) $< $@ +$(INSTSRC)%: $(ROOT)% + $(COPY) $< $@ +$(INST)share/locale/%/LC_MESSAGES/gettext.mo: $(ROOT)po/%.po + $(MKDIR) $(dir $@) + $(COMSPEC) /c "$(subst /,\\,set BEGINLIBPATH=$(OUT:/=) && \ + $(OUT)msgfmt.exe) --statistics --verbose -o $@ $<" + +# DO NOT DELETE this line -- makedep depends on it + +$(OUT)intl-compat.o: ../intl/libgnuintl.h ../intl/gettextP.h \ + ../intl/loadinfo.h ../intl/gettext.h +$(OUT)bindtextdom.o: ../intl/libgnuintl.h ../intl/gettextP.h \ + ../intl/loadinfo.h ../intl/gettext.h +$(OUT)dcgettext.o: ../intl/gettextP.h ../intl/loadinfo.h \ + ../intl/gettext.h ../intl/libgnuintl.h +$(OUT)dgettext.o: ../intl/gettextP.h ../intl/loadinfo.h \ + ../intl/gettext.h ../intl/libgnuintl.h +$(OUT)gettext.o: ../intl/gettextP.h ../intl/loadinfo.h \ + ../intl/gettext.h ../intl/libgnuintl.h +$(OUT)finddomain.o: ../intl/gettextP.h ../intl/loadinfo.h \ + ../intl/gettext.h ../intl/libgnuintl.h +$(OUT)loadmsgcat.o: ../intl/gettext.h ../intl/gettextP.h \ + ../intl/loadinfo.h +$(OUT)localealias.o: ../intl/gettextP.h ../intl/loadinfo.h \ + ../intl/gettext.h +$(OUT)textdomain.o: ../intl/libgnuintl.h ../intl/gettextP.h \ + ../intl/loadinfo.h ../intl/gettext.h +$(OUT)l10nflist.o: ../intl/loadinfo.h +$(OUT)explodename.o: ../intl/loadinfo.h +$(OUT)dcigettext.o: ../intl/gettextP.h ../intl/loadinfo.h \ + ../intl/gettext.h ../intl/libgnuintl.h ../intl/hash-string.h +$(OUT)dcngettext.o: ../intl/gettextP.h ../intl/loadinfo.h \ + ../intl/gettext.h ../intl/libgnuintl.h +$(OUT)dngettext.o: ../intl/gettextP.h ../intl/loadinfo.h \ + ../intl/gettext.h ../intl/libgnuintl.h +$(OUT)ngettext.o: ../intl/gettextP.h ../intl/loadinfo.h \ + ../intl/gettext.h ../intl/libgnuintl.h +$(OUT)plural.o: ../intl/gettextP.h ../intl/loadinfo.h \ + ../intl/gettext.h +$(OUT)os2compat.o: ../os2/iconv.c +$(OUT)dir-list.o: ../lib/system.h ../src/dir-list.h \ + ../src/str-list.h +$(OUT)message.o: ../lib/fstrcmp.h ../src/message.h ../src/str-list.h \ + ../src/pos.h ../lib/system.h +$(OUT)open-po.o: ../src/open-po.h ../src/dir-list.h ../lib/error.h \ + ../lib/system.h ../intl/libgettext.h +$(OUT)po-gram-gen.o: ../src/po-lex.h ../lib/error.h ../src/pos.h \ + ../src/po-gram.h ../lib/system.h ../intl/libgettext.h \ + ../src/po.h +$(OUT)po-hash-gen.o: ../src/po-hash.h ../src/po.h ../src/po-lex.h \ + ../lib/error.h ../src/pos.h +$(OUT)po-lex.o: ../intl/libgettext.h ../src/po-lex.h ../lib/error.h \ + ../src/pos.h ../src/open-po.h ../src/po-gram-gen2.h +$(OUT)po.o: ../src/po.h ../src/po-lex.h ../lib/error.h \ + ../src/pos.h ../src/po-hash.h ../lib/mbswidth.h \ + ../intl/libgettext.h +$(OUT)str-list.o: ../src/str-list.h +$(OUT)write-po.o: ../src/write-po.h ../src/message.h \ + ../src/str-list.h ../src/pos.h ../lib/c-ctype.h \ + ../lib/linebreak.h ../lib/error.h ../intl/libgettext.h +$(OUT)xget-lex.o: ../src/dir-list.h ../lib/error.h \ + ../intl/libgettext.h ../lib/hash.h ../src/str-list.h \ + ../src/xget-lex.h diff --git a/os2/README.OS2 b/os2/README.OS2 new file mode 100644 index 0000000..e3934b8 --- /dev/null +++ b/os2/README.OS2 @@ -0,0 +1,161 @@ + +Welcome! +======== + +This is the OS/2 port of GNU gettext 0.10.40 and possibly later versions. + + +Compatibility +============= + +The library has been compiled with -Zmt flag, but it doesn't matter as soon +as you use the EMX single-threaded runtime fix (emx-strt-fix-0.0.2.zip). + +The library is fully compatible with the previous port of gettext library +which is largely used especialy by XFree86 programs. All the old programs +that I have with gettext support run fine with the new version of the DLL. + + +Installation +============ + +If you set the GNULOCALEDIR environment variable to point to your +x:/xxx/share/locale directory, it will override any other setting. That is, +unpack the binary distribution over /emx, set GNULOCALEDIR=x:/emx/share/locale +(where x: is the drive letter of your EMX installation) and that's all. + +If you use the UNIXROOT environment variable, the default catalogue search +paths will be like on Unices, e.g. $(UNIXROOT)/usr/lib and +$(UNIXROOT)/usr/share/locale. GNULOCALEDIR always overrides this. + +Also this port supports character set conversions. This means that if your +.mo files were written using new gettext guidelines, e.g. they contain a +message like this: + +msgid "" +msgstr "Content-Type: text/plain; charset=koi8-r\n" + +the messages will be properly converted to your active codepage using OS/2 +Unicode API. For example, russian message catalog gettext.mo is in the +KOI8-R (codepage 878) encoding while OS/2 uses codepage 866. Now when you +run any of these tools it detects that the active OS/2 codepage is 866 and +performs the translation from CP878 -> CP866 for every message. + +If you want to override the character set used to output messages (for example +in XFree86 for Russian the KOI8-R encoding (codepage 878) is used) you can +set the OUTPUT_CHARSET environment variable like this: + +set OUTPUT_CHARSET=KOI8-R + +or (equivalent): + +set OUTPUT_CHARSET=CP878 + +or (same effect): + +set OUTPUT_CHARSET=IBM-878 + +Note that you don't need to set the OUTPUT_CHARSET initially; you may want to +set it just if you want to override the OS/2 active codepage (for example, +you can put it into your XFree86 startup script). + + +XFree86 setup +============= + +If you use XFree86 and the OS/2 default character set is different from the +XFree86 default character set (e.g. for Russain CP866 vs KOI8-R), you can add +the following (or similar) statement to your startx.cmd file (after the +commands dealing with HOME and X11SHELL): + +call VALUE 'OUTPUT_CHARSET', 'KOI8-R', env + +Otherwise you can get incorrect (wrong codepage) output from programs that +previously worked (e.g. GIMP 1.22). This is because earlier versions of gettext +didn't support character set translations. + + +Implementation remarks +====================== + +The codepage conversion code uses OS/2 Unicode API, thus it falls under the +limits that OS/2 Unicode API has. For example, OS/2 Unicode API does not +support the BIG5 Chinese character set nor ISO-8859-X where X > 9 (at least +with Warp4 with fixpack 14 that I have). Also libintl relies on a feature of +the GNU iconv which works differently in OS/2 Unicode API (well, someone may +call it even a bug in OS/2 API); as a results it is impossible to msgfmt any +.po files written in the UTF-8 character set; if someone is interested I can +explain the bug more detailed. + + +Additional API +============== + +This package provides additionaly the iconv() API that can be used by +developers for doing more feature-full Unix ports. The iconv() API is used +to convert text between various codepages. The intl.h header file contains +the prototypes and definitions needed for iconv(); if you configure software +with autoconf it possibly will find intl.h and set up the software accordingly. + +Also it provides an limited implementation of the nl_langinfo function which +is used for querying the active system codepage. Other software may find it +useful as well. + +All these functions are exported from INTL.DLL, thus if you use either iconv +or nl_langinfo you should link with it (-lintl). + + +Rebuilding the library +====================== + +The library is quite easy to rebuild. First of all, get and install the +original source code package, as of today it is gettext-0.10.40. Now copy +the contents of the src/gettext-$(VERSION)/ directory on top of the source +tree, e.g. intl/os2compat.c goes into the respective intl/ directory of the +original source package. As of today the support/ directory is missing from +the gettext source tree, thus you should just copy it recursively into the +root directory of the source code. + +Now apply the diff file, and resolve any conflicts (if you happen to compile +a newer version than the one the diff is supplied for). + +Now if you're a masochist you can go the clumsy configure/make Unix way, but +it is highly recommended to use an alternate way: go to support/os2 and just +run `make'. If you have all the required tools, it should painlessly compile. +Now if you want a binary distribution archive, do `make distr'. + +WARNING: Due to a bug in GNU Make 3.76.1 (at least in its OS/2 port) you will +have to do sometimes "make distr" twice to get a complete distribution archive; +if you see warnings from zip like these: + +zip warning: name not matched: emx/src/gettext-0.10.40/support/os2/iconv.h +zip warning: name not matched: emx/src/gettext-0.10.40/support/os2/langinfo.h + +it is best to interrupt zip and re-run make distr once more time. This happens +because make fails to execute two different rules that tells him to make two +different destination files from the same source file (e.g. iconv.h is copied +both to emx/src/gettext/support/os2 and to emx/include). + +If you want a debug version of library, you can do `make install DEBUG=1'. + +If you have no LxLite tool installed, do `make LXLITE=0' + +NB: For best results, it is highly recommended that you use at least emxbind.exe +and ld.exe from gcc 3.0.2 or later, since they contain a number of fixes that +will help you generate a more optimal DLL. + + +Contributors +============ + +Hung-Chi Chu <hcchu@r350.ee.ntu.edu.tw> + the original port of gettext (0.10.35) + +Jun SAWATAISHI <jsawa@attglobal.net> + some more work on it and submitted the patches to GNU team, although + they were not completely integrated. + +Andrew Zabolotny <zap@cobra.ru> + Succeeded to remove almost all OS/2-specific #ifdef's from mainstream + source code, wrote the dedicated OS/2 makefile, wrote the iconv wrapper + around OS/2 Unicode API, added support for locale translations. diff --git a/os2/backward.def b/os2/backward.def new file mode 100644 index 0000000..3183f9f --- /dev/null +++ b/os2/backward.def @@ -0,0 +1,13 @@ +; These exports are for backward compatibility with older ports +; of gettext for OS/2 that export everything by ordinals. + _$gettext=gettext @1 NONAME + _$gettext__=gettext__ @2 NONAME + _$dgettext=dgettext @3 NONAME + _$dgettext__=dgettext__ @4 NONAME + _$dcgettext=dcgettext @5 NONAME + _$dcgettext__=dcgettext__ @6 NONAME + _$textdomain=textdomain @7 NONAME + _$textdomain__=textdomain__ @8 NONAME + _$bindtextdomain=bindtextdomain @9 NONAME + _$bindtextdomain__=bindtextdomain__ @10 NONAME + _$_nl_msg_cat_cntr=_nl_msg_cat_cntr @11 NONAME diff --git a/os2/iconv/README b/os2/iconv/README new file mode 100644 index 0000000..2dc449c --- /dev/null +++ b/os2/iconv/README @@ -0,0 +1,2 @@ +This directory implements the POSIX iconv() function family, based on the +OS/2 Unicode API. It is independent of GNU gettext. diff --git a/os2/iconv/iconv.c b/os2/iconv/iconv.c new file mode 100644 index 0000000..b098a96 --- /dev/null +++ b/os2/iconv/iconv.c @@ -0,0 +1,148 @@ +/* OS/2 iconv() implementation through OS/2 Unicode API + Copyright (C) 2001 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + USA. */ + +/* + This file implements an iconv wrapper based on OS/2 Unicode API. +*/ + +#include <uconv.h> + +typedef struct _iconv_t +{ + UconvObject from; + UconvObject to; +} *iconv_t; + +/* Tell "iconv.h" to not define iconv_t by itself. */ +#define _ICONV_T +#include "iconv.h" + +#include <alloca.h> + +/* Convert an encoding name to te form understood by UniCreateUconvObject. */ +static inline void +cp_convert (const char *cp, UniChar *ucp) +{ + size_t sl = 0; + + /* Transform CPXXX naming style to IBM-XXX style */ + if ((cp[0] == 'C' || cp[0] == 'c') && (cp[1] == 'P' || cp[1] == 'p')) + { + ucp[sl++] = 'I'; + ucp[sl++] = 'B'; + ucp[sl++] = 'M'; + ucp[sl++] = '-'; + cp += 2; + } + + while (*cp != '\0') + ucp[sl++] = *cp++; + ucp[sl] = 0; +} + +iconv_t +iconv_open (const char *cp_to, const char *cp_from) +{ + UniChar *ucp; + iconv_t conv; + + conv = (iconv_t) malloc (sizeof (struct _iconv_t)); + if (conv == NULL) + { + errno = ENOMEM; + return (iconv_t)(-1); + } + + ucp = (UniChar *) alloca ((strlen (cp_from) + 2 + 1) * sizeof (UniChar)); + cp_convert (cp_from, ucp); + if (UniCreateUconvObject (ucp, &conv->from)) + { + free (conv); + errno = EINVAL; + return (iconv_t)(-1); + } + + ucp = (UniChar *) alloca ((strlen (cp_to) + 2 + 1) * sizeof (UniChar)); + cp_convert (cp_to, ucp); + if (UniCreateUconvObject (ucp, &conv->to)) + { + UniFreeUconvObject (conv->from); + free (conv); + errno = EINVAL; + return (iconv_t)(-1); + } + + return conv; +} + +size_t +iconv (iconv_t conv, + const char **in, size_t *in_left, + char **out, size_t *out_left) +{ + size_t bytes_converted = 0; + int rc; + size_t sl = *in_left, nonid; + UniChar *ucs = (UniChar *) alloca (sl * sizeof (UniChar)); + UniChar *orig_ucs = ucs; + + rc = UniUconvToUcs (conv->from, (void **)in, in_left, &ucs, &sl, &nonid); + if (rc) + goto error; + sl = ucs - orig_ucs; + ucs = orig_ucs; + /* Uh-oh, seems like a bug in UniUconvFromUcs, at least when + translating from KOI8-R to KOI8-R (null translation) */ +#if 0 + rc = UniUconvFromUcs (conv->to, &ucs, &sl, (void **)out, out_left, &nonid); + if (rc) + goto error; +#else + while (sl) + { + size_t usl = 0; + while (sl && (ucs[usl] != 0)) + usl++, sl--; + rc = UniUconvFromUcs (conv->to, &ucs, &usl, (void **)out, out_left, &nonid); + if (rc) + goto error; + if (sl && *out_left) + { + *(*out)++ = 0; + (*out_left)--; + ucs++; sl--; + } + } +#endif + return 0; + error: + errno = EILSEQ; + return (size_t)(-1); +} + +int +iconv_close (iconv_t conv) +{ + if (conv != (iconv_t)(-1)) + { + UniFreeUconvObject (conv->to); + UniFreeUconvObject (conv->from); + free (conv); + } + return 0; +} diff --git a/os2/iconv/iconv.h b/os2/iconv/iconv.h new file mode 100644 index 0000000..15e2fde --- /dev/null +++ b/os2/iconv/iconv.h @@ -0,0 +1,43 @@ +/* OS/2 iconv() implementation through OS/2 Unicode API + Copyright (C) 2001 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + USA. */ + +#ifndef __ICONV_H__ +#define __ICONV_H__ + +#include <stddef.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* FIXME: This belongs in <errno.h>. */ +#define EILSEQ 1729 + +#ifndef _ICONV_T +typedef void *iconv_t; +#endif + +extern iconv_t iconv_open (const char *, const char *); +extern size_t iconv (iconv_t, const char **, size_t *, char **, size_t *); +extern int iconv_close (iconv_t); + +#ifdef __cplusplus +} +#endif + +#endif /* __ICONV_H__ */ diff --git a/os2/os2compat.h b/os2/os2compat.h new file mode 100644 index 0000000..22ef1a2 --- /dev/null +++ b/os2/os2compat.h @@ -0,0 +1,77 @@ +/* OS/2 compatibility defines. + This file is intended to be included from config.h + Copyright (C) 2001 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + USA. */ + +/* When included from os2compat.h we need all the original definitions */ +#ifndef OS2_AWARE + +#undef LIBDIR +#define LIBDIR _os2_libdir +extern char *_os2_libdir; + +#undef LOCALEDIR +#define LOCALEDIR /* a 1024+1 bytes large buffer */ \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0\0\0\0\0\0\0\0\0\0" \ + "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" \ + "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" + +#undef LOCALE_ALIAS_PATH +#define LOCALE_ALIAS_PATH _os2_localealiaspath +extern char *_os2_localealiaspath; + +#endif + +#undef HAVE_STRCASECMP +#define HAVE_STRCASECMP 1 +#define strcasecmp stricmp +#define strncasecmp strnicmp + +/* We have our own getenv() which works even if library is compiled as DLL */ +#define getenv _nl_getenv + +/* Older versions of gettext used -1 as the value of LC_MESSAGES */ +#define LC_MESSAGES_COMPAT (-1) |