annotate th_string.c @ 49:598609fb49b0

Change how "config.h" is included, etc.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 03 Oct 2011 15:40:54 +0300
parents 669d2bc97c57
children b10f07101e67
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * Miscellaneous string-handling related utility-functions
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * Programmed and designed by Matti 'ccr' Hamalainen
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 * (C) Copyright 2002-2008 Tecnic Software productions (TNSP)
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 *
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 * Please read file 'COPYING' for information on license and distribution.
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 */
49
598609fb49b0 Change how "config.h" is included, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
8 #include "th_util.h"
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #include "th_string.h"
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10
8
acc2a8035dd5 Re-add th_strdup().
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
11 /* strdup with a NULL check
acc2a8035dd5 Re-add th_strdup().
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
12 */
acc2a8035dd5 Re-add th_strdup().
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
13 char *th_strdup(const char *s)
acc2a8035dd5 Re-add th_strdup().
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
14 {
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
15 char *res;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
16 if (s == NULL)
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
17 return NULL;
44
669d2bc97c57 More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
18
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
19 if ((res = th_malloc(strlen(s) + 1)) == NULL)
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
20 return NULL;
44
669d2bc97c57 More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
21
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
22 strcpy(res, s);
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
23 return res;
8
acc2a8035dd5 Re-add th_strdup().
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
24 }
acc2a8035dd5 Re-add th_strdup().
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
25
acc2a8035dd5 Re-add th_strdup().
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
26
43
8c015ac0c556 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
27 char *th_strncpy(char *dst, const char *src, const size_t n)
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 {
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
29 const char *s = src;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
30 char *d = dst;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
31 size_t i;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
32 assert(src != NULL);
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
33 assert(dst != NULL);
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
35 /* Copy to the destination */
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
36 i = n;
39
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
37 while (*s && i > 0)
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
38 {
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
39 *(d++) = *(s++);
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
40 i--;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
41 }
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
43 /* Fill rest of space with zeros */
39
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
44 while (i > 0)
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
45 {
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
46 *(d++) = 0;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
47 i--;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
48 }
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
50 /* Ensure that last is always zero */
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
51 dst[n - 1] = 0;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
53 return dst;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 }
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56
14
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
57 /* Simulate a sprintf() that allocates memory
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
58 */
43
8c015ac0c556 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
59 char *th_strdup_vprintf(const char *fmt, va_list args)
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 {
37
3986b139bbbd Fix th_strdup_vprintf(), another misuse of va_list without making a copy of it... :(
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
61 int size = 64;
14
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
62 char *buf, *nbuf = NULL;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63
14
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
64 if ((buf = th_malloc(size)) == NULL)
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
65 return NULL;
44
669d2bc97c57 More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
66
39
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
67 while (1)
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
68 {
37
3986b139bbbd Fix th_strdup_vprintf(), another misuse of va_list without making a copy of it... :(
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
69 int n;
3986b139bbbd Fix th_strdup_vprintf(), another misuse of va_list without making a copy of it... :(
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
70 va_list ap;
3986b139bbbd Fix th_strdup_vprintf(), another misuse of va_list without making a copy of it... :(
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
71 va_copy(ap, args);
3986b139bbbd Fix th_strdup_vprintf(), another misuse of va_list without making a copy of it... :(
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
72 n = vsnprintf(buf, size, fmt, ap);
3986b139bbbd Fix th_strdup_vprintf(), another misuse of va_list without making a copy of it... :(
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
73 va_end(ap);
3986b139bbbd Fix th_strdup_vprintf(), another misuse of va_list without making a copy of it... :(
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
74
14
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
75 if (n > -1 && n < size)
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
76 return buf;
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
77 if (n > -1)
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
78 size = n + 1;
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
79 else
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
80 size *= 2;
37
3986b139bbbd Fix th_strdup_vprintf(), another misuse of va_list without making a copy of it... :(
Matti Hamalainen <ccr@tnsp.org>
parents: 36
diff changeset
81
39
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
82 if ((nbuf = th_realloc(nbuf, size)) == NULL)
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
83 {
14
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
84 th_free(buf);
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
85 return NULL;
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
86 }
44
669d2bc97c57 More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
87
14
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
88 buf = nbuf;
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
89 }
14
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
90 }
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91
14
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
92
43
8c015ac0c556 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
93 char *th_strdup_printf(const char *fmt, ...)
14
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
94 {
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
95 char *res;
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
96 va_list ap;
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
97
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
98 va_start(ap, fmt);
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
99 res = th_strdup_vprintf(fmt, ap);
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
100 va_end(ap);
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
101
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
102 return res;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 }
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105
30
10d2dc143e4b Add helper functions th_pstr_vprintf() and th_pstr_printf().
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
106 void th_pstr_vprintf(char **buf, const char *fmt, va_list ap)
10d2dc143e4b Add helper functions th_pstr_vprintf() and th_pstr_printf().
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
107 {
10d2dc143e4b Add helper functions th_pstr_vprintf() and th_pstr_printf().
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
108 char *tmp = th_strdup_vprintf(fmt, ap);
10d2dc143e4b Add helper functions th_pstr_vprintf() and th_pstr_printf().
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
109 th_free(*buf);
10d2dc143e4b Add helper functions th_pstr_vprintf() and th_pstr_printf().
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
110 *buf = tmp;
10d2dc143e4b Add helper functions th_pstr_vprintf() and th_pstr_printf().
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
111 }
10d2dc143e4b Add helper functions th_pstr_vprintf() and th_pstr_printf().
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
112
10d2dc143e4b Add helper functions th_pstr_vprintf() and th_pstr_printf().
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
113
10d2dc143e4b Add helper functions th_pstr_vprintf() and th_pstr_printf().
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
114 void th_pstr_printf(char **buf, const char *fmt, ...)
10d2dc143e4b Add helper functions th_pstr_vprintf() and th_pstr_printf().
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
115 {
10d2dc143e4b Add helper functions th_pstr_vprintf() and th_pstr_printf().
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
116 char *tmp;
10d2dc143e4b Add helper functions th_pstr_vprintf() and th_pstr_printf().
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
117 va_list ap;
10d2dc143e4b Add helper functions th_pstr_vprintf() and th_pstr_printf().
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
118
10d2dc143e4b Add helper functions th_pstr_vprintf() and th_pstr_printf().
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
119 va_start(ap, fmt);
10d2dc143e4b Add helper functions th_pstr_vprintf() and th_pstr_printf().
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
120 tmp = th_strdup_vprintf(fmt, ap);
10d2dc143e4b Add helper functions th_pstr_vprintf() and th_pstr_printf().
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
121 va_end(ap);
10d2dc143e4b Add helper functions th_pstr_vprintf() and th_pstr_printf().
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
122
10d2dc143e4b Add helper functions th_pstr_vprintf() and th_pstr_printf().
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
123 th_free(*buf);
10d2dc143e4b Add helper functions th_pstr_vprintf() and th_pstr_printf().
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
124 *buf = tmp;
10d2dc143e4b Add helper functions th_pstr_vprintf() and th_pstr_printf().
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
125 }
10d2dc143e4b Add helper functions th_pstr_vprintf() and th_pstr_printf().
Matti Hamalainen <ccr@tnsp.org>
parents: 29
diff changeset
126
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 /* Compare two strings ignoring case [strcasecmp, strncasecmp]
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 */
43
8c015ac0c556 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
129 int th_strcasecmp(const char *str1, const char *str2)
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 {
14
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
131 const char *s1 = str1, *s2 = str2;
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
132 assert(str1 != NULL);
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
133 assert(str2 != NULL);
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
135 if (str1 == str2)
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
136 return 0;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137
39
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
138 while (*s1 && *s2 && th_tolower(*s1) == th_tolower(*s2))
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
139 {
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
140 s1++;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
141 s2++;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
142 }
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
144 return (th_tolower(*s1) - th_tolower(*s2));
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 }
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147
43
8c015ac0c556 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
148 int th_strncasecmp(const char *str1, const char *str2, size_t n)
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149 {
14
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
150 const char *s1 = str1, *s2 = str2;
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
151 assert(str1 != NULL);
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
152 assert(str2 != NULL);
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
154 if (str1 == str2)
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
155 return 0;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156
39
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
157 while (n > 0 && *s1 && *s2 && th_tolower(*s1) == th_tolower(*s2))
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
158 {
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
159 s1++;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
160 s2++;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
161 n--;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
162 }
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163
14
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
164 return n > 0 ? (th_tolower(*s1) - th_tolower(*s2)) : 0;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 }
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 /* Remove all occurences of control characters, in-place.
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 * Resulting string is always shorter or same length than original.
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 */
43
8c015ac0c556 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
171 void th_strip_ctrlchars(char *str)
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 {
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
173 char *i, *j;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
174 assert(str != NULL);
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
176 i = str;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
177 j = str;
39
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
178 while (*i)
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
179 {
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
180 if (!th_iscntrl(*i))
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
181 *(j++) = *i;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
182 i++;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
183 }
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
185 *j = 0;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 }
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189 /* Copy a given string over in *result.
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190 */
43
8c015ac0c556 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
191 int th_pstrcpy(char **result, const char *str)
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 {
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
193 assert(result != NULL);
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
195 if (str == NULL)
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
196 return -1;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
198 th_free(*result);
14
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
199 if ((*result = th_malloc(strlen(str) + 1)) == NULL)
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
200 return -2;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
202 strcpy(*result, str);
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
203 return 0;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 }
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207 /* Concatenates a given string into string pointed by *result.
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208 */
43
8c015ac0c556 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
209 int th_pstrcat(char **result, const char *str)
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210 {
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
211 assert(result != NULL);
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
213 if (str == NULL)
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
214 return -1;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215
39
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
216 if (*result != NULL)
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
217 {
14
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
218 *result = th_realloc(*result, strlen(*result) + strlen(str) + 1);
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
219 if (*result == NULL)
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
220 return -1;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
222 strcat(*result, str);
39
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
223 }
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
224 else
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
225 {
14
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
226 *result = th_malloc(strlen(str) + 1);
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
227 if (*result == NULL)
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
228 return -1;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
230 strcpy(*result, str);
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
231 }
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
233 return 0;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234 }
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237 /* Find next non-whitespace character in string.
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238 * Updates iPos into the position of such character and
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239 * returns pointer to the string.
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240 */
43
8c015ac0c556 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
241 const char *th_findnext(const char *str, size_t *pos)
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242 {
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
243 assert(str != NULL);
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
245 /* Terminating NULL-character is not whitespace! */
14
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
246 while (th_isspace(str[*pos]))
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
247 (*pos)++;
39
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
248
14
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
249 return &str[*pos];
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250 }
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252
14
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
253 /* Find next sep-character from string
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254 */
43
8c015ac0c556 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
255 const char *th_findsep(const char *str, size_t *pos, char sep)
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256 {
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
257 assert(str != NULL);
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258
14
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
259 while (str[*pos] && str[*pos] != sep)
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
260 (*pos)++;
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
261
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
262 return &str[*pos];
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263 }
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
264
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
265
14
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
266 /* Find next sep- or whitespace from string
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267 */
43
8c015ac0c556 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
268 const char *th_findseporspace(const char *str, size_t *pos, char sep)
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
269 {
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
270 assert(str != NULL);
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
271
14
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
272 while (!th_isspace(str[*pos]) && str[*pos] != sep)
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
273 (*pos)++;
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
274
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
275 return &str[*pos];
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276 }
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
277
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279 /* Compare a string to a pattern. Case-SENSITIVE version.
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280 * The matching pattern can consist of any normal characters plus
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
281 * wildcards ? and *. "?" matches any character and "*" matches
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282 * any number of characters.
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
283 */
43
8c015ac0c556 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
284 BOOL th_strmatch(const char *str, const char *pattern)
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285 {
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
286 BOOL didMatch = TRUE, isAnyMode = FALSE, isEnd = FALSE;
14
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
287 const char *tmpPattern = NULL;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
288
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
289 /* Check given pattern and string */
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
290 if (str == NULL || pattern == NULL)
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
291 return FALSE;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
292
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
293 /* Start comparision */
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
294 do {
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
295 didMatch = FALSE;
39
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
296 switch (*pattern)
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
297 {
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
298 case '?':
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
299 /* Any single character matches */
39
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
300 if (*str)
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
301 {
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
302 didMatch = TRUE;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
303 pattern++;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
304 str++;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
305 }
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
306 break;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
307
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
308 case '*':
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
309 didMatch = TRUE;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
310 pattern++;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
311 if (!*pattern)
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
312 isEnd = TRUE;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
313 isAnyMode = TRUE;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
314 tmpPattern = pattern;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
315 break;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
316
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
317 case 0:
39
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
318 if (isAnyMode)
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
319 {
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
320 if (*str)
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
321 str++;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
322 else
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
323 isEnd = TRUE;
39
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
324 }
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
325 else
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
326 {
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
327 if (*str)
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
328 {
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
329 if (tmpPattern)
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
330 {
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
331 isAnyMode = TRUE;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
332 pattern = tmpPattern;
39
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
333 }
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
334 else
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
335 didMatch = FALSE;
44
669d2bc97c57 More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
336 }
669d2bc97c57 More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
337 else
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
338 isEnd = TRUE;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
339 }
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
340 break;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
341 default:
39
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
342 if (isAnyMode)
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
343 {
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
344 if (*pattern == *str)
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
345 {
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
346 isAnyMode = FALSE;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
347 didMatch = TRUE;
39
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
348 }
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
349 else
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
350 {
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
351 if (*str)
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
352 {
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
353 didMatch = TRUE;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
354 str++;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
355 }
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
356 }
39
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
357 }
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
358 else
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
359 {
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
360 if (*pattern == *str)
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
361 {
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
362 didMatch = TRUE;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
363 if (*pattern)
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
364 pattern++;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
365 if (*str)
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
366 str++;
39
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
367 }
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
368 else
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
369 {
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
370 if (tmpPattern)
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
371 {
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
372 didMatch = TRUE;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
373 isAnyMode = TRUE;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
374 pattern = tmpPattern;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
375 }
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
376 }
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
377 }
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
378
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
379 if (!*str && !*pattern)
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
380 isEnd = TRUE;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
381 break;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
382
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
383 } /* switch */
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
384
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
385 } while (didMatch && !isEnd);
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
386
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
387 return didMatch;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
388 }
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
389
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
390
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
391 /* Compare a string to a pattern. Case-INSENSITIVE version.
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
392 */
43
8c015ac0c556 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
393 BOOL th_strcasematch(const char *str, const char *pattern)
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
394 {
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
395 BOOL didMatch = TRUE, isAnyMode = FALSE, isEnd = FALSE;
14
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
396 const char *tmpPattern = NULL;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
397
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
398 /* Check given pattern and string */
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
399 if (str == NULL || pattern == NULL)
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
400 return FALSE;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
401
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
402 /* Start comparision */
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
403 do {
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
404 switch (*pattern) {
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
405 case '?':
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
406 /* Any single character matches */
39
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
407 if (*str)
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
408 {
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
409 pattern++;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
410 str++;
44
669d2bc97c57 More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
411 }
669d2bc97c57 More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
412 else
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
413 didMatch = FALSE;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
414 break;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
415
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
416 case '*':
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
417 pattern++;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
418 if (!*pattern || *pattern == '?')
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
419 isEnd = TRUE;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
420 isAnyMode = TRUE;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
421 tmpPattern = pattern;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
422 break;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
423
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
424 case 0:
39
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
425 if (isAnyMode)
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
426 {
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
427 if (*str)
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
428 str++;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
429 else
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
430 isEnd = TRUE;
39
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
431 }
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
432 else
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
433 {
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
434 if (*str)
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
435 {
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
436 if (tmpPattern)
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
437 {
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
438 isAnyMode = TRUE;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
439 pattern = tmpPattern;
39
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
440 }
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
441 else
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
442 didMatch = FALSE;
44
669d2bc97c57 More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
443 }
669d2bc97c57 More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
444 else
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
445 isEnd = TRUE;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
446 }
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
447 break;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
448
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
449 default:
39
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
450 if (isAnyMode)
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
451 {
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
452 if (th_tolower(*pattern) == th_tolower(*str))
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
453 {
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
454 isAnyMode = FALSE;
39
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
455 }
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
456 else
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
457 {
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
458 if (*str)
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
459 str++;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
460 else
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
461 didMatch = FALSE;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
462 }
39
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
463 }
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
464 else
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
465 {
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
466 if (th_tolower(*pattern) == th_tolower(*str))
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
467 {
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
468 if (*pattern)
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
469 pattern++;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
470 if (*str)
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
471 str++;
39
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
472 }
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
473 else
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
474 {
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
475 if (tmpPattern)
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
476 {
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
477 isAnyMode = TRUE;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
478 pattern = tmpPattern;
39
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
479 }
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
480 else
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
481 didMatch = FALSE;
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
482 }
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
483 }
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
484
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
485 if (!*str && !*pattern)
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
486 isEnd = TRUE;
39
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
487
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
488 break;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
489
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
490 } /* switch */
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
491
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
492 } while (didMatch && !isEnd);
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
493
10
a25f5d22483e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
494 return didMatch;
0
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
495 }
bd61a80a6c54 Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
496
14
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
497
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
498 int th_get_hex_triplet(const char *str)
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
499 {
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
500 const char *p = str;
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
501 int len, val = 0;
44
669d2bc97c57 More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
502
39
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
503 for (len = 0; *p && len < 6; p++, len++)
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
504 {
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
505 if (*p >= '0' && *p <= '9')
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
506 {
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
507 val *= 16;
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
508 val += (*p - '0');
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
509 }
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
510 else if (*p >= 'A' && *p <= 'F')
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
511 {
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
512 val *= 16;
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
513 val += (*p - 'A') + 10;
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
514 }
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
515 else if (*p >= 'a' && *p <= 'f')
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
516 {
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
517 val *= 16;
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
518 val += (*p - 'a') + 10;
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
519 }
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
520 else
14
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
521 return -1;
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
522 }
44
669d2bc97c57 More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
523
14
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
524 return (len == 6) ? val : -1;
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
525 }
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
526
e5e6370217ef Various cleanups, additions and removals.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
527
35
e9a3fe655dd9 Make th_growbuf() public.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
528 BOOL th_growbuf(char **buf, size_t *bufsize, size_t *len, size_t grow)
21
1f7d8693fda8 Add functions for growing a string/buffer and concatenating characters and/or other strings to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
529 {
1f7d8693fda8 Add functions for growing a string/buffer and concatenating characters and/or other strings to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
530 if (*buf == NULL)
31
a3ad77382c64 Fix an annoying bug in th_growbuf().
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
531 *bufsize = *len = 0;
44
669d2bc97c57 More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
532
39
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
533 if (*buf == NULL || *len + grow >= *bufsize)
0d55592e0e01 Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 38
diff changeset
534 {
21
1f7d8693fda8 Add functions for growing a string/buffer and concatenating characters and/or other strings to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
535 *bufsize += grow + TH_BUFGROW;
1f7d8693fda8 Add functions for growing a string/buffer and concatenating characters and/or other strings to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
536 *buf = (char *) th_realloc(*buf, *bufsize);
1f7d8693fda8 Add functions for growing a string/buffer and concatenating characters and/or other strings to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
537 if (*buf == NULL)
1f7d8693fda8 Add functions for growing a string/buffer and concatenating characters and/or other strings to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
538 return FALSE;
1f7d8693fda8 Add functions for growing a string/buffer and concatenating characters and/or other strings to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
539 }
1f7d8693fda8 Add functions for growing a string/buffer and concatenating characters and/or other strings to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
540 return TRUE;
1f7d8693fda8 Add functions for growing a string/buffer and concatenating characters and/or other strings to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
541 }
1f7d8693fda8 Add functions for growing a string/buffer and concatenating characters and/or other strings to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
542
1f7d8693fda8 Add functions for growing a string/buffer and concatenating characters and/or other strings to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
543
29
04cfdefc3253 th_vputs() and th_vputch() now return a boolean value, TRUE if operation was successful, FALSE if it failed. If result was FALSE, the buffer pointer may now be NULL.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
544 BOOL th_vputch(char **buf, size_t *bufsize, size_t *len, const char ch)
21
1f7d8693fda8 Add functions for growing a string/buffer and concatenating characters and/or other strings to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
545 {
1f7d8693fda8 Add functions for growing a string/buffer and concatenating characters and/or other strings to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
546 if (!th_growbuf(buf, bufsize, len, 1))
29
04cfdefc3253 th_vputs() and th_vputch() now return a boolean value, TRUE if operation was successful, FALSE if it failed. If result was FALSE, the buffer pointer may now be NULL.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
547 return FALSE;
44
669d2bc97c57 More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
548
21
1f7d8693fda8 Add functions for growing a string/buffer and concatenating characters and/or other strings to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
549 (*buf)[*len] = ch;
1f7d8693fda8 Add functions for growing a string/buffer and concatenating characters and/or other strings to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
550 (*len)++;
29
04cfdefc3253 th_vputs() and th_vputch() now return a boolean value, TRUE if operation was successful, FALSE if it failed. If result was FALSE, the buffer pointer may now be NULL.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
551
04cfdefc3253 th_vputs() and th_vputch() now return a boolean value, TRUE if operation was successful, FALSE if it failed. If result was FALSE, the buffer pointer may now be NULL.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
552 return TRUE;
21
1f7d8693fda8 Add functions for growing a string/buffer and concatenating characters and/or other strings to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
553 }
1f7d8693fda8 Add functions for growing a string/buffer and concatenating characters and/or other strings to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
554
1f7d8693fda8 Add functions for growing a string/buffer and concatenating characters and/or other strings to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
555
29
04cfdefc3253 th_vputs() and th_vputch() now return a boolean value, TRUE if operation was successful, FALSE if it failed. If result was FALSE, the buffer pointer may now be NULL.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
556 BOOL th_vputs(char **buf, size_t *bufsize, size_t *len, const char *str)
21
1f7d8693fda8 Add functions for growing a string/buffer and concatenating characters and/or other strings to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
557 {
1f7d8693fda8 Add functions for growing a string/buffer and concatenating characters and/or other strings to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
558 size_t slen;
1f7d8693fda8 Add functions for growing a string/buffer and concatenating characters and/or other strings to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
559 if (str == NULL)
29
04cfdefc3253 th_vputs() and th_vputch() now return a boolean value, TRUE if operation was successful, FALSE if it failed. If result was FALSE, the buffer pointer may now be NULL.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
560 return FALSE;
44
669d2bc97c57 More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
561
21
1f7d8693fda8 Add functions for growing a string/buffer and concatenating characters and/or other strings to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
562 slen = strlen(str);
1f7d8693fda8 Add functions for growing a string/buffer and concatenating characters and/or other strings to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
563 if (!th_growbuf(buf, bufsize, len, slen))
29
04cfdefc3253 th_vputs() and th_vputch() now return a boolean value, TRUE if operation was successful, FALSE if it failed. If result was FALSE, the buffer pointer may now be NULL.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
564 return FALSE;
21
1f7d8693fda8 Add functions for growing a string/buffer and concatenating characters and/or other strings to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
565
32
7e0a2a125830 Use strcpy() instead of strcat() in th_vputs().
Matti Hamalainen <ccr@tnsp.org>
parents: 31
diff changeset
566 strcpy(*buf + *len, str);
21
1f7d8693fda8 Add functions for growing a string/buffer and concatenating characters and/or other strings to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
567 (*len) += slen;
44
669d2bc97c57 More cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
568
29
04cfdefc3253 th_vputs() and th_vputch() now return a boolean value, TRUE if operation was successful, FALSE if it failed. If result was FALSE, the buffer pointer may now be NULL.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
569 return TRUE;
21
1f7d8693fda8 Add functions for growing a string/buffer and concatenating characters and/or other strings to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 14
diff changeset
570 }