4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
40 #pragma ident "%Z%%M% %I% %E% SMI"
44 #include <sys/types.h>
48 * Convert a character, making appropriate changes to make it printable
49 * for a terminfo source entry. Change escape to \E, tab to \t, backspace
50 * to \b, formfeed to \f, newline to \n, and return to \r. Change other
51 * control characters into ^X notation. Change meta characters into octal
52 * (\nnn) notation. Also place a backslash in front of commas,
53 * carets(^), and backslashes(\). Return the number of characters printed.
56 #define BACKSLASH '\\'
57 #define BACKBACK "\\\\"
59 static char retbuffer
[1024];
62 * Expand a string taking terminfo sequences into consideration.
65 *iexpand(char *string
)
68 char *retptr
= retbuffer
;
71 while ((c
= *string
++) != 0) {
72 /* should check here to make sure that there is enough room */
73 /* in retbuffer and realloc it if necessary. */
75 /* we ignore the return value from sprintf because BSD/V7 */
76 /* systems return a (char *) rather than an int. */
78 (void) sprintf(retptr
, "\\%.3o", c
); retptr
+= 4; }
79 else if (c
== '\033') {
80 (void) sprintf(retptr
, "\\E"); retptr
+= 2; }
82 (void) sprintf(retptr
, "\\t"); retptr
+= 2; }
84 (void) sprintf(retptr
, "\\b"); retptr
+= 2; }
86 (void) sprintf(retptr
, "\\f"); retptr
+= 2; }
88 (void) sprintf(retptr
, "\\n"); retptr
+= 2; }
90 (void) sprintf(retptr
, "\\r"); retptr
+= 2; }
92 (void) sprintf(retptr
, "\\,"); retptr
+= 2; }
94 (void) sprintf(retptr
, "\\^"); retptr
+= 2; }
95 else if (c
== BACKSLASH
) {
96 (void) sprintf(retptr
, BACKBACK
); retptr
+= 2; }
98 (void) sprintf(retptr
, "\\s"); retptr
+= 2; }
99 else if (c
< ' ' || c
== 0177) {
100 (void) sprintf(retptr
, "^%c", c
^ 0100); retptr
+= 2; }
102 (void) sprintf(retptr
, "%c", c
); retptr
++; }
109 * Print out a string onto a stream, changing unprintables into
110 * terminfo printables.
113 tpr(FILE *stream
, char *string
)
116 (void) fprintf(stream
, "%s", iexpand(string
));