1 .\" $NetBSD: vis.3,v 1.45 2016/06/08 15:00:04 wiz Exp $
4 .\" Copyright (c) 1989, 1991, 1993
5 .\" The Regents of the University of California. All rights reserved.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\" notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice, this list of conditions and the following disclaimer in the
14 .\" documentation and/or other materials provided with the distribution.
15 .\" 3. Neither the name of the University nor the names of its contributors
16 .\" may be used to endorse or promote products derived from this software
17 .\" without specific prior written permission.
19 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 .\" @(#)vis.3 8.1 (Berkeley) 6/9/93
52 .Nd visually encode characters
58 .Fn vis "char *dst" "int c" "int flag" "int nextc"
60 .Fn nvis "char *dst" "size_t dlen" "int c" "int flag" "int nextc"
62 .Fn strvis "char *dst" "const char *src" "int flag"
64 .Fn stravis "char **dst" "const char *src" "int flag"
66 .Fn strnvis "char *dst" "size_t dlen" "const char *src" "int flag"
68 .Fn strvisx "char *dst" "const char *src" "size_t len" "int flag"
70 .Fn strnvisx "char *dst" "size_t dlen" "const char *src" "size_t len" "int flag"
72 .Fn strenvisx "char *dst" "size_t dlen" "const char *src" "size_t len" "int flag" "int *cerr_ptr"
74 .Fn svis "char *dst" "int c" "int flag" "int nextc" "const char *extra"
76 .Fn snvis "char *dst" "size_t dlen" "int c" "int flag" "int nextc" "const char *extra"
78 .Fn strsvis "char *dst" "const char *src" "int flag" "const char *extra"
80 .Fn strsnvis "char *dst" "size_t dlen" "const char *src" "int flag" "const char *extra"
82 .Fn strsvisx "char *dst" "const char *src" "size_t len" "int flag" "const char *extra"
84 .Fn strsnvisx "char *dst" "size_t dlen" "const char *src" "size_t len" "int flag" "const char *extra"
86 .Fn strsenvisx "char *dst" "size_t dlen" "const char *src" "size_t len" "int flag" "const char *extra" "int *cerr_ptr"
93 a string which represents the character
97 needs no encoding, it is copied in unaltered.
98 The string is null terminated, and a pointer to the end of the string is
100 The maximum length of any encoding is four
101 bytes (not including the trailing
104 encoding a set of characters into a buffer, the size of the buffer should
105 be four times the number of bytes encoded, plus one for the trailing
107 The flag parameter is used for altering the default range of
108 characters considered for encoding and for altering the visual
110 The additional character,
112 is only used when selecting the
114 encoding format (explained below).
125 a visual representation of
132 functions encode characters from
141 functions encode exactly
146 is useful for encoding a block of data that may contain
154 must be four times the number
155 of bytes encoded from
160 forms return the number of characters in
162 (not including the trailing
166 function allocates space dynamically to hold the string.
169 versions of the functions also take an additional argument
171 that indicates the length of the
176 is not large enough to fit the converted string then the
180 functions return \-1 and set
186 function takes an additional argument,
188 that is used to pass in and out a multibyte conversion error flag.
189 This is useful when processing single characters at a time when
190 it is possible that the locale may be set to something other
191 than the locale of the characters in the input data.
211 but have an additional argument
215 terminated list of characters.
216 These characters will be copied encoded or backslash-escaped into
218 These functions are useful e.g. to remove the special meaning
219 of certain characters to shells.
221 The encoding is a unique, invertible representation composed entirely of
222 graphic characters; it can be decoded back into the original form using
230 There are two parameters that can be controlled: the range of
231 characters that are encoded (applies only to
239 and the type of representation used.
240 By default, all non-graphic characters,
241 except space, tab, and newline are encoded (see
245 .Bl -tag -width VIS_WHITEX
247 Also encode the magic characters
256 Also encode the meta characters used by shells (in addition to the glob
283 .Dv VIS_SP | VIS_TAB | VIS_NL .
286 .Dv VIS_WHITE | VIS_GLOB | VIS_SHELL .
291 Unsafe means control characters which may cause common terminals to perform
292 unexpected functions.
293 Currently this form allows space, tab, newline, backspace, bell, and
294 return \(em in addition to all graphic characters \(em unencoded.
297 (The above flags have no effect for
305 When using these functions, place all graphic characters to be
306 encoded in an array pointed to by
308 In general, the backslash character should be included in this array, see the
309 warning on the use of the
313 There are four forms of encoding.
314 All forms use the backslash character
316 to introduce a special
317 sequence; two backslashes are used to represent a real backslash,
326 These are the visual formats:
327 .Bl -tag -width VIS_CSTYLE
331 to represent meta characters (characters with the 8th
332 bit set), and use caret
334 to represent control characters (see
336 The following formats are used:
337 .Bl -tag -width xxxxx
339 Represents the control character
352 with the 8th bit set.
358 Represents control character
360 with the 8th bit set.
374 Represents Meta-space.
378 Use C-style backslash sequences to represent standard non-printable
380 The following sequences are used to represent the indicated characters:
381 .Bd -unfilled -offset indent
382 .Li \ea Tn \(em BEL No (007)
383 .Li \eb Tn \(em BS No (010)
384 .Li \ef Tn \(em NP No (014)
385 .Li \en Tn \(em NL No (012)
386 .Li \er Tn \(em CR No (015)
387 .Li \es Tn \(em SP No (040)
388 .Li \et Tn \(em HT No (011)
389 .Li \ev Tn \(em VT No (013)
390 .Li \e0 Tn \(em NUL No (000)
393 When using this format, the
395 parameter is looked at to determine if a
397 character can be encoded as
403 is an octal digit, the latter representation is used to
406 Use a three digit octal sequence.
411 represents an octal digit.
413 Use URI encoding as described in RFC 1738.
418 represents a lower case hexadecimal digit.
420 Use MIME Quoted-Printable encoding as described in RFC 2045, only don't
421 break lines and don't handle CRLF.
426 represents an upper case hexadecimal digit.
429 There is one additional flag,
432 doubling of backslashes and the backslash before the default
433 format (that is, control characters are represented by
438 With this flag set, the encoding is
439 ambiguous and non-invertible.
440 .Sh MULTIBYTE CHARACTER SUPPORT
441 These functions support multibyte character input.
442 The encoding conversion is influenced by the setting of the
444 environment variable which defines the set of characters
445 that can be copied without encoding.
449 is set, processing is done assuming the C locale and overriding
450 any other environment settings.
452 When 8-bit data is present in the input,
454 must be set to the correct locale or to the C locale.
455 If the locales of the data and the conversion are mismatched,
456 multibyte character recognition may fail and encoding will be performed
457 byte-by-byte instead.
461 must be four times the number of bytes processed from
463 But note that each multibyte character can be up to
467 .\" .Xr multibyte 3 )
468 so in terms of multibyte characters,
472 times the number of characters processed from
475 .Bl -tag -width ".Ev LC_CTYPE"
477 Specify the locale of the input data.
478 Set to C if the input data locale is unknown.
493 will return \-1 when the
495 destination buffer size is not enough to perform the conversion while
499 .Bl -tag -width ".Bq Er ENOSPC"
501 The destination buffer size is not large enough to perform the conversion.
507 .\" .Xr multibyte 3 ,
511 .%T Uniform Resource Locators (URL)
515 .%T "Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies"
524 functions first appeared in
531 functions appeared in
535 The buffer size limited versions of the functions
547 Multibyte character support was added in