* Copyright (c) 1989 The Regents of the University of California.
* %sccs.include.redist.c%
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid
[] = "@(#)unvis.c 1.3 (Berkeley) %G%";
#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(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 char *dst
, *src
;
switch (unvis(dst
, c
, &state
, 0)) {
if (unvis(dst
, c
, &state
, UNVIS_END
) == UNVIS_VALID
)