1 .\" $NetBSD: vis.3,v 1.39 2013/02/20 20:05:26 christos Exp $
3 .\" Copyright (c) 1989, 1991, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)vis.3 8.1 (Berkeley) 6/9/93
50 .Nd visually encode characters
56 .Fn vis "char *dst" "int c" "int flag" "int nextc"
58 .Fn nvis "char *dst" "size_t dlen" "int c" "int flag" "int nextc"
60 .Fn strvis "char *dst" "const char *src" "int flag"
62 .Fn strnvis "char *dst" "size_t dlen" "const char *src" "int flag"
64 .Fn strvisx "char *dst" "const char *src" "size_t len" "int flag"
66 .Fn strnvisx "char *dst" "size_t dlen" "const char *src" "size_t len" "int flag"
68 .Fn strenvisx "char *dst" "size_t dlen" "const char *src" "size_t len" "int flag" "int *cerr_ptr"
70 .Fn svis "char *dst" "int c" "int flag" "int nextc" "const char *extra"
72 .Fn snvis "char *dst" "size_t dlen" "int c" "int flag" "int nextc" "const char *extra"
74 .Fn strsvis "char *dst" "const char *src" "int flag" "const char *extra"
76 .Fn strsnvis "char *dst" "size_t dlen" "const char *src" "int flag" "const char *extra"
78 .Fn strsvisx "char *dst" "const char *src" "size_t len" "int flag" "const char *extra"
80 .Fn strsnvisx "char *dst" "size_t dlen" "const char *src" "size_t len" "int flag" "const char *extra"
82 .Fn strsenvisx "char *dst" "size_t dlen" "const char *src" "size_t len" "int flag" "const char *extra" "int *cerr_ptr"
89 a string which represents the character
93 needs no encoding, it is copied in unaltered.
94 The string is null terminated, and a pointer to the end of the string is
96 The maximum length of any encoding is four
97 bytes (not including the trailing
100 encoding a set of characters into a buffer, the size of the buffer should
101 be four times the number of bytes encoded, plus one for the trailing
103 The flag parameter is used for altering the default range of
104 characters considered for encoding and for altering the visual
106 The additional character,
108 is only used when selecting the
110 encoding format (explained below).
120 a visual representation of
127 functions encode characters from
136 functions encode exactly
141 is useful for encoding a block of data that may contain
149 must be four times the number
150 of bytes encoded from
155 forms return the number of characters in
157 (not including the trailing
161 versions of the functions also take an additional argument
163 that indicates the length of the
168 is not large enough to fit the converted string then the
172 functions return \-1 and set
178 function takes an additional argument,
180 that is used to pass in and out a multibyte conversion error flag.
181 This is useful when processing single characters at a time when
182 it is possible that the locale may be set to something other
183 than the locale of the characters in the input data.
203 but have an additional argument
207 terminated list of characters.
208 These characters will be copied encoded or backslash-escaped into
210 These functions are useful e.g. to remove the special meaning
211 of certain characters to shells.
213 The encoding is a unique, invertible representation composed entirely of
214 graphic characters; it can be decoded back into the original form using
222 There are two parameters that can be controlled: the range of
223 characters that are encoded (applies only to
231 and the type of representation used.
232 By default, all non-graphic characters,
233 except space, tab, and newline are encoded (see
237 .Bl -tag -width VIS_WHITEX
239 Also encode the magic characters
264 Unsafe means control characters which may cause common terminals to perform
265 unexpected functions.
266 Currently this form allows space, tab, newline, backspace, bell, and
267 return \(em in addition to all graphic characters \(em unencoded.
270 (The above flags have no effect for
278 When using these functions, place all graphic characters to be
279 encoded in an array pointed to by
281 In general, the backslash character should be included in this array, see the
282 warning on the use of the
286 There are four forms of encoding.
287 All forms use the backslash character
289 to introduce a special
290 sequence; two backslashes are used to represent a real backslash,
299 These are the visual formats:
300 .Bl -tag -width VIS_CSTYLE
304 to represent meta characters (characters with the 8th
305 bit set), and use caret
307 to represent control characters (see
309 The following formats are used:
310 .Bl -tag -width xxxxx
312 Represents the control character
325 with the 8th bit set.
331 Represents control character
333 with the 8th bit set.
347 Represents Meta-space.
351 Use C-style backslash sequences to represent standard non-printable
353 The following sequences are used to represent the indicated characters:
354 .Bd -unfilled -offset indent
355 .Li \ea Tn \(em BEL No (007)
356 .Li \eb Tn \(em BS No (010)
357 .Li \ef Tn \(em NP No (014)
358 .Li \en Tn \(em NL No (012)
359 .Li \er Tn \(em CR No (015)
360 .Li \es Tn \(em SP No (040)
361 .Li \et Tn \(em HT No (011)
362 .Li \ev Tn \(em VT No (013)
363 .Li \e0 Tn \(em NUL No (000)
366 When using this format, the
368 parameter is looked at to determine if a
370 character can be encoded as
376 is an octal digit, the latter representation is used to
379 Use a three digit octal sequence.
384 represents an octal digit.
386 Use URI encoding as described in RFC 1738.
391 represents a lower case hexadecimal digit.
393 Use MIME Quoted-Printable encoding as described in RFC 2045, only don't
394 break lines and don't handle CRLF.
399 represents an upper case hexadecimal digit.
402 There is one additional flag,
405 doubling of backslashes and the backslash before the default
406 format (that is, control characters are represented by
411 With this flag set, the encoding is
412 ambiguous and non-invertible.
413 .Sh MULTIBYTE CHARACTER SUPPORT
414 These functions support multibyte character input.
415 The encoding conversion is influenced by the setting of the
417 environment variable which defines the set of characters
418 that can be copied without encoding.
420 When 8-bit data is present in the input,
422 must be set to the correct locale or to the C locale.
423 If the locales of the data and the conversion are mismatched,
424 multibyte character recognition may fail and encoding will be performed
425 byte-by-byte instead.
429 must be four times the number of bytes processed from
431 But note that each multibyte character can be up to
435 .\" .Xr multibyte 3 )
436 so in terms of multibyte characters,
440 times the number of characters processed from
443 .Bl -tag -width ".Ev LC_CTYPE"
445 Specify the locale of the input data.
446 Set to C if the input data locale is unknown.
461 will return \-1 when the
463 destination buffer size is not enough to perform the conversion while
467 .Bl -tag -width ".Bq Er ENOSPC"
469 The destination buffer size is not large enough to perform the conversion.
475 .\" .Xr multibyte 3 ,
479 .%T Uniform Resource Locators (URL)
483 .%T "Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies"
492 functions first appeared in
499 functions appeared in
501 The buffer size limited versions of the functions
513 Myltibyte character support was added in