forked from github/server
fix reading old data files.
This commit is contained in:
parent
1035a98fd3
commit
c3fce574fb
1 changed files with 15 additions and 8 deletions
|
@ -42,12 +42,13 @@ int read_attribs(gamedata *data, attrib **alist, void *owner) {
|
||||||
}
|
}
|
||||||
if (result == AT_READ_DEPR) {
|
if (result == AT_READ_DEPR) {
|
||||||
/* handle deprecated attributes */
|
/* handle deprecated attributes */
|
||||||
attrib *a = *alist;
|
attrib **ap = alist;
|
||||||
while (a) {
|
while (*ap) {
|
||||||
|
attrib *a = *ap;
|
||||||
if (a->type->upgrade) {
|
if (a->type->upgrade) {
|
||||||
a->type->upgrade(alist, a);
|
a->type->upgrade(alist, a);
|
||||||
}
|
}
|
||||||
a = a->nexttype;
|
ap = &a->nexttype;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -66,7 +67,7 @@ int a_readint(variant * var, void *owner, struct gamedata *data)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
READ_INT(data->store, &n);
|
READ_INT(data->store, &n);
|
||||||
if (var) var->i = n;
|
var->i = n;
|
||||||
return AT_READ_OK;
|
return AT_READ_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -426,11 +427,13 @@ static int a_read_i(gamedata *data, attrib ** attribs, void *owner, unsigned int
|
||||||
int retval = AT_READ_OK;
|
int retval = AT_READ_OK;
|
||||||
int(*reader)(variant *, void *, struct gamedata *) = 0;
|
int(*reader)(variant *, void *, struct gamedata *) = 0;
|
||||||
attrib_type *at = at_find_key(key);
|
attrib_type *at = at_find_key(key);
|
||||||
attrib * na = 0;
|
attrib * na = NULL;
|
||||||
|
variant var, *vp = &var;
|
||||||
|
|
||||||
if (at) {
|
if (at) {
|
||||||
reader = at->read;
|
reader = at->read;
|
||||||
na = a_new(at);
|
na = a_new(at);
|
||||||
|
vp = &na->data;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
void *match;
|
void *match;
|
||||||
|
@ -444,16 +447,20 @@ static int a_read_i(gamedata *data, attrib ** attribs, void *owner, unsigned int
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (reader) {
|
if (reader) {
|
||||||
int ret = reader(&na->data, owner, data);
|
int ret = reader(vp, owner, data);
|
||||||
if (na) {
|
if (na) {
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case AT_READ_DEPR:
|
case AT_READ_DEPR:
|
||||||
case AT_READ_OK:
|
case AT_READ_OK:
|
||||||
a_add(attribs, na);
|
if (na) {
|
||||||
|
a_add(attribs, na);
|
||||||
|
}
|
||||||
retval = ret;
|
retval = ret;
|
||||||
break;
|
break;
|
||||||
case AT_READ_FAIL:
|
case AT_READ_FAIL:
|
||||||
a_free(na);
|
if (na) {
|
||||||
|
a_free(na);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(!"invalid return value");
|
assert(!"invalid return value");
|
||||||
|
|
Loading…
Reference in a new issue