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.46 by root, Mon Oct 29 23:55:55 2012 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * 5 *
6 * Deliantra is free software: you can redistribute it and/or modify it under 6 * Deliantra is free software: you can redistribute it and/or modify it under
7 * the terms of the Affero GNU General Public License as published by the 7 * the terms of the Affero GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your 8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version. 9 * option) any later version.
10 * 10 *
11 * This program is distributed in the hope that it will be useful, 11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 * 15 *
16 * You should have received a copy of the Affero GNU General Public License 16 * You should have received a copy of the Affero GNU General Public License
17 * and the GNU General Public License along with this program. If not, see 17 * and the GNU General Public License along with this program. If not, see
18 * <http://www.gnu.org/licenses/>. 18 * <http://www.gnu.org/licenses/>.
19 * 19 *
20 * The authors can be reached via e-mail to <support@deliantra.net> 20 * The authors can be reached via e-mail to <support@deliantra.net>
21 */ 21 */
22 22
23#include "global.h" // bug in cfperl.h, doesn't include interface_class stuff 23#include "global.h" // bug in cfperl.h, doesn't include interface_class stuff
24#include "logger.h" 24#include "logger.h"
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 init ("(memory stream)");
115
116 av = perlav;
117 text = newSVpv (data, 0); sv_catpv (text, thawer_eof);
118 line = SvPVbyte_nolen (text);
119 next ();
120}
121
122object_thawer::object_thawer (const_utf8_string path)
123{
124 init_from_file (path);
125}
126
127// convenience constructor
128object_thawer::object_thawer (const_utf8_string dir, const_utf8_string file)
129{
130 init_from_file (format ("%s/%s", dir, file));
131}
132
133void
134object_thawer::init (const_utf8_string path)
135{
110: name (strdup (path)) 136 name = strdup (path);
111{
112 av = 0; 137 av = 0;
113 text = 0; 138 text = 0;
114 line = 0; 139 line = 0;
115 linenum = 0; 140 linenum = 0;
116 141
117 kw = KW_ERROR; 142 kw = KW_ERROR;
118 kw_str = 0; 143 kw_str = 0;
119 value = 0; 144 value = 0;
145}
120 146
147void
148object_thawer::init_from_file (const_utf8_string path)
149{
121 if (path) 150 init (path);
122 { 151
123 CALL_BEGIN (1); 152 CALL_BEGIN (1);
124 CALL_ARG_SV (newSVpv (path, 0)); 153 CALL_ARG_SV (newSVpv (path, 0));
125 CALL_CALL ("cf::object_thawer_load", G_ARRAY); 154 CALL_CALL ("cf::object_thawer_load", G_ARRAY);
126 155
127 if (count == 2) 156 if (count == 2)
128 { 157 {
129 // second value - perl objects 158 // second value - perl objects
130 { 159 {
131 SV *sv = POPs; 160 SV *sv = POPs;
132 if (SvROK (sv)) 161 if (SvROK (sv))
133 av = (AV *)SvREFCNT_inc (SvRV (sv)); 162 av = (AV *)SvREFCNT_inc (SvRV (sv));
134 } 163 }
135 164
136 // first value - text part, pad with 3 zeroes 165 // first value - text part, pad with 3 zeroes
137 { 166 {
138 SV *sv = POPs; 167 SV *sv = POPs;
139 STRLEN len; 168 STRLEN len;
140 char *sv_ = SvPVbyte (sv, len); 169 char *sv_ = SvPVbyte (sv, len);
141 text = newSV (len + sizeof (thawer_eof)); 170 text = newSV (len + sizeof (thawer_eof));
142 SvCUR_set (text, len + sizeof (thawer_eof)); 171 SvCUR_set (text, len + sizeof (thawer_eof));
143 memcpy (SvPVX (text), sv_, len); 172 memcpy (SvPVX (text), sv_, len);
144 memcpy (SvPVX (text) + len, thawer_eof, sizeof (thawer_eof)); 173 memcpy (SvPVX (text) + len, thawer_eof, sizeof (thawer_eof));
145 174
146 line = SvPVX (text); 175 line = SvPVX (text);
147 next (); 176 next ();
148 }
149 } 177 }
178 }
150 179
151 CALL_END; 180 CALL_END;
152 }
153}
154
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} 181}
164 182
165void 183void
166object_thawer::get (attachable *obj, int oid) 184object_thawer::get (attachable *obj, int oid)
167{ 185{
223 resolve_delayed_derefs (false); 241 resolve_delayed_derefs (false);
224 242
225 free ((void *)name); 243 free ((void *)name);
226} 244}
227 245
246static void
247error_out ()
248{
249 if (object_thawer::errors_are_fatal)
250 {
251 LOG (llevError, "(parse errors at this time are fatal, exiting)");
252 exit (1);
253 }
254}
255
228void 256void
229object_thawer::parse_warn (const char *msg) 257object_thawer::parse_warn (const char *msg) const
230{ 258{
231 LOG (llevWarn, "%s:%d, \"%s %s\": %s\n", 259 LOG (llevWarn, "%s:%d, \"%s %s\": %s\n",
232 this->name, linenum, 260 this->name, linenum,
233 kw_str ? kw_str : "<null>", 261 kw_str ? kw_str : "<null>",
234 value ? value : "<null>", 262 value ? value : "<null>",
235 msg); 263 msg);
236} 264}
237 265
238bool 266bool
239object_thawer::parse_error (const char *type, const char *name, bool skip) 267object_thawer::parse_error (const char *type, const char *name, bool skip) const
240{ 268{
241 if (!type) type = "file section"; 269 if (!type) type = "file section";
242 if (!name) name = "generic"; 270 if (!name) name = "generic";
243 271
244 switch (kw) 272 switch (kw)
245 { 273 {
246 case KW_EOF: 274 case KW_EOF:
247 LOG (llevError, "%s:%d end of file while reading %s '%s', aborting load.\n", 275 LOG (llevError, "%s:%d end of file while reading %s '%s', aborting load.\n",
248 this->name, linenum, type, name); 276 this->name, linenum, type, name);
277 error_out ();
249 return false; 278 return false;
250 279
251 case KW_ERROR: 280 case KW_ERROR:
252 LOG (llevError, "%s:%d error while reading %s '%s', at '%s', aborting load.\n", 281 LOG (llevError, "%s:%d error while reading %s '%s', at '%s', aborting load.\n",
253 this->name, linenum, 282 this->name, linenum,
254 type, name, 283 type, name,
255 kw_str ? kw_str : "<file load>"); 284 kw_str ? kw_str : "<file load>");
285 error_out ();
256 return false; 286 return false;
257 287
258 default: 288 default:
259 LOG (llevError, "%s:%d unexpected line (%s %s) while reading %s '%s', %s.\n", 289 LOG (llevError, "%s:%d unexpected line (%s %s) while reading %s '%s', %s.\n",
260 this->name, linenum, 290 this->name, linenum,
261 kw_str ? kw_str : "<null>", 291 kw_str ? kw_str : "<null>",
262 value ? value : "<null>", 292 value ? value : "<null>",
263 type, name, 293 type, name,
264 skip ? "skipping line" : "aborting load"); 294 skip ? "skipping line" : "aborting load");
295 error_out ();
265 return skip; 296 return skip;
266 } 297 }
267} 298}
268 299
269void 300void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines