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.10 by root, Thu Feb 15 21:07:49 2007 UTC

108object_thawer::object_thawer (const char *path) 108object_thawer::object_thawer (const char *path)
109: name (strdup (path)) 109: name (strdup (path))
110{ 110{
111 static const char eof[] = "\n\n\n\0\0\0"; 111 static const char eof[] = "\n\n\n\0\0\0";
112 112
113 av = 0; 113 av = 0;
114 text = 0; 114 text = 0;
115 line = 0; 115 line = 0;
116 linenum = 0; 116 linenum = 0;
117
118 kw = KW_ERROR;
119 kw_str = 0;
120 value = 0;
117 121
118 if (path) 122 if (path)
119 { 123 {
120 CALL_BEGIN (1); 124 CALL_BEGIN (1);
121 CALL_ARG_SV (newSVpv (path, 0)); 125 CALL_ARG_SV (newSVpv (path, 0));
247 251
248 return s == q ? 0 : s; 252 return s == q ? 0 : s;
249} 253}
250 254
251bool 255bool
252object_thawer::parse_error (keyword kw, const char *type, const char *name, bool skip) 256object_thawer::parse_error (const char *type, const char *name, bool skip)
253{ 257{
254 if (!type) type = "file section"; 258 if (!type) type = "file section";
255 if (!name) name = "generic"; 259 if (!name) name = "generic";
256 260
257 switch (kw) 261 switch (kw)
260 LOG (llevError, "%s:%d end of file while reading %s '%s', aborting load.\n", 264 LOG (llevError, "%s:%d end of file while reading %s '%s', aborting load.\n",
261 this->name, linenum, type, name); 265 this->name, linenum, type, name);
262 return false; 266 return false;
263 267
264 case KW_ERROR: 268 case KW_ERROR:
265 LOG (llevError, "%s:%d errornous line (%s) while reading %s '%s', aborting load.\n", 269 LOG (llevError, "%s:%d error while reading %s '%s', at '%s', aborting load.\n",
266 this->name, linenum, 270 this->name, linenum,
267 last_keyword ? last_keyword : "<null>",
268 type, name); 271 type, name,
272 kw_str ? kw_str : "<file load>");
269 return false; 273 return false;
270 274
271 default: 275 default:
272 LOG (llevError, "%s:%d unexpected line (%s) while reading %s '%s', %s.\n", 276 LOG (llevError, "%s:%d unexpected line (%s %s) while reading %s '%s', %s.\n",
273 this->name, linenum, 277 this->name, linenum,
274 last_keyword ? last_keyword : "<null>", 278 kw_str ? kw_str : "<null>",
275 last_value ? last_value : "<null>", 279 value ? value : "<null>",
276 type, name, 280 type, name,
277 skip ? "skipping line" : "aborting load"); 281 skip ? "skipping line" : "aborting load");
278 return skip; 282 return skip;
279 } 283 }
280} 284}
281 285
282keyword 286void
283object_thawer::get_kv () 287object_thawer::next_kv ()
284{ 288{
285 if (!line) 289 if (!line)
286 return KW_EOF; 290 {
291 kw = KW_ERROR;
292 return;
293 }
287 294
288 for (;;) 295 for (;;)
289 { 296 {
290 char *p = line; 297 char *p = line;
291 298
292 if (!*p) 299 if (!*p)
293 return KW_EOF; 300 {
301 kw = KW_EOF;
302 break;
303 }
294 304
295 // parse keyword 305 // parse keyword
296 while (*p > ' ') 306 while (*p > ' ')
297 p++; 307 p++;
298 308
302 { 312 {
303 // parse value 313 // parse value
304 while (*(unsigned char *)p <= ' ' && *p != '\n') // skip 0x01 .. 0x20 314 while (*(unsigned char *)p <= ' ' && *p != '\n') // skip 0x01 .. 0x20
305 ++p; 315 ++p;
306 316
307 last_value = p; 317 value = p;
308 318
309 while (*p != '\n') 319 while (*p != '\n')
310 p++; 320 p++;
311 321
312 *p++ = 0; 322 *p++ = 0;
313 } 323 }
314 else 324 else
315 last_value = 0; 325 value = 0;
316 326
317 ++linenum; 327 ++linenum;
318 line [klen] = 0; 328 line [klen] = 0;
319 keyword_idx *kw = kw_lex::match (line, klen); 329 keyword_idx *kw_idx = kw_lex::match (line, klen);
320 330
321 //printf ("KV %d<%s,%s>\n", kw ? kw->index : 0, line, last_value);//D 331 //printf ("KV %d<%s,%s>\n", kw ? kw->index : 0, line, value);//D
322 332
323 last_keyword = line; 333 kw_str = line;
324 line = p; 334 line = p;
325 335
326 if (kw) 336 if (kw_idx)
327 return kw->index; 337 {
338 kw = kw_idx->index;
339 break;
340 }
328 else if (!*last_keyword || *last_keyword == '#') 341 else if (!*kw_str || *kw_str == '#')
329 ; // empty/comment line 342 ; // empty/comment line
330 else 343 else
344 {
331 return KW_ERROR; 345 kw = KW_ERROR;
346 break;
347 }
332 } 348 }
333} 349}
334 350
335void 351void
336object_thawer::skip_kv (keyword kw) 352object_thawer::skip_kv ()
337{ 353{
338 shstr ml; 354 shstr ml;
339 355
340 switch (kw) 356 switch (kw)
341 { 357 {
342 case KW_msg: get_ml (KW_endmsg , ml); break; 358 case KW_msg: get_ml (KW_endmsg , ml); break;
343 case KW_lore: get_ml (KW_endlore , ml); break; 359 case KW_lore: get_ml (KW_endlore , ml); break;
344 case KW_maplore: get_ml (KW_endmaplore, ml); break; 360 case KW_maplore: get_ml (KW_endmaplore, ml); break;
345 } 361 }
362
363 next_kv ();
346} 364}
347 365
348void 366void
349object_thawer::get (shstr &sh) const 367object_thawer::get (shstr &sh) const
350{ 368{
351 if (last_value) 369 if (value)
352 sh = last_value; 370 sh = value;
353 else 371 else
354 { 372 {
355 sh = "<value missing>"; 373 sh = "<value missing>";
356 LOG (llevError, "keyword \"%s\" requires value, substituting with <value missing>\n", last_keyword);//TODO: add filename 374 LOG (llevError, "keyword \"%s\" requires value, substituting with <value missing>\n", kw_str);//TODO: add filename
357 } 375 }
358} 376}
359 377
360void 378void
361object_thawer::get_ml (keyword kend, shstr &sh) 379object_thawer::get_ml (keyword kend, shstr &sh)
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;
415 433
416 if (!p) 434 if (!p)
417 return 0; 435 return 0;
418 436
419 sint32 val = 0; 437 sint32 val = 0;
438} 456}
439 457
440sint64 458sint64
441object_thawer::get_sint64 () const 459object_thawer::get_sint64 () const
442{ 460{
443 return last_value ? atoll (last_value) : 0; 461 return value ? atoll (value) : 0;
444} 462}
445 463
446double 464double
447object_thawer::get_double () const 465object_thawer::get_double () const
448{ 466{
449 return last_value ? atof (last_value) : 0; 467 return value ? atof (value) : 0;
450} 468}
451 469

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines