# iconv and custom charactersets

**URL:** <https://forums.suse.com/t/iconv-and-custom-charactersets/25604>\
**Category:** SLES Configure-Administer\
**Created:** [May 19, 2014, 6:39pm UTC](https://forums.suse.com/t/iconv-and-custom-charactersets/25604 "2014-05-19T18:39:03Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![swadm](https://avatars.discourse-cdn.com/v4/letter/s/bc79bd/32.png) [@swadm](https://forums.suse.com/u/swadm)\
**Post date:** [May 19, 2014, 6:39pm UTC](https://forums.suse.com/t/iconv-and-custom-charactersets/25604/1 "2014-05-19T18:39:03Z")

</div>

Hi there,

does anybody know if it is possible to compile custom charactersets to be used with iconv.

We have a non-standard custom characterset developed by a company, and would like to easily recode output of their application to, say UNICODE.

Thanks in advance, Thomas

---

<div class="post-metadata">

**Author:** ![Jens-U](https://avatars.discourse-cdn.com/v4/letter/j/d78d45/32.png) [@Jens-U](https://forums.suse.com/u/Jens-U)\
**Post date:** [May 19, 2014, 7:37pm UTC](https://forums.suse.com/t/iconv-and-custom-charactersets/25604/2 "2014-05-19T19:37:18Z")

</div>

Hi Thomas,  
[QUOTE=swadm;21423]Hi there,

does anybody know if it is possible to compile custom charactersets to be used with iconv.

We have a non-standard custom characterset developed by a company, and would like to easily recode output of their application to, say UNICODE.

Thanks in advance, Thomas[/QUOTE]

it should be possible, as “all you need” seems to be a shared object carrying your implementation in /usr/lib(64)/gconf and appropriate customization of the mappings file in that directory.

I’ve never done this before, so all I can give you is the pointer to [http://git.savannah.gnu.org/cgit/libiconv.git/tree/HACKING](http://git.savannah.gnu.org/cgit/libiconv.git/tree/HACKING), where you will find the following comment:

# [QUOTE]Adding new encodings

For an indication which encodings are acceptable in the official version of  
GNU libiconv, take a look at NOTES.

For an indication which files need to be modified when adding a new encoding,  
look for example at the 2007-05-25 ChangeLog entry for RK1048. The lib/\*.h  
file for an encoding is usually generated by one of the tools in the tools/  
directory. All you need to provide is the conversion table in the format of  
the many \*.TXT files.  
[/QUOTE]

With regards,  
Jens

---

<div class="post-metadata">

**Author:** ![swadm](https://avatars.discourse-cdn.com/v4/letter/s/bc79bd/32.png) [@swadm](https://forums.suse.com/u/swadm)\
**Post date:** [May 20, 2014, 10:46am UTC](https://forums.suse.com/t/iconv-and-custom-charactersets/25604/3 "2014-05-20T10:46:23Z")

</div>

Jens, thanks, this is a very promising hint.

[http://git.savannah.gnu.org/cgit/libiconv.git/tree/NOTES](http://git.savannah.gnu.org/cgit/libiconv.git/tree/NOTES) has more details:

[QUOTE]Q: How do I add a new character set?  
A: 1. Explain the “why” in this file, above.  
2. You need to have a conversion table from/to Unicode. Transform it into  
the format used by the mapping tables found on [ftp.unicode.org](http://ftp.unicode.org): each line  
contains the character code, in hex, with 0x prefix, then whitespace,  
then the Unicode code point, in hex, 4 hex digits, with 0x prefix. ‘#’  
counts as a comment delimiter until end of line.  
Please also send your table to Mark Leisher [mleisher@crl.nmsu.edu](mailto:mleisher@crl.nmsu.edu) so he  
can include it in his collection.  
3. If it’s an 8-bit character set, use the ‘8bit\_tab\_to\_h’ program in the  
tools directory to generate the C code for the conversion. You may tweak  
the resulting C code if you are not satisfied with its quality, but this  
is rarely needed.  
If it’s a two-dimensional character set (with rows and columns), use the  
‘cjk\_tab\_to\_h’ program in the tools directory to generate the C code for  
the conversion. You will need to modify the main() function to recognize  
the new character set name, with the proper dimensions, but that shouldn’t  
be too hard. This yields the CCS. The CES you have to write by hand.  
4. Store the resulting C code file in the lib directory. Add a #include  
directive to converters.h, and add an entry to the encodings.def file.  
5. Compile the package, and test your new encoding using a program like  
iconv(1) or clisp(1).  
6. Augment the testsuite: Add a line to tests/Makefile.in. For a stateless  
encoding, create the complete table as a TXT file. For a stateful encoding,  
provide a text snippet encoded using your new encoding and its UTF-8  
equivalent.  
7. Update the README and man/iconv\_open.3, to mention the new encoding.  
Add a note in the NEWS file.  
[/QUOTE]

Now the translation file is no problem, already have one.

As SLES 11 does not include 8bit\_tab\_to\_h, we need to get libiconv compiled.

Somehow I cannot get libiconv compiled: version libiconv-1.14 does not have a ./configure file included,  
and ./configure present in libiconv-1.11 will not complete successfully:

[QUOTE]checking for strerror… yes  
checking for readlink… yes  
checking for ssize\_t… yes  
configure: creating ./config.status  
config.status: creating Makefile  
config.status: creating lib/Makefile  
config.status: creating srclib/Makefile  
config.status: creating src/Makefile  
config.status: creating po/Makefile.in  
config.status: creating man/Makefile  
config.status: creating tests/Makefile  
config.status: error: cannot find input file: include/iconv.h.build.in  
[/QUOTE]

Hm, should I try more versions of libiconf?

Tx, Thomas

---

<div class="post-metadata">

**Author:** ![Jens-U](https://avatars.discourse-cdn.com/v4/letter/j/d78d45/32.png) [@Jens-U](https://forums.suse.com/u/Jens-U)\
**Post date:** [May 20, 2014, 2:30pm UTC](https://forums.suse.com/t/iconv-and-custom-charactersets/25604/4 "2014-05-20T14:30:59Z")

</div>

Hi Thomas,

[QUOTE=swadm;21437]  
Somehow I cannot get libiconv compiled: version libiconv-1.14 does not have a ./configure file included,  
and ./configure present in libiconv-1.11 will not complete successfully:[/QUOTE]

I just pulled libiconv 1.14 from the web site ([http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz](http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz)) and clearly see a “configure” script in the top-most directory:

```auto
:/tmp/iconv/libiconv-1.14> l configure
-rwxr-xr-x 1 jmozdzen users 696987 7. Aug 2011 configure*
:/tmp/iconv/libiconv-1.14>
```

Maybe a bogus download?

Regards,  
Jens

---

<div class="post-metadata">

**Author:** ![swadm](https://avatars.discourse-cdn.com/v4/letter/s/bc79bd/32.png) [@swadm](https://forums.suse.com/u/swadm)\
**Post date:** [May 20, 2014, 4:00pm UTC](https://forums.suse.com/t/iconv-and-custom-charactersets/25604/5 "2014-05-20T16:00:14Z")

</div>

Jens,

thanks!

I pulled from  
[http://git.savannah.gnu.org/cgit/libiconv.git/snapshot/libiconv-1.14.tar.gz](http://git.savannah.gnu.org/cgit/libiconv.git/snapshot/libiconv-1.14.tar.gz)  
instead of [http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz:](http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz:)  
the later one appears not to be ready to be configured and compiled.

Now I was able to configure, compile and install.

The small utility 8bit\_tab\_to\_h.c seems not to be in the Makefiles, so I had to compile it manually:

> [@](#):
>
> gcc -o 8bit\_tab\_to\_h 8bit\_tab\_to\_h.c

Then I was successful in invoking 8bit\_tab\_to\_h:

[QUOTE] ./8bit\_tab\_to\_h MYCHARSET MYCHARSET \< MYCHARSET.TXT  
Creating MYCHARSET.h  
[/QUOTE]

I copied MYCHARSET.h to the lib directory, and did a “make clean” and  
“make” again.

Trying to invoke the iconv utility, I get a “conversion from MYCHARSET unsupported”.

I fear that I missed

[QUOTE]“You will need to modify the main() function to recognize the new  
character set name, with the proper dimensions, but that shouldn’t be  
too hard”  
[/QUOTE]

I looked at the main() funktion in iconv.c, but have no idea where I  
should do modifications to recognize my new characterset: too hard for me at last.

Thanks for further help, if you can afford the time.

Thomas

---

<div class="post-metadata">

**Author:** ![Jens-U](https://avatars.discourse-cdn.com/v4/letter/j/d78d45/32.png) [@Jens-U](https://forums.suse.com/u/Jens-U)\
**Post date:** [May 20, 2014, 4:30pm UTC](https://forums.suse.com/t/iconv-and-custom-charactersets/25604/6 "2014-05-20T16:30:14Z")

</div>

Hi Thomas,

while I’ve only had a glimpse at iconv.c, the key seems to be the file /usr/lib64/gconv/gconv-module - there the mapping names are defined, that will be usable to iconv\_open() (see man iconv\_open for a general description for that call, not too helpful in your case, though).

Please note that all entries in gconv-module need to be in UPPERCASE. And don’t forget to run iconvconfig after each change… or to at least remove the gconv-module.cache file before starting test runs.

The effective code for iconv\_open is in lib/iconv.c and the two includes iconf\_open1.h and iconv\_open2.h. Did your work give you a shared object file that you can put in /usr/lib64/gconv and reference in gconv-module?

Regards,  
Jens

---

<div class="post-metadata">

**Author:** ![swadm](https://avatars.discourse-cdn.com/v4/letter/s/bc79bd/32.png) [@swadm](https://forums.suse.com/u/swadm)\
**Post date:** [May 20, 2014, 4:59pm UTC](https://forums.suse.com/t/iconv-and-custom-charactersets/25604/7 "2014-05-20T16:59:59Z")

</div>

Jens, thanks for your hints.

I have the impression that the file /usr/lib64/gconv/gconv-modules (you missed the trailing “s”) is part of the glibc iconf implementation:  
[http://www.gnu.org/software/libc/manual/html\_node/glibc-iconv-Implementation.html](http://www.gnu.org/software/libc/manual/html_node/glibc-iconv-Implementation.html)

I’m not really a programmer (as you will have noticed), but I think that /usr/lib64/gconv/gconv-modules will not be used by my compilation of the iconv standalone program.

Also I wonder why we should list all possible conversions in gconv-modules:

Thanks and regards, Thomas

---

<div class="post-metadata">

**Author:** ![swadm](https://avatars.discourse-cdn.com/v4/letter/s/bc79bd/32.png) [@swadm](https://forums.suse.com/u/swadm)\
**Post date:** [May 20, 2014, 5:03pm UTC](https://forums.suse.com/t/iconv-and-custom-charactersets/25604/8 "2014-05-20T17:03:19Z")

</div>

and: no, there were no .so files that emanated from what I’ve done (which might stress my theory that /usr/lib64/gconv and gconv-modules is not relevant for what I’m planning)

---

<div class="post-metadata">

**Author:** ![Jens-U](https://avatars.discourse-cdn.com/v4/letter/j/d78d45/32.png) [@Jens-U](https://forums.suse.com/u/Jens-U)\
**Post date:** [May 20, 2014, 5:37pm UTC](https://forums.suse.com/t/iconv-and-custom-charactersets/25604/9 "2014-05-20T17:37:35Z")

</div>

Hi Thomas,

as I understand it, there is no stand-alone “iconv” program? “iconv” simply invokes the library functions from glibc (i.e. iconv\_open() ).

An easy test (that I had conducted before answering here) is to modify the modules list and then call “iconv --list”. I had inserted a simple alias statement with a distinct name into the module file, and the entry appeared in the list of available conversions. Thus I feel to have proven that indeed gconv-modules is relevant.

> Also I wonder why we should list all possible conversions in gconv-modules:

Because libiconv is a flexible and modular system - the conversion functions are placed in shared objects and the lib needs to know which one to load. That#s the only way you may extend this functionality at all, without risking your server installation by replacing glibc…

> no, there were no .so files that emanated from what I’ve done

unfortunately, that leaves a task for a programmer - to provide a way to create that module for you.

There are plenty of other gconv shared objects in /usr/lib64/gconv, I wonder where these come from. I had hoped that these were created during the libiconv build… but I don’t have the time right now to deep-dive into this subject ☹

Regards,  
Jens

---

<div class="post-metadata">

**Author:** ![Jens-U](https://avatars.discourse-cdn.com/v4/letter/j/d78d45/32.png) [@Jens-U](https://forums.suse.com/u/Jens-U)\
**Post date:** [May 20, 2014, 6:52pm UTC](https://forums.suse.com/t/iconv-and-custom-charactersets/25604/10 "2014-05-20T18:52:01Z")

</div>

[QUOTE=jmozdzen;21459]Hi Thomas,

as I understand it, there is no stand-alone “iconv” program? “iconv” simply invokes the library functions from glibc (i.e. iconv\_open() ).

[…]

> no, there were no .so files that emanated from what I’ve done

unfortunately, that leaves a task for a programmer - to provide a way to create that module for you.

There are plenty of other gconv shared objects in /usr/lib64/gconv, I wonder where these come from. I had hoped that these were created during the libiconv build… [/QUOTE]

I tried to follow my own advice: “If everything else fails, read the documentation”… [http://www.gnu.org/software/libc/manual/html\_node/glibc-iconv-Implementation.html#glibc-iconv-Implementation](http://www.gnu.org/software/libc/manual/html_node/glibc-iconv-Implementation.html#glibc-iconv-Implementation) , especially “6.5.4.4 iconv module interfaces” has it all - but you’ll probably need to find a programmer to get the job done.

Regards,  
Jens
