summaryrefslogtreecommitdiffstats
path: root/src/preproc/preconv/preconv.1.man
blob: 80929c1d835c259d40f499098979564031d6b0ed (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
.TH preconv @MAN1EXT@ "@MDATE@" "groff @VERSION@"
.SH Name
preconv \- prepare files for typesetting with groff
.
.
.\" ====================================================================
.\" Legal Terms
.\" ====================================================================
.\"
.\" Copyright (C) 2006-2018 Free Software Foundation, Inc.
.\"
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Permission is granted to copy and distribute modified versions of
.\" this manual under the conditions for verbatim copying, provided that
.\" the entire resulting derived work is distributed under the terms of
.\" a permission notice identical to this one.
.\"
.\" Permission is granted to copy and distribute translations of this
.\" manual into another language, under the above conditions for
.\" modified versions, except that this permission notice may be
.\" included in translations approved by the Free Software Foundation
.\" instead of in the original English.
.
.
.\" Save and disable compatibility mode (for, e.g., Solaris 10/11).
.do nr *groff_preconv_1_man_C \n[.cp]
.cp 0
.
.
.\" ====================================================================
.SH Synopsis
.\" ====================================================================
.
.SY preconv
.OP \-dr
.OP \-D default-encoding
.OP \-e encoding
.RI [ file
\&.\|.\|.\&]
.YS
.
.
.SY preconv
.B \-h
.
.SY preconv
.B \-\-help
.YS
.
.
.SY preconv
.B \-v
.
.SY preconv
.B \-\-version
.YS
.
.
.\" ====================================================================
.SH Description
.\" ====================================================================
.
.I preconv
reads each
.IR file ,
converts its encoded characters to a form
.IR groff (@MAN1EXT@)
can interpret,
and sends the result to the standard output stream.
.
Currently,
this means that code points in the range 0\[en]127
(in US-ASCII,
ISO\~8859,
or Unicode)
remain as-is and the remainder are converted to the
.I groff
special character form
.RB \[lq] \[rs][\c
.BI u XXXX ]\c
\[rq],
where
.I XXXX
is a hexadecimal number of four to six digits corresponding to a Unicode
code point.
.
By default,
.I preconv
also inserts a
.I roff
.B .lf
request at the beginning of each
.IR file ,
identifying it for the benefit of later processing
(including diagnostic messages);
the
.B \-r
option suppresses this behavior.
.
.
.PP
In typical usage scenarios,
.I preconv
need not be run directly;
instead it should be invoked with the
.B \-k
or
.B \-K
options of
.IR groff .
.
If
.I preconv
is given no
.I file
operands,
it reads the standard input stream.
.
.
.PP
.I preconv
tries to find the input encoding with the following algorithm,
stopping at the first success.
.
.
.IP 1.
If the input encoding has been explicitly specified with option
.BR \-e ,
use it.
.
.
.IP 2.
Check whether the input starts with a Unicode Byte Order Mark.
.
If so,
determine the encoding as UTF-8,
UTF-16,
or UTF-32 accordingly.
.
.
.IP 3.
If the input stream is seekable,
check the first and second input lines for a recognized GNU\~Emacs
file-local variable identifying the character encoding,
here referred to as the \[lq]coding tag\[rq] for brevity.
.
If found,
use it.
.
.
.IP 4.
If the input stream is seekable,
and if the
.I uchardet
library is available on the system,
use it to try to infer the encoding of the file.
.
.
.IP 5.
If the
.B \-D
option specifies an encoding,
use it.
.
.
.IP 6.
Use the encoding specified by the current locale
.RI ( LC_CTYPE ),
unless the locale is
\[lq]C\[rq],
\[lq]POSIX\[rq],
or empty,
in which case assume Latin-1
(ISO\~8859-1).
.
.
.PP
The coding tag and
.I uchardet
methods in the above procedure rely upon a seekable input stream;
when
.I preconv
reads from a pipe,
the stream is not seekable,
and these detection methods are skipped.
.
If character encoding detection of your input files is unreliable,
arrange for one of the other methods to succeed by using
.IR preconv 's
.B \-D
or
.B \-e
options,
or by configuring your locale appropriately.
.
.I groff
also supports a
.I \%GROFF_ENCODING
environment variable,
which can be overridden by its
.B \-K
option.
.
Valid values for
(or parameters to)
all of these are enumerated in the lists of recognized coding tags in
the next subsection,
and is further influenced by
.I iconv
library support.
.
.
.\" ====================================================================
.SS "Coding tags"
.\" ====================================================================
.
Text editors that support more than a single character encoding need
tags within the input files to mark the file's encoding.
.
While it is possible to guess the right input encoding with the help of
heuristics that are reliable for a preponderance of natural language
texts,
they are not absolutely reliable.
.
Heuristics can fail on inputs that are too short or don't represent a
natural language.
.
.
.PP
Consequently,
.I preconv
supports the coding tag convention
(with some restrictions)
used by GNU\~Emacs.
.
These are indicated in specially-marked regions of an input file
designated for \[lq]file-local variables\[rq].
.
.
.PP
.I preconv
interprets the following syntax if it occurs in a
.I roff
comment
in the first or second line of the input file.
.
Both \[lq]\[rs]"\[rq] and \[lq]\[rs]#\[rq] comment forms are recognized,
but the control
(or non-breaking control)
character must be the default and must begin the line.
.
Similarly,
the escape character must be the default.
.
.
.RS
.EX
.B \-*\- \c
.RB [.\|.\|. ; ]\~\c
.B coding: \c
.IB encoding\c
.RB [ ;\~ .\|.\|.\&]\~\c
.B \-*\-
.EE
.RE
.
.
.PP
The only variable
.I preconv
interprets is \[lq]coding\[rq],
which can take the values listed below.
.
.
.PP
The following list comprises all MIME \[lq]charset\[rq] parameter values
recognized,
case-insensitively,
by
.IR preconv .
.
.RS
\%big5,
\%cp1047,
\%euc\-jp,
\%euc\-kr,
\%gb2312,
\%iso\-8859\-1,
\%iso\-8859\-2,
\%iso\-8859\-5,
\%iso\-8859\-7,
\%iso\-8859\-9,
\%iso\-8859\-13,
\%iso\-8859\-15,
\%koi8\-r,
\%us\-ascii,
\%utf\-8,
\%utf\-16,
\%utf\-16be,
\%utf\-16le
.RE
.
.
.PP
In addition,
the following list of other coding tags is recognized,
each of which is mapped to an appropriate value from the list above.
.
.RS
\%ascii,
\%chinese\-big5,
\%chinese\-euc,
\%chinese\-iso\-8bit,
\%cn\-big5,
\%cn\-gb,
\%cn\-gb\-2312,
\%cp878,
\%csascii,
\%csisolatin1,
\%cyrillic\-iso\-8bit,
\%cyrillic\-koi8,
\%euc\-china,
\%euc\-cn,
\%euc\-japan,
\%euc\-japan\-1990,
\%euc\-korea,
\%greek\-iso\-8bit,
\%iso\-10646/utf8,
\%iso\-10646/utf\-8,
\%iso\-latin\-1,
\%iso\-latin\-2,
\%iso\-latin\-5,
\%iso\-latin\-7,
\%iso\-latin\-9,
\%japanese\-euc,
\%japanese\-iso\-8bit,
\%jis8,
\%koi8,
\%korean\-euc,
\%korean\-iso\-8bit,
\%latin\-0,
\%latin1,
\%latin\-1,
\%latin\-2,
\%latin\-5,
\%latin\-7,
\%latin\-9,
\%mule\-utf\-8,
\%mule\-utf\-16,
\%mule\-utf\-16be,
\%mule\-utf\-16\-be,
\%mule\-utf\-16be\-with\-signature,
\%mule\-utf\-16le,
\%mule\-utf\-16\-le,
\%mule\-utf\-16le\-with\-signature,
\%utf8,
\%utf\-16\-be,
\%utf\-16\-be\-with\-signature,
\%utf\-16be\-with\-signature,
\%utf\-16\-le,
\%utf\-16\-le\-with\-signature,
\%utf\-16le\-with\-signature
.RE
.
.
.PP
Trailing
\[lq]\-dos\[rq],
\[lq]\-unix\[rq],
and
\[lq]\-mac\[rq]
suffixes on coding tags
(which indicate the end-of-line convention used in the file)
are disregarded for the purpose of comparison with the above tags.
.
.
.\" ====================================================================
.SS "iconv support"
.\" ====================================================================
.
While
.I preconv
recognizes all of the coding tags listed above,
it is capable on its own of interpreting only three encodings:
Latin-1,
code page 1047,
and UTF-8.
.
If
.I iconv
support is configured at compile time and available at run time,
all other encodings are passed to
.I iconv
library functions.
.
The library may recognize many additional encoding strings.
.
The command
.RB \[lq] preconv\~\-v \[rq]
discloses whether
.I iconv
support is configured.
.
.
.PP
The use of
.I iconv
means that characters in the input that encode invalid code points for
that encoding may be dropped from the output stream or mapped to the
Unicode replacement character
(U+FFFD).
.
Compare the following examples using the input \[lq]caf\['e]\[rq]
(note the \[lq]e\[rq] with an acute accent),
which due to its short length challenges inference of the encoding used.
.
.RS
.EX
printf \[aq]caf\[rs]351\[rs]n\[aq] | LC_ALL=en_US.UTF\-8 preconv
printf \[aq]caf\[rs]351\[rs]n\[aq] | preconv \-e us\-ascii
printf \[aq]caf\[rs]351\[rs]n\[aq] | preconv \-e latin\-1
.EE
.RE
.
The fate of the accented \[lq]e\[rq] differs in each case.
.
In the first,
.I uchardet
fails to detect an encoding
(though the library on your system may behave differently)
and
.I preconv
falls back to the locale settings,
where octal 351 starts an incomplete UTF-8 sequence and results in the
Unicode replacement character.
.
In the second,
it is not a representable character in the declared input encoding of
US-ASCII and is discarded by
.IR iconv .
.
In the last,
it is correctly detected and mapped.
.
.
.\" ====================================================================
.SH Options
.\" ====================================================================
.
.B \-h
and
.B \-\-help
display a usage message,
while
.B \-v
and
.B \-\-version
show version information;
all exit afterward.
.
.
.TP
.B \-d
Emit debugging messages to the standard error stream.
.
.
.TP
.BI \-D\~ default-encoding
Report
.I default-encoding
if all detection methods fail.
.
.
.TP
.BI \-e\~ encoding
Override detection procedure and assume
.IR encoding .
.
This corresponds to
.IR groff 's
.RB \[lq] \-K
.IR encoding \[rq]
option.
.
.
.TP
.B \-r
Write files \[lq]raw\[rq];
do not add
.B .lf
requests.
.
.
.\" ====================================================================
.SH "See also"
.\" ====================================================================
.
.IR groff (@MAN1EXT@),
.IR iconv (3),
.IR locale (7)
.
.
.\" Restore compatibility mode (for, e.g., Solaris 10/11).
.cp \n[*groff_preconv_1_man_C]
.
.
.\" Local Variables:
.\" fill-column: 72
.\" mode: nroff
.\" End:
.\" vim: set filetype=groff textwidth=72: