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