* 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
[] = "@(#)vis.c 5.2 (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')
* vis - visually encode characters
if (isascii(c
) && isgraph(c
) ||
((flag
& VIS_WHITE
) == 0 &&
(c
== ' ' || c
== '\n' || (flag
& VIS_TAB
) == 0 && c
== '\t')) ||
((flag
& VIS_SAFE
) && (c
== '\b' || c
== '\007' || c
== '\r'))) {
if (c
== '\\' && (flag
& VIS_NOSLASH
) == 0)
if ((flag
& VIS_NOSLASH
) == 0)
case '\007': /* waiting for ansi compiler */
if ((flag
& VIS_NEXTC
) == 0 || isoctal(nextc
)) {
if (((c
& 0177) == ' ') || (flag
& VIS_OCTAL
)) {
*dst
++ = ((u_char
)c
>> 6 & 07) + '0';
*dst
++ = ((u_char
)c
>> 3 & 07) + '0';
*dst
++ = ((u_char
)c
& 07) + '0';
* decode driven by state machine
#define S_NORMAL 1 /* haven't seen escape char */
#define S_START 2 /* start decoding special sequence */
#define S_META 3 /* metachar started (M) */
#define S_META1 4 /* metachar more, regular char (-) */
#define S_CTRL 5 /* control char started (^) */
#define S_OCTAL 6 /* octal number */
static int state
= S_NORMAL
;
} else if (ostate
== S_META1
) {
/* slightly forgiving, if not wrong */
return(ostate
== S_NORMAL
? UNVIS_NOCHAR
: CDEC_SYNBAD
);
} else if (flags
&UNVIS_HAT
&& c
== '^') {
case 's': /* does anyone use this ? */
return(UNVIS_NOCHAR
); /* hidden newline */
buildchar
= (buildchar
<<3) + (c
-'0');
* 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
| VIS_NEXTC
, *(src
+1));