ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/path.C
(Generate patch)

Comparing deliantra/server/common/path.C (file contents):
Revision 1.5 by root, Mon May 28 21:21:40 2007 UTC vs.
Revision 1.10 by root, Thu Oct 15 20:45:01 2009 UTC

1/* 1/*
2 * This file is part of Crossfire TRT, the Multiplayer Online Role Playing Game. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Crossfire TRT is free software; you can redistribute it and/or modify it 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * under the terms of the GNU General Public License as published by the Free 9 * the terms of the Affero GNU General Public License as published by the
10 * Software Foundation; either version 2 of the License, or (at your option) 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * any later version. 11 * option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, but 13 * This program is distributed in the hope that it will be useful,
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License along 18 * You should have received a copy of the Affero GNU General Public License
19 * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 19 * and the GNU General Public License along with this program. If not, see
20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 * <http://www.gnu.org/licenses/>.
21 * 21 *
22 * The authors can be reached via e-mail to <crossfire@schmorp.de> 22 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 23 */
24 24
25#include <assert.h> 25#include <assert.h>
26#include <stdio.h> 26#include <stdio.h>
27#include <string.h> 27#include <string.h>
28#include <global.h> 28#include <global.h>
29#include <limits.h>
29 30
30#include "define.h" 31#include "define.h"
31#include "path.h" 32#include "path.h"
32 33
34#ifndef PATH_MAX
35# define PATH_MAX 8192
36#endif
33 37
34#if 0 38#if 0
35 39
36/** 40/**
37 * Define DEBUG_PATH to enable debug output. 41 * Define DEBUG_PATH to enable debug output.
55 59
56char * 60char *
57path_combine (const char *src, const char *dst) 61path_combine (const char *src, const char *dst)
58{ 62{
59 char *p; 63 char *p;
60 static char path[HUGE_BUF]; 64 static char path[PATH_MAX];
61 65
62 if (*dst == '/') 66 if (*dst == '/')
63 { 67 {
64 /* absolute destination path => ignore source path */ 68 /* absolute destination path => ignore source path */
65 strcpy (path, dst); 69 strcpy (path, dst);
67 else 71 else
68 { 72 {
69 /* relative destination path => add after last '/' of source */ 73 /* relative destination path => add after last '/' of source */
70 strcpy (path, src); 74 strcpy (path, src);
71 p = strrchr (path, '/'); 75 p = strrchr (path, '/');
72 if (p != NULL) 76 if (p)
73 {
74 p++; 77 p++;
75 }
76 else 78 else
77 { 79 {
78 p = path; 80 p = path;
79 if (*src == '/') 81 if (*src == '/')
80 *p++ = '/'; 82 *p++ = '/';
81 } 83 }
84
82 strcpy (p, dst); 85 strcpy (p, dst);
83 } 86 }
84 87
85#if defined(DEBUG_PATH) 88#if defined(DEBUG_PATH)
86 LOG (llevDebug, "path_combine(%s, %s) = %s\n", src, dst, path); 89 LOG (llevDebug, "path_combine(%s, %s) = %s\n", src, dst, path);
87#endif 90#endif
88 return (path); 91 return path;
89} 92}
90 93
91void 94void
92path_normalize (char *path) 95path_normalize (char *path)
93{ 96{
207} 210}
208 211
209static void 212static void
210check_normalize (const char *path, const char *exp0) 213check_normalize (const char *path, const char *exp0)
211{ 214{
212 char tmp[HUGE_BUF]; 215 char tmp[PATH_MAX];
213 char exp[HUGE_BUF]; 216 char exp[PATH_MAX];
214 217
215 strcpy (exp, exp0 == NULL ? path : exp0); 218 strcpy (exp, exp0 == NULL ? path : exp0);
216 219
217 strcpy (tmp, path); 220 strcpy (tmp, path);
218 fprintf (stderr, "path_normalize(%s) = ", tmp); 221 fprintf (stderr, "path_normalize(%s) = ", tmp);
219 path_normalize (tmp); 222 path_normalize (tmp);
220 fprintf (stderr, "%s", tmp); 223 fprintf (stderr, "%s", tmp);
221 if (strcmp (tmp, exp) != 0) 224 if (strcmp (tmp, exp) != 0)
222 {
223 fprintf (stderr, ", should be %s\n", exp); 225 fprintf (stderr, ", should be %s\n", exp);
224 }
225 else 226 else
226 {
227 fprintf (stderr, " (OK)\n"); 227 fprintf (stderr, " (OK)\n");
228 }
229} 228}
230 229
231static void 230static void
232check_combine_and_normalize (const char *src, const char *dst, const char *exp) 231check_combine_and_normalize (const char *src, const char *dst, const char *exp)
233{ 232{
235 234
236 fprintf (stderr, "path_combine_and_normalize(%s, %s) = ", src, dst); 235 fprintf (stderr, "path_combine_and_normalize(%s, %s) = ", src, dst);
237 res = path_combine_and_normalize (src, dst); 236 res = path_combine_and_normalize (src, dst);
238 fprintf (stderr, "%s", res); 237 fprintf (stderr, "%s", res);
239 if (strcmp (res, exp) != 0) 238 if (strcmp (res, exp) != 0)
240 {
241 fprintf (stderr, ", should be %s\n", exp); 239 fprintf (stderr, ", should be %s\n", exp);
242 }
243 else 240 else
244 {
245 fprintf (stderr, " (OK)\n"); 241 fprintf (stderr, " (OK)\n");
246 }
247} 242}
248 243
249int 244int
250main () 245main ()
251{ 246{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines