1 .\" $NetBSD: unvis.3,v 1.27 2012/12/15 07:34:36 wiz 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
39 .Nd decode a visual representation of characters
45 .Fn unvis "char *cp" "int c" "int *astate" "int flag"
47 .Fn strunvis "char *dst" "const char *src"
49 .Fn strnunvis "char *dst" "size_t dlen" "const char *src"
51 .Fn strunvisx "char *dst" "const char *src" "int flag"
53 .Fn strnunvisx "char *dst" "size_t dlen" "const char *src" "int flag"
61 are used to decode a visual representation of characters, as produced
69 function is called with successive characters in
71 until a valid sequence is recognized, at which time the decoded
72 character is available at the character pointed to by
77 function decodes the characters pointed to by
79 into the buffer pointed to by
83 function simply copies
87 decoding any escape sequences along the way,
88 and returns the number of characters placed into
91 invalid escape sequence was detected.
94 should be equal to the size of
96 (that is, no expansion takes place during decoding).
100 function does the same as the
103 but it allows you to add a flag that specifies the style the string
106 Currently, the supported flags are:
113 function implements a state machine that can be used to decode an
114 arbitrary stream of bytes.
115 All state associated with the bytes being decoded is stored outside the
117 function (that is, a pointer to the state is passed in), so
118 calls decoding different streams can be freely intermixed.
119 To start decoding a stream of bytes, first initialize an integer to zero.
122 with each successive byte, along with a pointer
123 to this integer, and a pointer to a destination character.
126 function has several return codes that must be handled properly.
128 .Bl -tag -width UNVIS_VALIDPUSH
130 Another character is necessary; nothing has been recognized yet.
132 A valid character has been recognized and is available at the location
135 .It Dv UNVIS_VALIDPUSH
136 A valid character has been recognized and is available at the location
139 however, the character currently passed in should be passed in again.
141 A valid sequence was detected, but no character was produced.
142 This return code is necessary to indicate a logical break between characters.
144 An invalid escape sequence was detected, or the decoder is in an unknown state.
145 The decoder is placed into the starting state.
148 When all bytes in the stream have been processed, call
150 one more time with flag set to
152 to extract any remaining character (the character passed in is ignored).
156 argument is also used to specify the encoding style of the source.
162 will decode URI strings as specified in RFC 1808.
166 will decode entity references and numeric character references
167 as specified in RFC 1866.
171 will decode MIME Quoted-Printable strings as specified in RFC 2045.
179 The following code fragment illustrates a proper use of
181 .Bd -literal -offset indent
185 while ((ch = getchar()) != EOF) {
187 switch(unvis(\*[Am]out, ch, \*[Am]state, 0)) {
194 case UNVIS_VALIDPUSH:
198 errx(EXIT_FAILURE, "Bad character sequence!");
201 if (unvis(\*[Am]out, '\e0', \*[Am]state, UNVIS_END) == UNVIS_VALID)
211 will return \-1 on error and set
216 An invalid escape sequence was detected, or the decoder is in an unknown state.
219 In addition the functions
228 Not enough space to perform the conversion.
236 .%T Relative Uniform Resource Locators
249 functions appeared in OS X 10.12.
256 Percent-encoding was defined in RFC 1738, the original RFC for URL.
257 RFC 1866 defines HTML 2.0, an application of SGML, from which it
258 inherits concepts of numeric character references and entity