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.21 by root, Mon May 28 21:28:36 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 it
11 * it under the terms of the GNU General Public License as published by 7 * under the terms of the GNU General Public License as published by the Free
12 * the Free Software Foundation; either version 2 of the License, or 8 * Software Foundation; either version 2 of the License, or (at your option)
13 * (at your option) any later version. 9 * 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, but
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 * GNU General Public License for more details. 14 * 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 along
21 * along with this program; if not, write to the Free Software 17 * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51
22 * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 * The authors can be reached via e-mail to <crossfire@schmorp.de>
23 */ 21 */
24 22
25#include "global.h" // bug in cfperl.h, doesn't include interface_class stuff 23#include "global.h" // bug in cfperl.h, doesn't include interface_class stuff
26#include "logger.h" 24#include "logger.h"
27#include "cfperl.h" 25#include "cfperl.h"
28#include "kw_hash.h" 26#include "kw_hash.h"
29 27
30object_freezer::object_freezer () 28object_freezer::object_freezer ()
31: dynbuf (128 * 1024, 64 * 1024) 29: dynbuf_text (128 * 1024, 64 * 1024)
32{ 30{
33 av = newAV (); 31 av = newAV ();
34} 32}
35 33
36object_freezer::~object_freezer () 34object_freezer::~object_freezer ()
82 CALL_END; 80 CALL_END;
83 81
84 return res; 82 return res;
85} 83}
86 84
85#if 0
87void 86void
88fprintf (object_freezer &freezer, const char *format, ...) 87fprintf (object_freezer &freezer, const char *format, ...)
89{ 88{
90 va_list ap; 89 va_list ap;
91 90
103void 102void
104fputs (const char *s, object_freezer &freezer) 103fputs (const char *s, object_freezer &freezer)
105{ 104{
106 freezer.add (s); 105 freezer.add (s);
107} 106}
107#endif
108 108
109static const char thawer_eof[] = "\n\n\n\0\0\0"; 109static const char thawer_eof[] = "\n\n\n\0\0\0";
110 110
111object_thawer::object_thawer (const char *path) 111object_thawer::object_thawer (const char *path)
112: name (strdup (path)) 112: name (strdup (path))
172 172
173 SV **svp = av_fetch ((AV *)av, oid, 0); 173 SV **svp = av_fetch ((AV *)av, oid, 0);
174 174
175 if (!svp || !SvROK (*svp)) 175 if (!svp || !SvROK (*svp))
176 { 176 {
177 printf ("trying to thaw duplicate or never-issued oid %d, ignoring.\n", oid); 177 LOG (llevError, "trying to thaw duplicate or never-issued oid %d, ignoring.\n", oid);
178 return; 178 return;
179 } 179 }
180 180
181 if (!SvROK (*svp)) 181 if (!SvROK (*svp))
182 { 182 {
183 LOG (llevError, "deserialised perl object is not an RV"); 183 LOG (llevError, "deserialised perl object is not an RV\n");
184 return; 184 return;
185 } 185 }
186 186
187 HV *hv = (HV *)SvRV (*svp); 187 HV *hv = (HV *)SvRV (*svp);
188 188
189 if (SvTYPE (hv) != SVt_PVHV) 189 if (SvTYPE (hv) != SVt_PVHV)
190 { 190 {
191 LOG (llevError, "deserialised perl object is not a PVHV"); 191 LOG (llevError, "deserialised perl object is not a PVHV\n");
192 return; 192 return;
193 } 193 }
194 194
195 if (obj->self) 195 if (obj->self)
196 { 196 {
297 297
298 for (;;) 298 for (;;)
299 { 299 {
300 char *p = line; 300 char *p = line;
301 301
302 if (*p <= ' ')
303 {
304 // skip whitespace (only some files need this)
305 while (*p == ' ' || *p == '\t')
306 p++;
307
308 line = p;
309 }
310
302 if (!*p) 311 if (!*p)
303 { 312 {
304 kw = KW_EOF; 313 kw = KW_EOF;
305 break; 314 break;
306 } 315 }
309 while (*p > ' ') 318 while (*p > ' ')
310 p++; 319 p++;
311 320
312 int klen = p - line; 321 int klen = p - line;
313 322
323 value_nn = "";
324 value = 0;
325
314 if (*p++ != '\n') 326 if (*p++ != '\n')
315 { 327 {
316 // parse value 328 // parse value
317 while (*(unsigned char *)p <= ' ' && *p != '\n') // skip 0x01 .. 0x20 329 while (*(unsigned char *)p <= ' ' && *p != '\n')
318 ++p; 330 ++p;
319 331
320 value = p; 332 value_nn = value = p;
321 333
322 while (*p != '\n') 334 while (*p != '\n')
323 p++; 335 p++;
324 336
325 *p++ = 0; 337 *p++ = 0;
326 } 338 }
327 else
328 value = 0;
329 339
330 ++linenum; 340 ++linenum;
331 line [klen] = 0; 341 line [klen] = 0;
332 keyword_idx *kw_idx = kw_lex::match (line, klen); 342 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 343
336 kw_str = line; 344 kw_str = line;
337 line = p; 345 line = p;
338 346
339 if (kw_idx) 347 if (kw_idx)
366 374
367 next (); 375 next ();
368} 376}
369 377
370void 378void
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) 379object_thawer::get_ml (keyword kend, shstr &sh)
384{ 380{
385 char kw[128]; 381 char kw[128];
386 382
387 int klen = keyword_len [kend]; 383 int klen = keyword_len [kend];
431} 427}
432 428
433sint32 429sint32
434object_thawer::get_sint32 () const 430object_thawer::get_sint32 () const
435{ 431{
436 char *p = value; 432 char *p = value_nn;
437
438 if (!p)
439 return 0;
440 433
441 sint32 val = 0; 434 sint32 val = 0;
442 bool negate; 435 bool negate;
443 436
444 if (*p == '-') 437 if (*p == '-')
457 while (*p); 450 while (*p);
458 451
459 return negate ? -val : val; 452 return negate ? -val : val;
460} 453}
461 454
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