xref: /csrg-svn/lib/libc/gen/vis.3 (revision 48352)
1*48352Scael.\" Copyright (c) 1989, 1991 The Regents of the University of California.
239288Smarc.\" All rights reserved.
339288Smarc.\"
443571Strent.\" %sccs.include.redist.man%
539288Smarc.\"
6*48352Scael.\"     @(#)vis.3	5.7 (Berkeley) 04/19/91
739288Smarc.\"
8*48352Scael.Dd
9*48352Scael.Dt VIS 3
10*48352Scael.Os
11*48352Scael.Sh NAME
12*48352Scael.Nm vis
13*48352Scael.Nd visually encode characters
14*48352Scael.Sh SYNOPSIS
15*48352Scael.Fd #include <vis.h>
16*48352Scael.Ft char *
17*48352Scael.Fn vis "char *dst" "char c" "int flag" "char nextc"
18*48352Scael.Ft int
19*48352Scael.Fn strvis "char *dst" "char *src" "int flag"
20*48352Scael.Ft int
21*48352Scael.Fn strvisx "char *dst" "char *src" "int len" "int flag"
22*48352Scael.Sh DESCRIPTION
23*48352ScaelThe
24*48352Scael.Fn vis
25*48352Scaelfunction
26*48352Scaelcopies into
27*48352Scael.Fa dst
28*48352Scaela string which represents the character
29*48352Scael.Fa c .
30*48352ScaelIf
31*48352Scael.Fa c
32*48352Scaelneeds no encoding, it is copied in unaltered.  The string is
3342139Smarcnull terminated, and a pointer to the end of the string is
3442438Smarcreturned.  The maximum length of any encoding is four
35*48352Scaelcharacters (not including the trailing
36*48352Scael.Dv NULL ) ;
37*48352Scaelthus, when
3842139Smarcencoding a set of characters into a buffer, the size of the buffer should
39*48352Scaelbe four times the number of characters encoded, plus one for the trailing
40*48352Scael.Dv NULL .
4142139SmarcThe flag parameter is used for altering the default range of
4242139Smarccharacters considered for encoding and for altering the visual
4342139Smarcrepresentation.
44*48352ScaelThe additional character,
45*48352Scael.Fa nextc ,
46*48352Scaelis only used when selecting the
47*48352Scael.Dv VIS_CSTYLE
48*48352Scaelencoding format (explained below).
49*48352Scael.Pp
50*48352ScaelThe
51*48352Scael.Fn strvis
52*48352Scaeland
53*48352Scael.Fn strvisx
54*48352Scaelfunctions copy into
55*48352Scael.Fa dst
56*48352Scaela visual representation of
57*48352Scaelthe string
58*48352Scael.Fa src .
59*48352ScaelThe
60*48352Scael.Fn strvis
61*48352Scaelfunction encodes characters from
62*48352Scael.Fa src
63*48352Scaelup to the
64*48352Scaelfirst
65*48352Scael.Dv NULL .
66*48352ScaelThe
67*48352Scael.Fn strvisx
68*48352Scaelfunction encodes exactly
69*48352Scael.Fa len
70*48352Scaelcharacters from
71*48352Scael.Fa src
72*48352Scael(this
73*48352Scaelis useful for encoding a block of data that may contain
74*48352Scael.Dv NULL Ns 's).
75*48352ScaelBoth forms
76*48352Scael.Dv NULL
77*48352Scaelterminate
78*48352Scael.Fa dst .
79*48352ScaelThe size of
80*48352Scael.Fa dst
81*48352Scaelmust be four times the number
82*48352Scaelof characters encoded from
83*48352Scael.Fa src
84*48352Scael(plus one for the
85*48352Scael.Dv NULL ) .
86*48352ScaelBoth
8742139Smarcforms return the number of characters in dst (not including
88*48352Scaelthe trailing
89*48352Scael.Dv NULL ) .
90*48352Scael.Pp
9142139SmarcThe encoding is a unique, invertible representation comprised entirely of
9242139Smarcgraphic characters; it can be decoded back into the original form using
93*48352Scaelthe
94*48352Scael.Xr unvis 3
95*48352Scaelor
96*48352Scael.Xr strunvis 3
97*48352Scaelfunctions.
98*48352Scael.Pp
9942139SmarcThere are two parameters that can be controlled: the range of
10042139Smarccharacters that are encoded, and the type
10142139Smarcof representation used.
102*48352ScaelBy default, all non-graphic characters.
103*48352Scaelexcept space, tab, and newline are encoded.
104*48352Scael(See
105*48352Scael.Xr isgraph 3 . )
106*48352ScaelThe following flags
10742139Smarcalter this:
108*48352Scael.Bl -tag -width VIS_WHITEX
109*48352Scael.It Dv VIS_SP
11042139SmarcAlso encode space.
111*48352Scael.It Dv VIS_TAB
11242139SmarcAlso encode tab.
113*48352Scael.It Dv VIS_NL
11442139SmarcAlso encode newline.
115*48352Scael.It Dv VIS_WHITE
116*48352ScaelSynonym for
117*48352Scael.Dv VIS_SP
118*48352Scael\&|
119*48352Scael.Dv VIS_TAB
120*48352Scael\&|
121*48352Scael.Dv VIS_NL .
122*48352Scael.It Dv VIS_SAFE
12342139SmarcOnly encode "unsafe" characters.  Unsafe means control
12442139Smarccharacters which may cause common terminals to perform
12542139Smarcunexpected functions.  Currently this form allows space,
12642139Smarctab, newline, backspace, bell, and return - in addition
12742139Smarcto all graphic characters - unencoded.
128*48352Scael.El
129*48352Scael.Pp
13042438SmarcThere are three forms of encoding.
131*48352ScaelAll forms use the backslash character
132*48352Scael.Ql \e
133*48352Scaelto introduce a special
13441758Smarcsequence; two backslashes are used to represent a real backslash.
13542139SmarcThese are the visual formats:
136*48352Scael.Bl -tag -width VIS_CSTYLE
137*48352Scael.It (default)
138*48352ScaelUse an
139*48352Scael.Ql M
140*48352Scaelto represent meta characters (characters with the 8th
141*48352Scaelbit set), and use carat
142*48352Scael.Ql ^
143*48352Scaelto represent control characters see
144*48352Scael.Pf ( Xr iscntrl 3 ) .
14542139SmarcThe following formats are used:
146*48352Scael.Bl -tag -width xxxxx
147*48352Scael.It Dv \e^C
148*48352ScaelRepresents the control character
149*48352Scael.Ql C .
150*48352ScaelSpans characters
151*48352Scael.Ql \e000
152*48352Scaelthrough
153*48352Scael.Ql \e037 ,
154*48352Scaeland
155*48352Scael.Ql \e177
156*48352Scael(as
157*48352Scael.Ql \e^? ) .
158*48352Scael.It Dv \eM-C
159*48352ScaelRepresents character
160*48352Scael.Ql C
161*48352Scaelwith the 8th bit set.
162*48352ScaelSpans characters
163*48352Scael.Ql \e241
164*48352Scaelthrough
165*48352Scael.Ql \e376 .
166*48352Scael.It Dv \eM^C
167*48352ScaelRepresents control character
168*48352Scael.Ql C
169*48352Scaelwith the 8th bit set.
170*48352ScaelSpans characters
171*48352Scael.Ql \e200
172*48352Scaelthrough
173*48352Scael.Ql \e237 ,
174*48352Scaeland
175*48352Scael.Ql \e377
176*48352Scael(as
177*48352Scael.Ql \eM^? ) .
178*48352Scael.It Dv \e040
179*48352ScaelRepresents
180*48352Scael.Tn ASCII
181*48352Scaelspace.
182*48352Scael.It Dv \e240
18342139SmarcRepresents Meta-space.
184*48352Scael.El
185*48352Scael.Pp
186*48352Scael.It Dv VIS_CSTYLE
18741758SmarcUse C-style backslash sequences to represent standard non-printable
18841758Smarccharacters.
18941758SmarcThe following sequences are used to represent the indicated characters:
190*48352Scael.Bd -unfilled -offset indent
191*48352Scael.Li \ea Tn  - BEL No (007)
192*48352Scael.Li \eb Tn  - BS No (010)
193*48352Scael.Li \ef Tn  - NP No (014)
194*48352Scael.Li \en Tn  - NL No (012)
195*48352Scael.Li \er Tn  - CR No (015)
196*48352Scael.Li \et Tn  - HT No (011)
197*48352Scael.Li \ev Tn  - VT No (013)
198*48352Scael.Li \e0 Tn  - NUL No (000)
199*48352Scael.Ed
200*48352Scael.Pp
20142139SmarcWhen using this format, the nextc parameter is looked at to determine
202*48352Scaelif a
203*48352Scael.Dv NULL
204*48352Scaelcharacter can be encoded as
205*48352Scael.Ql \e0
206*48352Scaelinstead of
207*48352Scael.Ql \e000 .
208*48352ScaelIf
209*48352Scael.Fa nextc
210*48352Scaelis an octal digit, the latter representation is used to
21142139Smarcavoid ambiguity.
212*48352Scael.It Dv VIS_OCTAL
213*48352ScaelUse a three digit octal sequence.  The form is
214*48352Scael.Ql \eddd
215*48352Scaelwhere
216*48352Scael.Em d
217*48352Scaelrepresents an octal digit.
218*48352Scael.El
219*48352Scael.Pp
220*48352ScaelThere is one additional flag,
221*48352Scael.Dv VIS_NOSLASH ,
222*48352Scaelwhich inhibits the
22342139Smarcdoubling of backslashes and the backslash before the default
224*48352Scaelformat (that is, control characters are represented by
225*48352Scael.Ql ^C
226*48352Scaeland
227*48352Scaelmeta characters as
228*48352Scael.Ql M-C ) .
229*48352ScaelWith this flag set, the encoding is
23042139Smarcambiguous and non-invertible.
231*48352Scael.Sh SEE ALSO
232*48352Scael.Xr unvis 1 ,
233*48352Scael.Xr unvis 3
234*48352Scael.Xr strunvis 3
235*48352Scael.Sh HISTORY
236*48352ScaelThese
237*48352Scaelfunctions are
238*48352Scael.Ud .
239