1 .\" $NetBSD: unvis.3,v 1.23 2011/03/17 14:06:29 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
134 .It Dv UNVIS_VALIDPUSH
135 A valid character has been recognized and is available at the location
136 pointed to by cp; however, the character currently passed in should
139 A valid sequence was detected, but no character was produced.
140 This return code is necessary to indicate a logical break between characters.
142 An invalid escape sequence was detected, or the decoder is in an unknown state.
143 The decoder is placed into the starting state.
146 When all bytes in the stream have been processed, call
148 one more time with flag set to
150 to extract any remaining character (the character passed in is ignored).
154 argument is also used to specify the encoding style of the source.
160 will decode URI strings as specified in RFC 1808.
164 will decode URI strings as specified in RFC 1866.
168 will decode MIME Quoted-Printable strings as specified in RFC 2045.
172 will not decode \e quoted characters.
174 The following code fragment illustrates a proper use of
176 .Bd -literal -offset indent
180 while ((ch = getchar()) != EOF) {
182 switch(unvis(\*[Am]out, ch, \*[Am]state, 0)) {
189 case UNVIS_VALIDPUSH:
193 errx(EXIT_FAILURE, "Bad character sequence!");
196 if (unvis(\*[Am]out, '\e0', \*[Am]state, UNVIS_END) == UNVIS_VALID)
206 will return \-1 on error and set
211 An invalid escape sequence was detected, or the decoder is in an unknown state.
214 In addition the functions
223 Not enough space to perform the conversion.
231 .%T Relative Uniform Resource Locators
244 functions appeared in