---
name: "m17nConv"
section: "3m17n"
platform: "linux"
package: "m17n-docs"
version: "1.8.4-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/m17nConv"
---

# m17nConv(3m17n)

\- Coding system objects and API for them.

## NAME

m17nConv\_-\_Code\_Conver -  - Coding system objects and API for them.

## SYNOPSIS

### Data Structures

struct **MConverter**\
 Structure to be used in code conversion.  struct **MCodingInfoISO2022**\
 Structure for a coding system of type **MCODING\_TYPE\_ISO\_2022**.  struct **MCodingInfoUTF**\
 Structure for extra information about a coding system of type **MCODING\_TYPE\_UTF**.

### Enumerations

enum **MConversionResult** { **MCONVERSION\_RESULT\_SUCCESS**, **MCONVERSION\_RESULT\_INVALID\_BYTE**, **MCONVERSION\_RESULT\_INVALID\_CHAR**, **MCONVERSION\_RESULT\_INSUFFICIENT\_SRC**, **MCONVERSION\_RESULT\_INSUFFICIENT\_DST**, **MCONVERSION\_RESULT\_IO\_ERROR** }\
 Codes that represent the result of code conversion.  enum **MCodingType** { **MCODING\_TYPE\_CHARSET**, **MCODING\_TYPE\_UTF**, **MCODING\_TYPE\_ISO\_2022**, **MCODING\_TYPE\_MISC** }\
 Types of coding system. \
\
  " enum **MCodingFlagISO2022** { **MCODING\_ISO\_RESET\_AT\_EOL** = 0x1, **MCODING\_ISO\_RESET\_AT\_CNTL** = 0x2, **MCODING\_ISO\_EIGHT\_BIT** = 0x4, **MCODING\_ISO\_LONG\_FORM** = 0x8, **MCODING\_ISO\_DESIGNATION\_G0** = 0x10, **MCODING\_ISO\_DESIGNATION\_G1** = 0x20, **MCODING\_ISO\_DESIGNATION\_CTEXT** = 0x40, **MCODING\_ISO\_DESIGNATION\_CTEXT\_EXT** = 0x80, **MCODING\_ISO\_LOCKING\_SHIFT** = 0x100, **MCODING\_ISO\_SINGLE\_SHIFT** = 0x200, **MCODING\_ISO\_SINGLE\_SHIFT\_7** = 0x400, **MCODING\_ISO\_EUC\_TW\_SHIFT** = 0x800, **MCODING\_ISO\_ISO6429** = 0x1000, **MCODING\_ISO\_REVISION\_NUMBER** = 0x2000, **MCODING\_ISO\_FULL\_SUPPORT** = 0x3000, **MCODING\_ISO\_FLAG\_MAX** }\
 Bit-masks to specify the detail of coding system whose type is MCODING\_TYPE\_ISO\_2022. \
\
  "

### Functions

MSymbol **mconv\_define\_coding** (const char \*name, **MPlist** \*plist, int(\*resetter)(**MConverter** \*), int(\*decoder)(const unsigned char \*, int, **MText** \*, **MConverter** \*), int(\*encoder)(**MText** \*, int, int, unsigned char \*, int, **MConverter** \*), void \*extra\_info)\
 MSymbol **mconv\_resolve\_coding** (MSymbol symbol)\
 Resolve coding system name.  int **mconv\_list\_codings** (MSymbol \*\*symbols)\
 List symbols representing coding systems.  **MConverter** \* **mconv\_buffer\_converter** (MSymbol name, const unsigned char \*buf, int n)\
 Create a code converter bound to a buffer.  **MConverter** \* **mconv\_stream\_converter** (MSymbol name, FILE \*fp)\
 Create a code converter bound to a stream.  int **mconv\_reset\_converter** (**MConverter** \*converter)\
 Reset a code converter.  void **mconv\_free\_converter** (**MConverter** \*converter)\
 Free a code converter.  **MConverter** \* **mconv\_rebind\_buffer** (**MConverter** \*converter, const unsigned char \*buf, int n)\
 Bind a buffer to a code converter.  **MConverter** \* **mconv\_rebind\_stream** (**MConverter** \*converter, FILE \*fp)\
 Bind a stream to a code converter.  **MText** \* **mconv\_decode** (**MConverter** \*converter, **MText** \*mt)\
 Decode a byte sequence into an M-text.  **MText** \* **mconv\_decode\_buffer** (MSymbol name, const unsigned char \*buf, int n)\
 Decode a buffer area based on a coding system.  **MText** \* **mconv\_decode\_stream** (MSymbol name, FILE \*fp)\
 Decode a stream input based on a coding system.  int **mconv\_encode** (**MConverter** \*converter, **MText** \*mt)\
 Encode an M-text into a byte sequence.  int **mconv\_encode\_range** (**MConverter** \*converter, **MText** \*mt, int from, int to)\
 Encode a part of an M-text.  int **mconv\_encode\_buffer** (MSymbol name, **MText** \*mt, unsigned char \*buf, int n)\
 Encode an M-text into a buffer area.  int **mconv\_encode\_stream** (MSymbol name, **MText** \*mt, FILE \*fp)\
 Encode an M-text to write to a stream.  int **mconv\_getc** (**MConverter** \*converter)\
 Read a character via a code converter.  int **mconv\_ungetc** (**MConverter** \*converter, int c)\
 Push a character back to a code converter.  int **mconv\_putc** (**MConverter** \*converter, int c)\
 Write a character via a code converter.  **MText** \* **mconv\_gets** (**MConverter** \*converter, **MText** \*mt)\
 Read a line using a code converter.

### Variables: Symbols representing coding systems

MSymbol **Mcoding\_us\_ascii**\
 Symbol for the coding system US-ASCII.  MSymbol **Mcoding\_iso\_8859\_1**\
 Symbol for the coding system ISO-8859-1.  MSymbol **Mcoding\_utf\_8**\
 Symbol for the coding system UTF-8.  MSymbol **Mcoding\_utf\_8\_full**\
 Symbol for the coding system UTF-8-FULL.  MSymbol **Mcoding\_utf\_16**\
 Symbol for the coding system UTF-16.  MSymbol **Mcoding\_utf\_16be**\
 Symbol for the coding system UTF-16BE.  MSymbol **Mcoding\_utf\_16le**\
 Symbol for the coding system UTF-16LE.  MSymbol **Mcoding\_utf\_32**\
 Symbol for the coding system UTF-32.  MSymbol **Mcoding\_utf\_32be**\
 Symbol for the coding system UTF-32BE.  MSymbol **Mcoding\_utf\_32le**\
 Symbol for the coding system UTF-32LE.  MSymbol **Mcoding\_sjis**\
 Symbol for the coding system SJIS.

### Variables: Parameter keys for mconv\_define\_coding(). \<br\>

MSymbol **Mtype**\
 MSymbol **Mcharsets**\
 MSymbol **Mflags**\
 MSymbol **Mdesignation**\
 MSymbol **Minvocation**\
 MSymbol **Mcode\_unit**\
 MSymbol **Mbom**\
 MSymbol **Mlittle\_endian**\

### Variables: Symbols representing coding system types. \<br\>

MSymbol **Mutf**\
 MSymbol **Miso\_2022**\

### Variables: Symbols appearing in the value of Mflags parameter. \<br\>

 Symbols that can be a value of the **Mflags** parameter of a coding system used in an argument to the **mconv\_define\_coding()** function (which see). \

MSymbol **Mreset\_at\_eol**\
 MSymbol **Mreset\_at\_cntl**\
 MSymbol **Meight\_bit**\
 MSymbol **Mlong\_form**\
 MSymbol **Mdesignation\_g0**\
 MSymbol **Mdesignation\_g1**\
 MSymbol **Mdesignation\_ctext**\
 MSymbol **Mdesignation\_ctext\_ext**\
 MSymbol **Mlocking\_shift**\
 MSymbol **Msingle\_shift**\
 MSymbol **Msingle\_shift\_7**\
 MSymbol **Meuc\_tw\_shift**\
 MSymbol **Miso\_6429**\
 MSymbol **Mrevision\_number**\
 MSymbol **Mfull\_support**\

### Variables: Others

 Remaining variables. \

MSymbol **Mmaybe**\
 Symbol whose name is 'maybe'.  MSymbol **Mcoding**\
 The symbol `Mcoding`.

## Detailed Description

Coding system objects and API for them.

The m17n library represents a character encoding scheme (CES) of coded character sets (CCS) as an object called *coding* *system*. Application programs can add original coding systems.

To *encode* means converting code-points to character codes and to *decode* means converting character codes back to code-points.

Application programs can decode a byte sequence with a specified coding system into an M-text, and inversely, can encode an M-text into a byte sequence. \

## Data Structure Documentation

### MConverter

Structure to be used in code conversion.

**FIELD DOCUMENTATION:**

**int MConverter::lenient** Set the value to nonzero if the conversion should be lenient. By default, the conversion is strict (i.e. not lenient).

If the conversion is strict, the converter stops at the first invalid byte (on decoding) or at the first character not supported by the coding system (on encoding). If this happens, `MConverter->result` is set to `MCONVERSION_RESULT_INVALID_BYTE` or `MCONVERSION_RESULT_INVALID_CHAR` accordingly.

If the conversion is lenient, on decoding, an invalid byte is kept per se, and on encoding, an invalid character is replaced with '\<U+XXXX\>' (if the character is a Unicode character) or with '\<M+XXXXXX\>' (otherwise). \

**int MConverter::last\_block** Set the value to nonzero before decoding or encoding the last block of the byte sequence or the character sequence respectively. The value influences the conversion as below.

On decoding, in the case that the last few bytes are too short to form a valid byte sequence:

If the value is nonzero, the conversion terminates by error (MCONVERSION\_RESULT\_INVALID\_BYTE) at the first byte of the sequence.

If the value is zero, the conversion terminates successfully. Those bytes are stored in the converter as carryover and are prepended to the byte sequence of the further conversion.

On encoding, in the case that the coding system is context dependent:

If the value is nonzero, the conversion may produce a byte sequence at the end to reset the context to the initial state even if the source characters are zero.

If the value is zero, the conversion never produce such a byte sequence at the end. \

**unsigned MConverter::at\_most** If the value is nonzero, it specifies at most how many characters to convert. \

**int MConverter::nchars** The following three members are to report the result of the conversion. \

Number of characters most recently decoded or encoded. \

**int MConverter::nbytes** Number of bytes recently decoded or encoded. \

**enum MConversionResult MConverter::result** **Result code of the conversion.** \

**void\* MConverter::ptr**

**double MConverter::dbl**

**char MConverter::c\[256\]**

**union { ... }  MConverter::status** **Various information about the status of code conversion. The contents depend on the type of coding system. It is assured that** `status` **is aligned so that any type of casting is safe and at least 256 bytes of memory space can be used.** \

**void\* MConverter::internal\_info** **This member is for internally use only. An application program should never touch it.** \

### MCodingInfoISO2022

**Structure for a coding system of type MCODING\_TYPE\_ISO\_2022.**

**FIELD DOCUMENTATION:**

**int MCodingInfoISO2022::initial\_invocation\[2\]** **Table of numbers of an ISO2022 code extension element invoked to each graphic plane (Graphic Left and Graphic Right). -1 means no code extension element is invoked to that plane.** \

**char MCodingInfoISO2022::designations\[32\]** **Table of code extension elements. The Nth element corresponds to the Nth charset in charset\_names, which is an argument given to the mconv\_define\_coding() function.**

**If an element value is 0..3, it specifies a graphic register number to designate the corresponds charset. In addition, the charset is initially designated to that graphic register.**

**If the value is -4..-1, it specifies a graphic register number 0..3 respectively to designate the corresponds charset. Initially, the charset is not designated to any graphic register.** \

**unsigned MCodingInfoISO2022::flags** **Bitwise OR of** `enum` `MCodingFlagISO2022` **.** \

### MCodingInfoUTF

**Structure for extra information about a coding system of type MCODING\_TYPE\_UTF.**

**FIELD DOCUMENTATION:**

**int MCodingInfoUTF::code\_unit\_bits** **Specify bits of a code unit. The value must be 8, 16, or 32.** \

**int MCodingInfoUTF::bom** **Specify how to handle the heading BOM (byte order mark). The value must be 0, 1, or 2. The meanings are as follows:**

**0: On decoding, check the first two byte. If they are BOM, decide endian by them. If not, decide endian by the member** `endian`**. On encoding, produce byte sequence according to** `endian` **with heading BOM.**

**1: On decoding, do not handle the first two bytes as BOM, and decide endian by** `endian`**. On encoding, produce byte sequence according to** `endian` **without BOM.**

**2: On decoding, handle the first two bytes as BOM and decide ending by them. On encoding, produce byte sequence according to** `endian` **with heading BOM.**

**If \<code\_unit\_bits\> is 8, the value has no meaning.** \

**int MCodingInfoUTF::endian** **Specify the endian type. The value must be 0 or 1. 0 means little endian, and 1 means big endian.**

**If \<code\_unit\_bits\> is 8, the value has no meaning.** \

## Enumeration Type Documentation

### enum MConversionResult

**Codes that represent the result of code conversion. One of these values is set in** `MConverter->result`**.** \

**Enumerator**

- *MCONVERSION\_RESULT\_SUCCESS*

  *Code conversion is successful.*

- *MCONVERSION\_RESULT\_INVALID\_BYTE*

  *On decoding, the source contains an invalid byte.*

- *MCONVERSION\_RESULT\_INVALID\_CHAR*

  *On encoding, the source contains a character that cannot be encoded by the specified coding system.* \

- *MCONVERSION\_RESULT\_INSUFFICIENT\_SRC*

  *On decoding, the source ends with an incomplete byte sequence.*

- *MCONVERSION\_RESULT\_INSUFFICIENT\_DST*

  *On encoding, the destination is too short to store the result.*

- *MCONVERSION\_RESULT\_IO\_ERROR*

  *An I/O error occurred in the conversion.*

### enum MCodingType

*Types of coding system.* \

**Enumerator**

- *MCODING\_TYPE\_CHARSET*

  *A coding system of this type supports charsets directly. The dimension of each charset defines the length of bytes to represent a single character of the charset, and a byte sequence directly represents the code-point of a character. The m17n library provides the default decoding and encoding routines of this type.* \

- *MCODING\_TYPE\_UTF*

  *A coding system of this type supports byte sequences of a UTF (UTF-8, UTF-16, UTF-32) like structure. The m17n library provides the default decoding and encoding routines of this type.* \

- *MCODING\_TYPE\_ISO\_2022*

  *A coding system of this type supports byte sequences of an ISO-2022 like structure. The details of each structure are specified by* **MCodingInfoISO2022** *. The m17n library provides decoding and encoding routines of this type.* \

- *MCODING\_TYPE\_MISC*

  *A coding system of this type is for byte sequences of miscellaneous structures. The m17n library does not provide decoding and encoding routines of this type. They must be provided by the application program.* \

### enum MCodingFlagISO2022

*Bit-masks to specify the detail of coding system whose type is MCODING\_TYPE\_ISO\_2022.* \

**Enumerator**

- *MCODING\_ISO\_RESET\_AT\_EOL*

  *On encoding, reset the invocation and designation status to initial at end of line.* \

- *MCODING\_ISO\_RESET\_AT\_CNTL*

  *On encoding, reset the invocation and designation status to initial before any control codes.* \

- *MCODING\_ISO\_EIGHT\_BIT*

  *Use the right graphic plane.* \

- *MCODING\_ISO\_LONG\_FORM*

  *Use the non-standard 4 bytes format for designation sequence for charsets JISX0208-1978, GB2312, and JISX0208-1983.* \

- *MCODING\_ISO\_DESIGNATION\_G0*

  *On encoding, unless explicitly specified, designate charsets to G0.* \

- *MCODING\_ISO\_DESIGNATION\_G1*

  *On encoding, unless explicitly specified, designate charsets except for ASCII to G1.* \

- *MCODING\_ISO\_DESIGNATION\_CTEXT*

  *On encoding, unless explicitly specified, designate 94-chars charsets to G0, 96-chars charsets to G1.* \

- *MCODING\_ISO\_DESIGNATION\_CTEXT\_EXT*

  *On encoding, encode such charsets not conforming to ISO-2022 by ESC % / ..., and encode non-supported Unicode characters by ESC % G ... ESC % @ . On decoding, handle those escape sequences.* \

- *MCODING\_ISO\_LOCKING\_SHIFT*

  *Use locking shift.* \

- *MCODING\_ISO\_SINGLE\_SHIFT*

  *Use single shift (SS2 (0x8E or ESC N), SS3 (0x8F or ESC O)).* \

- *MCODING\_ISO\_SINGLE\_SHIFT\_7*

  *Use 7-bit single shift 2 (SS2 (0x19)).* \

- *MCODING\_ISO\_EUC\_TW\_SHIFT*

  *Use EUC-TW like special shifting.* \

- *MCODING\_ISO\_ISO6429*

  *Use ISO-6429 escape sequences to indicate direction. Not yet implemented.* \

- *MCODING\_ISO\_REVISION\_NUMBER*

  *On encoding, if a charset has revision number, produce escape sequences to specify the number.* \

- *MCODING\_ISO\_FULL\_SUPPORT*

  *Support all ISO-2022 charsets.* \

- *MCODING\_ISO\_FLAG\_MAX*

  ## Variable Documentation

### MSymbol Mcoding\_us\_ascii

*Symbol for the coding system US-ASCII. The symbol* **Mcoding\_us\_ascii** *has name* `'us-ascii'` *and represents a coding system for the CES US-ASCII.* \

### MSymbol Mcoding\_iso\_8859\_1

*Symbol for the coding system ISO-8859-1. The symbol* **Mcoding\_iso\_8859\_1** *has name* `'iso-8859-1'` *and represents a coding system for the CES ISO-8859-1.* \

### MSymbol Mcoding\_utf\_8

*Symbol for the coding system UTF-8. The symbol* **Mcoding\_utf\_8** *has name* `'utf-8'` *and represents a coding system for the CES UTF-8.* \

### MSymbol Mcoding\_utf\_8\_full

*Symbol for the coding system UTF-8-FULL. The symbol* **Mcoding\_utf\_8\_full** *has name* `'utf-8-full'` *and represents a coding system that is a extension of UTF-8. This coding system uses the same encoding algorithm as UTF-8 but is not limited to the Unicode characters. It can encode all characters supported by the m17n library.* \

### MSymbol Mcoding\_utf\_16

*Symbol for the coding system UTF-16. The symbol* **Mcoding\_utf\_16** *has name* `'utf-16'` *and represents a coding system for the CES UTF-16 (RFC 2279).* \

### MSymbol Mcoding\_utf\_16be

*Symbol for the coding system UTF-16BE. The symbol* **Mcoding\_utf\_16be** *has name* `'utf-16be'` *and represents a coding system for the CES UTF-16BE (RFC 2279).* \

### MSymbol Mcoding\_utf\_16le

*Symbol for the coding system UTF-16LE. The symbol* **Mcoding\_utf\_16le** *has name* `'utf-16le'` *and represents a coding system for the CES UTF-16LE (RFC 2279).* \

### MSymbol Mcoding\_utf\_32

*Symbol for the coding system UTF-32. The symbol* **Mcoding\_utf\_32** *has name* `'utf-32'` *and represents a coding system for the CES UTF-32 (RFC 2279).* \

### MSymbol Mcoding\_utf\_32be

*Symbol for the coding system UTF-32BE. The symbol* **Mcoding\_utf\_32be** *has name* `'utf-32be'` *and represents a coding system for the CES UTF-32BE (RFC 2279).* \

### MSymbol Mcoding\_utf\_32le

*Symbol for the coding system UTF-32LE. The symbol* **Mcoding\_utf\_32le** *has name* `'utf-32le'` *and represents a coding system for the CES UTF-32LE (RFC 2279).* \

### MSymbol Mcoding\_sjis

*Symbol for the coding system SJIS. The symbol* **Mcoding\_sjis** *has name* `'sjis'` *and represents a coding system for the CES Shift-JIS.* \

### MSymbol Mtype

*Parameter key for* **mconv\_define\_coding()** *(which see).* \

### MSymbol Mcharsets

### MSymbol Mflags

### MSymbol Mdesignation

### MSymbol Minvocation

### MSymbol Mcode\_unit

### MSymbol Mbom

### MSymbol Mlittle\_endian

### MSymbol Mutf

*Symbol that can be a value of the* **Mtype** *parameter of a coding system used in an argument to the* **mconv\_define\_coding()** *function (which see).* \

### MSymbol Miso\_2022

### MSymbol Mreset\_at\_eol

### MSymbol Mreset\_at\_cntl

### MSymbol Meight\_bit

### MSymbol Mlong\_form

### MSymbol Mdesignation\_g0

### MSymbol Mdesignation\_g1

### MSymbol Mdesignation\_ctext

### MSymbol Mdesignation\_ctext\_ext

### MSymbol Mlocking\_shift

### MSymbol Msingle\_shift

### MSymbol Msingle\_shift\_7

### MSymbol Meuc\_tw\_shift

### MSymbol Miso\_6429

### MSymbol Mrevision\_number

### MSymbol Mfull\_support

### MSymbol Mmaybe

*Symbol whose name is 'maybe'. The variable* **Mmaybe** *is a symbol of name* `'maybe'`*. It is used a value of* **Mbom** *parameter of the function* **mconv\_define\_coding()** *(which see).* \

### MSymbol Mcoding

*The symbol* `Mcoding`*. Any decoded M-text has a text property whose key is the predefined symbol* `Mcoding`*. The name of* `Mcoding` *is* `'coding'`*.* \

## Author

*Generated automatically by Doxygen for The m17n Library from the source code.*

## COPYRIGHT

*Copyright (C) 2001 Information-technology Promotion Agency (IPA)*\
 *Copyright (C) 2001-2011 National Institute of Advanced Industrial Science and Technology (AIST)*\
 *Permission is granted to copy, distribute and/or modify this document* *under the terms of the GNU Free Documentation License*  *\<http://www.gnu.org/licenses/fdl.html\>.*
