* 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.1 (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
#define iswhite(c) ((c)==' '||(c)=='\t'||(c)=='\n')
#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')
cencode(sc
, flags
, rachar
)
if (isgraph(c
) || (!(flags
&CENC_WHITE
) && iswhite(c
))) {
if (!(flags
&CENC_RACHAR
) || isoctal(rachar
)) {
if ((flags
&CENC_GRAPH
) && (c
&0177) != ' ') {
if (flags
&CENC_RACHAR
&& !isoctal(rachar
))
(void)sprintf(s
, "%o", (int)c
);
(void)sprintf(s
, "%03o", (int)c
);
* 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
? CDEC_NOCHAR
: CDEC_SYNBAD
);
} else if (flags
&CDEC_HAT
&& c
== '^') {
case 's': /* does anyone use this ? */
return(CDEC_NOCHAR
); /* hidden newline */
buildchar
= (buildchar
<<3) + (c
-'0');