xref: /illumos-gate/usr/src/lib/libnsl/dial/strecpy.c (revision 7c478bd9)
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 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 #ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.1	*/
27 
28 #include	"uucp.h"
29 #include <rpc/trace.h>
30 
31 /*
32 	strecpy(output, input, except)
33 	strccpy copys the input string to the output string expanding
34 	any non-graphic character with the C escape sequence.
35 	Esacpe sequences produced are those defined in "The C Programming
36 	Language" pages 180-181.
37 	Characters in the except string will not be expanded.
38 */
39 
40 GLOBAL char *
41 strecpy(pout, pin, except)
42 register char	*pout;
43 register char	*pin;
44 char	*except;
45 {
46 	register unsigned	c;
47 	register char		*output;
48 
49 	trace1(TR_strecpy, 0);
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 	trace1(TR_strecpy, 1);
87 	return  (output);
88 }
89