1 | /* |
1 | /* |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
4 | * Copyright (©) 2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * |
5 | * |
6 | * Crossfire TRT is free software: you can redistribute it and/or modify |
6 | * Deliantra is free software: you can redistribute it and/or modify it under |
7 | * it under the terms of the GNU General Public License as published by |
7 | * the terms of the Affero GNU General Public License as published by the |
8 | * the Free Software Foundation, either version 3 of the License, or |
8 | * Free Software Foundation, either version 3 of the License, or (at your |
9 | * (at your 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 GNU General Public License |
16 | * You should have received a copy of the Affero GNU General Public License |
17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | * and the GNU General Public License along with this program. If not, see |
|
|
18 | * <http://www.gnu.org/licenses/>. |
18 | * |
19 | * |
19 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
20 | * The authors can be reached via e-mail to <support@deliantra.net> |
20 | */ |
21 | */ |
21 | |
22 | |
22 | #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 |
23 | #include "logger.h" |
24 | #include "logger.h" |
24 | #include "cfperl.h" |
25 | #include "cfperl.h" |
… | |
… | |
34 | { |
35 | { |
35 | SvREFCNT_dec (av); |
36 | SvREFCNT_dec (av); |
36 | } |
37 | } |
37 | |
38 | |
38 | void |
39 | void |
39 | object_freezer::put (attachable *ext) |
40 | object_freezer::put_ (attachable *ext) |
40 | { |
41 | { |
41 | ext->optimise (); |
42 | ext->optimise (); |
42 | |
43 | |
43 | if (ext->self) |
44 | if (ext->self) |
44 | { |
45 | { |
45 | int idx = AvFILLp ((AV *)av) + 1; |
46 | int idx = AvFILLp ((AV *)av) + 1; |
46 | av_store (av, idx, newRV_inc ((SV *)ext->self)); |
47 | av_store (av, idx, newRV_inc ((SV *)ext->self)); |
47 | |
48 | |
48 | add ((void *)"oid ", 4); |
49 | put (KW(oid), sint32(idx)); |
49 | add ((sint32)idx); |
|
|
50 | add ('\n'); |
|
|
51 | } |
50 | } |
52 | } |
51 | } |
53 | |
52 | |
54 | bool |
53 | bool |
55 | object_freezer::save (const char *path) |
54 | object_freezer::save (const char *path) |
… | |
… | |
108 | static const char thawer_eof[] = "\n\n\n\0\0\0"; |
107 | static const char thawer_eof[] = "\n\n\n\0\0\0"; |
109 | |
108 | |
110 | object_thawer::object_thawer (const char *path) |
109 | object_thawer::object_thawer (const char *path) |
111 | : name (strdup (path)) |
110 | : name (strdup (path)) |
112 | { |
111 | { |
113 | static const char eof[] = "\n\n\n\0\0\0"; |
|
|
114 | |
|
|
115 | av = 0; |
112 | av = 0; |
116 | text = 0; |
113 | text = 0; |
117 | line = 0; |
114 | line = 0; |
118 | linenum = 0; |
115 | linenum = 0; |
119 | |
116 | |
… | |
… | |
139 | // first value - text part, pad with 3 zeroes |
136 | // first value - text part, pad with 3 zeroes |
140 | { |
137 | { |
141 | SV *sv = POPs; |
138 | SV *sv = POPs; |
142 | STRLEN len; |
139 | STRLEN len; |
143 | char *sv_ = SvPVbyte (sv, len); |
140 | char *sv_ = SvPVbyte (sv, len); |
144 | text = newSV (len + sizeof (eof)); |
141 | text = newSV (len + sizeof (thawer_eof)); |
145 | SvCUR_set (text, len); |
142 | SvCUR_set (text, len + sizeof (thawer_eof)); |
146 | memcpy (SvPVX (text), sv_, len); |
143 | memcpy (SvPVX (text), sv_, len); |
147 | memcpy (SvEND (text), eof, sizeof (eof)); // just to be sure |
144 | memcpy (SvPVX (text) + len, thawer_eof, sizeof (thawer_eof)); |
148 | |
145 | |
149 | line = SvPVX (text); |
146 | line = SvPVX (text); |
150 | next (); |
147 | next (); |
151 | } |
148 | } |
152 | } |
149 | } |
… | |
… | |
389 | } |
386 | } |
390 | |
387 | |
391 | void |
388 | void |
392 | object_thawer::skip_block () |
389 | object_thawer::skip_block () |
393 | { |
390 | { |
394 | while (kw != KW_ERROR && kw != KW_EOF) |
391 | // must not stop at KW_ERROR, as those signify custom keys |
|
|
392 | while (kw != KW_EOF) |
395 | { |
393 | { |
396 | keyword w = kw; |
394 | keyword w = kw; |
397 | skip (); |
395 | skip (); |
|
|
396 | |
|
|
397 | if (0 && (w == KW_map || w == KW_arch || w == KW_object || w == KW_region)) |
|
|
398 | skip_block (); |
398 | if (w == KW_end) |
399 | else if (w == KW_end) |
399 | break; |
400 | break; |
400 | } |
401 | } |
401 | } |
402 | } |
402 | |
403 | |
403 | void |
404 | void |
… | |
… | |
452 | } |
453 | } |
453 | |
454 | |
454 | sint32 |
455 | sint32 |
455 | object_thawer::get_sint32 () const |
456 | object_thawer::get_sint32 () const |
456 | { |
457 | { |
457 | char *p = value_nn; |
458 | const char *p = value_nn; |
458 | |
459 | |
459 | sint32 val = 0; |
460 | sint32 val = 0; |
460 | bool negate; |
461 | bool negate; |
461 | |
462 | |
462 | if (*p == '-') |
463 | if (*p == '-') |