annotate th_string.c @ 47:e47955d42b55

Synced th-libs.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 29 Oct 2008 02:51:18 +0200
parents 707e35b03f89
children e36df57c5b0f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * Miscellaneous string-handling related utility-functions
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * Programmed and designed by Matti 'ccr' Hamalainen
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 * (C) Copyright 2002-2008 Tecnic Software productions (TNSP)
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 *
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 * Please read file 'COPYING' for information on license and distribution.
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 */
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #ifdef HAVE_CONFIG_H
2
ecfa4e3597e3 Cleanups in th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
9 #include "config.h"
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #endif
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 #include "th_string.h"
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 #define LPREV (pNode->pPrev)
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 #define LNEXT (pNode->pNext)
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 /* Allocate memory for a string with given length
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 */
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
18 char *th_stralloc(const size_t l)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 {
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 assert(l > 0);
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
21 return th_malloc(sizeof(char) * l);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
25 char *th_strrealloc(char * s, const size_t l)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 {
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
27 assert(l > 0);
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
28 return th_realloc(s, sizeof(char) * l);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31
47
e47955d42b55 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
32 char *th_strncpy(char * dst, const char * src, size_t n)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 {
47
e47955d42b55 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
34 const char *s = src;
e47955d42b55 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
35 char *d = dst;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 size_t i;
47
e47955d42b55 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
37 assert(src != NULL);
e47955d42b55 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
38 assert(dst != NULL);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 /* Copy to the destination */
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 i = n;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 while (*s && (i > 0)) {
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 *(d++) = *(s++);
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 i--;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 /* Fill rest of space with zeros */
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 while (i > 0) {
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 *(d++) = 0;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 i--;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 /* Ensure that last is always zero */
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
54 dst[n - 1] = 0;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
56 return dst;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
60 int th_strncmp(char * str1, char * str2, size_t n)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 {
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
62 char *s1, *s2;
47
e47955d42b55 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
63 assert(str1 != NULL);
e47955d42b55 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
64 assert(str2 != NULL);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 /* Check the string pointers */
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
67 if (str1 == str2)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 return 0;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 /* Go through the string */
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
71 s1 = str1;
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
72 s2 = str2;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 while ((n > 0) && *s1 && *s2 && (*s1 == *s2)) {
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 s1++;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 s2++;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 n--;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 if (n > 0)
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 return ((*s1) - (*s2));
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 else
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 return 0;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 /* Compare two strings ignoring case [strcasecmp, strncasecmp]
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 */
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
88 int th_strcasecmp(char * str1, char * str2)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 {
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
90 char *s1 = str1, *s2 = str2;
47
e47955d42b55 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
91 assert(str1 != NULL);
e47955d42b55 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
92 assert(str2 != NULL);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 /* Check the string pointers */
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
95 if (str1 == str2)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 return 0;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 /* Go through the string */
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 while (*s1 && *s2 && (th_tolower(*s1) == th_tolower(*s2))) {
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 s1++;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 s2++;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 return (th_tolower(*s1) - th_tolower(*s2));
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
108 int th_strncasecmp(char * str1, char * str2, size_t n)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 {
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
110 char *s1 = str1, *s2 = str2;
47
e47955d42b55 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
111 assert(str1 != NULL);
e47955d42b55 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
112 assert(str2 != NULL);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 /* Check the string pointers */
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
115 if (str1 == str2)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 return 0;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 /* Go through the string */
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 while ((n > 0) && *s1 && *s2 && (th_tolower(*s1) == th_tolower(*s2))) {
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 s1++;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 s2++;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 n--;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 if (n > 0)
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 return (th_tolower(*s1) - th_tolower(*s2));
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 else
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 return 0;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 /* Remove all occurences of control characters, in-place.
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 * Resulting string is always shorter or same length than original.
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134 */
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
135 void th_strip_ctrlchars(char * str)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 {
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
137 char *i, *j;
47
e47955d42b55 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
138 assert(str != NULL);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
140 i = str;
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
141 j = str;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 while (*i) {
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 if (!th_iscntrl(*i))
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144 *(j++) = *i;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 i++;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 *j = 0;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
152 /* Copy a given string over in *result.
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 */
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
154 int th_pstrcpy(char ** result, char * str)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 {
47
e47955d42b55 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
156 assert(result != NULL);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 /* Check the string pointers */
47
e47955d42b55 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
159 if (str == NULL)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 return -1;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 /* Allocate memory for destination */
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
163 th_free(*result);
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
164 *result = th_stralloc(strlen(str) + 1);
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
165 if (!*result)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166 return -2;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 /* Copy to the destination */
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
169 strcpy(*result, str);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 return 0;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
175 /* Concatenates a given string into string pointed by *result.
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176 */
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
177 int th_pstrcat(char ** result, char * str)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 {
47
e47955d42b55 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
179 assert(result != NULL);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 /* Check the string pointers */
47
e47955d42b55 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
182 if (str == NULL)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 return -1;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
185 if (*result != NULL) {
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
186 *result = th_strrealloc(*result, strlen(*result) + strlen(str) + 1);
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
187 if (*result == NULL)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188 return -1;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
190 strcat(*result, str);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191 } else {
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
192 *result = th_stralloc(strlen(str) + 1);
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
193 if (*result == NULL)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194 return -1;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
196 strcpy(*result, str);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 return 0;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 /* Find next non-whitespace character in string.
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 * Updates iPos into the position of such character and
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205 * returns pointer to the string.
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206 */
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
207 char *th_findnext(char * str, size_t * iPos)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208 {
47
e47955d42b55 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
209 assert(str != NULL);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211 /* Terminating NULL-character is not whitespace! */
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
212 while (th_isspace(str[*iPos]))
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213 (*iPos)++;
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
214 return &str[*iPos];
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218 /* Find next chSep-character from string
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219 */
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
220 char *th_findsep(char * str, size_t * iPos, char chSep)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221 {
47
e47955d42b55 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
222 assert(str != NULL);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224 /* Terminating NULL-character is not digit! */
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
225 while (str[*iPos] && (str[*iPos] != chSep))
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226 (*iPos)++;
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
227 return &str[*iPos];
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
228 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 /* Find next chSep- or whitespace from string
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232 */
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
233 char *th_findseporspace(char * str, size_t * iPos, char chSep)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234 {
47
e47955d42b55 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
235 assert(str != NULL);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237 /* Terminating NULL-character is not digit! */
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
238 while (!th_isspace(str[*iPos]) && (str[*iPos] != chSep))
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239 (*iPos)++;
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
240 return &str[*iPos];
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
241 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244 /* Compare a string to a pattern. Case-SENSITIVE version.
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245 * The matching pattern can consist of any normal characters plus
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246 * wildcards ? and *. "?" matches any character and "*" matches
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247 * any number of characters.
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248 */
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
249 BOOL th_strmatch(char * str, char * pattern)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250 {
47
e47955d42b55 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
251 BOOL didMatch = TRUE, isAnyMode = FALSE, isEnd = FALSE;
e47955d42b55 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
252 char *tmpPattern = NULL;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254 /* Check given pattern and string */
47
e47955d42b55 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
255 if (str == NULL || pattern == NULL)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256 return FALSE;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258 /* Start comparision */
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259 do {
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260 didMatch = FALSE;
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
261 switch (*pattern) {
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262 case '?':
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263 /* Any single character matches */
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
264 if (*str) {
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
265 didMatch = TRUE;
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
266 pattern++;
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
267 str++;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
269 break;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
270
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
271 case '*':
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
272 didMatch = TRUE;
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
273 pattern++;
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
274 if (!*pattern)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
275 isEnd = TRUE;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276 isAnyMode = TRUE;
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
277 tmpPattern = pattern;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278 break;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280 case 0:
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
281 if (isAnyMode) {
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
282 if (*str)
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
283 str++;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284 else
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285 isEnd = TRUE;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
286 } else {
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
287 if (*str) {
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
288 if (tmpPattern) {
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
289 isAnyMode = TRUE;
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
290 pattern = tmpPattern;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291 } else
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
292 didMatch = FALSE;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
293 } else
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
294 isEnd = TRUE;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
295 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296 break;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
297 default:
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
298 if (isAnyMode) {
47
e47955d42b55 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
299 if (*pattern == *str) {
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
300 isAnyMode = FALSE;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
301 didMatch = TRUE;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
302 } else {
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
303 if (*str) {
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
304 didMatch = TRUE;
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
305 str++;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
306 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
307 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
308 } else {
47
e47955d42b55 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
309 if (*pattern == *str) {
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
310 didMatch = TRUE;
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
311 if (*pattern)
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
312 pattern++;
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
313 if (*str)
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
314 str++;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
315 } else {
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
316 if (tmpPattern) {
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
317 didMatch = TRUE;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
318 isAnyMode = TRUE;
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
319 pattern = tmpPattern;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
320 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
321 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
322 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
323
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
324 if (!*str && !*pattern)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
325 isEnd = TRUE;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
326 break;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
327
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
328 } /* switch */
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
329
47
e47955d42b55 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
330 } while (didMatch && !isEnd);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
331
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
332 return didMatch;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
333 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
334
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
335
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
336 /* Compare a string to a pattern. Case-INSENSITIVE version.
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
337 */
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
338 BOOL th_strcasematch(char * str, char * pattern)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339 {
47
e47955d42b55 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
340 BOOL didMatch = TRUE, isAnyMode = FALSE, isEnd = FALSE;
e47955d42b55 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
341 char *tmpPattern = NULL;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
342
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
343 /* Check given pattern and string */
47
e47955d42b55 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
344 if (str == NULL || pattern == NULL)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
345 return FALSE;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
346
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
347 /* Start comparision */
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
348 do {
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
349 switch (*pattern) {
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
350 case '?':
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
351 /* Any single character matches */
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
352 if (*str) {
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
353 pattern++;
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
354 str++;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
355 } else
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
356 didMatch = FALSE;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
357 break;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
358
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
359 case '*':
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
360 pattern++;
47
e47955d42b55 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
361 if (!*pattern || *pattern == '?')
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
362 isEnd = TRUE;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
363 isAnyMode = TRUE;
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
364 tmpPattern = pattern;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
365 break;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
366
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
367 case 0:
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
368 if (isAnyMode) {
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
369 if (*str)
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
370 str++;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
371 else
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
372 isEnd = TRUE;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
373 } else {
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
374 if (*str) {
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
375 if (tmpPattern) {
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
376 isAnyMode = TRUE;
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
377 pattern = tmpPattern;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
378 } else
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
379 didMatch = FALSE;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
380 } else
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
381 isEnd = TRUE;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
382 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
383 break;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
384
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
385 default:
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
386 if (isAnyMode) {
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
387 if (th_tolower(*pattern) == th_tolower(*str)) {
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
388 isAnyMode = FALSE;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
389 } else {
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
390 if (*str)
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
391 str++;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
392 else
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
393 didMatch = FALSE;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
394 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
395 } else {
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
396 if (th_tolower(*pattern) == th_tolower(*str)) {
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
397 if (*pattern)
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
398 pattern++;
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
399 if (*str)
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
400 str++;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
401 } else {
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
402 if (tmpPattern) {
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
403 isAnyMode = TRUE;
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
404 pattern = tmpPattern;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
405 } else
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
406 didMatch = FALSE;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
407 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
408 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
409
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
410 if (!*str && !*pattern)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
411 isEnd = TRUE;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
412 break;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
413
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
414 } /* switch */
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
415
47
e47955d42b55 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
416 } while (didMatch && !isEnd);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
417
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
418 return didMatch;
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
419 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
420