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.38 by root, Thu Apr 15 04:56:47 2010 UTC vs.
Revision 1.42 by root, Thu Apr 29 12:24:04 2010 UTC

104} 104}
105#endif 105#endif
106 106
107static const char thawer_eof[] = "\n\n\n\0\0\0"; 107static const char thawer_eof[] = "\n\n\n\0\0\0";
108 108
109bool object_thawer::errors_are_fatal = true;
110
109object_thawer::object_thawer (const char *path) 111object_thawer::object_thawer (const char *data, AV *perlav)
112: name (strdup ("(memory stream)"))
113{
114 av = perlav;
115 text = newSVpv (data, 0);
116 sv_catpv (text, thawer_eof);
117 line = SvPVbyte_nolen (text);
118 next ();
119}
120
121object_thawer::object_thawer (const_utf8_string path)
122{
123 new_from_path (path);
124}
125
126// convenience constructor
127object_thawer::object_thawer (const_utf8_string dir, const_utf8_string file)
128{
129 new_from_path (format ("%s/%s", dir, file));
130}
131
132void
133object_thawer::new_from_path (const_utf8_string path)
134{
110: name (strdup (path)) 135 name = strdup (path);
111{
112 av = 0; 136 av = 0;
113 text = 0; 137 text = 0;
114 line = 0; 138 line = 0;
115 linenum = 0; 139 linenum = 0;
116 140
150 174
151 CALL_END; 175 CALL_END;
152 } 176 }
153} 177}
154 178
155object_thawer::object_thawer (const char *data, AV *perlav)
156: name (strdup ("(memory stream)"))
157{
158 av = perlav;
159 text = newSVpv (data, 0);
160 sv_catpv (text, thawer_eof);
161 line = SvPVbyte_nolen (text);
162 next ();
163}
164
165void 179void
166object_thawer::get (attachable *obj, int oid) 180object_thawer::get (attachable *obj, int oid)
167{ 181{
168 if (!av || oid < 0) // this is actually an error of sorts 182 if (!av || oid < 0) // this is actually an error of sorts
169 return; 183 return;
223 resolve_delayed_derefs (false); 237 resolve_delayed_derefs (false);
224 238
225 free ((void *)name); 239 free ((void *)name);
226} 240}
227 241
242static void
243error_out ()
244{
245 if (object_thawer::errors_are_fatal)
246 {
247 LOG (llevError, "(parse errors at this time are fatal, exiting)");
248 exit (1);
249 }
250}
251
228void 252void
229object_thawer::parse_warn (const char *msg) 253object_thawer::parse_warn (const char *msg) const
230{ 254{
231 LOG (llevWarn, "%s:%d, \"%s %s\": %s\n", 255 LOG (llevWarn, "%s:%d, \"%s %s\": %s\n",
232 this->name, linenum, 256 this->name, linenum,
233 kw_str ? kw_str : "<null>", 257 kw_str ? kw_str : "<null>",
234 value ? value : "<null>", 258 value ? value : "<null>",
235 msg); 259 msg);
236} 260}
237 261
238bool 262bool
239object_thawer::parse_error (const char *type, const char *name, bool skip) 263object_thawer::parse_error (const char *type, const char *name, bool skip) const
240{ 264{
241 if (!type) type = "file section"; 265 if (!type) type = "file section";
242 if (!name) name = "generic"; 266 if (!name) name = "generic";
243 267
244 switch (kw) 268 switch (kw)
245 { 269 {
246 case KW_EOF: 270 case KW_EOF:
247 LOG (llevError, "%s:%d end of file while reading %s '%s', aborting load.\n", 271 LOG (llevError, "%s:%d end of file while reading %s '%s', aborting load.\n",
248 this->name, linenum, type, name); 272 this->name, linenum, type, name);
273 error_out ();
249 return false; 274 return false;
250 275
251 case KW_ERROR: 276 case KW_ERROR:
252 LOG (llevError, "%s:%d error while reading %s '%s', at '%s', aborting load.\n", 277 LOG (llevError, "%s:%d error while reading %s '%s', at '%s', aborting load.\n",
253 this->name, linenum, 278 this->name, linenum,
254 type, name, 279 type, name,
255 kw_str ? kw_str : "<file load>"); 280 kw_str ? kw_str : "<file load>");
281 error_out ();
256 return false; 282 return false;
257 283
258 default: 284 default:
259 LOG (llevError, "%s:%d unexpected line (%s %s) while reading %s '%s', %s.\n", 285 LOG (llevError, "%s:%d unexpected line (%s %s) while reading %s '%s', %s.\n",
260 this->name, linenum, 286 this->name, linenum,
261 kw_str ? kw_str : "<null>", 287 kw_str ? kw_str : "<null>",
262 value ? value : "<null>", 288 value ? value : "<null>",
263 type, name, 289 type, name,
264 skip ? "skipping line" : "aborting load"); 290 skip ? "skipping line" : "aborting load");
291 error_out ();
265 return skip; 292 return skip;
266 } 293 }
267} 294}
268 295
269void 296void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines