* Copyright (c) 1989 The Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid
[] = "@(#)unvis.c 1.1 (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 */
* 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)
* strvis - visually encode characters from src into dst
* If len >= 0, encodes exactly len chars from src (including NULL's).
* Otherwise, stops before first NULL in src. In all cases, dst is
* Dst must be 4 times the size of src to account for possible
* expansion. The length of dst, not including the trailing NULL,
strvis(dst
, src
, len
, flag
)
register char *dst
, *src
;
dst
= vis(dst
, *src
, flag
, *(src
+1));