1 |
/* |
2 |
* This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 |
* |
4 |
* Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 |
* Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 |
* Copyright (©) 1992,2007 Frank Tore Johansen |
7 |
* |
8 |
* Deliantra is free software: you can redistribute it and/or modify |
9 |
* it under the terms of the GNU General Public License as published by |
10 |
* the Free Software Foundation, either version 3 of the License, or |
11 |
* (at your option) any later version. |
12 |
* |
13 |
* This program is distributed in the hope that it will be useful, |
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
* GNU General Public License for more details. |
17 |
* |
18 |
* You should have received a copy of the GNU General Public License |
19 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 |
* |
21 |
* The authors can be reached via e-mail to <support@deliantra.net> |
22 |
*/ |
23 |
|
24 |
/* This file contains various functions that are not really unique for |
25 |
* crossfire, but rather provides what should be standard functions |
26 |
* for systems that do not have them. In this way, most of the |
27 |
* nasty system dependent stuff is contained here, with the program |
28 |
* calling these functions. |
29 |
*/ |
30 |
|
31 |
|
32 |
/* Need to pull in the HAVE_... values somehow */ |
33 |
|
34 |
#include <autoconf.h> |
35 |
|
36 |
#include <cstdio> |
37 |
#include <cstdlib> |
38 |
#include <cstdarg> |
39 |
|
40 |
#include <cctype> |
41 |
|
42 |
#include <sys/stat.h> |
43 |
#include <sys/wait.h> |
44 |
|
45 |
#include <sys/param.h> |
46 |
|
47 |
#include <unistd.h> |
48 |
|
49 |
/* Has to be after above includes so we don't redefine some values */ |
50 |
#include "global.h" |
51 |
|
52 |
#define DIGIT(x) (isdigit(x) ? (x) - '0' : \ |
53 |
islower (x) ? (x) + 10 - 'a' : (x) + 10 - 'A') |
54 |
#define MBASE ('z' - 'a' + 1 + 10) |
55 |
|
56 |
char * |
57 |
strcasestr_local (const char *s, const char *find) |
58 |
{ |
59 |
char c, sc; |
60 |
size_t len; |
61 |
|
62 |
if ((c = *find++) != 0) |
63 |
{ |
64 |
c = tolower (c); |
65 |
len = strlen (find); |
66 |
do |
67 |
{ |
68 |
do |
69 |
{ |
70 |
if ((sc = *s++) == 0) |
71 |
return NULL; |
72 |
} |
73 |
while (tolower (sc) != c); |
74 |
} |
75 |
while (strncasecmp (s, find, len) != 0); |
76 |
s--; |
77 |
} |
78 |
return (char *) s; |
79 |
} |
80 |
|
81 |
/** |
82 |
* open_and_uncompress() first searches for the original filename. If it exist, |
83 |
* then it opens it and returns the file-pointer. |
84 |
*/ |
85 |
FILE * |
86 |
open_and_uncompress (const char *name, int flag, int *compressed) |
87 |
{ |
88 |
*compressed = 0; |
89 |
return fopen (name, "r"); |
90 |
} |
91 |
|
92 |
/* |
93 |
* See open_and_uncompress(). |
94 |
*/ |
95 |
|
96 |
void |
97 |
close_and_delete (FILE * fp, int compressed) |
98 |
{ |
99 |
fclose (fp); |
100 |
} |
101 |
|