annotate th_string.c @ 127:f741718d13c5

Portability fixes.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 29 Oct 2010 23:12:23 +0300
parents 9ae3d87a686f
children 3896861974ac
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
79
e36df57c5b0f Use th_strdup() again.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
13 /* strdup with a NULL check
e36df57c5b0f Use th_strdup() again.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
14 */
e36df57c5b0f Use th_strdup() again.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
15 char *th_strdup(const char *s)
e36df57c5b0f Use th_strdup() again.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
16 {
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
17 char *res;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
18 if (s == NULL)
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
19 return NULL;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
20
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
21 if ((res = th_malloc(strlen(s) + 1)) == NULL)
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
22 return NULL;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
23
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
24 strcpy(res, s);
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
25 return res;
79
e36df57c5b0f Use th_strdup() again.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
26 }
e36df57c5b0f Use th_strdup() again.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
27
e36df57c5b0f Use th_strdup() again.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
28
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
29 char *th_strncpy(char * dst, const char * src, const size_t n)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 {
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
31 const char *s = src;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
32 char *d = dst;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
33 size_t i;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
34 assert(src != NULL);
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
35 assert(dst != NULL);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
37 /* Copy to the destination */
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
38 i = n;
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
39 while (*s && i > 0) {
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
40 *(d++) = *(s++);
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
41 i--;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
42 }
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
44 /* Fill rest of space with zeros */
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
45 while (i > 0) {
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
46 *(d++) = 0;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
47 i--;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
48 }
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
50 /* Ensure that last is always zero */
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
51 dst[n - 1] = 0;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
53 return dst;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56
126
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
57 /* Simulate a sprintf() that allocates memory
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
58 */
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
59 char * th_strdup_vprintf(const char *fmt, va_list args)
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
60 {
127
f741718d13c5 Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
61 int size = 100;
126
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
62 char *buf, *nbuf = NULL;
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
63
126
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
64 if ((buf = th_malloc(size)) == NULL)
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
65 return NULL;
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
66
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
67 while (1) {
127
f741718d13c5 Portability fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 126
diff changeset
68 int n = vsnprintf(buf, size, fmt, args);
126
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
69 if (n > -1 && n < size)
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
70 return buf;
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
71 if (n > -1)
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
72 size = n + 1;
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
73 else
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
74 size *= 2;
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
75
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
76 if ((nbuf = th_realloc(nbuf, size)) == NULL) {
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
77 th_free(buf);
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
78 return NULL;
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
79 }
126
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
80
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
81 buf = nbuf;
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
82 }
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
83 }
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
84
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
85
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
86 char * th_strdup_printf(const char *fmt, ...)
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
87 {
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
88 char *res;
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
89 va_list ap;
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
90
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
91 va_start(ap, fmt);
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
92 res = th_strdup_vprintf(fmt, ap);
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
93 va_end(ap);
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
94
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
95 return res;
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
96 }
126
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
97
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
98
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
99 /* Compare two strings ignoring case [strcasecmp, strncasecmp]
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
100 */
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
101 int th_strcasecmp(const char * str1, const char * str2)
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
102 {
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
103 const char *s1 = str1, *s2 = str2;
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
104 assert(str1 != NULL);
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
105 assert(str2 != NULL);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
107 if (str1 == str2)
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
108 return 0;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
110 while (*s1 && *s2 && th_tolower(*s1) == th_tolower(*s2)) {
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
111 s1++;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
112 s2++;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
113 }
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
115 return (th_tolower(*s1) - th_tolower(*s2));
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
119 int th_strncasecmp(const char * str1, const char * str2, size_t n)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 {
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
121 const char *s1 = str1, *s2 = str2;
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
122 assert(str1 != NULL);
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
123 assert(str2 != NULL);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
125 if (str1 == str2)
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
126 return 0;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
128 while (n > 0 && *s1 && *s2 && th_tolower(*s1) == th_tolower(*s2)) {
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
129 s1++;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
130 s2++;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
131 n--;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
132 }
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
134 return n > 0 ? (th_tolower(*s1) - th_tolower(*s2)) : 0;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 /* Remove all occurences of control characters, in-place.
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 * Resulting string is always shorter or same length than original.
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 */
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
141 void th_strip_ctrlchars(char * str)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 {
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
143 char *i, *j;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
144 assert(str != NULL);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
146 i = str;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
147 j = str;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
148 while (*i) {
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
149 if (!th_iscntrl(*i))
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
150 *(j++) = *i;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
151 i++;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
152 }
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
154 *j = 0;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
158 /* Copy a given string over in *result.
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 */
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
160 int th_pstrcpy(char ** result, const char * str)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 {
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
162 assert(result != NULL);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
164 if (str == NULL)
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
165 return -1;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
167 th_free(*result);
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
168 if ((*result = th_malloc(strlen(str) + 1)) == NULL)
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
169 return -2;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
171 strcpy(*result, str);
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
172 return 0;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175
11
707e35b03f89 Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
176 /* Concatenates a given string into string pointed by *result.
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 */
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
178 int th_pstrcat(char ** result, const char * str)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 {
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
180 assert(result != NULL);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
182 if (str == NULL)
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
183 return -1;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
185 if (*result != NULL) {
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
186 *result = th_realloc(*result, strlen(*result) + strlen(str) + 1);
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
187 if (*result == NULL)
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
188 return -1;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
190 strcat(*result, str);
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
191 } else {
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
192 *result = th_malloc(strlen(str) + 1);
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
193 if (*result == NULL)
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
194 return -1;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
196 strcpy(*result, str);
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
197 }
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
199 return 0;
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 */
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
207 const char *th_findnext(const char * str, size_t * pos)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208 {
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
209 assert(str != NULL);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
211 /* Terminating NULL-character is not whitespace! */
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
212 while (th_isspace(str[*pos]))
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
213 (*pos)++;
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
214 return &str[*pos];
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
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
218 /* Find next sep-character from string
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219 */
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
220 const char *th_findsep(const char * str, size_t * pos, char sep)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221 {
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
222 assert(str != NULL);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
224 while (str[*pos] && str[*pos] != sep)
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
225 (*pos)++;
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
226
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
227 return &str[*pos];
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
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
231 /* Find next sep- or whitespace from string
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232 */
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
233 const char *th_findseporspace(const char * str, size_t * pos, char sep)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234 {
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
235 assert(str != NULL);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
237 while (!th_isspace(str[*pos]) && str[*pos] != sep)
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
238 (*pos)++;
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
239
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
240 return &str[*pos];
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 */
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
249 BOOL th_strmatch(const char * str, const char * pattern)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250 {
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
251 BOOL didMatch = TRUE, isAnyMode = FALSE, isEnd = FALSE;
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
252 const char *tmpPattern = NULL;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
254 /* Check given pattern and string */
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
255 if (str == NULL || pattern == NULL)
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
256 return FALSE;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
258 /* Start comparision */
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
259 do {
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
260 didMatch = FALSE;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
261 switch (*pattern) {
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
262 case '?':
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
263 /* Any single character matches */
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
264 if (*str) {
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
265 didMatch = TRUE;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
266 pattern++;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
267 str++;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
268 }
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
269 break;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
270
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
271 case '*':
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
272 didMatch = TRUE;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
273 pattern++;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
274 if (!*pattern)
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
275 isEnd = TRUE;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
276 isAnyMode = TRUE;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
277 tmpPattern = pattern;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
278 break;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
280 case 0:
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
281 if (isAnyMode) {
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
282 if (*str)
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
283 str++;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
284 else
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
285 isEnd = TRUE;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
286 } else {
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
287 if (*str) {
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
288 if (tmpPattern) {
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
289 isAnyMode = TRUE;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
290 pattern = tmpPattern;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
291 } else
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
292 didMatch = FALSE;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
293 } else
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
294 isEnd = TRUE;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
295 }
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
296 break;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
297 default:
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
298 if (isAnyMode) {
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
299 if (*pattern == *str) {
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
300 isAnyMode = FALSE;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
301 didMatch = TRUE;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
302 } else {
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
303 if (*str) {
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
304 didMatch = TRUE;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
305 str++;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
306 }
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
307 }
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
308 } else {
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
309 if (*pattern == *str) {
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
310 didMatch = TRUE;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
311 if (*pattern)
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
312 pattern++;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
313 if (*str)
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
314 str++;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
315 } else {
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
316 if (tmpPattern) {
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
317 didMatch = TRUE;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
318 isAnyMode = TRUE;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
319 pattern = tmpPattern;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
320 }
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
321 }
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
322 }
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
323
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
324 if (!*str && !*pattern)
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
325 isEnd = TRUE;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
326 break;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
327
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
328 } /* switch */
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
329
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
330 } while (didMatch && !isEnd);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
331
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
332 return didMatch;
0
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 */
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
338 BOOL th_strcasematch(const char * str, const char * pattern)
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339 {
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
340 BOOL didMatch = TRUE, isAnyMode = FALSE, isEnd = FALSE;
124
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
341 const char *tmpPattern = NULL;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
342
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
343 /* Check given pattern and string */
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
344 if (str == NULL || pattern == NULL)
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
345 return FALSE;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
346
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
347 /* Start comparision */
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
348 do {
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
349 switch (*pattern) {
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
350 case '?':
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
351 /* Any single character matches */
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
352 if (*str) {
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
353 pattern++;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
354 str++;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
355 } else
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
356 didMatch = FALSE;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
357 break;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
358
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
359 case '*':
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
360 pattern++;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
361 if (!*pattern || *pattern == '?')
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
362 isEnd = TRUE;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
363 isAnyMode = TRUE;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
364 tmpPattern = pattern;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
365 break;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
366
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
367 case 0:
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
368 if (isAnyMode) {
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
369 if (*str)
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
370 str++;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
371 else
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
372 isEnd = TRUE;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
373 } else {
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
374 if (*str) {
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
375 if (tmpPattern) {
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
376 isAnyMode = TRUE;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
377 pattern = tmpPattern;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
378 } else
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
379 didMatch = FALSE;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
380 } else
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
381 isEnd = TRUE;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
382 }
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
383 break;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
384
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
385 default:
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
386 if (isAnyMode) {
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
387 if (th_tolower(*pattern) == th_tolower(*str)) {
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
388 isAnyMode = FALSE;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
389 } else {
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
390 if (*str)
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
391 str++;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
392 else
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
393 didMatch = FALSE;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
394 }
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
395 } else {
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
396 if (th_tolower(*pattern) == th_tolower(*str)) {
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
397 if (*pattern)
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
398 pattern++;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
399 if (*str)
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
400 str++;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
401 } else {
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
402 if (tmpPattern) {
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
403 isAnyMode = TRUE;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
404 pattern = tmpPattern;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
405 } else
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
406 didMatch = FALSE;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
407 }
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
408 }
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
409
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
410 if (!*str && !*pattern)
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
411 isEnd = TRUE;
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
412 break;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
413
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
414 } /* switch */
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
415
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
416 } while (didMatch && !isEnd);
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
417
81
69aed051f84d Synced th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 79
diff changeset
418 return didMatch;
0
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
419 }
728243125263 Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
420