1 /*
2 * CDDL HEADER START
3 *
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
7 * with the License.
8 *
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.
13 *
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]
19 *
20 * CDDL HEADER END
21 */
22
23 /*
24 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
26 */
27
28 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
29 /* All Rights Reserved */
30
31 #include "mt.h"
32 #include "uucp.h"
33
34 #ifndef SMALL
35 /*
36 * strecpy(output, input, except)
37 * strccpy copys the input string to the output string expanding
38 * any non-graphic character with the C escape sequence.
39 * Escape sequences produced are those defined in "The C Programming
40 * Language" pages 180-181.
41 * Characters in the except string will not be expanded.
42 */
43
44 static char *
strecpy(char * pout,char * pin,char * except)45 strecpy(char *pout, char *pin, char *except)
46 {
47 unsigned c;
48 char *output;
49
50 output = pout;
51 while ((c = *pin++) != 0) {
52 if (!isprint(c) && (!except || !strchr(except, c))) {
53 *pout++ = '\\';
54 switch (c) {
55 case '\n':
56 *pout++ = 'n';
57 continue;
58 case '\t':
59 *pout++ = 't';
60 continue;
61 case '\b':
62 *pout++ = 'b';
63 continue;
64 case '\r':
65 *pout++ = 'r';
66 continue;
67 case '\f':
68 *pout++ = 'f';
69 continue;
70 case '\v':
71 *pout++ = 'v';
72 continue;
73 case '\\':
74 continue;
75 default:
76 sprintf(pout, "%.3o", c);
77 pout += 3;
78 continue;
79 }
80 }
81 if (c == '\\' && (!except || !strchr(except, c)))
82 *pout++ = '\\';
83 *pout++ = (char)c;
84 }
85 *pout = '\0';
86 return (output);
87 }
88 #endif
89