info > recode

```html

πŸ“– NAME

recode β€” This recoding library converts files between various coded character sets and surface encodings. When this cannot be achieved exactly, it may get rid of the offending characters or fall back on approximations. The library recognises or produces more than 300 different character sets and is able to convert files between almost any pair. Most RFC 1345 character sets, and all 'libiconv' character sets, are supported. The 'recode' program is a handy front-end to the library.

πŸš€ Quick Reference

Use CaseCommandDescription
πŸ” Filter Mac to Latin-1recode macConvert Macintosh file (stdin) to Latin-1 (stdout)
πŸ” Filter IBM-PC to Latin-1recode pcConvert IBM-PC/CR-LF to Latin-1
πŸ” Remove Quoted-Printablerecode /qpStrip QP encoding from input
πŸ” Reverse: Latin-1 to Macrecode ..macConvert Latin-1 to Macintosh/CR
πŸ” Reverse: Latin-1 to IBM-PCrecode ..pcConvert Latin-1 to IBM-PC/CR-LF
πŸ” Force recoding despite errorsrecode -f BEFORE..AFTERProceed even if irreversible
πŸ“‹ List charsets and surfacesrecode -lShow all available charsets/aliases
πŸ“‹ List with grep filterrecode -l | grep -i greekFind Greek-related charsets
πŸ“‹ Show charset table (decimal)recode -ld l1Display Latin-1 in decimal
πŸ“‹ Show charset table (full)recode -lf l1Display Latin-1 with comments
πŸ”Ž Guess unknown charsetrecode -k 130:233Identify charset from known mappings
πŸ”„ Overwrite file in placerecode BEFORE..AFTER FILERecode FILE over itself
πŸ”„ Filter with shell redirectionrecode BEFORE..AFTER <in >outRecode stdin to stdout
πŸ“ Recode only diacriticsrecode -d l1..texLimit to non-English letters (LaTeX)
πŸ“ Recode strings/comments onlyrecode -Spo pc/..u8Only recode msgstr in .po files
πŸ”¬ Verbose step listingrecode -v BEFORE..AFTERShow intermediate steps and quality
πŸ§ͺ Strict mode (lossy)recode -s BEFORE..AFTERDrop unmapped characters

πŸ“š Table of Contents

πŸ“– 1 Quick Tutorial

When you just want to use 'recode' quickly:

Use recode -l to list all charsets/surfaces, recode --help for option summary.

πŸ“– 2 Terminology and purpose

Charset β€” A particular association between computer codes (small integers starting at 0) and a repertoire of intended characters. Roughly a table giving meaning to each allowable code value.

Surface β€” A surface transformation of a charset stream. Any kind of (usually reversible) mapping associating physical bits to a stream of characters. Examples: end-of-line encoding, Base64, gzip compression. The "trivial" surface puts characters into fixed-width 8-bit chunks.

Purpose β€” Convert files between various charsets and surfaces. When exact conversion is impossible, the program may drop offending characters or fall back on approximations. The library recognises around 175 charsets under 500 names, and handles a dozen surfaces.

πŸ“– 2.1 Overview of charsets

Recoding is possible between many charsets, described by RFC 1345 tables or available in the 'iconv' library. The 'recode' library also handles specialised charsets:

Exceptions β€” Cannot recode from 'flat', 'count-characters' or 'dump-with-names'; cannot recode from/to 'data', 'tree' or ':libiconv:'. Surfaces and charsets live in disjoint recoding spaces.

πŸ“– 2.2 Overview of surfaces

Surfaces are tricks used to fit a charset into practical constraints (7-bit medium, variable-length codes, special newline treatment, etc.). A "pure charset" is a charset free of any surface. When a specialised surface is practical to consider as a charset, this is preferred.

πŸ“– 2.3 Contributions and bug reports

Send suggestions, documentation errors and bug reports to recode-bugs AT iro.ca or directly to pinard AT iro.ca, FranΓ§ois Pinard. Provide good, solid, verifiable references for tables when contributing new charsets or surfaces.

πŸ“– 3 How to use this program

πŸ“– 3.1 Synopsis of 'recode' call

General format:

recode [OPTION]... [CHARSET | REQUEST [FILE]... ]

For simple cases, the request looks like:

BEFORE..AFTER

Each FILE is read assuming charset BEFORE, recoded over itself to charset AFTER. If no FILE, acts as a Unix filter (stdin to stdout).

Example β€” prepare a distribution from Latin-1 to MSDOS:

mkdir package
cp -p Makefile *.[ch] package
recode Latin-1..MSDOS package/*
zoo ah package.zoo package/*
rm -rf package

Example β€” filter without altering original:

recode -d l1..tex <datum.txt >datum.tex

πŸ“– 3.2 The REQUEST parameter

Charset names may contain any character besides comma, forward slash, or two periods in a row. The complete syntax allows intermediate charsets:

BEFORE..INTERIM1..INTERIM2..AFTER

Sub-requests may be separated by commas:

BEFORE..INTERIM1,INTERIM1..INTERIM2,INTERIM2..AFTER

Surfaces are introduced with slashes:

PURE-CHARSET/SURFACE1/SURFACE2...

Some charsets have implied surfaces. For example, 'pc' has 'CR-LF' as its usual surface. The request pc/..l1 defeats automatic removal of surfaces.

Charset names, surface names, or aliases may be abbreviated to any unambiguous prefix. 'recode' ignores all characters besides letters and digits when recognising names, and is case-insensitive.

If a charset name is omitted, the value of the DEFAULT_CHARSET environment variable is used (falling back to the current locale's encoding).

πŸ“– 3.3 Asking for various lists

FORMAT values for -l: decimal (default), octal, hexadecimal, full.

πŸ“– 3.4 Controlling how files are recoded

πŸ“– 3.5 Reversibility issues

Reversibility notes:

Without -s, 'recode' fills mappings with invented correspondences, preferring small permutation cycles. This may produce funny characters but aids reversibility. Use -s to avoid this.

πŸ“– 3.6 Selecting sequencing methods

πŸ“– 3.7 Using mixed charset input

πŸ“– 3.8 Using 'recode' within Emacs

Recode the whole buffer from IBM-PC to current charset:

C-x h C-u M-| recode ibmpc RET

Bind keys to recode region from Easy French to Latin-1:

(global-set-key "\C-cT" 'recode-texte)

(defun recode-texte (flag)
  (interactive "P")
  (shell-command-on-region
   (region-beginning) (region-end)
   (concat "recode " (if flag "..txte" "txte")) t)
  (exchange-point-and-mark))

πŸ“– 3.9 Debugging considerations

When 'recode' doesn't provide satisfying results, common causes: incorrect call, doubts about correct results, or mangled input files. To debug:

πŸ“– 4 A recoding library

The 'recode' program is an application of the recoding library. To use the library in C programs:

#include <recode.h>

Link with -lrecode.

The library has four levels: outer, request, task, and charset functions.

πŸ“– 4.1 Outer level functions

Prepare the library for use. Example (minimal program that does nothing useful):

#include <stdbool.h>
#include <recode.h>

const char *program_name;

int
main (int argc, char *const *argv)
{
  program_name = argv[0];
  RECODE_OUTER outer = recode_new_outer (true);

  recode_delete_outer (outer);
  exit (0);
}

Functions:

The program_name variable is used by the library when it diagnoses and aborts.

πŸ“– 4.2 Request level functions

Cover most recoding needs. Example β€” filter ibmpc to latin1:

#include <stdio.h>
#include <stdbool.h>
#include <recode.h>

const char *program_name;

int
main (int argc, char *const *argv)
{
  program_name = argv[0];
  RECODE_OUTER outer = recode_new_outer (true);
  RECODE_REQUEST request = recode_new_request (outer);
  bool success;

  recode_scan_request (request, "ibmpc..latin1");

  success = recode_file_to_file (request, stdin, stdout);

  recode_delete_request (request);
  recode_delete_outer (outer);

  exit (success ? 0 : 1);
}

Functions:

Fields of struct recode_request (accessible via recodext.h):

πŸ“– 4.3 Task level functions

Allow more explicit control over input/output. Example β€” filter ibmpc to latin1 at task level:

#include <stdio.h>
#include <stdbool.h>
#include <recodext.h>

const char *program_name;

int
main (int argc, char *const *argv)
{
  program_name = argv[0];
  RECODE_OUTER outer = recode_new_outer (false);
  RECODE_REQUEST request = recode_new_request (outer);
  RECODE_TASK task;
  bool success;

  recode_scan_request (request, "ibmpc..latin1");

  task = recode_new_task (request);
  task->input.file = "";
  task->output.file = "";
  success = recode_perform_task (task);

  recode_delete_task (task);
  recode_delete_request (request);
  recode_delete_outer (outer);

  exit (success ? 0 : 1);
}

Functions:

Key fields of struct task_request (via recodext.h):

πŸ“– 4.4 Charset level functions

Internal functions made external:

RECODE_CHARSET find_charset (NAME, CLEANING-TYPE);
bool list_all_charsets (CHARSET);
bool list_concise_charset (CHARSET, LIST-FORMAT);
bool list_full_charset (CHARSET);

πŸ“– 4.5 Handling errors

Error levels (increasing severity):

Set fail_level and abort_level in the task structure to control behaviour.

πŸ“– 5 The universal charset

ISO 10646 defines a universal character set (UCS) based on wide characters, offering possibilities for 2^31 characters. In 'recode', surfaces of UCS are presented as genuine charsets:

πŸ“– 6 The 'iconv' library

The 'recode' library incorporates most code and tables from the portable 'iconv' library by Bruno Haible. The :libiconv: charset is a conceptual pivot within the iconv part. Using -x: or --ignore=:libiconv: disables iconv paths.

Supported charsets include: US-ASCII, UTF-8, UCS-2, UCS-2BE, UCS-2LE, UCS-4, UCS-4BE, UCS-4LE, UTF-16, UTF-16BE, UTF-16LE, UTF-7, ISO-8859-1 through -16, KOI8-R, KOI8-U, KOI8-RU, Windows CP1250-1258, DOS CP850/CP866, MacRoman/MacCentralEurope/MacCroatian/MacIceland/MacRomania/MacCyrillic/MacUkraine/MacGreek/MacTurkish/MacHebrew/MacArabic/MacThai, HP-ROMAN8, NEXTSTEP, ARMSCII-8, Georgian-Academy/PS, MuleLao-1, CP1133, TIS-620, CP874, VISCII, TCVN, and many CJK charsets (JIS, GB, KSC, EUC, SJIS, BIG5, etc.).

Full alias lists are provided in the original documentation for each charset.

πŸ“– 7 Tabular sources (RFC 1345)

An important part of the tabular charset knowledge comes from RFC 1345 ("Character Mnemonics & Character Sets", K. Simonsen, June 1992). The 'recode' library implements most of RFC 1345, with these exceptions:

The RFC1345 charset (aliases: mnemonic, 1345) uses ISO 646 mnemonics with ampersand prefixes. The original documentation lists over 200 charsets with their aliases and sources.

πŸ“– 8 ASCII and some derivatives

πŸ“– 9 Some IBM or Microsoft charsets

πŸ“– 10 Charsets for CDC machines

πŸ“– 11 Other micro-computer charsets

πŸ“– 12 Various other charsets

πŸ“– 13 All about surfaces

πŸ“– 14 Internal aspects

πŸ“– 14.1 Overall organisation

The 'recode' driver constructs a table of all conversion routines ("single steps") as nodes in a directed graph. A cost is attributed to each arc. Given start and goal charsets, 'recode' computes the most economical route. Optimisation merges simple subsequences, and "double steps" (via UCS-2) are dynamically merged into efficient reversible single steps. Statistics: average steps after optimisation is ~1.8 (reversible) or ~1.3 (strict mode).

πŸ“– 14.2 Adding new charsets

Create a .c file (or .l Flex file for multi-character recognition) with two conversion functions (from an old charset to the new one, and from the new charset to an old one). The initialisation function module_CHARSET calls declare_step. Predefined functions: file_one_to_one (for 1-to-1 tables), file_one_to_many (for 1-to-many). Edit Makefile.am to add to C_STEPS or L_STEPS.

πŸ“– 14.3 Adding new surfaces

Similar to adding a charset, but transformations are from/to the special charsets data or tree. declare_step recognises these and installs the charset as a surface.

πŸ“– 14.4 Comments on the library design

Shared library β€” All tables are precompiled into binaries and made into a shared library, avoiding external data files and disk accesses. Initialisation overhead is acceptable.

Central charset β€” UCS-2 is almost always used as a trampoline between charsets, but is optimised out into single-step permutation tables. The library is not forcefully restrained to UCS-2.

Why not 'iconv' β€” The iconv buffer-to-buffer model is hard to synchronise across long recoding sequences. The stream-based approach is simpler and more efficient. Iconv can be emulated if needed.

πŸ“– Concept Index

Alphabetical list of concepts: abbreviated names, adding new charsets/surfaces, African charsets, aliases, ambiguous output, ASCII table, average number of recoding steps, bool data type, box-drawing characters, bug reports, byte order mark, caret ASCII code, CDC charsets, chaining, character entities, charset level functions, codepages, combining characters, commutativity of surfaces, contributing, conversions (unavailable), counting characters, CR surface, CR-LF surface, Cyrillic charsets, debugging surfaces, default charset, description of individual characters, diacritics, diaeresis, disable map filling, double step, dumping characters, Easy French, EBCDIC, end of line format, endianness, error handling, file sequencing, file time stamps, filter operation, force recoding, French description, guessing charsets, Haible Bruno, HTML, IBM codepages, iconv, identifying subsets, ignore charsets, implied surfaces, impossible conversions, interface with iconv, intermediate charsets, internal functions, invalid input, invocation synopsis, irreversible recoding, ISO 10646, LaTeX, Latin charsets, libiconv, listing charsets, Macintosh, map filling, MIME, MS-DOS, MULE, multiplexed charsets, new charsets/surfaces, NeXT, non-canonical input, NOS 6/12 code, numeric character references, outer level functions, partial conversion, permutations, pipe sequencing, pseudo-charsets, pure charset, quality of recoding, recoding library, recoding path rejection, recoding steps statistics, request level functions, reversibility, RFC 1345, RFC 2045, sequencing, SGML, shared library, silent operation, single step, source file generation, strict operation, structural surfaces, subsets, super-charsets, suppressing diagnostics, surface, task level functions, TeX, Texinfo, threshold for error reporting, time stamps, trivial surface, tutorial, UCS, Unicode, unknown charsets, untranslatable input, valid characters in charset names, verbose operation, Vietnamese, Web, XML.

πŸ“– Option Index

πŸ“– Library Index

Alphabetical index of important functions, data structures, and variables in the recoding library: abort_level, ascii_graphics, byte_order_mark, declare_step, DEFAULT_CHARSET, diacritics_only, diaeresis_char, error_so_far, fail_level, file_one_to_many, file_one_to_one, find_charset, LANG, LANGUAGE, list_all_charsets, list_concise_charset, list_full_charset, make_header_flag, RECODE_AMBIGUOUS_OUTPUT, recode_buffer_to_buffer, recode_buffer_to_file, recode_delete_outer, recode_delete_request, recode_delete_task, recode_file_to_buffer, recode_file_to_file, recode_filter_close, recode_filter_open, recode_format_table, RECODE_INTERNAL_ERROR, RECODE_INVALID_INPUT, RECODE_MAXIMUM_ERROR, recode_new_outer, recode_new_request, recode_new_task, RECODE_NOT_CANONICAL, RECODE_NO_ERROR, RECODE_OUTER, recode_perform_task, RECODE_REQUEST, recode_request, recode_scan_request, RECODE_SEQUENCE_IN_MEMORY, RECODE_SEQUENCE_WITH_FILES, RECODE_SEQUENCE_WITH_PIPE, RECODE_STRATEGY_UNDECIDED, recode_string, recode_string_to_buffer, recode_string_to_file, RECODE_SYSTEM_ERROR, RECODE_TASK, RECODE_UNTRANSLATABLE, RECODE_USER_ERROR, strategy, task_request, verbose_flag.

πŸ“– Charset and Surface Index

This is an alphabetical list of all the charsets and surfaces supported by 'recode', and their aliases. The full index covers over 600 entries including all standard aliases, EBCDIC variants, IBM code pages, ISO standards, RFC-defined names, and surface names. Key entries include: ASCII, UTF-8, ISO-8859-*, CP125*, IBM*, EBCDIC, MacRoman, KOI8-R, Base64, Quoted-Printable, and many more. Refer to the original documentation for the complete list.

```
recode
πŸ“– NAME πŸš€ Quick Reference πŸ“š Table of Contents πŸ“– 1 Quick Tutorial πŸ“– 2 Terminology and purpose
πŸ“– 2.1 Overview of charsets πŸ“– 2.2 Overview of surfaces πŸ“– 2.3 Contributions and bug reports
πŸ“– 3 How to use this program
πŸ“– 3.1 Synopsis of 'recode' call πŸ“– 3.2 The REQUEST parameter πŸ“– 3.3 Asking for various lists πŸ“– 3.4 Controlling how files are recoded πŸ“– 3.5 Reversibility issues πŸ“– 3.6 Selecting sequencing methods πŸ“– 3.7 Using mixed charset input πŸ“– 3.8 Using 'recode' within Emacs πŸ“– 3.9 Debugging considerations
πŸ“– 4 A recoding library
πŸ“– 4.1 Outer level functions πŸ“– 4.2 Request level functions πŸ“– 4.3 Task level functions πŸ“– 4.4 Charset level functions πŸ“– 4.5 Handling errors
πŸ“– 5 The universal charset πŸ“– 6 The 'iconv' library πŸ“– 7 Tabular sources (RFC 1345) πŸ“– 8 ASCII and some derivatives πŸ“– 9 Some IBM or Microsoft charsets πŸ“– 10 Charsets for CDC machines πŸ“– 11 Other micro-computer charsets πŸ“– 12 Various other charsets πŸ“– 13 All about surfaces πŸ“– 14 Internal aspects
πŸ“– 14.1 Overall organisation πŸ“– 14.2 Adding new charsets πŸ“– 14.3 Adding new surfaces πŸ“– 14.4 Comments on the library design
πŸ“– Concept Index πŸ“– Option Index πŸ“– Library Index πŸ“– Charset and Surface Index

Generated by phpman v4.9.26-1-g511901d · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-31 10:39 @216.73.217.152
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format

^_top_^