Welcome to Linux Knowledge Base and Tutorial
"The place where you learn linux"
Linux Magazine

 Create an AccountHome | Submit News | Your Account  

Tutorial Menu
Linux Tutorial Home
Table of Contents

· Introduction to Operating Systems
· Linux Basics
· Working with the System
· Shells and Utilities
· Editing Files
· Basic Administration
· The Operating System
· The X Windowing System
· The Computer Itself
· Networking
· System Monitoring
· Solving Problems
· Security
· Installing and Upgrading
· Linux and Windows

Man Pages
Linux Topics
Test Your Knowledge

Site Menu
Site Map
Copyright Info
Terms of Use
Privacy Info
Masthead / Impressum
Your Account

Private Messages

News Archive
Submit News
User Articles
Web Links


The Web

Who's Online
There are currently, 79 guest(s) and 0 member(s) that are online.

You are an Anonymous user. You can register for free by clicking here




         enc2xs -[options]
         enc2xs -M ModName mapfiles...
         enc2xs -C


       enc2xs builds a Perl extension for use by Encode from
       either Unicode Character Mapping files (.ucm) or Tcl
       Encoding Files (.enc).  Besides being used internally dur­
       ing the build process of the Encode module, you can use
       enc2xs to add your own encoding to perl.  No knowledge of
       XS is necessary.

Quick Guide

       If you want to know as little about Perl as possible but
       need to add a new encoding, just read this chapter and
       forget the rest.

       0.  Have a .ucm file ready.  You can get it from somewhere
           or you can write your own from scratch or you can grab
           one from the Encode distribution and customize it.
           For the UCM format, see the next Chapter.  In the
           example below, I'll call my theoretical encoding
           myascii, defined in my.ucm.  "$" is a shell prompt.

             $ ls -F

       1.  Issue a command as follows;

             $ enc2xs -M My my.ucm
             generating Makefile.PL
             generating My.pm
             generating README
             generating Changes

           Now take a look at your current directory.  It should
           look like this.

             $ ls -F
             Makefile.PL   My.pm         my.ucm        t/

           The following files were created.

             Makefile.PL - MakeMaker script
             My.pm       - Encode submodule
             t/My.t      - test file

               If you want *.ucm installed together with the mod­
               ules, do as follows;

       4.  Now all you have to do is make.

             $ make
             cp My.pm blib/lib/Encode/My.pm
             /usr/local/bin/perl /usr/local/bin/enc2xs -Q -O \
               -o encode_t.c -f encode_t.fnm
             Reading myascii (myascii)
             Writing compiled form
             128 bytes in string tables
             384 bytes (25%) saved spotting duplicates
             1 bytes (99.2%) saved using substrings
             chmod 644 blib/arch/auto/Encode/My/My.bs

           The time it takes varies depending on how fast your
           machine is and how large your encoding is.  Unless you
           are working on something big like euc-tw, it won't
           take too long.

       5.  You can "make install" already but you should test

             $ make test
             PERL_DL_NONLAZY=1 /usr/local/bin/perl -Iblib/arch -Iblib/lib \
               -e 'use Test::Harness  qw(&runtests $verbose); \
               $verbose=0; runtests @ARGV;' t/*.t
             All tests successful.
             Files=1, Tests=2,  0 wallclock secs
              ( 0.09 cusr + 0.01 csys = 0.09 CPU)

       6.  If you are content with the test result, just "make

       7.  If you want to add your encoding to Encode's demand-
           loading list (so you don't have to "use
           Encode::YourEncoding"), run

             enc2xs -C

           to update Encode::ConfigLocal, a module that controls
           local settings.  After that, "use Encode;" is enough
           to load your encodings on demand.

The Unicode Character Map

       Encode uses the Unicode Character Map (UCM) format for
       source character mappings.  This format is used by IBM's
       ICU package and was adopted by Nick Ing-Simmons for use
       with the Encode module.  Since UCM is more flexible than
       Tcl's Encoding Map and far more user-friendly, this is the
       recommended formet for Encode now.
         <subchar> \x3F             # Substitution char
         <U0000> \x00 |0 # <control>
         <U0001> \x01 |0 # <control>
         <U0002> \x02 |0 # <control>
         <U007C> \x7C |0 # VERTICAL LINE
         <U007D> \x7D |0 # RIGHT CURLY BRACKET
         <U007E> \x7E |0 # TILDE
         <U007F> \x7F |0 # <control>
         END CHARMAP

       ·   Anything that follows "#" is treated as a comment.

       ·   The header section continues until a line containing
           the word CHARMAP. This section has a form of <keyword>
           value, one pair per line.  Strings used as values must
           be quoted. Barewords are treated as numbers.  \xXX
           represents a byte.

           Most of the keywords are self-explanatory. subchar
           means substitution character, not subcharacter.  When
           you decode a Unicode sequence to this encoding but no
           matching character is found, the byte sequence defined
           here will be used.  For most cases, the value here is
           \x3F; in ASCII, this is a question mark.

       ·   CHARMAP starts the character map section.  Each line
           has a form as follows:

             <UXXXX> \xXX.. |0 # comment
               ^     ^      ^
               |     |      +- Fallback flag
               |     +-------- Encoded byte sequence
               +-------------- Unicode Character ID in hex

           The format is roughly the same as a header section
           except for the fallback flag: | followed by 0..3.
           The meaning of the possible values is as follows:

           |0  Round trip safe.  A character decoded to Unicode
               encodes back to the same byte sequence.  Most
               characters have this flag.

           |1  Fallback for unicode -> encoding.  When seen,
               enc2xs adds this character for the encode map

           |2  Skip sub-char mapping should there be no code

       example, icu:state is not used.  Because of that, you need
       to write a perl module if you want to support algorithmi­
       cal encodings, notably the ISO-2022 series.  Such modules
       include Encode::JP::2022_JP, Encode::KR::2022_KR, and

       Coping with duplicate mappings

       When you create a map, you SHOULD make your mappings
       round-trip safe.  That is, "encode('your-encoding',
       decode('your-encoding', $data)) eq $data" stands for all
       characters that are marked as "|0".  Here is how to make

       ·   Sort your map in Unicode order.

       ·   When you have a duplicate entry, mark either one with
           '|1' or '|3'.

       ·   And make sure the '|1' or '|3' entry FOLLOWS the '|0'

       Here is an example from big5-eten.

         <U2550> \xF9\xF9 |0
         <U2550> \xA2\xA4 |3

       Internally Encoding -> Unicode and Unicode -> Encoding Map
       looks like this;

         E to U               U to E
         \xF9\xF9 => U2550    U2550 => \xF9\xF9
         \xA2\xA4 => U2550

       So it is round-trip safe for \xF9\xF9.  But if the line
       above is upside down, here is what happens.

         E to U               U to E
         \xA2\xA4 => U2550    U2550 => \xF9\xF9
         (\xF9\xF9 => U2550 is now overwritten!)

       The Encode package comes with ucmlint, a crude but suffi­
       cient utility to check the integrity of a UCM file.  Check
       under the Encode/bin directory for this.


       ·   ICU Home Page <http://oss.software.ibm.com/icu/>

       ·   ICU Character Mapping Tables <http://oss.soft­
Show your Support for the Linux Tutorial

Purchase one of the products from our new online shop. For each product you purchase, the Linux Tutorial gets a portion of the proceeds to help keep us going.



Security Code
Security Code
Type Security Code

Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name.

Help if you can!

Amazon Wish List

Did You Know?
You can get all the latest Site and Linux news by checking out our news page.


Tell a Friend About Us

Bookmark and Share

Web site powered by PHP-Nuke

Is this information useful? At the very least you can help by spreading the word to your favorite newsgroups, mailing lists and forums.
All logos and trademarks in this site are property of their respective owner. The comments are property of their posters. Articles are the property of their respective owners. Unless otherwise stated in the body of the article, article content (C) 1994-2013 by James Mohr. All rights reserved. The stylized page/paper, as well as the terms "The Linux Tutorial", "The Linux Server Tutorial", "The Linux Knowledge Base and Tutorial" and "The place where you learn Linux" are service marks of James Mohr. All rights reserved.
The Linux Knowledge Base and Tutorial may contain links to sites on the Internet, which are owned and operated by third parties. The Linux Tutorial is not responsible for the content of any such third-party site. By viewing/utilizing this web site, you have agreed to our disclaimer, terms of use and privacy policy. Use of automated download software ("harvesters") such as wget, httrack, etc. causes the site to quickly exceed its bandwidth limitation and are therefore expressly prohibited. For more details on this, take a look here

PHP-Nuke Copyright © 2004 by Francisco Burzi. This is free software, and you may redistribute it under the GPL. PHP-Nuke comes with absolutely no warranty, for details, see the license.
Page Generation: 0.09 Seconds