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