Sortix cross-volatile manual
This manual documents Sortix cross-volatile. You can instead view this document in the latest official manual.
ENC2XS(1) | Perl Programmers Reference Guide | ENC2XS(1) |
NAME
enc2xs -- Perl Encode Module GeneratorDESCRIPTION
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 during 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
my.ucm
- 1.
-
Issue a command as follows;
$ enc2xs -M My my.ucm
generating Makefile.PL
generating My.pm
generating README
generating Changes
$ ls -F
Makefile.PL My.pm my.ucm t/
Makefile.PL - MakeMaker script
My.pm - Encode submodule
t/My.t - test file
- 1.1.
-
If you want *.ucm installed together with the modules, do as follows;
$ mkdir Encode
$ mv *.ucm Encode
$ enc2xs -M My Encode/*ucm
- 2.
- Edit the files generated. You don't have to if you have no time AND no intention to give it to someone else. But it is a good idea to edit the pod and to add more tests.
- 3.
-
Now issue a command all Perl Mongers love:
$ perl Makefile.PL
Writing Makefile for Encode::My
- 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 (75%) saved spotting duplicates
1 bytes (0.775%) saved using substrings
....
chmod 644 blib/arch/auto/Encode/My/My.bs
$
- 5.
-
You can "make install" already but you should test first.
$ 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
t/My....ok
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 install"
- 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
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 format for Encode now.#
# Comments
#
<code_set_name> "US-ascii" # Required
<code_set_alias> "ascii" # Optional
<mb_cur_min> 1 # Required; usually 1
<mb_cur_max> 1 # Max. # of bytes/char
<subchar> \x3F # Substitution char
#
CHARMAP
<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.
- •
-
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
- |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 only.
- |2
- Skip sub-char mapping should there be no code point.
- |3
- Fallback for encoding -> unicode. When seen, enc2xs adds this character for the decode map only.
- •
- And finally, END OF CHARMAP ends the section.
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 sure:- •
- 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' entry.
<U2550> \xF9\xF9 |0
<U2550> \xA2\xA4 |3
E to U U to E
--------------------------------------
\xF9\xF9 => U2550 U2550 => \xF9\xF9
\xA2\xA4 => U2550
E to U U to E
--------------------------------------
\xA2\xA4 => U2550 U2550 => \xF9\xF9
(\xF9\xF9 => U2550 is now overwritten!)
Bookmarks
- •
- ICU Home Page <http://www.icu-project.org/>
- •
- ICU Character Mapping Tables <http://site.icu-project.org/charts/charset>
- •
- ICU:Conversion Data <http://www.icu-project.org/userguide/conversion-data.html>
SEE ALSO
Encode, perlmod, perlpod2024-11-23 | perl v5.32.0 |