]> git.saurik.com Git - apple/libc.git/blame - gen/vis.3
Libc-262.3.2.tar.gz
[apple/libc.git] / gen / 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
33.\" $FreeBSD: src/lib/libc/gen/vis.3,v 1.18 2001/10/01 16:08:51 ru Exp $
34.\"
35.Dd July 25, 1996
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
61needs no encoding, it is copied in unaltered. The string is
62null terminated, and a pointer to the end of the string is
63returned. The maximum length of any encoding is four
64characters (not including the trailing
65.Dv NUL ) ;
66thus, when
67encoding a set of characters into a buffer, the size of the buffer should
68be four times the number of characters encoded, plus one for the trailing
69.Dv NUL .
70The flag parameter is used for altering the default range of
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
138.It Dv VIS_SP
139Also encode space.
140.It Dv VIS_TAB
141Also encode tab.
142.It Dv VIS_NL
143Also encode newline.
144.It Dv VIS_WHITE
145Synonym for
146.Dv VIS_SP
147\&|
148.Dv VIS_TAB
149\&|
150.Dv VIS_NL .
151.It Dv VIS_SAFE
152Only encode "unsafe" characters. Unsafe means control
153characters which may cause common terminals to perform
154unexpected functions. Currently this form allows space,
155tab, newline, backspace, bell, and return - in addition
156to all graphic characters - unencoded.
157.El
158.Pp
159There are four forms of encoding.
160Most forms use the backslash character
161.Ql \e
162to introduce a special
163sequence; two backslashes are used to represent a real backslash.
164These are the visual formats:
165.Bl -tag -width VIS_HTTPSTYLE
166.It (default)
167Use an
168.Ql M
169to represent meta characters (characters with the 8th
170bit set), and use carat
171.Ql ^
172to represent control characters see
173.Pf ( Xr iscntrl 3 ) .
174The following formats are used:
175.Bl -tag -width xxxxx
176.It Dv \e^C
177Represents the control character
178.Ql C .
179Spans characters
180.Ql \e000
181through
182.Ql \e037 ,
183and
184.Ql \e177
185(as
186.Ql \e^? ) .
187.It Dv \eM-C
188Represents character
189.Ql C
190with the 8th bit set.
191Spans characters
192.Ql \e241
193through
194.Ql \e376 .
195.It Dv \eM^C
196Represents control character
197.Ql C
198with the 8th bit set.
199Spans characters
200.Ql \e200
201through
202.Ql \e237 ,
203and
204.Ql \e377
205(as
206.Ql \eM^? ) .
207.It Dv \e040
208Represents
209.Tn ASCII
210space.
211.It Dv \e240
212Represents Meta-space.
213.El
214.Pp
215.It Dv VIS_CSTYLE
216Use C-style backslash sequences to represent standard non-printable
217characters.
218The following sequences are used to represent the indicated characters:
219.Bd -unfilled -offset indent
220.Li \ea Tn - BEL No (007)
221.Li \eb Tn - BS No (010)
222.Li \ef Tn - NP No (014)
223.Li \en Tn - NL No (012)
224.Li \er Tn - CR No (015)
225.Li \et Tn - HT No (011)
226.Li \ev Tn - VT No (013)
227.Li \e0 Tn - NUL No (000)
228.Ed
229.Pp
230When using this format, the nextc parameter is looked at to determine
231if a
232.Dv NUL
233character can be encoded as
234.Ql \e0
235instead of
236.Ql \e000 .
237If
238.Fa nextc
239is an octal digit, the latter representation is used to
240avoid ambiguity.
241.It Dv VIS_HTTPSTYLE
242Use URI encoding as described in RFC 1808.
243The form is
244.Ql %dd
245where
246.Em d
247represents a hexadecimal digit.
248.It Dv VIS_OCTAL
249Use a three digit octal sequence. The form is
250.Ql \eddd
251where
252.Em d
253represents an octal digit.
254.El
255.Pp
256There is one additional flag,
257.Dv VIS_NOSLASH ,
258which inhibits the
259doubling of backslashes and the backslash before the default
260format (that is, control characters are represented by
261.Ql ^C
262and
263meta characters as
264.Ql M-C ) .
265With this flag set, the encoding is
266ambiguous and non-invertible.
267.Sh SEE ALSO
268.Xr unvis 1 ,
269.Xr unvis 3
270.Rs
271.%A R. Fielding
272.%T Relative Uniform Resource Locators
273.%O RFC1808
274.Re
275.Sh HISTORY
276These functions first appeared in
277.Bx 4.4 .