Clean up library dependencies
Move stuff to untangle the ugly cyclic dependencies between the archives built for selected subdirectories of src/lib/: * Move common/io.c to empthread/ because it requires empthread stuff * Move parts of subs/nstr.c to common/nstreval.c to satisfy common/ef_verify.o * Move getstarg.c getstring.c onearg.c from gen/ to subs/ because they require stuff from there * Move bridgefall.c check.c damage.c empobj.c journal.c maps.c sectdamage.c from common/ to subs/ because they require stuff from there * Move cnumb.c from subs/ to common/ to satisfy common/type.o * Move log.c fsize.c from common/ to gen/ because they really belong there * Move emp_config.c mapdist.c from gen/ to common/ because they really belong there, and require stuff from libglobal.a Also package as/ as libas.a to satisfy common/path.o. Remaining dependencies: lib needs -------------------------------------------- libas.a libglobal.a libcommon.a libas.a libglobal.a libgen.a libgen.a libglobal.a liblwp.a libgen.a libw32.a[*] libgen.a [*] Except for service.o, which can only be linked into the server Link order now: liblwp.a libcommon.a libas.a libgen.a libglobal.a libw32.a. The position of libw32.a is not quite right, but works anyway.
This commit is contained in:
parent
1cbb37d4fb
commit
77e95bd788
20 changed files with 235 additions and 191 deletions
17
Make.mk
17
Make.mk
|
@ -102,7 +102,7 @@ obj := $(csrc:.c=.o) $(filter %.o, $(ac:.c=.o))
|
||||||
# Dependencies:
|
# Dependencies:
|
||||||
deps := $(obj:.o=.d)
|
deps := $(obj:.o=.d)
|
||||||
# Library archives:
|
# Library archives:
|
||||||
libs := $(addprefix lib/, libcommon.a libgen.a libglobal.a)
|
libs := $(addprefix lib/, libcommon.a libas.a libgen.a libglobal.a)
|
||||||
# Programs:
|
# Programs:
|
||||||
util := $(addprefix src/util/, $(addsuffix $(EXEEXT), empsched fairland files pconfig))
|
util := $(addprefix src/util/, $(addsuffix $(EXEEXT), empsched fairland files pconfig))
|
||||||
client := src/client/empire$(EXEEXT)
|
client := src/client/empire$(EXEEXT)
|
||||||
|
@ -115,17 +115,17 @@ info.nr := $(addprefix info.nr/, $(info))
|
||||||
info.html := $(addprefix info.html/, $(addsuffix .html, $(info)))
|
info.html := $(addprefix info.html/, $(addsuffix .html, $(info)))
|
||||||
|
|
||||||
# Conditionally generated files:
|
# Conditionally generated files:
|
||||||
|
empth_obj := src/lib/empthread/io.o
|
||||||
|
empth_lib :=
|
||||||
ifeq ($(empthread),LWP)
|
ifeq ($(empthread),LWP)
|
||||||
empth_obj := src/lib/empthread/lwp.o src/lib/empthread/posix.o
|
empth_obj += src/lib/empthread/lwp.o src/lib/empthread/posix.o
|
||||||
empth_lib := lib/liblwp.a
|
empth_lib += lib/liblwp.a
|
||||||
endif
|
endif
|
||||||
ifeq ($(empthread),POSIX)
|
ifeq ($(empthread),POSIX)
|
||||||
empth_obj := src/lib/empthread/pthread.o src/lib/empthread/posix.o
|
empth_obj += src/lib/empthread/pthread.o src/lib/empthread/posix.o
|
||||||
empth_lib :=
|
|
||||||
endif
|
endif
|
||||||
ifeq ($(empthread),Windows)
|
ifeq ($(empthread),Windows)
|
||||||
empth_obj := src/lib/empthread/ntthread.o
|
empth_obj += src/lib/empthread/ntthread.o
|
||||||
empth_lib :=
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(empthread),Windows) # really: W32, regardless of thread package
|
ifeq ($(empthread),Windows) # really: W32, regardless of thread package
|
||||||
|
@ -262,7 +262,7 @@ info.html/%.html: info/%.t
|
||||||
|
|
||||||
# Compilation
|
# Compilation
|
||||||
|
|
||||||
$(server): $(filter src/server/% src/lib/as/% src/lib/commands/% src/lib/player/% src/lib/subs/% src/lib/update/%, $(obj)) $(empth_obj) $(libs) $(empth_lib)
|
$(server): $(filter src/server/% src/lib/commands/% src/lib/player/% src/lib/subs/% src/lib/update/%, $(obj)) $(empth_obj) $(empth_lib) $(libs)
|
||||||
$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
|
$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
|
||||||
|
|
||||||
$(client): $(filter src/client/%, $(obj)) src/lib/global/version.o
|
$(client): $(filter src/client/%, $(obj)) src/lib/global/version.o
|
||||||
|
@ -273,6 +273,7 @@ endif
|
||||||
|
|
||||||
$(util): $(libs)
|
$(util): $(libs)
|
||||||
|
|
||||||
|
lib/libas.a: $(filter src/lib/as/%, $(obj))
|
||||||
lib/libcommon.a: $(filter src/lib/common/%, $(obj))
|
lib/libcommon.a: $(filter src/lib/common/%, $(obj))
|
||||||
lib/libgen.a: $(filter src/lib/gen/%, $(obj))
|
lib/libgen.a: $(filter src/lib/gen/%, $(obj))
|
||||||
lib/libglobal.a: $(filter src/lib/global/%, $(obj))
|
lib/libglobal.a: $(filter src/lib/global/%, $(obj))
|
||||||
|
|
|
@ -259,38 +259,16 @@ int zdon(void);
|
||||||
*/
|
*/
|
||||||
/* bestpath.c */
|
/* bestpath.c */
|
||||||
extern char *bestownedpath(char *, char *, int, int, int, int, int);
|
extern char *bestownedpath(char *, char *, int, int, int, int, int);
|
||||||
/* bridgefall.c */
|
|
||||||
extern void bridgefall(struct sctstr *, struct emp_qelem *);
|
|
||||||
extern void knockdown(struct sctstr *, struct emp_qelem *);
|
|
||||||
/* damage.c */
|
|
||||||
extern void landdamage(struct lndstr *, int);
|
|
||||||
extern void ship_damage(struct shpstr *, int);
|
|
||||||
extern int damage(int, int);
|
|
||||||
extern void shipdamage(struct shpstr *, int);
|
|
||||||
extern void land_damage(struct lndstr *, int);
|
|
||||||
extern void planedamage(struct plnstr *, int);
|
|
||||||
extern int nukedamage(struct nchrstr *, int, int);
|
|
||||||
extern int effdamage(int, int);
|
|
||||||
extern void item_damage(int, short *);
|
|
||||||
extern int commdamage(int, int, i_type);
|
|
||||||
/* check.c */
|
|
||||||
extern int check_sect_ok(struct sctstr *);
|
|
||||||
extern int check_ship_ok(struct shpstr *);
|
|
||||||
extern int check_land_ok(struct lndstr *);
|
|
||||||
extern int check_nuke_ok(struct nukstr *);
|
|
||||||
extern int check_plane_ok(struct plnstr *);
|
|
||||||
extern int check_comm_ok(struct comstr *);
|
|
||||||
extern int check_loan_ok(struct lonstr *);
|
|
||||||
extern int check_trade_ok(struct trdstr *);
|
|
||||||
/* conftab.c */
|
/* conftab.c */
|
||||||
extern int read_builtin_tables(void);
|
extern int read_builtin_tables(void);
|
||||||
extern int read_custom_tables(void);
|
extern int read_custom_tables(void);
|
||||||
|
/* cnumb.c */
|
||||||
|
extern int cnumb(char *);
|
||||||
/* ef_verify.c */
|
/* ef_verify.c */
|
||||||
/* in file.h */
|
/* in file.h */
|
||||||
/* fsize.c */
|
/* emp_config.c */
|
||||||
extern int fsize(int);
|
extern int emp_config(char *file);
|
||||||
extern int blksize(int);
|
extern void print_config(FILE * fp);
|
||||||
extern time_t fdate(int);
|
|
||||||
/* hap_fact.c */
|
/* hap_fact.c */
|
||||||
extern double hap_fact(struct natstr *, struct natstr *);
|
extern double hap_fact(struct natstr *, struct natstr *);
|
||||||
extern double hap_req(struct natstr *np);
|
extern double hap_req(struct natstr *np);
|
||||||
|
@ -303,17 +281,15 @@ extern int loginit(char *);
|
||||||
extern int logreopen(void);
|
extern int logreopen(void);
|
||||||
extern void logerror(char *, ...) ATTRIBUTE((format (printf, 1, 2)));
|
extern void logerror(char *, ...) ATTRIBUTE((format (printf, 1, 2)));
|
||||||
/* more in misc.h */
|
/* more in misc.h */
|
||||||
/* maps.c */
|
/* mapdist.c */
|
||||||
extern int do_map(int bmap, int unit_type, char *arg1, char *arg2);
|
extern int diffx(int, int);
|
||||||
extern int draw_map(int, char, int, struct nstr_sect *);
|
extern int diffy(int, int);
|
||||||
extern int unit_map(int, int, struct nstr_sect *, char *);
|
extern int deltax(int, int);
|
||||||
extern int display_region_map(int bmap, int unit_type, coord curx,
|
extern int deltay(int, int);
|
||||||
coord cury, char *arg);
|
extern int mapdist(int, int, int, int);
|
||||||
extern int bmaps_intersect(natid, natid);
|
|
||||||
extern int share_bmap(natid, natid, struct nstr_sect *, char, char *);
|
|
||||||
/* move.c */
|
/* move.c */
|
||||||
/* in path.h */
|
/* in path.h */
|
||||||
/* nstr_subs.c */
|
/* nstreval.c */
|
||||||
/* in nsc.h */
|
/* in nsc.h */
|
||||||
/* path.c */
|
/* path.c */
|
||||||
extern void bp_enable_cachepath(void);
|
extern void bp_enable_cachepath(void);
|
||||||
|
@ -331,9 +307,6 @@ extern int read_schedule(char *, time_t[], int, time_t, time_t);
|
||||||
/* res_pop.c */
|
/* res_pop.c */
|
||||||
extern int max_population(float, int, int);
|
extern int max_population(float, int, int);
|
||||||
extern int max_pop(float, struct sctstr *);
|
extern int max_pop(float, struct sctstr *);
|
||||||
/* sectdamage.c */
|
|
||||||
extern int sect_damage(struct sctstr *, int, struct emp_qelem *);
|
|
||||||
extern int sectdamage(struct sctstr *, int, struct emp_qelem *);
|
|
||||||
/* stmtch.c */
|
/* stmtch.c */
|
||||||
/* in match.h */
|
/* in match.h */
|
||||||
/* type.c */
|
/* type.c */
|
||||||
|
@ -348,21 +321,16 @@ extern int xundump(FILE *, char *, int *, int);
|
||||||
/*
|
/*
|
||||||
* src/lib/gen/ *.c
|
* src/lib/gen/ *.c
|
||||||
*/
|
*/
|
||||||
/* emp_config.c */
|
/* fsize.c */
|
||||||
extern int emp_config(char *file);
|
extern int fsize(int);
|
||||||
extern void print_config(FILE * fp);
|
extern int blksize(int);
|
||||||
|
extern time_t fdate(int);
|
||||||
|
|
||||||
extern int roll(int);
|
extern int roll(int);
|
||||||
extern int roundavg(double);
|
extern int roundavg(double);
|
||||||
extern int chance(double);
|
extern int chance(double);
|
||||||
extern int disassoc(void);
|
extern int disassoc(void);
|
||||||
extern int diffx(int, int);
|
|
||||||
extern int diffy(int, int);
|
|
||||||
extern int deltax(int, int);
|
|
||||||
extern int deltay(int, int);
|
|
||||||
extern int mapdist(int, int, int, int);
|
|
||||||
extern char *effadv(int);
|
extern char *effadv(int);
|
||||||
extern int onearg(char *, char *);
|
|
||||||
extern int parse(char *, char *, char **, char **, char **, char **);
|
extern int parse(char *, char *, char **, char **, char **, char **);
|
||||||
extern int ldround(double, int);
|
extern int ldround(double, int);
|
||||||
extern int roundintby(int, int);
|
extern int roundintby(int, int);
|
||||||
|
@ -430,19 +398,40 @@ extern void stop_service(void);
|
||||||
/* askyn.c */
|
/* askyn.c */
|
||||||
extern int confirm(char *);
|
extern int confirm(char *);
|
||||||
extern int askyn(char *);
|
extern int askyn(char *);
|
||||||
|
/* bridgefall.c */
|
||||||
|
extern void bridgefall(struct sctstr *, struct emp_qelem *);
|
||||||
|
extern void knockdown(struct sctstr *, struct emp_qelem *);
|
||||||
/* bsanct.c */
|
/* bsanct.c */
|
||||||
extern void bsanct(void);
|
extern void bsanct(void);
|
||||||
/* caploss.c */
|
/* caploss.c */
|
||||||
extern void caploss(struct sctstr *, natid, char *);
|
extern void caploss(struct sctstr *, natid, char *);
|
||||||
|
/* check.c */
|
||||||
|
extern int check_sect_ok(struct sctstr *);
|
||||||
|
extern int check_ship_ok(struct shpstr *);
|
||||||
|
extern int check_land_ok(struct lndstr *);
|
||||||
|
extern int check_nuke_ok(struct nukstr *);
|
||||||
|
extern int check_plane_ok(struct plnstr *);
|
||||||
|
extern int check_comm_ok(struct comstr *);
|
||||||
|
extern int check_loan_ok(struct lonstr *);
|
||||||
|
extern int check_trade_ok(struct trdstr *);
|
||||||
/* chkmoney.c */
|
/* chkmoney.c */
|
||||||
extern int chkmoney(long, long, char *);
|
extern int chkmoney(long, long, char *);
|
||||||
extern int check_cost(int, int, long, int *, char *);
|
extern int check_cost(int, int, long, int *, char *);
|
||||||
/* cnumb.c */
|
|
||||||
extern int cnumb(char *);
|
|
||||||
/* coastal.c */
|
/* coastal.c */
|
||||||
extern void set_coastal(struct sctstr *, int, int);
|
extern void set_coastal(struct sctstr *, int, int);
|
||||||
/* control.c */
|
/* control.c */
|
||||||
extern int military_control(struct sctstr *);
|
extern int military_control(struct sctstr *);
|
||||||
|
/* damage.c */
|
||||||
|
extern void landdamage(struct lndstr *, int);
|
||||||
|
extern void ship_damage(struct shpstr *, int);
|
||||||
|
extern int damage(int, int);
|
||||||
|
extern void shipdamage(struct shpstr *, int);
|
||||||
|
extern void land_damage(struct lndstr *, int);
|
||||||
|
extern void planedamage(struct plnstr *, int);
|
||||||
|
extern int nukedamage(struct nchrstr *, int, int);
|
||||||
|
extern int effdamage(int, int);
|
||||||
|
extern void item_damage(int, short *);
|
||||||
|
extern int commdamage(int, int, i_type);
|
||||||
/* detonate.c */
|
/* detonate.c */
|
||||||
extern int detonate(struct nukstr *, coord, coord, int);
|
extern int detonate(struct nukstr *, coord, coord, int);
|
||||||
/* disloan.c */
|
/* disloan.c */
|
||||||
|
@ -486,7 +475,15 @@ extern int num_shipsatxy(coord, coord, int, int);
|
||||||
extern int has_units(coord, coord, natid, struct lndstr *);
|
extern int has_units(coord, coord, natid, struct lndstr *);
|
||||||
extern int adj_units(coord, coord, natid);
|
extern int adj_units(coord, coord, natid);
|
||||||
extern int islist(char *);
|
extern int islist(char *);
|
||||||
/* src/lib/subs/mission.c */
|
/* maps.c */
|
||||||
|
extern int do_map(int bmap, int unit_type, char *arg1, char *arg2);
|
||||||
|
extern int draw_map(int, char, int, struct nstr_sect *);
|
||||||
|
extern int unit_map(int, int, struct nstr_sect *, char *);
|
||||||
|
extern int display_region_map(int bmap, int unit_type, coord curx,
|
||||||
|
coord cury, char *arg);
|
||||||
|
extern int bmaps_intersect(natid, natid);
|
||||||
|
extern int share_bmap(natid, natid, struct nstr_sect *, char, char *);
|
||||||
|
/* mission.c */
|
||||||
extern char *mission_name(short);
|
extern char *mission_name(short);
|
||||||
extern int collateral_damage(coord, coord, int, struct emp_qelem *);
|
extern int collateral_damage(coord, coord, int, struct emp_qelem *);
|
||||||
extern int mission_pln_equip(struct plist *, struct ichrstr *, int, char);
|
extern int mission_pln_equip(struct plist *, struct ichrstr *, int, char);
|
||||||
|
@ -536,6 +533,8 @@ extern int nuk_on_plane(struct nukstr *, int);
|
||||||
extern int nxtitem(struct nstr_item *, void *);
|
extern int nxtitem(struct nstr_item *, void *);
|
||||||
/* nxtsct.c */
|
/* nxtsct.c */
|
||||||
extern int nxtsct(struct nstr_sect *, struct sctstr *);
|
extern int nxtsct(struct nstr_sect *, struct sctstr *);
|
||||||
|
/* onearg.c */
|
||||||
|
extern int onearg(char *, char *);
|
||||||
/* plane.c */
|
/* plane.c */
|
||||||
extern char *prplane(struct plnstr *);
|
extern char *prplane(struct plnstr *);
|
||||||
extern int pln_postread(int, void *);
|
extern int pln_postread(int, void *);
|
||||||
|
@ -631,6 +630,9 @@ extern int sct_postread(int, void *);
|
||||||
extern int sct_prewrite(int, void *);
|
extern int sct_prewrite(int, void *);
|
||||||
extern void item_prewrite(short *);
|
extern void item_prewrite(short *);
|
||||||
extern int issector(char *);
|
extern int issector(char *);
|
||||||
|
/* sectdamage.c */
|
||||||
|
extern int sect_damage(struct sctstr *, int, struct emp_qelem *);
|
||||||
|
extern int sectdamage(struct sctstr *, int, struct emp_qelem *);
|
||||||
/* ship.c */
|
/* ship.c */
|
||||||
extern char *prship(struct shpstr *);
|
extern char *prship(struct shpstr *);
|
||||||
extern int shp_postread(int, void *);
|
extern int shp_postread(int, void *);
|
||||||
|
|
173
src/lib/common/nstreval.c
Normal file
173
src/lib/common/nstreval.c
Normal file
|
@ -0,0 +1,173 @@
|
||||||
|
/*
|
||||||
|
* Empire - A multi-player, client/server Internet based war game.
|
||||||
|
* Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
|
||||||
|
* Ken Stevens, Steve McClure
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
* ---
|
||||||
|
*
|
||||||
|
* See files README, COPYING and CREDITS in the root of the source
|
||||||
|
* tree for related information and legal notices. It is expected
|
||||||
|
* that future projects/authors will amend these files as needed.
|
||||||
|
*
|
||||||
|
* ---
|
||||||
|
*
|
||||||
|
* nstreval.c: evaluate compiled values
|
||||||
|
*
|
||||||
|
* Known contributors to this file:
|
||||||
|
* Dave Pare, 1989
|
||||||
|
* Steve McClure, 1997
|
||||||
|
* Markus Armbruster, 2004-2006
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
|
#include "file.h"
|
||||||
|
#include "nat.h"
|
||||||
|
#include "nsc.h"
|
||||||
|
#include "optlist.h"
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Evaluate VAL.
|
||||||
|
* If VAL is symbolic, evaluate it into a promoted value type.
|
||||||
|
* Use coordinate system of country CNUM.
|
||||||
|
* PTR points to a context object of the type that was used to compile
|
||||||
|
* the value.
|
||||||
|
* Unless WANT is NSC_NOTYPE, coerce the value to promoted value type
|
||||||
|
* WANT. VAL must be coercible. That's the case if a previous
|
||||||
|
* nstr_coerce_val(VAL, WANT, STR) succeeded.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
nstr_exec_val(struct valstr *val, natid cnum, void *ptr, nsc_type want)
|
||||||
|
{
|
||||||
|
char *memb_ptr;
|
||||||
|
nsc_type valtype;
|
||||||
|
int idx;
|
||||||
|
struct natstr *natp;
|
||||||
|
|
||||||
|
switch (val->val_cat) {
|
||||||
|
default:
|
||||||
|
CANT_REACH();
|
||||||
|
/* fall through */
|
||||||
|
case NSC_VAL:
|
||||||
|
valtype = val->val_type;
|
||||||
|
break;
|
||||||
|
case NSC_OFF:
|
||||||
|
valtype = NSC_LONG;
|
||||||
|
memb_ptr = ptr;
|
||||||
|
memb_ptr += val->val_as.sym.off;
|
||||||
|
idx = val->val_as.sym.idx;
|
||||||
|
switch (val->val_type) {
|
||||||
|
case NSC_CHAR:
|
||||||
|
val->val_as.lng = ((signed char *)memb_ptr)[idx];
|
||||||
|
break;
|
||||||
|
case NSC_UCHAR:
|
||||||
|
val->val_as.lng = ((unsigned char *)memb_ptr)[idx];
|
||||||
|
break;
|
||||||
|
case NSC_SHORT:
|
||||||
|
val->val_as.lng = ((short *)memb_ptr)[idx];
|
||||||
|
break;
|
||||||
|
case NSC_USHORT:
|
||||||
|
val->val_as.lng = ((unsigned short *)memb_ptr)[idx];
|
||||||
|
break;
|
||||||
|
case NSC_INT:
|
||||||
|
val->val_as.lng = ((int *)memb_ptr)[idx];
|
||||||
|
break;
|
||||||
|
case NSC_LONG:
|
||||||
|
val->val_as.lng = ((long *)memb_ptr)[idx];
|
||||||
|
break;
|
||||||
|
case NSC_XCOORD:
|
||||||
|
val->val_as.lng = xrel(getnatp(cnum), ((short *)memb_ptr)[idx]);
|
||||||
|
break;
|
||||||
|
case NSC_YCOORD:
|
||||||
|
val->val_as.lng = yrel(getnatp(cnum), ((short *)memb_ptr)[idx]);
|
||||||
|
break;
|
||||||
|
case NSC_HIDDEN:
|
||||||
|
val->val_as.lng = -1;
|
||||||
|
if (CANT_HAPPEN(((struct natstr *)ptr)->ef_type != EF_NATION))
|
||||||
|
break;
|
||||||
|
natp = getnatp(cnum);
|
||||||
|
if (!opt_HIDDEN
|
||||||
|
|| natp->nat_stat == STAT_GOD
|
||||||
|
|| (getcontact(natp, idx) && getcontact(ptr, idx)))
|
||||||
|
val->val_as.lng = ((unsigned char *)memb_ptr)[idx];
|
||||||
|
break;
|
||||||
|
case NSC_FLOAT:
|
||||||
|
val->val_as.dbl = ((float *)memb_ptr)[idx];
|
||||||
|
valtype = NSC_DOUBLE;
|
||||||
|
break;
|
||||||
|
case NSC_DOUBLE:
|
||||||
|
val->val_as.dbl = ((double *)memb_ptr)[idx];
|
||||||
|
valtype = NSC_DOUBLE;
|
||||||
|
break;
|
||||||
|
case NSC_STRINGY:
|
||||||
|
CANT_HAPPEN(idx);
|
||||||
|
val->val_as.str.maxsz = val->val_as.sym.len;
|
||||||
|
val->val_as.str.base = (char *)memb_ptr;
|
||||||
|
valtype = NSC_STRING;
|
||||||
|
break;
|
||||||
|
case NSC_STRING:
|
||||||
|
val->val_as.str.base = ((char **)memb_ptr)[idx];
|
||||||
|
val->val_as.str.maxsz = INT_MAX;
|
||||||
|
valtype = NSC_STRING;
|
||||||
|
break;
|
||||||
|
case NSC_TIME:
|
||||||
|
val->val_as.lng = ((time_t *)memb_ptr)[idx];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
CANT_REACH();
|
||||||
|
val->val_as.lng = 0;
|
||||||
|
}
|
||||||
|
val->val_cat = NSC_VAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (valtype == want)
|
||||||
|
;
|
||||||
|
else if (want == NSC_DOUBLE) {
|
||||||
|
if (valtype == NSC_LONG) {
|
||||||
|
valtype = want;
|
||||||
|
val->val_as.dbl = val->val_as.lng;
|
||||||
|
}
|
||||||
|
} else if (want == NSC_STRING)
|
||||||
|
CANT_REACH(); /* FIXME implement */
|
||||||
|
|
||||||
|
if (CANT_HAPPEN(valtype != want && want != NSC_NOTYPE)) {
|
||||||
|
valtype = want;
|
||||||
|
switch (want) {
|
||||||
|
case NSC_LONG: val->val_as.lng = 0; break;
|
||||||
|
case NSC_DOUBLE: val->val_as.dbl = 0.0; break;
|
||||||
|
case NSC_STRING: val->val_as.str.base = NULL; break;
|
||||||
|
default:
|
||||||
|
CANT_REACH();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val->val_type = valtype;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
symbol_by_value(int key, struct symbol *table)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; table[i].name; i++)
|
||||||
|
if (key == table[i].value)
|
||||||
|
return table[i].name;
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
|
@ -39,8 +39,6 @@
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "match.h"
|
#include "match.h"
|
||||||
#include "nat.h"
|
|
||||||
#include "optlist.h"
|
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
|
|
||||||
|
@ -568,133 +566,3 @@ nstr_coerce_val(struct valstr *val, nsc_type to, char *str)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Evaluate VAL.
|
|
||||||
* If VAL is symbolic, evaluate it into a promoted value type.
|
|
||||||
* Use coordinate system of country CNUM.
|
|
||||||
* PTR points to a context object of the type that was used to compile
|
|
||||||
* the value.
|
|
||||||
* Unless WANT is NSC_NOTYPE, coerce the value to promoted value type
|
|
||||||
* WANT. VAL must be coercible. That's the case if a previous
|
|
||||||
* nstr_coerce_val(VAL, WANT, STR) succeeded.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
nstr_exec_val(struct valstr *val, natid cnum, void *ptr, nsc_type want)
|
|
||||||
{
|
|
||||||
char *memb_ptr;
|
|
||||||
nsc_type valtype;
|
|
||||||
int idx;
|
|
||||||
struct natstr *natp;
|
|
||||||
|
|
||||||
switch (val->val_cat) {
|
|
||||||
default:
|
|
||||||
CANT_REACH();
|
|
||||||
/* fall through */
|
|
||||||
case NSC_VAL:
|
|
||||||
valtype = val->val_type;
|
|
||||||
break;
|
|
||||||
case NSC_OFF:
|
|
||||||
valtype = NSC_LONG;
|
|
||||||
memb_ptr = ptr;
|
|
||||||
memb_ptr += val->val_as.sym.off;
|
|
||||||
idx = val->val_as.sym.idx;
|
|
||||||
switch (val->val_type) {
|
|
||||||
case NSC_CHAR:
|
|
||||||
val->val_as.lng = ((signed char *)memb_ptr)[idx];
|
|
||||||
break;
|
|
||||||
case NSC_UCHAR:
|
|
||||||
val->val_as.lng = ((unsigned char *)memb_ptr)[idx];
|
|
||||||
break;
|
|
||||||
case NSC_SHORT:
|
|
||||||
val->val_as.lng = ((short *)memb_ptr)[idx];
|
|
||||||
break;
|
|
||||||
case NSC_USHORT:
|
|
||||||
val->val_as.lng = ((unsigned short *)memb_ptr)[idx];
|
|
||||||
break;
|
|
||||||
case NSC_INT:
|
|
||||||
val->val_as.lng = ((int *)memb_ptr)[idx];
|
|
||||||
break;
|
|
||||||
case NSC_LONG:
|
|
||||||
val->val_as.lng = ((long *)memb_ptr)[idx];
|
|
||||||
break;
|
|
||||||
case NSC_XCOORD:
|
|
||||||
val->val_as.lng = xrel(getnatp(cnum), ((short *)memb_ptr)[idx]);
|
|
||||||
break;
|
|
||||||
case NSC_YCOORD:
|
|
||||||
val->val_as.lng = yrel(getnatp(cnum), ((short *)memb_ptr)[idx]);
|
|
||||||
break;
|
|
||||||
case NSC_HIDDEN:
|
|
||||||
val->val_as.lng = -1;
|
|
||||||
if (CANT_HAPPEN(((struct natstr *)ptr)->ef_type != EF_NATION))
|
|
||||||
break;
|
|
||||||
natp = getnatp(cnum);
|
|
||||||
if (!opt_HIDDEN
|
|
||||||
|| natp->nat_stat == STAT_GOD
|
|
||||||
|| (getcontact(natp, idx) && getcontact(ptr, idx)))
|
|
||||||
val->val_as.lng = ((unsigned char *)memb_ptr)[idx];
|
|
||||||
break;
|
|
||||||
case NSC_FLOAT:
|
|
||||||
val->val_as.dbl = ((float *)memb_ptr)[idx];
|
|
||||||
valtype = NSC_DOUBLE;
|
|
||||||
break;
|
|
||||||
case NSC_DOUBLE:
|
|
||||||
val->val_as.dbl = ((double *)memb_ptr)[idx];
|
|
||||||
valtype = NSC_DOUBLE;
|
|
||||||
break;
|
|
||||||
case NSC_STRINGY:
|
|
||||||
CANT_HAPPEN(idx);
|
|
||||||
val->val_as.str.maxsz = val->val_as.sym.len;
|
|
||||||
val->val_as.str.base = (char *)memb_ptr;
|
|
||||||
valtype = NSC_STRING;
|
|
||||||
break;
|
|
||||||
case NSC_STRING:
|
|
||||||
val->val_as.str.base = ((char **)memb_ptr)[idx];
|
|
||||||
val->val_as.str.maxsz = INT_MAX;
|
|
||||||
valtype = NSC_STRING;
|
|
||||||
break;
|
|
||||||
case NSC_TIME:
|
|
||||||
val->val_as.lng = ((time_t *)memb_ptr)[idx];
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
CANT_REACH();
|
|
||||||
val->val_as.lng = 0;
|
|
||||||
}
|
|
||||||
val->val_cat = NSC_VAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (valtype == want)
|
|
||||||
;
|
|
||||||
else if (want == NSC_DOUBLE) {
|
|
||||||
if (valtype == NSC_LONG) {
|
|
||||||
valtype = want;
|
|
||||||
val->val_as.dbl = val->val_as.lng;
|
|
||||||
}
|
|
||||||
} else if (want == NSC_STRING)
|
|
||||||
CANT_REACH(); /* FIXME implement */
|
|
||||||
|
|
||||||
if (CANT_HAPPEN(valtype != want && want != NSC_NOTYPE)) {
|
|
||||||
valtype = want;
|
|
||||||
switch (want) {
|
|
||||||
case NSC_LONG: val->val_as.lng = 0; break;
|
|
||||||
case NSC_DOUBLE: val->val_as.dbl = 0.0; break;
|
|
||||||
case NSC_STRING: val->val_as.str.base = NULL; break;
|
|
||||||
default:
|
|
||||||
CANT_REACH();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val->val_type = valtype;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *
|
|
||||||
symbol_by_value(int key, struct symbol *table)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; table[i].name; i++)
|
|
||||||
if (key == table[i].value)
|
|
||||||
return table[i].name;
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue