File: wstring.c

package info (click to toggle)
kinput2 3.1-10.2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 3,012 kB
  • ctags: 5,584
  • sloc: ansic: 49,959; makefile: 106; sh: 68
file content (157 lines) | stat: -rw-r--r-- 2,243 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
 *	wstring.c  -- BSD string(3) for wchar
 */

/*
 * Copyright (c) 1989  Software Research Associates, Inc.
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose and without fee is hereby granted, provided
 * that the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the name of Software Research Associates not be
 * used in advertising or publicity pertaining to distribution of the
 * software without specific, written prior permission.  Software Research
 * Associates makes no representations about the suitability of this software
 * for any purpose.  It is provided "as is" without express or implied
 * warranty.
 *
 * Author:  Makoto Ishisone, Software Research Associates, Inc., Japan
 *		ishisone@sra.co.jp
 */

/* $Id: wstring.c,v 2.2 1994/06/06 05:20:40 ishisone Rel $ */

#include "WStr.h"

wchar *
wstrcat(s1, s2)
wchar *s1, *s2;
{
	wchar	*ret = s1;

	while (*s1++)
		;
	s1--;

	while (*s1++ = *s2++)
		;

	return ret;
}

wchar *
wstrncat(s1, s2, n)
wchar *s1, *s2;
int n;
{
	wchar	*ret = s1;

	while (*s1++)
		;
	s1--;

	while (n-- > 0 && (*s1++ = *s2++))
		;
	if (n < 0)
		*s1 = 0;

	return ret;
}

int
wstrcmp(s1, s2)
wchar *s1, *s2;
{
	while (*s1 && *s1 == *s2)
		s1++, s2++;
	return (int)(*s1 - *s2);
}

int
wstrncmp(s1, s2, n)
wchar *s1, *s2;
int n;
{
	while (n-- > 0 && *s1 && *s1 == *s2)
		s1++, s2++;
	if (n < 0)
		return 0;
	return (int)(*s1 - *s2);
}

wchar *
wstrcpy(s1, s2)
wchar *s1, *s2;
{
	wchar	*ret = s1;

	while (*s1++ = *s2++)
		;

	return ret;
}

wchar *
wstrncpy(s1, s2, n)
wchar *s1, *s2;
int n;
{
	wchar	*ret = s1;

	while (n-- > 0 && (*s1++ = *s2++))
		;
	while (n-- > 0)
		*s1++ = 0;

	return ret;
}

int
wstrlen(s)
wchar *s;
{
	int	n = 0;

	while (*s++)
	    n++;
	return n;
}

wchar *
#if __STDC__ == 1
windex(wchar *s, wchar c)
#else
windex(s, c)
wchar *s, c;
#endif
{
	int	x;

	while (x = *s++) {
		if (x == c)
			return s - 1;
	}

	return 0;
}

wchar *
#if __STDC__ == 1
wrindex(wchar *s, wchar c)
#else
wrindex(s, c)
wchar *s, c;
#endif
{
	wchar	*r = 0;
	int	x;

	while (x = *s++) {
		if (x == c)
			r = s - 1;
	}

	return r;
}