Split ef_verify() into ef_verify_config(), ef_verify_state()

This commit is contained in:
Markus Armbruster 2011-07-10 17:23:02 +02:00
parent c4a32b2fda
commit d63b0e1a7b
4 changed files with 35 additions and 9 deletions

View file

@ -225,7 +225,8 @@ extern int ef_nelem(int);
extern int ef_flags(int);
extern int ef_byname(char *);
extern int ef_byname_from(char *, int *);
extern int ef_verify(int);
extern int ef_verify_config(void);
extern int ef_verify_state(int);
extern int ef_elt_byname(int, char *);
extern struct empfile empfile[EF_MAX + 1];

View file

@ -312,24 +312,45 @@ verify_products(void)
}
/*
* Verify game state and configuration are sane.
* Verify game configuration is sane.
* Return 0 on success, -1 on failure.
*/
int
ef_verify_config(void)
{
int retval = 0;
int i;
for (i = 0; i < EF_MAX; i++) {
if (!EF_IS_GAME_STATE(i) && !EF_IS_VIEW(i))
retval |= verify_table(i);
}
/* Special checks */
retval |= verify_products();
return retval;
}
/*
* Verify game state is sane.
* Correct minor problems, but write corrections to backing files only
* if MAY_PUT is non-zero.
* Return -1 if uncorrected problems remain, else 0.
*/
int
ef_verify(int may_put)
ef_verify_state(int may_put)
{
struct empfile *ep;
int retval = 0;
int i;
for (ep = empfile; ep->name; ep++)
retval |= verify_table(ep->uid);
for (i = 0; i < EF_MAX; i++) {
if (EF_IS_GAME_STATE(i) || EF_IS_VIEW(i))
retval |= verify_table(i);
}
/* Special checks */
retval |= verify_planes(may_put);
retval |= verify_lands(may_put);
retval |= verify_nukes(may_put);
retval |= verify_products();
return retval;
}

View file

@ -72,7 +72,9 @@ ef_init_srv(void)
nsc_init();
ef_open_srv();
if (ef_verify(1) < 0)
if (ef_verify_config() < 0)
exit(EXIT_FAILURE);
if (ef_verify_state(1) < 0)
exit(EXIT_FAILURE);
global_init();
unit_cargo_init();

View file

@ -150,7 +150,9 @@ main(int argc, char *argv[])
exit(1);
}
if (ef_verify(0) < 0)
if (ef_verify_config() < 0)
exit(1);
if (ef_verify_state(0) < 0)
exit(1);
/* export to stdout */