1 |
/* wptUtil.cpp - Helper functions |
/* wptUtil.cpp - Helper functions |
2 |
* Copyright (C) 2005 Timo Schulz |
* Copyright (C) 2005, 2006 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 |
* General Public License for more details. |
* General Public License for more details. |
|
* |
|
|
* You should have received a copy of the GNU General Public License |
|
|
* along with WinPT; if not, write to the Free Software Foundation, |
|
|
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
15 |
*/ |
*/ |
|
|
|
16 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
17 |
#include <config.h> |
#include <config.h> |
18 |
#endif |
#endif |
19 |
|
|
20 |
|
#include <windows.h> |
21 |
#include <string.h> |
#include <string.h> |
22 |
#include <stdlib.h> |
#include <stdlib.h> |
23 |
#include <stdio.h> |
#include <stdio.h> |
24 |
#include <ctype.h> |
#include <ctype.h> |
25 |
|
|
26 |
|
#include "wptTypes.h" |
27 |
|
|
28 |
|
|
29 |
/* code taken from glibc-2.2.1/sysdeps/generic/strsep.c */ |
/* code taken from glibc-2.2.1/sysdeps/generic/strsep.c */ |
30 |
char* |
char* |
31 |
strsep (char **stringp, const char *delim) |
strsep (char **stringp, const char *delim) |
75 |
size_t n; |
size_t n; |
76 |
size_t buflen = strlen (buf); |
size_t buflen = strlen (buf); |
77 |
|
|
78 |
for( t=buf, n=buflen, s=sub ; n ; t++, n-- ) { |
for (t=buf, n=buflen, s=sub ; n ; t++, n--) { |
79 |
if( toupper(*t) == toupper(*s) ) { |
if (toupper (*t) == toupper (*s)) { |
80 |
for( buf=t++, buflen = n--, s++; |
for( buf=t++, buflen = n--, s++; |
81 |
n && toupper(*t) == toupper(*s); t++, s++, n-- ) |
n && toupper(*t) == toupper(*s); t++, s++, n-- ) |
82 |
; |
; |
83 |
if( !*s ) |
if (!*s) |
84 |
return buf; |
return buf; |
85 |
t = buf; n = buflen; s = sub ; |
t = buf; n = buflen; s = sub ; |
86 |
} |
} |
99 |
|
|
100 |
/* If we are not in path mode (@is_path = 1) we also consider |
/* If we are not in path mode (@is_path = 1) we also consider |
101 |
path separators as illegal chars. */ |
path separators as illegal chars. */ |
102 |
if (!is_path) { |
if (!is_path && (strchr (fname, ':') || strchr (fname, '\\'))) |
103 |
if (strchr (fname, ':') || strchr (fname, '\\')) |
return -1; |
|
return -1; |
|
|
} |
|
104 |
|
|
105 |
for (i=0; i < strlen (fname); i++) { |
for (i=0; i < strlen (fname); i++) { |
106 |
if (strchr (not_allowed, fname[i])) |
if (strchr (not_allowed, fname[i])) |
144 |
|
|
145 |
p = new char[end-begin+1]; |
p = new char[end-begin+1]; |
146 |
if (!p) |
if (!p) |
147 |
abort (); |
BUG (0); |
|
|
|
148 |
for (i = begin, pos=0; i < end; i++) |
for (i = begin, pos=0; i < end; i++) |
149 |
p[pos++] = str[i]; |
p[pos++] = str[i]; |
150 |
p[pos] = '\0'; |
p[pos] = '\0'; |
180 |
out[i] = 0; |
out[i] = 0; |
181 |
*r_out = out; |
*r_out = out; |
182 |
} |
} |
183 |
|
|
184 |
|
|
185 |
|
/* Safe strdup version (C++ version). */ |
186 |
|
char* |
187 |
|
m_strdup (const char *str) |
188 |
|
{ |
189 |
|
char *p = new char[strlen (str) + 1]; |
190 |
|
if (!p) |
191 |
|
BUG (NULL); |
192 |
|
strcpy (p, str); |
193 |
|
return p; |
194 |
|
} |