-->

Previous | Table of Contents | Next

Page 1063

Part IV:

Special Files

Page 1064

INTRODUCTION

This part describes special files.

FILES

/dev/*     Device files

AUTHORS

Look at the header of the manual page for the author(s) and copyright conditions. Note that these can be different from page to page.

Linux, 24 July 1993

charsets

charsets—Programmer's view of character sets and internationalization

DESCRIPTION

Linux is an international operating system. Several of its utilities and device drivers (including the console driver) support multilingual character sets including Latin-alphabet letters with diacritical marks, accents, ligatures, and entire non-Latin alphabets including Greek, Cyrillic, Arabic, and Hebrew.

This manual page presents a programmer's-eye view of different character-set standards and how they fit together on Linux. Standards discussed include ASCII, ISO 8859, KOI8-R, Unicode, ISO 2022, and ISO 4873.

ASCII

ASCII (American Standard Code for Information) is the original 7-bit character set, originally designed for American English. It is currently described by the ECMA-6 standard.

An ASCII variant replacing the American crosshatch/octothorpe/hash pound symbol with the British pound-sterling symbol is used in Great Britain; when needed, the American and British variants may be distinguished as U.S. ASCII and U.K. ASCII.

As Linux was written for hardware designed in the United States, it natively supports U.S. ASCII.

ISO 8859

ISO 8859 is a series of 10 8-bit character sets, all of which have U.S. ASCII in their low (7-bit) half, invisible control characters in positions 128 to 159, and 96 fixed-width graphics in positions 160-255.

Of these, the most important is ISO 8859-1 (Latin-1). It is natively supported in the Linux console driver, fairly well supported in X11R6, and is the base character set of HTML.

Console support for the other 8859 character sets is available under Linux through user-mode utilities (such as setfont(8)) that modify keyboard bindings and the EGA graphics table and employ the "user mapping" font table in the console driver.

Here are brief descriptions of each set:

8859-1 (Latin-1) Latin-1 covers most Western European languages such as Albanian, Catalan, Danish, Dutch, English, Faroese, Finnish, French, German, Galician, Irish, Icelandic, Italian, Norwegian, Portuguese, Spanish, and Swedish. The lack of the ligatures Dutch ij, French oe, and old-style German quotation marks is tolerable.
8859-2 (Latin-2) Latin-2 supports most Latin-written Slavic and Central European languages: Czech, German, Hungarian, Polish, Rumanian, Croatian, Slovak, and Slovene.
859-3 (Latin-3) Latin-3 is popular with authors of Esperanto, Galician, Maltese, and Turkish.
8859-4 (Latin-4) Latin-4 introduced letters for Estonian, Latvian, and Lithuanian. It is essentially obsolete; see 8859-10 (Latin-6).

Page 1065

8859-5 Cyrillic letters supporting Bulgarian, Byelorussian, Macedonian, Russian, Serbian, and Ukrainian. Ukrainians read the letter ghe with downstroke as heh and would need a ghe with upstroke to write a correct ghe. (See the discussion of KOI8-R in the next subsection.)
8859-6 Supports Arabic. The 8859-6 glyph table is a fixed font of separate letter forms, but a proper display engine should combine there pairwise into initial, medial, and final forms.
8859-7 Supports modern Greek.
8859-8 Supports Hebrew.
8859-9 (Latin-5) This is a variant of Latin-1 that replaces rarely used Icelandic letters with Turkish ones.
8859-10 (Latin-6) Latin-6 adds the last Inuit (Greenlandic) and Sami (Lappish) letters that were missing in Latin 4 to cover the entire Nordic area. RFC 1345 listed a preliminary and different Latin 6. Skolt Sami still needs a few more accents than these.

KOI8-R

KOI8-R is a non-ISO character set popular in Russia. The lower half is U.S. ASCII; the upper is a Cyrillic character set somewhat better designed than ISO 8859-5.

Console support for KOI8-R is available under Linux through user-mode utilities that modify keyboard bindings and the EGA graphics table, and that employ the "user mapping" font table in the console driver.

UNICODE

Unicode (ISO 10646) is a standard that aims to unambiguously represent every known glyph in every human language. Unicode's native encoding is 32-bit (older versions used 16 bits). Information on Unicode is available at http://www. unicode.com.

Linux represents Unicode using the 8-bit Unicode Transfer Format (UTF-8). UTF-8 is a variable length encoding of Unicode. It uses 1 byte to code 7 bits, 2 bytes for 11 bits, 3 bytes for 16 bits, 4 bytes for 21 bits, 5 bytes for 26 bits, and
6 bytes for 31 bits.

Let 0, 1, x stand for a zero, one, or arbitrary bit. A byte 0xxxxxxx stands for the Unicode 00000000 0xxxxxxx, which codes the same symbol as the ASCII 0xxxxxxx. Thus, ASCII goes unchanged into UTF-8, and people using only ASCII do not notice any change—not in code, and not in file size.

A byte 110xxxxx is the start of a 2-byte code, and 110xxxxx 10yyyyyy is assembled into 00000xxx xxyyyyyy. A byte 1110xxxx is the start of a 3-byte code, and 1110xxxx 10yyyyyy 10zzzzzz is assembled into xxxxyyyy yyzzzzzz. (When UTF-8 is used to code the 31-bit ISO 10646, then this progression continues up to 6-byte codes.)

For ISO-8859-1 users this means that the characters with high bit set now are coded with two bytes. This tends to expand ordinary text files by one or two percent. There are no conversion problems, however, since the Unicode value of ISO-8859-1 symbols equals their ISO-8859-1 value (extended by eight leading zero bits). For Japanese users, this means that the 16-bit codes now in common use will take three bytes, and extensive mapping tables are required. Many Japanese therefore prefer ISO 2022.

Note that UTF-8 is self-synchronizing: 10xxxxxx is a tail, any other byte is the head of a code. Note that the only way ASCII bytes occur in a UTF-8 stream is as themselves. In particular, there are no embedded NULs or /s that form part of some larger code.

Because ASCII, and, in particular, NUL and /, are unchanged, the kernel does not notice that UTF-8 is being used. It does not care at all what the bytes it is handling stand for.

Rendering of Unicode data streams is typically handled through subfont tables that map a subset of Unicode to glyphs. Internally, the kernel uses Unicode to describe the subfont loaded in video RAM. This means that in UTF-8 mode one can use a character set with 512 different symbols. This is not enough for Japanese, Chinese, and Korean, but it is enough for most other purposes.

Previous | Table of Contents | Next