1 .\" $NetBSD: unvis.3,v 1.29 2017/10/24 19:14:55 abhinav Exp $
4 .\" Copyright (c) 1989, 1991, 1993
5 .\" The Regents of the University of California. All rights reserved.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\" notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice, this list of conditions and the following disclaimer in the
14 .\" documentation and/or other materials provided with the distribution.
15 .\" 3. Neither the name of the University nor the names of its contributors
16 .\" may be used to endorse or promote products derived from this software
17 .\" without specific prior written permission.
19 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 .\" @(#)unvis.3 8.2 (Berkeley) 12/11/93
42 .Nd decode a visual representation of characters
48 .Fn unvis "char *cp" "int c" "int *astate" "int flag"
50 .Fn strunvis "char *dst" "const char *src"
52 .Fn strnunvis "char *dst" "size_t dlen" "const char *src"
54 .Fn strunvisx "char *dst" "const char *src" "int flag"
56 .Fn strnunvisx "char *dst" "size_t dlen" "const char *src" "int flag"
64 are used to decode a visual representation of characters, as produced
72 function is called with successive characters in
74 until a valid sequence is recognized, at which time the decoded
75 character is available at the character pointed to by
80 function decodes the characters pointed to by
82 into the buffer pointed to by
86 function simply copies
90 decoding any escape sequences along the way,
91 and returns the number of characters placed into
94 invalid escape sequence was detected.
97 should be equal to the size of
99 (that is, no expansion takes place during decoding).
103 function does the same as the
106 but it allows you to add a flag that specifies the style the string
109 Currently, the supported flags are:
116 function implements a state machine that can be used to decode an
117 arbitrary stream of bytes.
118 All state associated with the bytes being decoded is stored outside the
120 function (that is, a pointer to the state is passed in), so
121 calls decoding different streams can be freely intermixed.
122 To start decoding a stream of bytes, first initialize an integer to zero.
125 with each successive byte, along with a pointer
126 to this integer, and a pointer to a destination character.
129 function has several return codes that must be handled properly.
131 .Bl -tag -width UNVIS_VALIDPUSH
133 Another character is necessary; nothing has been recognized yet.
135 A valid character has been recognized and is available at the location
138 .It Dv UNVIS_VALIDPUSH
139 A valid character has been recognized and is available at the location
142 however, the character currently passed in should be passed in again.
144 A valid sequence was detected, but no character was produced.
145 This return code is necessary to indicate a logical break between characters.
147 An invalid escape sequence was detected, or the decoder is in an unknown state.
148 The decoder is placed into the starting state.
151 When all bytes in the stream have been processed, call
153 one more time with flag set to
155 to extract any remaining character (the character passed in is ignored).
159 argument is also used to specify the encoding style of the source.
165 will decode URI strings as specified in RFC 1808.
169 will decode entity references and numeric character references
170 as specified in RFC 1866.
174 will decode MIME Quoted-Printable strings as specified in RFC 2045.
182 The following code fragment illustrates a proper use of
184 .Bd -literal -offset indent
188 while ((ch = getchar()) != EOF) {
190 switch(unvis(&out, ch, &state, 0)) {
197 case UNVIS_VALIDPUSH:
201 errx(EXIT_FAILURE, "Bad character sequence!");
204 if (unvis(&out, '\e0', &state, UNVIS_END) == UNVIS_VALID)
214 will return \-1 on error and set
219 An invalid escape sequence was detected, or the decoder is in an unknown state.
222 In addition the functions
231 Not enough space to perform the conversion.
239 .%T Relative Uniform Resource Locators
252 functions appeared in
262 Percent-encoding was defined in RFC 1738, the original RFC for URL.
263 RFC 1866 defines HTML 2.0, an application of SGML, from which it
264 inherits concepts of numeric character references and entity