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.8 by root, Thu Feb 1 19:15:39 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 ()
61 CALL_ARG_SV (newSVpv (path, 0)); 59 CALL_ARG_SV (newSVpv (path, 0));
62 CALL_ARG_SV (newRV_noinc (newSVpvn ((char *)linearise (), size ()))); 60 CALL_ARG_SV (newRV_noinc (newSVpvn ((char *)linearise (), size ())));
63 CALL_ARG_SV (newRV_inc ((SV *)av)); 61 CALL_ARG_SV (newRV_inc ((SV *)av));
64 CALL_CALL ("cf::object_freezer_save", G_VOID | G_DISCARD); 62 CALL_CALL ("cf::object_freezer_save", G_VOID | G_DISCARD);
65 CALL_END; 63 CALL_END;
64
65 return 1;
66} 66}
67 67
68char * 68char *
69object_freezer::as_string () 69object_freezer::as_string ()
70{ 70{
80 CALL_END; 80 CALL_END;
81 81
82 return res; 82 return res;
83} 83}
84 84
85int 85#if 0
86void
86fprintf (object_freezer &freezer, const char *format, ...) 87fprintf (object_freezer &freezer, const char *format, ...)
87{ 88{
88 va_list ap; 89 va_list ap;
89 90
90 va_start (ap, format); 91 va_start (ap, format);
95 freezer.alloc (len); 96 freezer.alloc (len);
96 97
97 va_end (ap); 98 va_end (ap);
98} 99}
99 100
100int 101// XXX: function not returning an int
102void
101fputs (const char *s, object_freezer &freezer) 103fputs (const char *s, object_freezer &freezer)
102{ 104{
103 freezer.add (s); 105 freezer.add (s);
104} 106}
107#endif
105 108
106static const char thawer_eof[] = "\n\n\n\0\0\0"; 109static const char thawer_eof[] = "\n\n\n\0\0\0";
107 110
108object_thawer::object_thawer (const char *path) 111object_thawer::object_thawer (const char *path)
109: name (strdup (path)) 112: name (strdup (path))
110{ 113{
111 static const char eof[] = "\n\n\n\0\0\0"; 114 static const char eof[] = "\n\n\n\0\0\0";
112 115
113 av = 0; 116 av = 0;
114 text = 0; 117 text = 0;
115 line = 0; 118 line = 0;
116 linenum = 0; 119 linenum = 0;
120
121 kw = KW_ERROR;
122 kw_str = 0;
123 value = 0;
117 124
118 if (path) 125 if (path)
119 { 126 {
120 CALL_BEGIN (1); 127 CALL_BEGIN (1);
121 CALL_ARG_SV (newSVpv (path, 0)); 128 CALL_ARG_SV (newSVpv (path, 0));
165 172
166 SV **svp = av_fetch ((AV *)av, oid, 0); 173 SV **svp = av_fetch ((AV *)av, oid, 0);
167 174
168 if (!svp || !SvROK (*svp)) 175 if (!svp || !SvROK (*svp))
169 { 176 {
170 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);
171 return; 178 return;
172 } 179 }
173 180
174 if (!SvROK (*svp)) 181 if (!SvROK (*svp))
175 { 182 {
176 LOG (llevError, "deserialised perl object is not an RV"); 183 LOG (llevError, "deserialised perl object is not an RV\n");
177 return; 184 return;
178 } 185 }
179 186
180 HV *hv = (HV *)SvRV (*svp); 187 HV *hv = (HV *)SvRV (*svp);
181 188
182 if (SvTYPE (hv) != SVt_PVHV) 189 if (SvTYPE (hv) != SVt_PVHV)
183 { 190 {
184 LOG (llevError, "deserialised perl object is not a PVHV"); 191 LOG (llevError, "deserialised perl object is not a PVHV\n");
185 return; 192 return;
186 } 193 }
187 194
188 if (obj->self) 195 if (obj->self)
189 { 196 {
247 254
248 return s == q ? 0 : s; 255 return s == q ? 0 : s;
249} 256}
250 257
251bool 258bool
252object_thawer::parse_error (keyword kw, const char *type, const char *name, bool skip) 259object_thawer::parse_error (const char *type, const char *name, bool skip)
253{ 260{
254 if (!type) type = "file section"; 261 if (!type) type = "file section";
255 if (!name) name = "generic"; 262 if (!name) name = "generic";
256 263
257 switch (kw) 264 switch (kw)
260 LOG (llevError, "%s:%d end of file while reading %s '%s', aborting load.\n", 267 LOG (llevError, "%s:%d end of file while reading %s '%s', aborting load.\n",
261 this->name, linenum, type, name); 268 this->name, linenum, type, name);
262 return false; 269 return false;
263 270
264 case KW_ERROR: 271 case KW_ERROR:
265 LOG (llevError, "%s:%d errornous line (%s) while reading %s '%s', aborting load.\n", 272 LOG (llevError, "%s:%d error while reading %s '%s', at '%s', aborting load.\n",
266 this->name, linenum, 273 this->name, linenum,
267 last_keyword ? last_keyword : "<null>",
268 type, name); 274 type, name,
275 kw_str ? kw_str : "<file load>");
269 return false; 276 return false;
270 277
271 default: 278 default:
272 LOG (llevError, "%s:%d unexpected line (%s) while reading %s '%s', %s.\n", 279 LOG (llevError, "%s:%d unexpected line (%s %s) while reading %s '%s', %s.\n",
273 this->name, linenum, 280 this->name, linenum,
274 last_keyword ? last_keyword : "<null>", 281 kw_str ? kw_str : "<null>",
275 last_value ? last_value : "<null>", 282 value ? value : "<null>",
276 type, name, 283 type, name,
277 skip ? "skipping line" : "aborting load"); 284 skip ? "skipping line" : "aborting load");
278 return skip; 285 return skip;
279 } 286 }
280} 287}
281 288
282keyword 289void
283object_thawer::get_kv () 290object_thawer::next ()
284{ 291{
285 if (!line) 292 if (!line)
286 return KW_EOF; 293 {
294 kw = KW_ERROR;
295 return;
296 }
287 297
288 for (;;) 298 for (;;)
289 { 299 {
290 char *p = line; 300 char *p = line;
291 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
292 if (!*p) 311 if (!*p)
293 return KW_EOF; 312 {
313 kw = KW_EOF;
314 break;
315 }
294 316
295 // parse keyword 317 // parse keyword
296 while (*p > ' ') 318 while (*p > ' ')
297 p++; 319 p++;
298 320
299 int klen = p - line; 321 int klen = p - line;
300 322
323 value_nn = "";
324 value = 0;
325
301 if (*p++ != '\n') 326 if (*p++ != '\n')
302 { 327 {
303 // parse value 328 // parse value
304 while (*(unsigned char *)p <= ' ' && *p != '\n') // skip 0x01 .. 0x20 329 while (*(unsigned char *)p <= ' ' && *p != '\n')
305 ++p; 330 ++p;
306 331
307 last_value = p; 332 value_nn = value = p;
308 333
309 while (*p != '\n') 334 while (*p != '\n')
310 p++; 335 p++;
311 336
312 *p++ = 0; 337 *p++ = 0;
313 } 338 }
314 else
315 last_value = 0;
316 339
317 ++linenum; 340 ++linenum;
318 line [klen] = 0; 341 line [klen] = 0;
319 keyword_idx *kw = kw_lex::match (line, klen); 342 keyword_idx *kw_idx = kw_lex::match (line, klen);
320 343
321 //printf ("KV %d<%s,%s>\n", kw ? kw->index : 0, line, last_value);//D 344 kw_str = line;
322
323 last_keyword = line;
324 line = p; 345 line = p;
325 346
326 if (kw) 347 if (kw_idx)
327 return kw->index; 348 {
349 kw = kw_idx->index;
350 break;
351 }
328 else if (!*last_keyword || *last_keyword == '#') 352 else if (!*kw_str || *kw_str == '#')
329 ; // empty/comment line 353 ; // empty/comment line
330 else 354 else
355 {
331 return KW_ERROR; 356 kw = KW_ERROR;
357 break;
358 }
332 } 359 }
333} 360}
334 361
335void 362void
336object_thawer::skip_kv (keyword kw) 363object_thawer::skip ()
337{ 364{
338 shstr ml; 365 shstr ml;
339 366
340 switch (kw) 367 switch (kw)
341 { 368 {
342 case KW_msg: get_ml (KW_endmsg , ml); break; 369 case KW_msg: get_ml (KW_endmsg , ml); break;
343 case KW_lore: get_ml (KW_endlore , ml); break; 370 case KW_lore: get_ml (KW_endlore , ml); break;
344 case KW_maplore: get_ml (KW_endmaplore, ml); break; 371 case KW_maplore: get_ml (KW_endmaplore, ml); break;
372 default: break;
345 } 373 }
374
375 next ();
346} 376}
347 377
348void
349object_thawer::get (shstr &sh) const
350{
351 if (last_value)
352 sh = last_value;
353 else
354 {
355 sh = "<value missing>";
356 LOG (llevError, "keyword \"%s\" requires value, substituting with <value missing>\n", last_keyword);//TODO: add filename
357 }
358}
359
360void 378void
361object_thawer::get_ml (keyword kend, shstr &sh) 379object_thawer::get_ml (keyword kend, shstr &sh)
362{ 380{
363 char kw[128]; 381 char kw[128];
364 382
409} 427}
410 428
411sint32 429sint32
412object_thawer::get_sint32 () const 430object_thawer::get_sint32 () const
413{ 431{
414 char *p = last_value; 432 char *p = value_nn;
415
416 if (!p)
417 return 0;
418 433
419 sint32 val = 0; 434 sint32 val = 0;
420 bool negate; 435 bool negate;
421 436
422 if (*p == '-') 437 if (*p == '-')
435 while (*p); 450 while (*p);
436 451
437 return negate ? -val : val; 452 return negate ? -val : val;
438} 453}
439 454
440sint64
441object_thawer::get_sint64 () const
442{
443 return last_value ? atoll (last_value) : 0;
444}
445
446double
447object_thawer::get_double () const
448{
449 return last_value ? atof (last_value) : 0;
450}
451

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines