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.40 by root, Wed Apr 28 19:49:50 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"
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; 109bool object_thawer::errors_are_fatal = true;
110 110
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
111object_thawer::object_thawer (const_utf8_string path) 122object_thawer::object_thawer (const_utf8_string path)
112{ 123{
113 new_from_path (path); 124 init_from_file (path);
114} 125}
115 126
116// convenience constructor 127// convenience constructor
117object_thawer::object_thawer (const_utf8_string dir, const_utf8_string file) 128object_thawer::object_thawer (const_utf8_string dir, const_utf8_string file)
118{ 129{
119 new_from_path (format ("%s/%s", dir, file)); 130 init_from_file (format ("%s/%s", dir, file));
120} 131}
121 132
122void 133void
123object_thawer::new_from_path (const_utf8_string path) 134object_thawer::init (const_utf8_string path)
124{ 135{
125 name = strdup (path); 136 name = strdup (path);
126 av = 0; 137 av = 0;
127 text = 0; 138 text = 0;
128 line = 0; 139 line = 0;
129 linenum = 0; 140 linenum = 0;
130 141
131 kw = KW_ERROR; 142 kw = KW_ERROR;
132 kw_str = 0; 143 kw_str = 0;
133 value = 0; 144 value = 0;
145}
134 146
147void
148object_thawer::init_from_file (const_utf8_string path)
149{
135 if (path) 150 init (path);
136 { 151
137 CALL_BEGIN (1); 152 CALL_BEGIN (1);
138 CALL_ARG_SV (newSVpv (path, 0)); 153 CALL_ARG_SV (newSVpv (path, 0));
139 CALL_CALL ("cf::object_thawer_load", G_ARRAY); 154 CALL_CALL ("cf::object_thawer_load", G_ARRAY);
140 155
141 if (count == 2) 156 if (count == 2)
142 { 157 {
143 // second value - perl objects 158 // second value - perl objects
144 { 159 {
145 SV *sv = POPs; 160 SV *sv = POPs;
146 if (SvROK (sv)) 161 if (SvROK (sv))
147 av = (AV *)SvREFCNT_inc (SvRV (sv)); 162 av = (AV *)SvREFCNT_inc (SvRV (sv));
148 } 163 }
149 164
150 // first value - text part, pad with 3 zeroes 165 // first value - text part, pad with 3 zeroes
151 { 166 {
152 SV *sv = POPs; 167 SV *sv = POPs;
153 STRLEN len; 168 STRLEN len;
154 char *sv_ = SvPVbyte (sv, len); 169 char *sv_ = SvPVbyte (sv, len);
155 text = newSV (len + sizeof (thawer_eof)); 170 text = newSV (len + sizeof (thawer_eof));
156 SvCUR_set (text, len + sizeof (thawer_eof)); 171 SvCUR_set (text, len + sizeof (thawer_eof));
157 memcpy (SvPVX (text), sv_, len); 172 memcpy (SvPVX (text), sv_, len);
158 memcpy (SvPVX (text) + len, thawer_eof, sizeof (thawer_eof)); 173 memcpy (SvPVX (text) + len, thawer_eof, sizeof (thawer_eof));
159 174
160 line = SvPVX (text); 175 line = SvPVX (text);
161 next (); 176 next ();
162 }
163 } 177 }
178 }
164 179
165 CALL_END; 180 CALL_END;
166 }
167}
168
169object_thawer::object_thawer (const char *data, AV *perlav)
170: name (strdup ("(memory stream)"))
171{
172 av = perlav;
173 text = newSVpv (data, 0);
174 sv_catpv (text, thawer_eof);
175 line = SvPVbyte_nolen (text);
176 next ();
177} 181}
178 182
179void 183void
180object_thawer::get (attachable *obj, int oid) 184object_thawer::get (attachable *obj, int oid)
181{ 185{
248 exit (1); 252 exit (1);
249 } 253 }
250} 254}
251 255
252void 256void
253object_thawer::parse_warn (const char *msg) 257object_thawer::parse_warn (const char *msg) const
254{ 258{
255 LOG (llevWarn, "%s:%d, \"%s %s\": %s\n", 259 LOG (llevWarn, "%s:%d, \"%s %s\": %s\n",
256 this->name, linenum, 260 this->name, linenum,
257 kw_str ? kw_str : "<null>", 261 kw_str ? kw_str : "<null>",
258 value ? value : "<null>", 262 value ? value : "<null>",
259 msg); 263 msg);
260} 264}
261 265
262bool 266bool
263object_thawer::parse_error (const char *type, const char *name, bool skip) 267object_thawer::parse_error (const char *type, const char *name, bool skip) const
264{ 268{
265 if (!type) type = "file section"; 269 if (!type) type = "file section";
266 if (!name) name = "generic"; 270 if (!name) name = "generic";
267 271
268 switch (kw) 272 switch (kw)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines