]> git.saurik.com Git - apple/libc.git/blame - gen/FreeBSD/vis.3
Libc-1082.50.1.tar.gz
[apple/libc.git] / gen / FreeBSD / vis.3
CommitLineData
5b2abdfb
A
1.\" Copyright (c) 1989, 1991, 1993
2.\" The Regents of the University of California. All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\" notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\" notice, this list of conditions and the following disclaimer in the
11.\" documentation and/or other materials provided with the distribution.
5b2abdfb
A
12.\" 4. Neither the name of the University nor the names of its contributors
13.\" may be used to endorse or promote products derived from this software
14.\" without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.\" From: @(#)vis.3 8.1 (Berkeley) 6/9/93
1f2f436a 29.\" $FreeBSD: src/lib/libc/gen/vis.3,v 1.30 2007/01/09 00:27:56 imp Exp $
5b2abdfb 30.\"
1f2f436a 31.Dd April 9, 2006
5b2abdfb
A
32.Dt VIS 3
33.Os
34.Sh NAME
35.Nm vis
36.Nd visually encode characters
37.Sh LIBRARY
38.Lb libc
39.Sh SYNOPSIS
40.In vis.h
41.Ft char *
42.Fn vis "char *dst" "int c" "int flag" "int nextc"
43.Ft int
44.Fn strvis "char *dst" "const char *src" "int flag"
45.Ft int
46.Fn strvisx "char *dst" "const char *src" "size_t len" "int flag"
47.Sh DESCRIPTION
48The
49.Fn vis
50function
51copies into
52.Fa dst
53a string which represents the character
54.Fa c .
55If
56.Fa c
3d9156a7
A
57needs no encoding, it is copied in unaltered.
58The string is
5b2abdfb 59null terminated, and a pointer to the end of the string is
3d9156a7
A
60returned.
61The maximum length of any encoding is four
5b2abdfb
A
62characters (not including the trailing
63.Dv NUL ) ;
64thus, when
65encoding a set of characters into a buffer, the size of the buffer should
66be four times the number of characters encoded, plus one for the trailing
67.Dv NUL .
9385eb3d
A
68The
69.Fa flag
70argument is used for altering the default range of
5b2abdfb
A
71characters considered for encoding and for altering the visual
72representation.
73The additional character,
74.Fa nextc ,
75is only used when selecting the
76.Dv VIS_CSTYLE
77encoding format (explained below).
78.Pp
79The
80.Fn strvis
81and
82.Fn strvisx
83functions copy into
84.Fa dst
85a visual representation of
86the string
87.Fa src .
88The
89.Fn strvis
90function encodes characters from
91.Fa src
92up to the
93first
94.Dv NUL .
95The
96.Fn strvisx
97function encodes exactly
98.Fa len
99characters from
100.Fa src
101(this
102is useful for encoding a block of data that may contain
103.Dv NUL Ns 's ) .
104Both forms
105.Dv NUL
106terminate
107.Fa dst .
108The size of
109.Fa dst
110must be four times the number
111of characters encoded from
112.Fa src
113(plus one for the
114.Dv NUL ) .
115Both
116forms return the number of characters in dst (not including
117the trailing
118.Dv NUL ) .
119.Pp
120The encoding is a unique, invertible representation composed entirely of
121graphic characters; it can be decoded back into the original form using
122the
123.Xr unvis 3
124or
125.Xr strunvis 3
126functions.
127.Pp
128There are two parameters that can be controlled: the range of
129characters that are encoded, and the type
130of representation used.
131By default, all non-graphic characters
132except space, tab, and newline are encoded.
133(See
134.Xr isgraph 3 . )
135The following flags
136alter this:
137.Bl -tag -width VIS_WHITEX
3d9156a7
A
138.It Dv VIS_GLOB
139Also encode magic characters
140.Ql ( * ,
141.Ql \&? ,
142.Ql \&[
143and
144.Ql # )
145recognized by
146.Xr glob 3 .
5b2abdfb
A
147.It Dv VIS_SP
148Also encode space.
149.It Dv VIS_TAB
150Also encode tab.
151.It Dv VIS_NL
152Also encode newline.
153.It Dv VIS_WHITE
154Synonym for
155.Dv VIS_SP
156\&|
157.Dv VIS_TAB
158\&|
159.Dv VIS_NL .
160.It Dv VIS_SAFE
3d9156a7
A
161Only encode "unsafe" characters.
162Unsafe means control
5b2abdfb 163characters which may cause common terminals to perform
3d9156a7
A
164unexpected functions.
165Currently this form allows space,
5b2abdfb
A
166tab, newline, backspace, bell, and return - in addition
167to all graphic characters - unencoded.
168.El
169.Pp
170There are four forms of encoding.
171Most forms use the backslash character
172.Ql \e
173to introduce a special
174sequence; two backslashes are used to represent a real backslash.
175These are the visual formats:
176.Bl -tag -width VIS_HTTPSTYLE
177.It (default)
178Use an
179.Ql M
180to represent meta characters (characters with the 8th
3d9156a7 181bit set), and use caret
5b2abdfb
A
182.Ql ^
183to represent control characters see
184.Pf ( Xr iscntrl 3 ) .
185The following formats are used:
186.Bl -tag -width xxxxx
187.It Dv \e^C
188Represents the control character
189.Ql C .
190Spans characters
191.Ql \e000
192through
193.Ql \e037 ,
194and
195.Ql \e177
196(as
197.Ql \e^? ) .
198.It Dv \eM-C
199Represents character
200.Ql C
201with the 8th bit set.
202Spans characters
203.Ql \e241
204through
205.Ql \e376 .
206.It Dv \eM^C
207Represents control character
208.Ql C
209with the 8th bit set.
210Spans characters
211.Ql \e200
212through
213.Ql \e237 ,
214and
215.Ql \e377
216(as
217.Ql \eM^? ) .
218.It Dv \e040
219Represents
220.Tn ASCII
221space.
222.It Dv \e240
223Represents Meta-space.
224.El
225.Pp
226.It Dv VIS_CSTYLE
227Use C-style backslash sequences to represent standard non-printable
228characters.
229The following sequences are used to represent the indicated characters:
1f2f436a
A
230.Pp
231.Bl -tag -width ".Li \e0" -offset indent -compact
232.It Li \ea
233.Dv BEL No (007)
234.It Li \eb
235.Dv BS No (010)
236.It Li \ef
237.Dv NP No (014)
238.It Li \en
239.Dv NL No (012)
240.It Li \er
241.Dv CR No (015)
242.It Li \es
243.Dv SP No (040)
244.It Li \et
245.Dv HT No (011)
246.It Li \ev
247.Dv VT No (013)
248.It Li \e0
249.Dv NUL No (000)
250.El
5b2abdfb 251.Pp
9385eb3d
A
252When using this format, the
253.Fa nextc
254argument is looked at to determine
5b2abdfb
A
255if a
256.Dv NUL
257character can be encoded as
258.Ql \e0
259instead of
260.Ql \e000 .
261If
262.Fa nextc
263is an octal digit, the latter representation is used to
264avoid ambiguity.
265.It Dv VIS_HTTPSTYLE
266Use URI encoding as described in RFC 1808.
267The form is
268.Ql %dd
269where
9385eb3d 270.Ar d
5b2abdfb
A
271represents a hexadecimal digit.
272.It Dv VIS_OCTAL
3d9156a7
A
273Use a three digit octal sequence.
274The form is
5b2abdfb
A
275.Ql \eddd
276where
9385eb3d 277.Ar d
5b2abdfb
A
278represents an octal digit.
279.El
280.Pp
281There is one additional flag,
282.Dv VIS_NOSLASH ,
283which inhibits the
284doubling of backslashes and the backslash before the default
285format (that is, control characters are represented by
286.Ql ^C
287and
288meta characters as
289.Ql M-C ) .
290With this flag set, the encoding is
291ambiguous and non-invertible.
292.Sh SEE ALSO
293.Xr unvis 1 ,
294.Xr unvis 3
295.Rs
296.%A R. Fielding
297.%T Relative Uniform Resource Locators
298.%O RFC1808
299.Re
300.Sh HISTORY
301These functions first appeared in
302.Bx 4.4 .
3d9156a7
A
303.Sh BUGS
304The
305.Nm
306family of functions do not recognize multibyte characters, and thus
307may consider them to be non-printable when they are in fact printable
308(and vice versa.)