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

Comparing deliantra/server/server/freezethaw.C (file contents):
Revision 1.14 by pippijn, Fri Mar 2 10:15:40 2007 UTC vs.
Revision 1.22 by root, Sun Jul 1 05:00:20 2007 UTC

1/*****************************************************************************/
2/* CrossFire, A roguelike realtime multiplayer game */
3/*****************************************************************************/
4
5/* 1/*
6 * This code is placed under the GNU General Public Licence (GPL) 2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
7 * 3 *
8 * Copyright (C) 2006 by Marc Lehmann <crossfire@schmorp.de> 4 * Copyright (©) 2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team
9 * 5 *
10 * This program is free software; you can redistribute it and/or modify 6 * Crossfire TRT is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or 8 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version. 9 * (at your option) any later version.
14 * 10 *
15 * This program is distributed in the hope that it will be useful, 11 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details. 14 * GNU General Public License for more details.
19 * 15 *
20 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software 17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 *
19 * The authors can be reached via e-mail to <crossfire@schmorp.de>
23 */ 20 */
24 21
25#include "global.h" // bug in cfperl.h, doesn't include interface_class stuff 22#include "global.h" // bug in cfperl.h, doesn't include interface_class stuff
26#include "logger.h" 23#include "logger.h"
27#include "cfperl.h" 24#include "cfperl.h"
28#include "kw_hash.h" 25#include "kw_hash.h"
29 26
30object_freezer::object_freezer () 27object_freezer::object_freezer ()
31: dynbuf (128 * 1024, 64 * 1024) 28: dynbuf_text (128 * 1024, 64 * 1024)
32{ 29{
33 av = newAV (); 30 av = newAV ();
34} 31}
35 32
36object_freezer::~object_freezer () 33object_freezer::~object_freezer ()
82 CALL_END; 79 CALL_END;
83 80
84 return res; 81 return res;
85} 82}
86 83
84#if 0
87void 85void
88fprintf (object_freezer &freezer, const char *format, ...) 86fprintf (object_freezer &freezer, const char *format, ...)
89{ 87{
90 va_list ap; 88 va_list ap;
91 89
103void 101void
104fputs (const char *s, object_freezer &freezer) 102fputs (const char *s, object_freezer &freezer)
105{ 103{
106 freezer.add (s); 104 freezer.add (s);
107} 105}
106#endif
108 107
109static const char thawer_eof[] = "\n\n\n\0\0\0"; 108static const char thawer_eof[] = "\n\n\n\0\0\0";
110 109
111object_thawer::object_thawer (const char *path) 110object_thawer::object_thawer (const char *path)
112: name (strdup (path)) 111: name (strdup (path))
172 171
173 SV **svp = av_fetch ((AV *)av, oid, 0); 172 SV **svp = av_fetch ((AV *)av, oid, 0);
174 173
175 if (!svp || !SvROK (*svp)) 174 if (!svp || !SvROK (*svp))
176 { 175 {
177 printf ("trying to thaw duplicate or never-issued oid %d, ignoring.\n", oid); 176 LOG (llevError, "trying to thaw duplicate or never-issued oid %d, ignoring.\n", oid);
178 return; 177 return;
179 } 178 }
180 179
181 if (!SvROK (*svp)) 180 if (!SvROK (*svp))
182 { 181 {
183 LOG (llevError, "deserialised perl object is not an RV"); 182 LOG (llevError, "deserialised perl object is not an RV\n");
184 return; 183 return;
185 } 184 }
186 185
187 HV *hv = (HV *)SvRV (*svp); 186 HV *hv = (HV *)SvRV (*svp);
188 187
189 if (SvTYPE (hv) != SVt_PVHV) 188 if (SvTYPE (hv) != SVt_PVHV)
190 { 189 {
191 LOG (llevError, "deserialised perl object is not a PVHV"); 190 LOG (llevError, "deserialised perl object is not a PVHV\n");
192 return; 191 return;
193 } 192 }
194 193
195 if (obj->self) 194 if (obj->self)
196 { 195 {
297 296
298 for (;;) 297 for (;;)
299 { 298 {
300 char *p = line; 299 char *p = line;
301 300
301 if (*p <= ' ')
302 {
303 // skip whitespace (only some files need this)
304 while (*p == ' ' || *p == '\t')
305 p++;
306
307 line = p;
308 }
309
302 if (!*p) 310 if (!*p)
303 { 311 {
304 kw = KW_EOF; 312 kw = KW_EOF;
305 break; 313 break;
306 } 314 }
309 while (*p > ' ') 317 while (*p > ' ')
310 p++; 318 p++;
311 319
312 int klen = p - line; 320 int klen = p - line;
313 321
322 value_nn = "";
323 value = 0;
324
314 if (*p++ != '\n') 325 if (*p++ != '\n')
315 { 326 {
316 // parse value 327 // parse value
317 while (*(unsigned char *)p <= ' ' && *p != '\n') // skip 0x01 .. 0x20 328 while (*(unsigned char *)p <= ' ' && *p != '\n')
318 ++p; 329 ++p;
319 330
320 value = p; 331 value_nn = value = p;
321 332
322 while (*p != '\n') 333 while (*p != '\n')
323 p++; 334 p++;
324 335
325 *p++ = 0; 336 *p++ = 0;
326 } 337 }
327 else
328 value = 0;
329 338
330 ++linenum; 339 ++linenum;
331 line [klen] = 0; 340 line [klen] = 0;
332 keyword_idx *kw_idx = kw_lex::match (line, klen); 341 keyword_idx *kw_idx = kw_lex::match (line, klen);
333
334 //printf ("KV %d<%s,%s>\n", kw ? kw->index : 0, line, value);//D
335 342
336 kw_str = line; 343 kw_str = line;
337 line = p; 344 line = p;
338 345
339 if (kw_idx) 346 if (kw_idx)
366 373
367 next (); 374 next ();
368} 375}
369 376
370void 377void
371object_thawer::get (shstr &sh) const
372{
373 if (value)
374 sh = value;
375 else
376 {
377 sh = "<value missing>";
378 LOG (llevError, "keyword \"%s\" requires value, substituting with <value missing>\n", kw_str);//TODO: add filename
379 }
380}
381
382void
383object_thawer::get_ml (keyword kend, shstr &sh) 378object_thawer::get_ml (keyword kend, shstr &sh)
384{ 379{
385 char kw[128]; 380 char kw[128];
386 381
387 int klen = keyword_len [kend]; 382 int klen = keyword_len [kend];
431} 426}
432 427
433sint32 428sint32
434object_thawer::get_sint32 () const 429object_thawer::get_sint32 () const
435{ 430{
436 char *p = value; 431 char *p = value_nn;
437
438 if (!p)
439 return 0;
440 432
441 sint32 val = 0; 433 sint32 val = 0;
442 bool negate; 434 bool negate;
443 435
444 if (*p == '-') 436 if (*p == '-')
457 while (*p); 449 while (*p);
458 450
459 return negate ? -val : val; 451 return negate ? -val : val;
460} 452}
461 453
462sint64
463object_thawer::get_sint64 () const
464{
465 return value ? atoll (value) : 0;
466}
467
468double
469object_thawer::get_double () const
470{
471 return value ? atof (value) : 0;
472}
473

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines