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.18 by root, Mon Apr 30 05:54:14 2007 UTC

26#include "logger.h" 26#include "logger.h"
27#include "cfperl.h" 27#include "cfperl.h"
28#include "kw_hash.h" 28#include "kw_hash.h"
29 29
30object_freezer::object_freezer () 30object_freezer::object_freezer ()
31: dynbuf (128 * 1024, 64 * 1024) 31: dynbuf_text (128 * 1024, 64 * 1024)
32{ 32{
33 av = newAV (); 33 av = newAV ();
34} 34}
35 35
36object_freezer::~object_freezer () 36object_freezer::~object_freezer ()
61 CALL_ARG_SV (newSVpv (path, 0)); 61 CALL_ARG_SV (newSVpv (path, 0));
62 CALL_ARG_SV (newRV_noinc (newSVpvn ((char *)linearise (), size ()))); 62 CALL_ARG_SV (newRV_noinc (newSVpvn ((char *)linearise (), size ())));
63 CALL_ARG_SV (newRV_inc ((SV *)av)); 63 CALL_ARG_SV (newRV_inc ((SV *)av));
64 CALL_CALL ("cf::object_freezer_save", G_VOID | G_DISCARD); 64 CALL_CALL ("cf::object_freezer_save", G_VOID | G_DISCARD);
65 CALL_END; 65 CALL_END;
66
67 return 1;
66} 68}
67 69
68char * 70char *
69object_freezer::as_string () 71object_freezer::as_string ()
70{ 72{
80 CALL_END; 82 CALL_END;
81 83
82 return res; 84 return res;
83} 85}
84 86
85int 87void
86fprintf (object_freezer &freezer, const char *format, ...) 88fprintf (object_freezer &freezer, const char *format, ...)
87{ 89{
88 va_list ap; 90 va_list ap;
89 91
90 va_start (ap, format); 92 va_start (ap, format);
95 freezer.alloc (len); 97 freezer.alloc (len);
96 98
97 va_end (ap); 99 va_end (ap);
98} 100}
99 101
100int 102// XXX: function not returning an int
103void
101fputs (const char *s, object_freezer &freezer) 104fputs (const char *s, object_freezer &freezer)
102{ 105{
103 freezer.add (s); 106 freezer.add (s);
104} 107}
105 108
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 = 0;
324
301 if (*p++ != '\n') 325 if (*p++ != '\n')
302 { 326 {
303 // parse value 327 // parse value
304 while (*(unsigned char *)p <= ' ' && *p != '\n') // skip 0x01 .. 0x20 328 while (*(unsigned char *)p <= ' ' && *p != '\n')
305 ++p; 329 ++p;
306 330
307 last_value = p; 331 value = p;
308 332
309 while (*p != '\n') 333 while (*p != '\n')
310 p++; 334 p++;
311 335
312 *p++ = 0; 336 *p++ = 0;
313 } 337 }
314 else
315 last_value = 0;
316 338
317 ++linenum; 339 ++linenum;
318 line [klen] = 0; 340 line [klen] = 0;
319 keyword_idx *kw = kw_lex::match (line, klen); 341 keyword_idx *kw_idx = kw_lex::match (line, klen);
320 342
321 //printf ("KV %d<%s,%s>\n", kw ? kw->index : 0, line, last_value);//D 343 kw_str = line;
322
323 last_keyword = line;
324 line = p; 344 line = p;
325 345
326 if (kw) 346 if (kw_idx)
327 return kw->index; 347 {
348 kw = kw_idx->index;
349 break;
350 }
328 else if (!*last_keyword || *last_keyword == '#') 351 else if (!*kw_str || *kw_str == '#')
329 ; // empty/comment line 352 ; // empty/comment line
330 else 353 else
354 {
331 return KW_ERROR; 355 kw = KW_ERROR;
356 break;
357 }
332 } 358 }
333} 359}
334 360
335void 361void
336object_thawer::skip_kv (keyword kw) 362object_thawer::skip ()
337{ 363{
338 shstr ml; 364 shstr ml;
339 365
340 switch (kw) 366 switch (kw)
341 { 367 {
342 case KW_msg: get_ml (KW_endmsg , ml); break; 368 case KW_msg: get_ml (KW_endmsg , ml); break;
343 case KW_lore: get_ml (KW_endlore , ml); break; 369 case KW_lore: get_ml (KW_endlore , ml); break;
344 case KW_maplore: get_ml (KW_endmaplore, ml); break; 370 case KW_maplore: get_ml (KW_endmaplore, ml); break;
371 default: break;
345 } 372 }
373
374 next ();
346} 375}
347 376
348void 377void
349object_thawer::get (shstr &sh) const 378object_thawer::get (shstr &sh) const
350{ 379{
351 if (last_value) 380 if (value)
352 sh = last_value; 381 sh = value;
353 else 382 else
354 { 383 {
355 sh = "<value missing>"; 384 sh = "<value missing>";
356 LOG (llevError, "keyword \"%s\" requires value, substituting with <value missing>\n", last_keyword);//TODO: add filename 385 LOG (llevError, "keyword \"%s\" requires value, substituting with <value missing>\n", kw_str);//TODO: add filename
357 } 386 }
358} 387}
359 388
360void 389void
361object_thawer::get_ml (keyword kend, shstr &sh) 390object_thawer::get_ml (keyword kend, shstr &sh)
409} 438}
410 439
411sint32 440sint32
412object_thawer::get_sint32 () const 441object_thawer::get_sint32 () const
413{ 442{
414 char *p = last_value; 443 char *p = value;
415 444
416 if (!p) 445 if (!p)
417 return 0; 446 return 0;
418 447
419 sint32 val = 0; 448 sint32 val = 0;
438} 467}
439 468
440sint64 469sint64
441object_thawer::get_sint64 () const 470object_thawer::get_sint64 () const
442{ 471{
443 return last_value ? atoll (last_value) : 0; 472 return value ? atoll (value) : 0;
444} 473}
445 474
446double 475double
447object_thawer::get_double () const 476object_thawer::get_double () const
448{ 477{
449 return last_value ? atof (last_value) : 0; 478 return value ? atof (value) : 0;
450} 479}
451 480

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines