annotate th_string.c @ 79:e36df57c5b0f

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