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