Clean up maintenance of config table sentinels

Xundump had special hackery to maintain configuration tables'
sentinels: xubody() and getobj() added a sentinel element when
initializing or growing a table, which xubody() stripped off again
before returning.  The latter was an unclean hack.

Replace this by building knowledge of sentinels into struct empfile:
new flag EFF_SENTINEL, set for the appropriate members of empfile[],
obeyed by ef_extend() and ef_truncate().
This commit is contained in:
Markus Armbruster 2008-09-01 09:20:08 -04:00
parent 02254398e8
commit 1492845c12
4 changed files with 20 additions and 23 deletions

View file

@ -482,17 +482,16 @@ static void *
getobj(void)
{
struct empfile *ep = &empfile[cur_type];
int need_sentinel = !EF_IS_GAME_STATE(cur_type);
if (!cur_obj) {
cur_obj_is_blank = cur_id >= ep->fids - !!need_sentinel;
cur_obj_is_blank = cur_id >= ep->fids;
if (cur_obj_is_blank) {
if (ef_ensure_space(cur_type, cur_id + !!need_sentinel, 1))
if (ef_ensure_space(cur_type, cur_id, 1))
cur_obj = ef_ptr(cur_type, cur_id);
/* FIXME diagnose out of dynamic memory vs. static table full */
if (!cur_obj)
gripe("Can't put ID %d into table %s, it holds only 0..%d.",
cur_id, ep->name, ep->fids - !!need_sentinel - 1);
cur_id, ep->name, ep->fids - 1);
} else
cur_obj = ef_ptr(cur_type, cur_id);
}
@ -962,13 +961,8 @@ static int
xubody(FILE *fp)
{
struct empfile *ep = &empfile[cur_type];
int need_sentinel = !EF_IS_GAME_STATE(cur_type);
int old_maxid = ep->fids;
int i, maxid, ch;
if (old_maxid == 0 && need_sentinel)
ef_ensure_space(cur_type, 0, 1);
maxid = 0;
for (i = 0;; ++i) {
while ((ch = skipfs(fp)) == '\n')
@ -983,12 +977,6 @@ xubody(FILE *fp)
maxid = MAX(maxid, cur_id + 1);
}
if (maxid >= old_maxid && need_sentinel) {
/* appended a sentinel, strip it off */
ep->fids--;
ep->cids--;
}
if (CANT_HAPPEN(maxid > ep->fids))
maxid = ep->fids;
if (maxid < ep->fids) {