Debian Codegraph @

doc/Encoding.3

raw
1 '\"
2 '\" Copyright (c) 1997-1998 Sun Microsystems, Inc.
3 '\"
4 '\" See the file "license.terms" for information on usage and redistribution
5 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
6 '\"
7 .TH Tcl_GetEncoding 3 "8.1" Tcl "Tcl Library Procedures"
8 .so man.macros
9 .BS
10 .SH NAME
11 Tcl_GetEncoding, Tcl_FreeEncoding, Tcl_GetEncodingFromObj, Tcl_ExternalToUtfDString, Tcl_ExternalToUtf, Tcl_UtfToExternalDString, Tcl_UtfToExternal, Tcl_WinTCharToUtf, Tcl_WinUtfToTChar, Tcl_GetEncodingName, Tcl_SetSystemEncoding, Tcl_GetEncodingNameFromEnvironment, Tcl_GetEncodingNames, Tcl_CreateEncoding, Tcl_GetEncodingSearchPath, Tcl_SetEncodingSearchPath, Tcl_GetDefaultEncodingDir, Tcl_SetDefaultEncodingDir \- procedures for creating and using encodings
12 .SH SYNOPSIS
13 .nf
14 \fB#include <tcl.h>\fR
15 .sp
16 Tcl_Encoding
17 \fBTcl_GetEncoding\fR(\fIinterp, name\fR)
18 .sp
19 void
20 \fBTcl_FreeEncoding\fR(\fIencoding\fR)
21 .sp
22 int
23 \fBTcl_GetEncodingFromObj\fR(\fIinterp, objPtr, encodingPtr\fR)
24 .sp
25 char *
26 \fBTcl_ExternalToUtfDString\fR(\fIencoding, src, srcLen, dstPtr\fR)
27 .sp
28 char *
29 \fBTcl_UtfToExternalDString\fR(\fIencoding, src, srcLen, dstPtr\fR)
30 .sp
31 int
32 \fBTcl_ExternalToUtf\fR(\fIinterp, encoding, src, srcLen, flags, statePtr,
33 dst, dstLen, srcReadPtr, dstWrotePtr, dstCharsPtr\fR)
34 .sp
35 int
36 \fBTcl_UtfToExternal\fR(\fIinterp, encoding, src, srcLen, flags, statePtr,
37 dst, dstLen, srcReadPtr, dstWrotePtr, dstCharsPtr\fR)
38 .sp
39 char *
40 \fBTcl_WinTCharToUtf\fR(\fItsrc, srcLen, dstPtr\fR)
41 .sp
42 TCHAR *
43 \fBTcl_WinUtfToTChar\fR(\fIsrc, srcLen, dstPtr\fR)
44 .sp
45 const char *
46 \fBTcl_GetEncodingName\fR(\fIencoding\fR)
47 .sp
48 int
49 \fBTcl_SetSystemEncoding\fR(\fIinterp, name\fR)
50 .sp
51 const char *
52 \fBTcl_GetEncodingNameFromEnvironment\fR(\fIbufPtr\fR)
53 .sp
54 void
55 \fBTcl_GetEncodingNames\fR(\fIinterp\fR)
56 .sp
57 Tcl_Encoding
58 \fBTcl_CreateEncoding\fR(\fItypePtr\fR)
59 .sp
60 Tcl_Obj *
61 \fBTcl_GetEncodingSearchPath\fR()
62 .sp
63 int
64 \fBTcl_SetEncodingSearchPath\fR(\fIsearchPath\fR)
65 .sp
66 const char *
67 \fBTcl_GetDefaultEncodingDir\fR(\fIvoid\fR)
68 .sp
69 void
70 \fBTcl_SetDefaultEncodingDir\fR(\fIpath\fR)
71 .SH ARGUMENTS
72 .AS "const Tcl_EncodingType" *dstWrotePtr in/out
73 .AP Tcl_Interp *interp in
74 Interpreter to use for error reporting, or NULL if no error reporting is
75 desired.
76 .AP "const char" *name in
77 Name of encoding to load.
78 .AP Tcl_Encoding encoding in
79 The encoding to query, free, or use for converting text. If \fIencoding\fR is
80 NULL, the current system encoding is used.
81 .AP Tcl_Obj *objPtr in
82 Name of encoding to get token for.
83 .AP Tcl_Encoding *encodingPtr out
84 Points to storage where encoding token is to be written.
85 .AP "const char" *src in
86 For the \fBTcl_ExternalToUtf\fR functions, an array of bytes in the
87 specified encoding that are to be converted to UTF-8. For the
88 \fBTcl_UtfToExternal\fR and \fBTcl_WinUtfToTChar\fR functions, an array of
89 UTF-8 characters to be converted to the specified encoding.
90 .AP "const TCHAR" *tsrc in
91 An array of Windows TCHAR characters to convert to UTF-8.
92 .AP int srcLen in
93 Length of \fIsrc\fR or \fItsrc\fR in bytes. If the length is negative, the
94 encoding-specific length of the string is used.
95 .AP Tcl_DString *dstPtr out
96 Pointer to an uninitialized or free \fBTcl_DString\fR in which the converted
97 result will be stored.
98 .AP int flags in
99 Various flag bits OR-ed together.
100 \fBTCL_ENCODING_START\fR signifies that the
101 source buffer is the first block in a (potentially multi-block) input
102 stream, telling the conversion routine to reset to an initial state and
103 perform any initialization that needs to occur before the first byte is
104 converted. \fBTCL_ENCODING_END\fR signifies that the source buffer is the last
105 block in a (potentially multi-block) input stream, telling the conversion
106 routine to perform any finalization that needs to occur after the last
107 byte is converted and then to reset to an initial state.
108 \fBTCL_ENCODING_STOPONERROR\fR signifies that the conversion routine should
109 return immediately upon reading a source character that does not exist in
110 the target encoding; otherwise a default fallback character will
111 automatically be substituted.
112 .AP Tcl_EncodingState *statePtr in/out
113 Used when converting a (generally long or indefinite length) byte stream
114 in a piece-by-piece fashion. The conversion routine stores its current
115 state in \fI*statePtr\fR after \fIsrc\fR (the buffer containing the
116 current piece) has been converted; that state information must be passed
117 back when converting the next piece of the stream so the conversion
118 routine knows what state it was in when it left off at the end of the
119 last piece. May be NULL, in which case the value specified for \fIflags\fR
120 is ignored and the source buffer is assumed to contain the complete string to
121 convert.
122 .AP char *dst out
123 Buffer in which the converted result will be stored. No more than
124 \fIdstLen\fR bytes will be stored in \fIdst\fR.
125 .AP int dstLen in
126 The maximum length of the output buffer \fIdst\fR in bytes.
127 .AP int *srcReadPtr out
128 Filled with the number of bytes from \fIsrc\fR that were actually
129 converted. This may be less than the original source length if there was
130 a problem converting some source characters. May be NULL.
131 .AP int *dstWrotePtr out
132 Filled with the number of bytes that were actually stored in the output
133 buffer as a result of the conversion. May be NULL.
134 .AP int *dstCharsPtr out
135 Filled with the number of characters that correspond to the number of bytes
136 stored in the output buffer. May be NULL.
137 .AP Tcl_DString *bufPtr out
138 Storage for the prescribed system encoding name.
139 .AP "const Tcl_EncodingType" *typePtr in
140 Structure that defines a new type of encoding.
141 .AP Tcl_Obj *searchPath in
142 List of filesystem directories in which to search for encoding data files.
143 .AP "const char" *path in
144 A path to the location of the encoding file.
145 .BE
146 .SH INTRODUCTION
147 .PP
148 These routines convert between Tcl's internal character representation,
149 UTF-8, and character representations used by various operating systems or
150 file systems, such as Unicode, ASCII, or Shift-JIS. When operating on
151 strings, such as such as obtaining the names of files or displaying
152 characters using international fonts, the strings must be translated into
153 one or possibly multiple formats that the various system calls can use. For
154 instance, on a Japanese Unix workstation, a user might obtain a filename
155 represented in the EUC-JP file encoding and then translate the characters to
156 the jisx0208 font encoding in order to display the filename in a Tk widget.
157 The purpose of the encoding package is to help bridge the translation gap.
158 UTF-8 provides an intermediate staging ground for all the various
159 encodings. In the example above, text would be translated into UTF-8 from
160 whatever file encoding the operating system is using. Then it would be
161 translated from UTF-8 into whatever font encoding the display routines
162 require.
163 .PP
164 Some basic encodings are compiled into Tcl. Others can be defined by the
165 user or dynamically loaded from encoding files in a
166 platform-independent manner.
167 .SH DESCRIPTION
168 .PP
169 \fBTcl_GetEncoding\fR finds an encoding given its \fIname\fR. The name may
170 refer to a built-in Tcl encoding, a user-defined encoding registered by
171 calling \fBTcl_CreateEncoding\fR, or a dynamically-loadable encoding
172 file. The return value is a token that represents the encoding and can be
173 used in subsequent calls to procedures such as \fBTcl_GetEncodingName\fR,
174 \fBTcl_FreeEncoding\fR, and \fBTcl_UtfToExternal\fR. If the name did not
175 refer to any known or loadable encoding, NULL is returned and an error
176 message is returned in \fIinterp\fR.
177 .PP
178 The encoding package maintains a database of all encodings currently in use.
179 The first time \fIname\fR is seen, \fBTcl_GetEncoding\fR returns an
180 encoding with a reference count of 1. If the same \fIname\fR is requested
181 further times, then the reference count for that encoding is incremented
182 without the overhead of allocating a new encoding and all its associated
183 data structures.
184 .PP
185 When an \fIencoding\fR is no longer needed, \fBTcl_FreeEncoding\fR
186 should be called to release it. When an \fIencoding\fR is no longer in use
187 anywhere (i.e., it has been freed as many times as it has been gotten)
188 \fBTcl_FreeEncoding\fR will release all storage the encoding was using
189 and delete it from the database.
190 .PP
191 \fBTcl_GetEncodingFromObj\fR treats the string representation of
192 \fIobjPtr\fR as an encoding name, and finds an encoding with that
193 name, just as \fBTcl_GetEncoding\fR does. When an encoding is found,
194 it is cached within the \fBobjPtr\fR value for future reference, the
195 \fBTcl_Encoding\fR token is written to the storage pointed to by
196 \fIencodingPtr\fR, and the value \fBTCL_OK\fR is returned. If no such
197 encoding is found, the value \fBTCL_ERROR\fR is returned, and no
198 writing to \fB*\fR\fIencodingPtr\fR takes place. Just as with
199 \fBTcl_GetEncoding\fR, the caller should call \fBTcl_FreeEncoding\fR
200 on the resulting encoding token when that token will no longer be
201 used.
202 .PP
203 \fBTcl_ExternalToUtfDString\fR converts a source buffer \fIsrc\fR from the
204 specified \fIencoding\fR into UTF-8. The converted bytes are stored in
205 \fIdstPtr\fR, which is then null-terminated. The caller should eventually
206 call \fBTcl_DStringFree\fR to free any information stored in \fIdstPtr\fR.
207 When converting, if any of the characters in the source buffer cannot be
208 represented in the target encoding, a default fallback character will be
209 used. The return value is a pointer to the value stored in the DString.
210 .PP
211 \fBTcl_ExternalToUtf\fR converts a source buffer \fIsrc\fR from the specified
212 \fIencoding\fR into UTF-8. Up to \fIsrcLen\fR bytes are converted from the
213 source buffer and up to \fIdstLen\fR converted bytes are stored in \fIdst\fR.
214 In all cases, \fI*srcReadPtr\fR is filled with the number of bytes that were
215 successfully converted from \fIsrc\fR and \fI*dstWrotePtr\fR is filled with
216 the corresponding number of bytes that were stored in \fIdst\fR. The return
217 value is one of the following:
218 .RS
219 .IP \fBTCL_OK\fR 29
220 All bytes of \fIsrc\fR were converted.
221 .IP \fBTCL_CONVERT_NOSPACE\fR 29
222 The destination buffer was not large enough for all of the converted data; as
223 many characters as could fit were converted though.
224 .IP \fBTCL_CONVERT_MULTIBYTE\fR 29
225 The last few bytes in the source buffer were the beginning of a multibyte
226 sequence, but more bytes were needed to complete this sequence. A
227 subsequent call to the conversion routine should pass a buffer containing
228 the unconverted bytes that remained in \fIsrc\fR plus some further bytes
229 from the source stream to properly convert the formerly split-up multibyte
230 sequence.
231 .IP \fBTCL_CONVERT_SYNTAX\fR 29
232 The source buffer contained an invalid character sequence. This may occur
233 if the input stream has been damaged or if the input encoding method was
234 misidentified.
235 .IP \fBTCL_CONVERT_UNKNOWN\fR 29
236 The source buffer contained a character that could not be represented in
237 the target encoding and \fBTCL_ENCODING_STOPONERROR\fR was specified.
238 .RE
239 .LP
240 \fBTcl_UtfToExternalDString\fR converts a source buffer \fIsrc\fR from UTF-8
241 into the specified \fIencoding\fR. The converted bytes are stored in
242 \fIdstPtr\fR, which is then terminated with the appropriate encoding-specific
243 null. The caller should eventually call \fBTcl_DStringFree\fR to free any
244 information stored in \fIdstPtr\fR. When converting, if any of the
245 characters in the source buffer cannot be represented in the target
246 encoding, a default fallback character will be used. The return value is
247 a pointer to the value stored in the DString.
248 .PP
249 \fBTcl_UtfToExternal\fR converts a source buffer \fIsrc\fR from UTF-8 into
250 the specified \fIencoding\fR. Up to \fIsrcLen\fR bytes are converted from
251 the source buffer and up to \fIdstLen\fR converted bytes are stored in
252 \fIdst\fR. In all cases, \fI*srcReadPtr\fR is filled with the number of
253 bytes that were successfully converted from \fIsrc\fR and \fI*dstWrotePtr\fR
254 is filled with the corresponding number of bytes that were stored in
255 \fIdst\fR. The return values are the same as the return values for
256 \fBTcl_ExternalToUtf\fR.
257 .PP
258 \fBTcl_WinUtfToTChar\fR and \fBTcl_WinTCharToUtf\fR are
259 Windows-only convenience
260 functions for converting between UTF-8 and Windows strings
261 based on the TCHAR type which is by convention
262 a Unicode character on Windows NT.
263 .PP
264 \fBTcl_GetEncodingName\fR is roughly the inverse of \fBTcl_GetEncoding\fR.
265 Given an \fIencoding\fR, the return value is the \fIname\fR argument that
266 was used to create the encoding. The string returned by
267 \fBTcl_GetEncodingName\fR is only guaranteed to persist until the
268 \fIencoding\fR is deleted. The caller must not modify this string.
269 .PP
270 \fBTcl_SetSystemEncoding\fR sets the default encoding that should be used
271 whenever the user passes a NULL value for the \fIencoding\fR argument to
272 any of the other encoding functions. If \fIname\fR is NULL, the system
273 encoding is reset to the default system encoding, \fBbinary\fR. If the
274 name did not refer to any known or loadable encoding, \fBTCL_ERROR\fR is
275 returned and an error message is left in \fIinterp\fR. Otherwise, this
276 procedure increments the reference count of the new system encoding,
277 decrements the reference count of the old system encoding, and returns
278 \fBTCL_OK\fR.
279 .PP
280 \fBTcl_GetEncodingNameFromEnvironment\fR provides a means for the Tcl
281 library to report the encoding name it believes to be the correct one
282 to use as the system encoding, based on system calls and examination of
283 the environment suitable for the platform. It accepts \fIbufPtr\fR,
284 a pointer to an uninitialized or freed \fBTcl_DString\fR and writes
285 the encoding name to it. The \fBTcl_DStringValue\fR is returned.
286 .PP
287 \fBTcl_GetEncodingNames\fR sets the \fIinterp\fR result to a list
288 consisting of the names of all the encodings that are currently defined
289 or can be dynamically loaded, searching the encoding path specified by
290 \fBTcl_SetDefaultEncodingDir\fR. This procedure does not ensure that the
291 dynamically-loadable encoding files contain valid data, but merely that they
292 exist.
293 .PP
294 \fBTcl_CreateEncoding\fR defines a new encoding and registers the C
295 procedures that are called back to convert between the encoding and
296 UTF-8. Encodings created by \fBTcl_CreateEncoding\fR are thereafter
297 visible in the database used by \fBTcl_GetEncoding\fR. Just as with the
298 \fBTcl_GetEncoding\fR procedure, the return value is a token that
299 represents the encoding and can be used in subsequent calls to other
300 encoding functions. \fBTcl_CreateEncoding\fR returns an encoding with a
301 reference count of 1. If an encoding with the specified \fIname\fR
302 already exists, then its entry in the database is replaced with the new
303 encoding; the token for the old encoding will remain valid and continue
304 to behave as before, but users of the new token will now call the new
305 encoding procedures.
306 .PP
307 The \fItypePtr\fR argument to \fBTcl_CreateEncoding\fR contains information
308 about the name of the encoding and the procedures that will be called to
309 convert between this encoding and UTF-8. It is defined as follows:
310 .PP
311 .CS
312 typedef struct Tcl_EncodingType {
313 const char *\fIencodingName\fR;
314 Tcl_EncodingConvertProc *\fItoUtfProc\fR;
315 Tcl_EncodingConvertProc *\fIfromUtfProc\fR;
316 Tcl_EncodingFreeProc *\fIfreeProc\fR;
317 ClientData \fIclientData\fR;
318 int \fInullSize\fR;
319 } \fBTcl_EncodingType\fR;
320 .CE
321 .PP
322 The \fIencodingName\fR provides a string name for the encoding, by
323 which it can be referred in other procedures such as
324 \fBTcl_GetEncoding\fR. The \fItoUtfProc\fR refers to a callback
325 procedure to invoke to convert text from this encoding into UTF-8.
326 The \fIfromUtfProc\fR refers to a callback procedure to invoke to
327 convert text from UTF-8 into this encoding. The \fIfreeProc\fR refers
328 to a callback procedure to invoke when this encoding is deleted. The
329 \fIfreeProc\fR field may be NULL. The \fIclientData\fR contains an
330 arbitrary one-word value passed to \fItoUtfProc\fR, \fIfromUtfProc\fR,
331 and \fIfreeProc\fR whenever they are called. Typically, this is a
332 pointer to a data structure containing encoding-specific information
333 that can be used by the callback procedures. For instance, two very
334 similar encodings such as \fBascii\fR and \fBmacRoman\fR may use the
335 same callback procedure, but use different values of \fIclientData\fR
336 to control its behavior. The \fInullSize\fR specifies the number of
337 zero bytes that signify end-of-string in this encoding. It must be
338 \fB1\fR (for single-byte or multi-byte encodings like ASCII or
339 Shift-JIS) or \fB2\fR (for double-byte encodings like Unicode).
340 Constant-sized encodings with 3 or more bytes per character (such as
341 CNS11643) are not accepted.
342 .PP
343 The callback procedures \fItoUtfProc\fR and \fIfromUtfProc\fR should match the
344 type \fBTcl_EncodingConvertProc\fR:
345 .PP
346 .CS
347 typedef int \fBTcl_EncodingConvertProc\fR(
348 ClientData \fIclientData\fR,
349 const char *\fIsrc\fR,
350 int \fIsrcLen\fR,
351 int \fIflags\fR,
352 Tcl_EncodingState *\fIstatePtr\fR,
353 char *\fIdst\fR,
354 int \fIdstLen\fR,
355 int *\fIsrcReadPtr\fR,
356 int *\fIdstWrotePtr\fR,
357 int *\fIdstCharsPtr\fR);
358 .CE
359 .PP
360 The \fItoUtfProc\fR and \fIfromUtfProc\fR procedures are called by the
361 \fBTcl_ExternalToUtf\fR or \fBTcl_UtfToExternal\fR family of functions to
362 perform the actual conversion. The \fIclientData\fR parameter to these
363 procedures is the same as the \fIclientData\fR field specified to
364 \fBTcl_CreateEncoding\fR when the encoding was created. The remaining
365 arguments to the callback procedures are the same as the arguments,
366 documented at the top, to \fBTcl_ExternalToUtf\fR or
367 \fBTcl_UtfToExternal\fR, with the following exceptions. If the
368 \fIsrcLen\fR argument to one of those high-level functions is negative,
369 the value passed to the callback procedure will be the appropriate
370 encoding-specific string length of \fIsrc\fR. If any of the \fIsrcReadPtr\fR,
371 \fIdstWrotePtr\fR, or \fIdstCharsPtr\fR arguments to one of the high-level
372 functions is NULL, the corresponding value passed to the callback
373 procedure will be a non-NULL location.
374 .PP
375 The callback procedure \fIfreeProc\fR, if non-NULL, should match the type
376 \fBTcl_EncodingFreeProc\fR:
377 .PP
378 .CS
379 typedef void \fBTcl_EncodingFreeProc\fR(
380 ClientData \fIclientData\fR);
381 .CE
382 .PP
383 This \fIfreeProc\fR function is called when the encoding is deleted. The
384 \fIclientData\fR parameter is the same as the \fIclientData\fR field
385 specified to \fBTcl_CreateEncoding\fR when the encoding was created.
386 .PP
387 \fBTcl_GetEncodingSearchPath\fR and \fBTcl_SetEncodingSearchPath\fR
388 are called to access and set the list of filesystem directories searched
389 for encoding data files.
390 .PP
391 The value returned by \fBTcl_GetEncodingSearchPath\fR
392 is the value stored by the last successful call to
393 \fBTcl_SetEncodingSearchPath\fR. If no calls to
394 \fBTcl_SetEncodingSearchPath\fR have occurred, Tcl will compute an initial
395 value based on the environment. There is one encoding search path for the
396 entire process, shared by all threads in the process.
397 .PP
398 \fBTcl_SetEncodingSearchPath\fR stores \fIsearchPath\fR and returns
399 \fBTCL_OK\fR, unless \fIsearchPath\fR is not a valid Tcl list, which
400 causes \fBTCL_ERROR\fR to be returned. The elements of \fIsearchPath\fR
401 are not verified as existing readable filesystem directories. When
402 searching for encoding data files takes place, and non-existent or
403 non-readable filesystem directories on the \fIsearchPath\fR are silently
404 ignored.
405 .PP
406 \fBTcl_GetDefaultEncodingDir\fR and \fBTcl_SetDefaultEncodingDir\fR
407 are obsolete interfaces best replaced with calls to
408 \fBTcl_GetEncodingSearchPath\fR and \fBTcl_SetEncodingSearchPath\fR.
409 They are called to access and set the first element of the \fIsearchPath\fR
410 list. Since Tcl searches \fIsearchPath\fR for encoding data files in
411 list order, these routines establish the
412 .QW default
413 directory in which to find encoding data files.
414 .SH "ENCODING FILES"
415 Space would prohibit precompiling into Tcl every possible encoding
416 algorithm, so many encodings are stored on disk as dynamically-loadable
417 encoding files. This behavior also allows the user to create additional
418 encoding files that can be loaded using the same mechanism. These
419 encoding files contain information about the tables and/or escape
420 sequences used to map between an external encoding and Unicode. The
421 external encoding may consist of single-byte, multi-byte, or double-byte
422 characters.
423 .PP
424 Each dynamically-loadable encoding is represented as a text file. The
425 initial line of the file, beginning with a
426 .QW #
427 symbol, is a comment
428 that provides a human-readable description of the file. The next line
429 identifies the type of encoding file. It can be one of the following
430 letters:
431 .IP "[1] \fBS\fR"
432 A single-byte encoding, where one character is always one byte long in the
433 encoding. An example is \fBiso8859-1\fR, used by many European languages.
434 .IP "[2] \fBD\fR"
435 A double-byte encoding, where one character is always two bytes long in the
436 encoding. An example is \fBbig5\fR, used for Chinese text.
437 .IP "[3] \fBM\fR"
438 A multi-byte encoding, where one character may be either one or two bytes long.
439 Certain bytes are lead bytes, indicating that another byte must follow
440 and that together the two bytes represent one character. Other bytes are not
441 lead bytes and represent themselves. An example is \fBshiftjis\fR, used by
442 many Japanese computers.
443 .IP "[4] \fBE\fR"
444 An escape-sequence encoding, specifying that certain sequences of bytes
445 do not represent characters, but commands that describe how following bytes
446 should be interpreted.
447 .PP
448 The rest of the lines in the file depend on the type.
449 .PP
450 Cases [1], [2], and [3] are collectively referred to as table-based encoding
451 files. The lines in a table-based encoding file are in the same
452 format as this example taken from the \fBshiftjis\fR encoding (this is not
453 the complete file):
454 .PP
455 .CS
456 # Encoding file: shiftjis, multi-byte
457 M
458 003F 0 40
459 00
460 0000000100020003000400050006000700080009000A000B000C000D000E000F
461 0010001100120013001400150016001700180019001A001B001C001D001E001F
462 0020002100220023002400250026002700280029002A002B002C002D002E002F
463 0030003100320033003400350036003700380039003A003B003C003D003E003F
464 0040004100420043004400450046004700480049004A004B004C004D004E004F
465 0050005100520053005400550056005700580059005A005B005C005D005E005F
466 0060006100620063006400650066006700680069006A006B006C006D006E006F
467 0070007100720073007400750076007700780079007A007B007C007D203E007F
468 0080000000000000000000000000000000000000000000000000000000000000
469 0000000000000000000000000000000000000000000000000000000000000000
470 0000FF61FF62FF63FF64FF65FF66FF67FF68FF69FF6AFF6BFF6CFF6DFF6EFF6F
471 FF70FF71FF72FF73FF74FF75FF76FF77FF78FF79FF7AFF7BFF7CFF7DFF7EFF7F
472 FF80FF81FF82FF83FF84FF85FF86FF87FF88FF89FF8AFF8BFF8CFF8DFF8EFF8F
473 FF90FF91FF92FF93FF94FF95FF96FF97FF98FF99FF9AFF9BFF9CFF9DFF9EFF9F
474 0000000000000000000000000000000000000000000000000000000000000000
475 0000000000000000000000000000000000000000000000000000000000000000
476 81
477 0000000000000000000000000000000000000000000000000000000000000000
478 0000000000000000000000000000000000000000000000000000000000000000
479 0000000000000000000000000000000000000000000000000000000000000000
480 0000000000000000000000000000000000000000000000000000000000000000
481 300030013002FF0CFF0E30FBFF1AFF1BFF1FFF01309B309C00B4FF4000A8FF3E
482 FFE3FF3F30FD30FE309D309E30034EDD30053006300730FC20152010FF0F005C
483 301C2016FF5C2026202520182019201C201DFF08FF0930143015FF3BFF3DFF5B
484 FF5D30083009300A300B300C300D300E300F30103011FF0B221200B100D70000
485 00F7FF1D2260FF1CFF1E22662267221E22342642264000B0203220332103FFE5
486 FF0400A200A3FF05FF03FF06FF0AFF2000A72606260525CB25CF25CE25C725C6
487 25A125A025B325B225BD25BC203B301221922190219121933013000000000000
488 000000000000000000000000000000002208220B2286228722822283222A2229
489 000000000000000000000000000000002227222800AC21D221D4220022030000
490 0000000000000000000000000000000000000000222022A52312220222072261
491 2252226A226B221A223D221D2235222B222C0000000000000000000000000000
492 212B2030266F266D266A2020202100B6000000000000000025EF000000000000
493 .CE
494 .PP
495 The third line of the file is three numbers. The first number is the
496 fallback character (in base 16) to use when converting from UTF-8 to this
497 encoding. The second number is a \fB1\fR if this file represents the
498 encoding for a symbol font, or \fB0\fR otherwise. The last number (in base
499 10) is how many pages of data follow.
500 .PP
501 Subsequent lines in the example above are pages that describe how to map
502 from the encoding into 2-byte Unicode. The first line in a page identifies
503 the page number. Following it are 256 double-byte numbers, arranged as 16
504 rows of 16 numbers. Given a character in the encoding, the high byte of
505 that character is used to select which page, and the low byte of that
506 character is used as an index to select one of the double-byte numbers in
507 that page \- the value obtained being the corresponding Unicode character.
508 By examination of the example above, one can see that the characters 0x7E
509 and 0x8163 in \fBshiftjis\fR map to 203E and 2026 in Unicode, respectively.
510 .PP
511 Following the first page will be all the other pages, each in the same
512 format as the first: one number identifying the page followed by 256
513 double-byte Unicode characters. If a character in the encoding maps to the
514 Unicode character 0000, it means that the character does not actually exist.
515 If all characters on a page would map to 0000, that page can be omitted.
516 .PP
517 Case [4] is the escape-sequence encoding file. The lines in an this type of
518 file are in the same format as this example taken from the \fBiso2022-jp\fR
519 encoding:
520 .PP
521 .CS
522 .ta 1.5i
523 # Encoding file: iso2022-jp, escape-driven
524 E
525 init {}
526 final {}
527 iso8859-1 \ex1b(B
528 jis0201 \ex1b(J
529 jis0208 \ex1b$@
530 jis0208 \ex1b$B
531 jis0212 \ex1b$(D
532 gb2312 \ex1b$A
533 ksc5601 \ex1b$(C
534 .CE
535 .PP
536 In the file, the first column represents an option and the second column
537 is the associated value. \fBinit\fR is a string to emit or expect before
538 the first character is converted, while \fBfinal\fR is a string to emit
539 or expect after the last character. All other options are names of
540 table-based encodings; the associated value is the escape-sequence that
541 marks that encoding. Tcl syntax is used for the values; in the above
542 example, for instance,
543 .QW \fB{}\fR
544 represents the empty string and
545 .QW \fB\ex1b\fR
546 represents character 27.
547 .PP
548 When \fBTcl_GetEncoding\fR encounters an encoding \fIname\fR that has not
549 been loaded, it attempts to load an encoding file called \fIname\fB.enc\fR
550 from the \fBencoding\fR subdirectory of each directory that Tcl searches
551 for its script library. If the encoding file exists, but is
552 malformed, an error message will be left in \fIinterp\fR.
553 .SH KEYWORDS
554 utf, encoding, convert