* Copyright (c) 1989 The Regents of the University of California.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid
[] = "@(#)unvis.c 1.4 (Berkeley) 2/23/91";
#endif /* LIBC_SCCS and not lint */
* decode driven by state machine
#define S_GROUND 0 /* haven't seen escape char */
#define S_START 1 /* start decoding special sequence */
#define S_META 2 /* metachar started (M) */
#define S_META1 3 /* metachar more, regular char (-) */
#define S_CTRL 4 /* control char started (^) */
#define S_OCTAL2 5 /* octal digit 2 */
#define S_OCTAL3 6 /* octal digit 3 */
#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')
* unvis - decode characters previously encoded by vis
unvis(char *cp
, char c
, int *astate
, int flag
)
unvis(cp
, c
, astate
, flag
)
if (*astate
== S_OCTAL2
|| *astate
== S_OCTAL3
) {
return (*astate
== S_GROUND
? UNVIS_NOCHAR
: UNVIS_SYNBAD
);
case '0': case '1': case '2': case '3':
case '4': case '5': case '6': case '7':
case S_OCTAL2
: /* second possible octal digit */
* yes - and maybe a third
*cp
= (*cp
<< 3) + (c
- '0');
* no - done with current sequence, push back passed char
return (UNVIS_VALIDPUSH
);
case S_OCTAL3
: /* third possible octal digit */
*cp
= (*cp
<< 3) + (c
- '0');
* we were done, push back passed char
return (UNVIS_VALIDPUSH
);
* decoder in unknown state - (probably uninitialized)
* strunvis - decode src into dst
* Number of chars decoded into dst is returned, -1 on error.
* Dst is null terminated.
register const char *src
;
switch (unvis(dst
, c
, &state
, 0)) {
if (unvis(dst
, c
, &state
, UNVIS_END
) == UNVIS_VALID
)