1 .\" $NetBSD: vis.3,v 1.49 2017/08/05 20:22:29 wiz 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
51 .Nd visually encode characters
57 .Fn vis "char *dst" "int c" "int flag" "int nextc"
59 .Fn nvis "char *dst" "size_t dlen" "int c" "int flag" "int nextc"
61 .Fn strvis "char *dst" "const char *src" "int flag"
63 .Fn stravis "char **dst" "const char *src" "int flag"
65 .Fn strnvis "char *dst" "const char *src" "size_t len" "int flag"
67 .Fn strvisx "char *dst" "const char *src" "size_t len" "int flag"
69 .Fn strnvisx "char *dst" "size_t dlen" "const char *src" "size_t len" "int flag"
71 .Fn strenvisx "char *dst" "size_t dlen" "const char *src" "size_t len" "int flag" "int *cerr_ptr"
73 .Fn svis "char *dst" "int c" "int flag" "int nextc" "const char *extra"
75 .Fn snvis "char *dst" "size_t dlen" "int c" "int flag" "int nextc" "const char *extra"
77 .Fn strsvis "char *dst" "const char *src" "int flag" "const char *extra"
79 .Fn strsnvis "char *dst" "size_t dlen" "const char *src" "int flag" "const char *extra"
81 .Fn strsvisx "char *dst" "const char *src" "size_t len" "int flag" "const char *extra"
83 .Fn strsnvisx "char *dst" "size_t dlen" "const char *src" "size_t len" "int flag" "const char *extra"
85 .Fn strsenvisx "char *dst" "size_t dlen" "const char *src" "size_t len" "int flag" "const char *extra" "int *cerr_ptr"
92 a string which represents the character
96 needs no encoding, it is copied in unaltered.
97 The string is null terminated, and a pointer to the end of the string is
99 The maximum length of any encoding is four
100 bytes (not including the trailing
103 encoding a set of characters into a buffer, the size of the buffer should
104 be four times the number of bytes encoded, plus one for the trailing
108 parameter is used for altering the default range of
109 characters considered for encoding and for altering the visual
111 The additional character,
113 is only used when selecting the
115 encoding format (explained below).
126 a visual representation of
133 functions encode characters from
142 functions encode exactly
147 is useful for encoding a block of data that may contain
155 must be four times the number
156 of bytes encoded from
161 forms return the number of characters in
163 (not including the trailing
167 function allocates space dynamically to hold the string.
170 versions of the functions also take an additional argument
172 that indicates the length of the
177 is not large enough to fit the converted string then the
181 functions return \-1 and set
187 function takes an additional argument,
189 that is used to pass in and out a multibyte conversion error flag.
190 This is useful when processing single characters at a time when
191 it is possible that the locale may be set to something other
192 than the locale of the characters in the input data.
212 but have an additional argument
216 terminated list of characters.
217 These characters will be copied encoded or backslash-escaped into
219 These functions are useful e.g. to remove the special meaning
220 of certain characters to shells.
222 The encoding is a unique, invertible representation composed entirely of
223 graphic characters; it can be decoded back into the original form using
231 There are two parameters that can be controlled: the range of
232 characters that are encoded (applies only to
240 and the type of representation used.
241 By default, all non-graphic characters,
242 except space, tab, and newline are encoded (see
246 .Bl -tag -width ".Dv VIS_HTTPSTYLE"
248 Encode all characters, whether visible or not.
250 Also encode double quotes.
252 Also encode the magic characters
261 Also encode the meta characters used by shells (in addition to the glob
288 .Dv VIS_SP | VIS_TAB | VIS_NL .
291 .Dv VIS_WHITE | VIS_GLOB | VIS_SHELL .
296 Unsafe means control characters which may cause common terminals to perform
297 unexpected functions.
298 Currently this form allows space, tab, newline, backspace, bell, and
299 return \(em in addition to all graphic characters \(em unencoded.
302 (The above flags have no effect for
310 When using these functions, place all graphic characters to be
311 encoded in an array pointed to by
313 In general, the backslash character should be included in this array, see the
314 warning on the use of the
318 There are six forms of encoding.
319 All forms use the backslash character
321 to introduce a special
322 sequence; two backslashes are used to represent a real backslash,
331 These are the visual formats:
332 .Bl -tag -width ".Dv VIS_HTTPSTYLE"
336 to represent meta characters (characters with the 8th
337 bit set), and use caret
339 to represent control characters (see
341 The following formats are used:
342 .Bl -tag -width xxxxx
344 Represents the control character
357 with the 8th bit set.
363 Represents control character
365 with the 8th bit set.
379 Represents Meta-space.
382 Use C-style backslash sequences to represent standard non-printable
384 The following sequences are used to represent the indicated characters:
386 .Bl -tag -width ".Li \e0" -offset indent -compact
405 When using this format, the
407 parameter is looked at to determine if a
409 character can be encoded as
415 is an octal digit, the latter representation is used to
418 Non-printable characters without C-style
419 backslash sequences use the default representation.
421 Use a three digit octal sequence.
426 represents an octal digit.
427 .It Dv VIS_CSTYLE \&| Dv VIS_OCTAL
430 except that non-printable characters without C-style
431 backslash sequences use a three digit octal sequence.
433 Use URI encoding as described in RFC 1738.
438 represents a lower case hexadecimal digit.
440 Use MIME Quoted-Printable encoding as described in RFC 2045, only don't
441 break lines and don't handle CRLF.
446 represents an upper case hexadecimal digit.
449 There is one additional flag,
452 doubling of backslashes and the backslash before the default
453 format (that is, control characters are represented by
458 With this flag set, the encoding is
459 ambiguous and non-invertible.
460 .Sh MULTIBYTE CHARACTER SUPPORT
461 These functions support multibyte character input.
462 The encoding conversion is influenced by the setting of the
464 environment variable which defines the set of characters
465 that can be copied without encoding.
469 is set, processing is done assuming the C locale and overriding
470 any other environment settings.
472 When 8-bit data is present in the input,
474 must be set to the correct locale or to the C locale.
475 If the locales of the data and the conversion are mismatched,
476 multibyte character recognition may fail and encoding will be performed
477 byte-by-byte instead.
481 must be four times the number of bytes processed from
483 But note that each multibyte character can be up to
487 .\" .Xr multibyte 3 )
488 so in terms of multibyte characters,
492 times the number of characters processed from
495 .Bl -tag -width ".Ev LC_CTYPE"
497 Specify the locale of the input data.
498 Set to C if the input data locale is unknown.
513 will return \-1 when the
515 destination buffer size is not enough to perform the conversion while
519 .Bl -tag -width ".Bq Er ENOSPC"
521 The destination buffer size is not large enough to perform the conversion.
527 .\" .Xr multibyte 3 ,
531 .%T Uniform Resource Locators (URL)
535 .%T "Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies"
544 functions first appeared in
551 functions appeared in
553 The buffer size limited versions of the functions
565 Multibyte character support was added in
571 flag first appeared in