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.4 by root, Sun Jan 7 02:39:14 2007 UTC vs.
Revision 1.8 by root, Thu Feb 1 19:15:39 2007 UTC

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 117
117 if (path) 118 if (path)
118 { 119 {
119 CALL_BEGIN (1); 120 CALL_BEGIN (1);
120 CALL_ARG_SV (newSVpv (path, 0)); 121 CALL_ARG_SV (newSVpv (path, 0));
186 187
187 if (obj->self) 188 if (obj->self)
188 { 189 {
189 // the hard way(?) 190 // the hard way(?)
190 191
191 // the dirty blues: "just" swap the XPVHV's 192 CALL_BEGIN (2);
192 swap (SvANY (obj->self), SvANY (hv)); 193 CALL_ARG_SV (newRV_inc ((SV *)obj->self));
193 194 CALL_ARG_SV (newRV_inc ((SV *)hv));
194 // do not swap magic, though 195 PUTBACK;
195 swap (SvMAGIC (obj->self), SvMAGIC (hv)); 196 call_method ("thawer_merge", G_DISCARD | G_EVAL);
197 SPAGAIN;
198 CALL_END;
196 } 199 }
197 else 200 else
198 { 201 {
199 // the easy way(?) 202 // the easy way(?)
200 203
201 obj->self = hv; 204 obj->self = hv;
202 SvRV_set (*svp, &PL_sv_undef); 205 SvRV_set (*svp, &PL_sv_undef);
203 206
204 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0); 207 sv_magicext ((SV *)obj->self, 0, PERL_MAGIC_ext, &attachable::vtbl, (char *)obj, 0);
205
206 // borrow a refcount for the perl object
207 obj->flags |= attachable::F_BORROWED;
208 obj->refcnt_dec ();
209 } 208 }
210 209
211 obj->reattach (); 210 obj->reattach ();
212} 211}
213 212
217 if (av) SvREFCNT_dec (av); 216 if (av) SvREFCNT_dec (av);
218 217
219 free ((void *)name); 218 free ((void *)name);
220} 219}
221 220
221//TODO: remove
222char * 222char *
223fgets (char *s, int n, object_thawer &thawer) 223fgets (char *s, int n, object_thawer &thawer)
224{ 224{
225 char *p = thawer.line; 225 char *p = thawer.line;
226 char *q = s; 226 char *q = s;
234 break; 234 break;
235 235
236 *q++ = *p; 236 *q++ = *p;
237 237
238 if (*p++ == '\n') 238 if (*p++ == '\n')
239 {
240 ++thawer.linenum;
239 break; 241 break;
242 }
240 } 243 }
241 244
242 *q = 0; 245 *q = 0;
243 thawer.line = p; 246 thawer.line = p;
244 247
245 return s == q ? 0 : s; 248 return s == q ? 0 : s;
249}
250
251bool
252object_thawer::parse_error (keyword kw, const char *type, const char *name, bool skip)
253{
254 if (!type) type = "file section";
255 if (!name) name = "generic";
256
257 switch (kw)
258 {
259 case KW_EOF:
260 LOG (llevError, "%s:%d end of file while reading %s '%s', aborting load.\n",
261 this->name, linenum, type, name);
262 return false;
263
264 case KW_ERROR:
265 LOG (llevError, "%s:%d errornous line (%s) while reading %s '%s', aborting load.\n",
266 this->name, linenum,
267 last_keyword ? last_keyword : "<null>",
268 type, name);
269 return false;
270
271 default:
272 LOG (llevError, "%s:%d unexpected line (%s) while reading %s '%s', %s.\n",
273 this->name, linenum,
274 last_keyword ? last_keyword : "<null>",
275 last_value ? last_value : "<null>",
276 type, name,
277 skip ? "skipping line" : "aborting load");
278 return skip;
279 }
246} 280}
247 281
248keyword 282keyword
249object_thawer::get_kv () 283object_thawer::get_kv ()
250{ 284{
278 *p++ = 0; 312 *p++ = 0;
279 } 313 }
280 else 314 else
281 last_value = 0; 315 last_value = 0;
282 316
317 ++linenum;
283 line [klen] = 0; 318 line [klen] = 0;
284 keyword_idx *kw = kw_lex::match (line, klen); 319 keyword_idx *kw = kw_lex::match (line, klen);
285 320
286 //printf ("KV %d<%s,%s>\n", kw ? kw->index : 0, line, last_value);//D 321 //printf ("KV %d<%s,%s>\n", kw ? kw->index : 0, line, last_value);//D
287 322
316 if (last_value) 351 if (last_value)
317 sh = last_value; 352 sh = last_value;
318 else 353 else
319 { 354 {
320 sh = "<value missing>"; 355 sh = "<value missing>";
321 LOG (llevError, "keyword requires value: <%.320s>\n", line);//TODO: add filename 356 LOG (llevError, "keyword \"%s\" requires value, substituting with <value missing>\n", last_keyword);//TODO: add filename
322 } 357 }
323} 358}
324 359
325void 360void
326object_thawer::get_ml (keyword kend, shstr &sh) 361object_thawer::get_ml (keyword kend, shstr &sh)
331 366
332 kw [0] = '\n'; 367 kw [0] = '\n';
333 memcpy (kw + 1, keyword_str [kend], klen); 368 memcpy (kw + 1, keyword_str [kend], klen);
334 kw [klen + 1] = '\n'; 369 kw [klen + 1] = '\n';
335 kw [klen + 2] = 0; 370 kw [klen + 2] = 0;
371
372 ++linenum;
336 373
337 // first test for completely empty msg... "endXXX\n" 374 // first test for completely empty msg... "endXXX\n"
338 if (!strncmp (line, kw + 1, klen + 1)) 375 if (!strncmp (line, kw + 1, klen + 1))
339 { 376 {
340 sh = 0; 377 sh = 0;
356 } 393 }
357 394
358 *end = 0; 395 *end = 0;
359 sh = line; 396 sh = line;
360 397
398 // count line numbers
399 while (line < end)
400 linenum += *line++ == '\n';
401
361 line = end + keyword_len [kend] + 1; 402 line += keyword_len [kend];
362 403
363 while (*line++ != '\n') 404 while (*line++ != '\n')
364 ; 405 ;
406
407 ++linenum;
365 } 408 }
366} 409}
367 410
368sint32 411sint32
369object_thawer::get_sint32 () const 412object_thawer::get_sint32 () const

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines