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.14 by pippijn, Fri Mar 2 10:15:40 2007 UTC

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));
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
292 if (!*p) 302 if (!*p)
293 return KW_EOF; 303 {
304 kw = KW_EOF;
305 break;
306 }
294 307
295 // parse keyword 308 // parse keyword
296 while (*p > ' ') 309 while (*p > ' ')
297 p++; 310 p++;
298 311
302 { 315 {
303 // parse value 316 // parse value
304 while (*(unsigned char *)p <= ' ' && *p != '\n') // skip 0x01 .. 0x20 317 while (*(unsigned char *)p <= ' ' && *p != '\n') // skip 0x01 .. 0x20
305 ++p; 318 ++p;
306 319
307 last_value = p; 320 value = p;
308 321
309 while (*p != '\n') 322 while (*p != '\n')
310 p++; 323 p++;
311 324
312 *p++ = 0; 325 *p++ = 0;
313 } 326 }
314 else 327 else
315 last_value = 0; 328 value = 0;
316 329
317 ++linenum; 330 ++linenum;
318 line [klen] = 0; 331 line [klen] = 0;
319 keyword_idx *kw = kw_lex::match (line, klen); 332 keyword_idx *kw_idx = kw_lex::match (line, klen);
320 333
321 //printf ("KV %d<%s,%s>\n", kw ? kw->index : 0, line, last_value);//D 334 //printf ("KV %d<%s,%s>\n", kw ? kw->index : 0, line, value);//D
322 335
323 last_keyword = line; 336 kw_str = line;
324 line = p; 337 line = p;
325 338
326 if (kw) 339 if (kw_idx)
327 return kw->index; 340 {
341 kw = kw_idx->index;
342 break;
343 }
328 else if (!*last_keyword || *last_keyword == '#') 344 else if (!*kw_str || *kw_str == '#')
329 ; // empty/comment line 345 ; // empty/comment line
330 else 346 else
347 {
331 return KW_ERROR; 348 kw = KW_ERROR;
349 break;
350 }
332 } 351 }
333} 352}
334 353
335void 354void
336object_thawer::skip_kv (keyword kw) 355object_thawer::skip ()
337{ 356{
338 shstr ml; 357 shstr ml;
339 358
340 switch (kw) 359 switch (kw)
341 { 360 {
342 case KW_msg: get_ml (KW_endmsg , ml); break; 361 case KW_msg: get_ml (KW_endmsg , ml); break;
343 case KW_lore: get_ml (KW_endlore , ml); break; 362 case KW_lore: get_ml (KW_endlore , ml); break;
344 case KW_maplore: get_ml (KW_endmaplore, ml); break; 363 case KW_maplore: get_ml (KW_endmaplore, ml); break;
364 default: break;
345 } 365 }
366
367 next ();
346} 368}
347 369
348void 370void
349object_thawer::get (shstr &sh) const 371object_thawer::get (shstr &sh) const
350{ 372{
351 if (last_value) 373 if (value)
352 sh = last_value; 374 sh = value;
353 else 375 else
354 { 376 {
355 sh = "<value missing>"; 377 sh = "<value missing>";
356 LOG (llevError, "keyword \"%s\" requires value, substituting with <value missing>\n", last_keyword);//TODO: add filename 378 LOG (llevError, "keyword \"%s\" requires value, substituting with <value missing>\n", kw_str);//TODO: add filename
357 } 379 }
358} 380}
359 381
360void 382void
361object_thawer::get_ml (keyword kend, shstr &sh) 383object_thawer::get_ml (keyword kend, shstr &sh)
409} 431}
410 432
411sint32 433sint32
412object_thawer::get_sint32 () const 434object_thawer::get_sint32 () const
413{ 435{
414 char *p = last_value; 436 char *p = value;
415 437
416 if (!p) 438 if (!p)
417 return 0; 439 return 0;
418 440
419 sint32 val = 0; 441 sint32 val = 0;
438} 460}
439 461
440sint64 462sint64
441object_thawer::get_sint64 () const 463object_thawer::get_sint64 () const
442{ 464{
443 return last_value ? atoll (last_value) : 0; 465 return value ? atoll (value) : 0;
444} 466}
445 467
446double 468double
447object_thawer::get_double () const 469object_thawer::get_double () const
448{ 470{
449 return last_value ? atof (last_value) : 0; 471 return value ? atof (value) : 0;
450} 472}
451 473

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines