xref: /titanic_50/usr/src/cmd/sh/string.c (revision 275c9da86e89f8abf71135cf63d9fc23671b2e60)
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 1995 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 
32 #pragma ident	"%Z%%M%	%I%	%E% SMI"
33 /*
34  * UNIX shell
35  */
36 
37 #include	"defs.h"
38 
39 
40 /* ========	general purpose string handling ======== */
41 
42 
43 unsigned char *
44 movstr(unsigned char *a, unsigned char *b)
45 {
46 	while (*b++ = *a++);
47 	return(--b);
48 }
49 
50 int
51 any(wchar_t c, unsigned char *s)
52 {
53 	unsigned int d;
54 
55 	while (d = *s++)
56 	{
57 		if (d == c)
58 			return(TRUE);
59 	}
60 	return(FALSE);
61 }
62 
63 int anys(c, s)
64 unsigned char *c, *s;
65 {
66 	wchar_t f, e;
67 	wchar_t d;
68 	int n;
69 	if((n = mbtowc(&f, (char *)c, MULTI_BYTE_MAX)) <= 0)
70 		return(FALSE);
71 	d = f;
72 	while(1) {
73 		if((n = mbtowc(&e, (char *)s, MULTI_BYTE_MAX)) <= 0)
74 			return(FALSE);
75 		if(d == e)
76 			return(TRUE);
77 		s += n;
78 	}
79 }
80 
81 int
82 cf(unsigned char *s1, unsigned char *s2)
83 {
84 	while (*s1++ == *s2)
85 		if (*s2++ == 0)
86 			return(0);
87 	return(*--s1 - *s2);
88 }
89 
90 int length(as)
91 unsigned char	*as;
92 {
93 	unsigned char	*s;
94 
95 	if (s = as)
96 		while (*s++);
97 	return(s - as);
98 }
99 
100 unsigned char *
101 movstrn(unsigned char *a, unsigned char *b, int n)
102 {
103 	while ((n-- > 0) && *a)
104 		*b++ = *a++;
105 
106 	return(b);
107 }
108