From d89c268b8b68ba3d71dbb509f75371f418335ac1 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 4 Sep 2004 08:07:51 +0000 Subject: [PATCH] (keymatch): Replace member km_func by km_type. Initializers adapted. (emp_config, print_config): Cope with km_type. (worldxset, intset, floatset, optstrset, doubleset, longset): Unused, remove. (emp_config): Fail if specified file can't be read or contains errors. Used to succeed always, returning RET_OK. RET_OK is not appropriate, since this is not a command. Return 0 on success, -1 on failure. Callers ignore failure at the moment. A missing or unreadable econfig file used to be silently ignored. It is still ignored, but no longer silently. It is questionable whether ignoring is wise, but that's left for another day. (emp_config): Improve diagnostic messages. (set_option): Move diagnostics to caller. (emp_config): Ignore leading whitespace in `#' comment lines. (print_config): Simplify printing of km_comment. (set_option): New parameter val, so it can set and clear options. (delete_option): Remove. (KM_ALLOC): Turn macro into enumeration constant. (KM_INTERNAL): New. (xdump, xdver): New version dump. (keymatch, infodir, datadir, teldir, upfil, downfil, disablefil, telfil, annfil, banfil, timestampfil, privname, privlog, update_times, update_demandtimes, game_days, game_hours): Use plain char * instead of s_char * for strings, void * for generic pointers. --- include/econfig-spec.h | 220 ++++++++++++++--------------- include/optlist.h | 33 +++-- src/lib/commands/xdump.c | 32 +++++ src/lib/gen/emp_config.c | 280 ++++++++++++++----------------------- src/lib/global/constants.c | 12 +- src/lib/global/path.c | 24 ++-- 6 files changed, 282 insertions(+), 319 deletions(-) diff --git a/include/econfig-spec.h b/include/econfig-spec.h index b0b71863..c0352022 100644 --- a/include/econfig-spec.h +++ b/include/econfig-spec.h @@ -44,259 +44,259 @@ #endif /* EMP_CONFIG_C_OUTPUT || EMP_CONFIG_H_OUTPUT */ #define EMPCF_COMMENT(comment) \ -EMPCFONLYC("", emp_config_dummy, , intset, 0, (comment)) +EMPCFONLYC("", emp_config_dummy, , NSC_NOTYPE, 0, (comment)) /* things that can be changed */ EMPCF_COMMENT("\n### Server configuration and information") -EMPCFBOTH("data", datadir, s_char *, optstrset, 0, +EMPCFBOTH("data", datadir, char *, NSC_STRING, KM_INTERNAL, "Directory the data is stored in") -EMPCFBOTH("info", infodir, s_char *, optstrset, 0, +EMPCFBOTH("info", infodir, char *, NSC_STRING, KM_INTERNAL, "Directory the info pages are stored in") -EMPCFBOTH("port", loginport, s_char *, optstrset, 0, +EMPCFBOTH("port", loginport, char *, NSC_STRING, KM_INTERNAL, "TCP/IP port the server will start up on") -EMPCFBOTH("privname", privname, s_char *, optstrset, 0, +EMPCFBOTH("privname", privname, char *, NSC_STRING, 0, "Name of the deity") -EMPCFBOTH("privlog", privlog, s_char *, optstrset, 0, +EMPCFBOTH("privlog", privlog, char *, NSC_STRING, 0, "E-mail of the deity") -EMPCFBOTH("WORLD_X", WORLD_X, int, worldxset, 0, +EMPCFBOTH("WORLD_X", WORLD_X, int, NSC_INT, 0, "World size X dimension (enforced to be even by subtracting 1 if necessary)") -EMPCFBOTH("WORLD_Y", WORLD_Y, int, intset, 0, +EMPCFBOTH("WORLD_Y", WORLD_Y, int, NSC_INT, 0, "World size Y dimension") EMPCF_COMMENT("\n\n### Update policy") -EMPCFBOTH("update_policy", update_policy, int, intset, 0, +EMPCFBOTH("update_policy", update_policy, int, NSC_INT, 0, "0 - normal, 1 - update_times, 2 - blitz, 3 - demand only") -EMPCFBOTH("etu_per_update", etu_per_update, int, intset, 0, +EMPCFBOTH("etu_per_update", etu_per_update, int, NSC_INT, 0, "Number of ETUs per update") -EMPCFBOTH("s_p_etu", s_p_etu, int, intset, 0, +EMPCFBOTH("s_p_etu", s_p_etu, int, NSC_INT, 0, "Seconds per etu, updates will occur every s_p_etu * etu_per_update seconds") -EMPCFBOTH("adj_update", adj_update, int, intset, 0, +EMPCFBOTH("adj_update", adj_update, int, NSC_INT, KM_INTERNAL, "Move the update forward or backward (in seconds)") -EMPCFBOTH("update_window", update_window, int, intset, 0, +EMPCFBOTH("update_window", update_window, int, NSC_INT, 0, "Window the update will occur in (in seconds) before and after the update time") -EMPCFBOTH("update_times", update_times, s_char *, optstrset, 0, +EMPCFBOTH("update_times", update_times, char *, NSC_STRING, 0, "Times when updates occur under policy #1. Must coincide with schedule.") -EMPCFBOTH("hourslop", hourslop, int, intset, 0, +EMPCFBOTH("hourslop", hourslop, int, NSC_INT, KM_INTERNAL, "Number of minutes update check can slip to match update_times") -EMPCFBOTH("blitz_time", blitz_time, int, intset, 0, +EMPCFBOTH("blitz_time", blitz_time, int, NSC_INT, 0, "Number of minutes between updates under policy #2.") EMPCF_COMMENT("\n\n### Demand update policy") -EMPCFBOTH("update_demandpolicy", update_demandpolicy, int, intset, 0, +EMPCFBOTH("update_demandpolicy", update_demandpolicy, int, NSC_INT, 0, "0 - emp_tm checks, 1 - after setting, 2 - demand updates disabled") -EMPCFBOTH("update_wantmin", update_wantmin, int, intset, 0, +EMPCFBOTH("update_wantmin", update_wantmin, int, NSC_INT, 0, "number of requests needed for demand update") -EMPCFBOTH("update_missed", update_missed, int, intset, 0, +EMPCFBOTH("update_missed", update_missed, int, NSC_INT, 0, "number of demand updates country can miss before veto update") -EMPCFBOTH("update_demandtimes", update_demandtimes, s_char *, optstrset, 0, +EMPCFBOTH("update_demandtimes", update_demandtimes, char *, NSC_STRING, 0, "Times when demand updates can occur. Ranges CANNOT cross midnight.") EMPCF_COMMENT("\n\n### Game hours restrictions") -EMPCFBOTH("game_days", game_days, s_char *, optstrset, 0, +EMPCFBOTH("game_days", game_days, char *, NSC_STRING, 0, "Days game is up and running (Su Mo Tu We Th Fr Sa)") -EMPCFBOTH("game_hours", game_hours, s_char *, optstrset, 0, +EMPCFBOTH("game_hours", game_hours, char *, NSC_STRING, 0, "Hours game is up and running (6:00-18:00)") EMPCF_COMMENT("\n\n### Options\n") -EMPCFONLYC("option", emp_config_dummy, , optionset, 0, NULL) -EMPCFONLYC("nooption", emp_config_dummy, , optiondel, 0, NULL) +EMPCFONLYC("option", emp_config_dummy, , NSC_NOTYPE, 0, NULL) +EMPCFONLYC("nooption", emp_config_dummy, , NSC_NOTYPE, 0, NULL) EMPCF_COMMENT("\n\n### Countries") -EMPCFBOTH("btu_build_rate", btu_build_rate, float, floatset, 0, +EMPCFBOTH("btu_build_rate", btu_build_rate, float, NSC_FLOAT, 0, "Rate at which BTUs accumulate (etu * civ * eff * btu_build_rate)") -EMPCFBOTH("m_m_p_d", m_m_p_d, int, intset, 0, +EMPCFBOTH("m_m_p_d", m_m_p_d, int, NSC_INT, 0, "Maximum minutes per day a country is allowed to be logged in") -EMPCFBOTH("max_btus", max_btus, int, intset, 0, +EMPCFBOTH("max_btus", max_btus, int, NSC_INT, 0, "Maximum number of BTUs a country can have") -EMPCFBOTH("max_idle", max_idle, int, intset, 0, +EMPCFBOTH("max_idle", max_idle, int, NSC_INT, 0, "Maximum number of minutes a player can sit idle while logged in") -EMPCFBOTH("players_at_00", players_at_00, int, intset, 0, +EMPCFBOTH("players_at_00", players_at_00, int, NSC_INT, 0, "Players have their coordinate system at deity 0,0 (0 - no, 1 - yes)") -EMPCFBOTH("at_least_one_100", at_least_one_100, int, intset, 0, +EMPCFBOTH("at_least_one_100", at_least_one_100, int, NSC_INT, KM_INTERNAL, "Initialize new countries with at least one sector with 100 of all resource") -EMPCFBOTH("powe_cost", powe_cost, double, doubleset, 0, +EMPCFBOTH("powe_cost", powe_cost, double, NSC_DOUBLE, 0, "Number of BTUs needed to generate a new power report") -EMPCFBOTH("war_cost", War_Cost, int, intset, 0, +EMPCFBOTH("war_cost", War_Cost, int, NSC_INT, 0, "Cost to declare war (if SLOW_WAR is on)") EMPCF_COMMENT("\n\n### Technology/Research/Education/Happiness") -EMPCFBOTH("easy_tech", easy_tech, float, floatset, 0, +EMPCFBOTH("easy_tech", easy_tech, float, NSC_FLOAT, 0, "Amount of tech built with no penalty") -EMPCFBOTH("start_tech", start_technology, float, floatset, 0, +EMPCFBOTH("start_tech", start_technology, float, NSC_FLOAT, KM_INTERNAL, "Starting technology for new countries") -EMPCFBOTH("start_happy", start_happiness, float, floatset, 0, +EMPCFBOTH("start_happy", start_happiness, float, NSC_FLOAT, KM_INTERNAL, "Starting happiness for new countries") -EMPCFBOTH("start_research", start_research, float, floatset, 0, +EMPCFBOTH("start_research", start_research, float, NSC_FLOAT, KM_INTERNAL, "Starting research for new countries") -EMPCFBOTH("start_edu", start_education, float, floatset, 0, +EMPCFBOTH("start_edu", start_education, float, NSC_FLOAT, KM_INTERNAL, "Starting education for new countries") -EMPCFBOTH("level_age_rate", level_age_rate, float, floatset, 0, +EMPCFBOTH("level_age_rate", level_age_rate, float, NSC_FLOAT, 0, "ETU rate at which tech decays (0 -> no decline)") -EMPCFBOTH("tech_log_base", tech_log_base, float, floatset, 0, +EMPCFBOTH("tech_log_base", tech_log_base, float, NSC_FLOAT, 0, "Log base to apply to tech breakthroughs above the easy tech level") -EMPCFBOTH("ally_factor", ally_factor, float, floatset, 0, +EMPCFBOTH("ally_factor", ally_factor, float, NSC_FLOAT, 0, "Shared tech with allies (1 / ally_factor)") -EMPCFBOTH("edu_avg", edu_avg, float, floatset, 0, +EMPCFBOTH("edu_avg", edu_avg, float, NSC_FLOAT, 0, "Number of ETUs education is averaged over") -EMPCFBOTH("hap_avg", hap_avg, float, floatset, 0, +EMPCFBOTH("hap_avg", hap_avg, float, NSC_FLOAT, 0, "Number of ETUs happiness is averaged over") -EMPCFBOTH("edu_cons", edu_cons, double, doubleset, 0, +EMPCFBOTH("edu_cons", edu_cons, double, NSC_DOUBLE, 0, "Education consumption (1 breakthrough per edu_cons)") -EMPCFBOTH("hap_cons", hap_cons, double, doubleset, 0, +EMPCFBOTH("hap_cons", hap_cons, double, NSC_DOUBLE, 0, "Happiness consumption (1 breakthrough per hap_cons)") EMPCF_COMMENT("\n\n### Sectors") -EMPCFBOTH("startmob", startmob, int, intset, 0, +EMPCFBOTH("startmob", startmob, int, NSC_INT, KM_INTERNAL, "Starting mobility for sanctuaries") -EMPCFBOTH("sect_mob_scale", sect_mob_scale, float, floatset, 0, +EMPCFBOTH("sect_mob_scale", sect_mob_scale, float, NSC_FLOAT, 0, "Sector mobility accumulation (sect_mob_scale * ETUs per update)") -EMPCFBOTH("sect_mob_max", sect_mob_max, int, intset, 0, +EMPCFBOTH("sect_mob_max", sect_mob_max, int, NSC_INT, 0, "Maximum mobility for sectors") -EMPCFBOTH("buil_bh", buil_bh, int, intset, 0, +EMPCFBOTH("buil_bh", buil_bh, int, NSC_INT, 0, "Number of hcms required to build a bridge span") -EMPCFBOTH("buil_bc", buil_bc, double, doubleset, 0, +EMPCFBOTH("buil_bc", buil_bc, double, NSC_DOUBLE, 0, "Cash required to build a bridge span") -EMPCFBOTH("buil_bt", buil_bt, double, doubleset, 0, +EMPCFBOTH("buil_bt", buil_bt, double, NSC_DOUBLE, 0, "Technology required to build a bridge span") -EMPCFBOTH("buil_tower_bh", buil_tower_bh, int, intset, 0, +EMPCFBOTH("buil_tower_bh", buil_tower_bh, int, NSC_INT, 0, "Number of hcms required to build a bridge tower") -EMPCFBOTH("buil_tower_bc", buil_tower_bc, double, doubleset, 0, +EMPCFBOTH("buil_tower_bc", buil_tower_bc, double, NSC_DOUBLE, 0, "Cash required to build a bridge tower") -EMPCFBOTH("buil_tower_bt", buil_tower_bt, double, doubleset, 0, +EMPCFBOTH("buil_tower_bt", buil_tower_bt, double, NSC_DOUBLE, 0, "Technology required to build a bridge tower") EMPCF_COMMENT("\n\n### Land Units") -EMPCFBOTH("land_mob_scale", land_mob_scale, float, floatset, 0, +EMPCFBOTH("land_mob_scale", land_mob_scale, float, NSC_FLOAT, 0, "Land unit mobility accumulation (land_mob_scale * ETUs per update)") -EMPCFBOTH("land_grow_scale", land_grow_scale, int, intset, 0, +EMPCFBOTH("land_grow_scale", land_grow_scale, int, NSC_INT, 0, "How fast efficiency grows for land units each update (* ETUs)") -EMPCFBOTH("land_mob_max", land_mob_max, int, intset, 0, +EMPCFBOTH("land_mob_max", land_mob_max, int, NSC_INT, 0, "Maximum mobility for land units") -EMPCFBOTH("money_land", money_land, double, doubleset, 0, +EMPCFBOTH("money_land", money_land, double, NSC_DOUBLE, 0, "Cost per ETU to maintain land units (percentage of unit price)") -EMPCFBOTH("morale_base", morale_base, int, intset, 0, +EMPCFBOTH("morale_base", morale_base, int, NSC_INT, KM_INTERNAL, "Base level for setting morale of land units") EMPCF_COMMENT("\n\n### Planes") -EMPCFBOTH("plane_mob_scale", plane_mob_scale, float, floatset, 0, +EMPCFBOTH("plane_mob_scale", plane_mob_scale, float, NSC_FLOAT, 0, "Plane mobility accumulation (plane_mob_scale * ETUs per update)") -EMPCFBOTH("plane_grow_scale", plane_grow_scale, int, intset, 0, +EMPCFBOTH("plane_grow_scale", plane_grow_scale, int, NSC_INT, 0, "How fast efficiency grows for planes each update (* ETUs)") -EMPCFBOTH("plane_mob_max", plane_mob_max, int, intset, 0, +EMPCFBOTH("plane_mob_max", plane_mob_max, int, NSC_INT, 0, "Maximum mobility for planes") -EMPCFBOTH("money_plane", money_plane, double, doubleset, 0, +EMPCFBOTH("money_plane", money_plane, double, NSC_DOUBLE, 0, "Cost per ETU to maintain planes (percentage of plane price)") EMPCF_COMMENT("\n\n### Ships") -EMPCFBOTH("ship_mob_scale", ship_mob_scale, float, floatset, 0, +EMPCFBOTH("ship_mob_scale", ship_mob_scale, float, NSC_FLOAT, 0, "Ship mobility accumulation (ship_mob_scale * ETUs per update)") -EMPCFBOTH("ship_grow_scale", ship_grow_scale, int, intset, 0, +EMPCFBOTH("ship_grow_scale", ship_grow_scale, int, NSC_INT, 0, "How fast efficiency grows for ships each update (* ETUs)") -EMPCFBOTH("ship_mob_max", ship_mob_max, int, intset, 0, +EMPCFBOTH("ship_mob_max", ship_mob_max, int, NSC_INT, 0, "Maximum mobility for ships") -EMPCFBOTH("money_ship", money_ship, double, doubleset, 0, +EMPCFBOTH("money_ship", money_ship, double, NSC_DOUBLE, 0, "Cost per ETU to maintain ships (percentage of ship price)") -EMPCFBOTH("torpedo_damage", torpedo_damage, int, intset, 0, +EMPCFBOTH("torpedo_damage", torpedo_damage, int, NSC_INT, 0, "Torpedo damage (damage is X + 1dX + 1dX)") EMPCF_COMMENT("\n\n### Combat/Damage") -EMPCFBOTH("fort_max_interdiction_range", fort_max_interdiction_range, int, intset, 0, +EMPCFBOTH("fort_max_interdiction_range", fort_max_interdiction_range, int, NSC_INT, 0, "Maximum range (in sectors) a fort will try to interdict another country") -EMPCFBOTH("land_max_interdiction_range", land_max_interdiction_range, int, intset, 0, +EMPCFBOTH("land_max_interdiction_range", land_max_interdiction_range, int, NSC_INT, 0, "Maximum range (in sectors) a land unit will try to interdict another country") -EMPCFBOTH("ship_max_interdiction_range", ship_max_interdiction_range, int, intset, 0, +EMPCFBOTH("ship_max_interdiction_range", ship_max_interdiction_range, int, NSC_INT, 0, "Maximum range (in sectors) a ship will try to interdict another country") -EMPCFBOTH("flakscale", flakscale, double, doubleset, 0, +EMPCFBOTH("flakscale", flakscale, double, NSC_DOUBLE, 0, "Scale factor for flak damage") -EMPCFBOTH("combat_mob", combat_mob, double, doubleset, 0, +EMPCFBOTH("combat_mob", combat_mob, double, NSC_DOUBLE, 0, "How much mobility do units spend for combat (* casualties/bodies)") -EMPCFBOTH("people_damage", people_damage, double, doubleset, 0, +EMPCFBOTH("people_damage", people_damage, double, NSC_DOUBLE, 0, "People take this amount of normal damage") -EMPCFBOTH("unit_damage", unit_damage, double, doubleset, 0, +EMPCFBOTH("unit_damage", unit_damage, double, NSC_DOUBLE, 0, "Land units take this amount of normal damage") -EMPCFBOTH("collateral_dam", collateral_dam, double, doubleset, 0, +EMPCFBOTH("collateral_dam", collateral_dam, double, NSC_DOUBLE, 0, "Side effect damage amount done to sector") -EMPCFBOTH("assault_penalty", assault_penalty, double, doubleset, 0, +EMPCFBOTH("assault_penalty", assault_penalty, double, NSC_DOUBLE, 0, "Amount of normal attacking efficiency for paratroopers and assaulting") -EMPCFBOTH("fire_range_factor", fire_range_factor, float, floatset, 0, +EMPCFBOTH("fire_range_factor", fire_range_factor, float, NSC_FLOAT, 0, "Scale normal firing ranges by this amount") -EMPCFBOTH("sect_mob_neg_factor", sect_mob_neg_factor, int, intset, 0, +EMPCFBOTH("sect_mob_neg_factor", sect_mob_neg_factor, int, NSC_INT, 0, "Amount of negative mobility a sector has after takeover (ETU / x) (MOB_ACCESS)") -EMPCFBOTH("mission_mob_cost", mission_mob_cost, double, doubleset, 0, +EMPCFBOTH("mission_mob_cost", mission_mob_cost, double, NSC_DOUBLE, 0, "Cost to put something on a mission (percentage of max mob)") EMPCF_COMMENT("\n\n### Populace") -EMPCFBOTH("uwbrate", uwbrate, double, doubleset, 0, +EMPCFBOTH("uwbrate", uwbrate, double, NSC_DOUBLE, 0, "Birth rate for uw's") -EMPCFBOTH("money_civ", money_civ, double, doubleset, 0, +EMPCFBOTH("money_civ", money_civ, double, NSC_DOUBLE, 0, "Money gained from taxes on a civilian in one ETU") -EMPCFBOTH("money_mil", money_mil, double, doubleset, 0, +EMPCFBOTH("money_mil", money_mil, double, NSC_DOUBLE, 0, "Money gained from taxes on an active soldier in one ETU") -EMPCFBOTH("money_res", money_res, double, doubleset, 0, +EMPCFBOTH("money_res", money_res, double, NSC_DOUBLE, 0, "Money gained from taxes on a soldier on active reserve in one ETU") -EMPCFBOTH("money_uw", money_uw, double, doubleset, 0, +EMPCFBOTH("money_uw", money_uw, double, NSC_DOUBLE, 0, "Money gained from taxes on an uncompensated worker in one ETU") -EMPCFBOTH("babyeat", babyeat, double, doubleset, 0, +EMPCFBOTH("babyeat", babyeat, double, NSC_DOUBLE, 0, "Amount of food to mature 1 baby into a civilian") -EMPCFBOTH("bankint", bankint, double, doubleset, 0, +EMPCFBOTH("bankint", bankint, double, NSC_DOUBLE, 0, "Bank dollar gain (per bar per etu)") -EMPCFBOTH("eatrate", eatrate, double, doubleset, 0, +EMPCFBOTH("eatrate", eatrate, double, NSC_DOUBLE, 0, "Food eating rate for mature people") -EMPCFBOTH("fcrate", fcrate, double, doubleset, 0, +EMPCFBOTH("fcrate", fcrate, double, NSC_DOUBLE, 0, "Food cultivation rate (* workforce in sector)") -EMPCFBOTH("fgrate", fgrate, double, doubleset, 0, +EMPCFBOTH("fgrate", fgrate, double, NSC_DOUBLE, 0, "Food growth rate (* fertility of sector)") -EMPCFBOTH("obrate", obrate, double, doubleset, 0, +EMPCFBOTH("obrate", obrate, double, NSC_DOUBLE, 0, "Civilian birth rate") -EMPCFBOTH("rollover_avail_max", rollover_avail_max, int, intset, 0, +EMPCFBOTH("rollover_avail_max", rollover_avail_max, int, NSC_INT, 0, "Maximum avail that can roll over an update") EMPCF_COMMENT("\n\n### Nukes") -EMPCFBOTH("decay_per_etu", decay_per_etu, double, doubleset, 0, +EMPCFBOTH("decay_per_etu", decay_per_etu, double, NSC_DOUBLE, 0, "Decay of fallout per ETU") -EMPCFBOTH("fallout_spread", fallout_spread, double, doubleset, 0, +EMPCFBOTH("fallout_spread", fallout_spread, double, NSC_DOUBLE, 0, "Amount of fallout that leaks into surrounding sectors") -EMPCFBOTH("drnuke_const", drnuke_const, float, floatset, 0, +EMPCFBOTH("drnuke_const", drnuke_const, float, NSC_FLOAT, 0, "Amount of research to tech needed to build a nuke (if DR_NUKE is on)") EMPCF_COMMENT("\n\n### Market/Trade") -EMPCFBOTH("MARK_DELAY", MARK_DELAY, int, intset, 0, +EMPCFBOTH("MARK_DELAY", MARK_DELAY, int, NSC_INT, 0, "Number of seconds commodities stay on the market for bidding") -EMPCFBOTH("TRADE_DELAY", TRADE_DELAY, int, intset, 0, +EMPCFBOTH("TRADE_DELAY", TRADE_DELAY, int, NSC_INT, 0, "Number of seconds ships, planes, and units stay on the market for bidding") -EMPCFBOTH("buytax", buytax, double, doubleset, 0, +EMPCFBOTH("buytax", buytax, double, NSC_DOUBLE, 0, "Tax (in percentage points) charged to the buyer on market purchases") -EMPCFBOTH("tradetax", tradetax, double, doubleset, 0, +EMPCFBOTH("tradetax", tradetax, double, NSC_DOUBLE, 0, "Amount of a trade transaction the seller makes (the rest is tax)") EMPCF_COMMENT("\n\n### Trade ships") -EMPCFBOTH("trade_1_dist", trade_1_dist, int, intset, 0, +EMPCFBOTH("trade_1_dist", trade_1_dist, int, NSC_INT, 0, "Less than this distance no money for cashing in") -EMPCFBOTH("trade_2_dist", trade_2_dist, int, intset, 0, +EMPCFBOTH("trade_2_dist", trade_2_dist, int, NSC_INT, 0, "Less than this distance gets trade_1 money for cashing in") -EMPCFBOTH("trade_3_dist", trade_3_dist, int, intset, 0, +EMPCFBOTH("trade_3_dist", trade_3_dist, int, NSC_INT, 0, "Less than this distance gets trade_2 money for cashing in (>= gets trade_3") -EMPCFBOTH("trade_1", trade_1, float, floatset, 0, +EMPCFBOTH("trade_1", trade_1, float, NSC_FLOAT, 0, "Return per sector on trade_1 distance amount") -EMPCFBOTH("trade_2", trade_2, float, floatset, 0, +EMPCFBOTH("trade_2", trade_2, float, NSC_FLOAT, 0, "Return per sector on trade_2 distance amount") -EMPCFBOTH("trade_3", trade_3, float, floatset, 0, +EMPCFBOTH("trade_3", trade_3, float, NSC_FLOAT, 0, "Return per sector on trade_3 distance amount") -EMPCFBOTH("trade_ally_bonus", trade_ally_bonus, float, floatset, 0, +EMPCFBOTH("trade_ally_bonus", trade_ally_bonus, float, NSC_FLOAT, 0, "Bonus you get for cashing in with an ally") -EMPCFBOTH("trade_ally_cut", trade_ally_cut, float, floatset, 0, +EMPCFBOTH("trade_ally_cut", trade_ally_cut, float, NSC_FLOAT, 0, "Bonus your ally gets for you cashing in with them") EMPCF_COMMENT("\n\n### Misc.") -EMPCFBOTH("anno_keep_days", anno_keep_days, int, intset, 0, +EMPCFBOTH("anno_keep_days", anno_keep_days, int, NSC_INT, KM_INTERNAL, "How long until announcements expire (<0 means never)") -EMPCFBOTH("fuel_mult", fuel_mult, int, intset, 0, +EMPCFBOTH("fuel_mult", fuel_mult, int, NSC_INT, 0, "Multiplier for fuel to mobility calculation") -EMPCFBOTH("lost_items_timeout", lost_items_timeout, int, intset, 0, +EMPCFBOTH("lost_items_timeout", lost_items_timeout, int, NSC_INT, KM_INTERNAL, "Seconds before a lost item is timed out of the database") -EMPCFONLYC(NULL, emp_config_dummy, NULL, NULL, 0, NULL) +EMPCFONLYC(NULL, emp_config_dummy, NULL, NSC_NOTYPE, 0, NULL) #undef EMPCFONLYC #undef EMPCFBOTH diff --git a/include/optlist.h b/include/optlist.h index 05fe84de..c11eb8c9 100644 --- a/include/optlist.h +++ b/include/optlist.h @@ -99,24 +99,27 @@ int start_unit_type[]; #endif /* Variables that get values derived from econfig */ -extern s_char *upfil; -extern s_char *downfil; -extern s_char *disablefil; -extern s_char *banfil; -extern s_char *authfil; -extern s_char *annfil; -extern s_char *timestampfil; -extern s_char *teldir; -extern s_char *telfil; +extern char *upfil; +extern char *downfil; +extern char *disablefil; +extern char *banfil; +extern char *authfil; +extern char *annfil; +extern char *timestampfil; +extern char *teldir; +extern char *telfil; + +enum { + KM_ALLOC = 0x01, /* memory allocated */ + KM_INTERNAL = 0x02 /* not to be disclosed to players */ +}; struct keymatch { - s_char *km_key; /* the key */ - void (*km_func)(struct keymatch * kp, s_char **av); - /* the function to call if matches */ - void *km_data; /* associated data */ + char *km_key; /* the key */ + nsc_type km_type; /* type of associated data */ + void *km_data; /* pointer to associated data */ int km_flags; /* useful flags */ -#define KM_ALLOC 0x01 /* memory allocated */ - s_char *km_comment; /* Comment (hopefully useful) */ + char *km_comment; /* Comment (hopefully useful) */ }; extern struct keymatch configkeys[]; diff --git a/src/lib/commands/xdump.c b/src/lib/commands/xdump.c index 650d4a27..543d3dbb 100644 --- a/src/lib/commands/xdump.c +++ b/src/lib/commands/xdump.c @@ -491,6 +491,36 @@ xdopt(void) return RET_OK; } +static int +xdver(void) +{ + struct keymatch *kp; + char *sep; + struct valstr val; + + xdhdr1("version"); + + sep = ""; + for (kp = configkeys; kp->km_key; ++kp) { + if (kp->km_type != NSC_NOTYPE && !(kp->km_flags & KM_INTERNAL)) { + pr("%s%s", sep, kp->km_key); + sep = " "; + } + } + pr("\n"); + + sep = ""; + for (kp = configkeys; kp->km_key; ++kp) { + if (kp->km_type != NSC_NOTYPE && !(kp->km_flags & KM_INTERNAL)) { + xdeval(&val, kp->km_type, kp->km_data, 0, 0); + sep = xdprval(&val, sep); + } + } + pr("\n"); + + return RET_OK; +} + /* Experimental extended dump command */ int xdump(void) @@ -510,6 +540,8 @@ xdump(void) return xdchr(chridx_by_name(player->argp[2])); } else if (!strncmp(p, "opt", strlen(p))) { return xdopt(); + } else if (!strncmp(p, "ver", strlen(p))) { + return xdver(); } return RET_SYN; diff --git a/src/lib/gen/emp_config.c b/src/lib/gen/emp_config.c index 287a25a4..22cf2a34 100644 --- a/src/lib/gen/emp_config.c +++ b/src/lib/gen/emp_config.c @@ -43,6 +43,8 @@ * */ +#include +#include #include #include /* atoi free atol */ #include @@ -63,15 +65,6 @@ extern char *strdup(); /* Dummy one */ static int emp_config_dummy; -static void optstrset(struct keymatch *kp, s_char **av); -static void intset(struct keymatch *kp, s_char **av); -static void floatset(struct keymatch *kp, s_char **av); -static void doubleset(struct keymatch *kp, s_char **av); -static void longset(struct keymatch *kp, s_char **av); -static void optionset(struct keymatch *kp, s_char **av); -static void optiondel(struct keymatch *kp, s_char **av); -static void worldxset(struct keymatch *kp, s_char **av); - /* things that can be changed */ struct keymatch configkeys[] = { #define EMP_CONFIG_C_OUTPUT @@ -81,7 +74,7 @@ struct keymatch configkeys[] = { static void fixup_files(void); static struct keymatch *keylookup(s_char *key, struct keymatch tbl[]); - +static int set_option(const char *, int); /* * read in empire configuration @@ -90,36 +83,93 @@ int emp_config(char *file) { FILE *fp; - s_char scanspace[1024]; - s_char *av[65]; + char scanspace[1024]; + char *av[65]; char buf[BUFSIZ]; struct keymatch *kp; + int lno = 0; + int errors = 0; + int i; - if (file == NULL || (fp = fopen(file, "r")) == NULL) { + if (file == NULL) { fixup_files(); - return RET_OK; + return 0; } + if ((fp = fopen(file, "r")) == NULL) { + fprintf(stderr, "Can't open %s for reading (%s)\n", + file, strerror(errno)); + return -1; + } + while (fgets(buf, sizeof buf, fp) != NULL) { - if (buf[0] == '#' || buf[0] == '\n') + ++lno; + for (i = 0; buf[i] && isspace(buf[i]); ++i) ; + if (!buf[i] || buf[i] == '#') continue; if (parse(buf, av, 0, scanspace, 0) < 0) { - fprintf(stderr, "Can't parse line %s", buf); + fprintf(stderr, "%s:%d: Can't parse line %s", file, lno, buf); + errors = 1; continue; } - if ((kp = keylookup(av[0], configkeys)) != NULL) { - (*kp->km_func) (kp, av + 1); - } else { - fprintf(stderr, "Unknown config key %s\n", av[0]); + if ((kp = keylookup(av[0], configkeys)) == NULL) { + fprintf(stderr, "%s:%d: Unknown config key %s\n", + file, lno, av[0]); + errors = 1; + continue; + } + if (av[1] == NULL) { + fprintf(stderr, "%s:%d: Config key %s needs a value\n", + file, lno, av[0]); + errors = 1; + continue; + } + i = 2; + switch (kp->km_type) { + case NSC_INT: + *(int *)kp->km_data = atoi(av[1]); + break; + case NSC_FLOAT: + *(float *)kp->km_data = atof(av[1]); + break; + case NSC_DOUBLE: + *(double *)kp->km_data = atof(av[1]); + break; + case NSC_LONG: + *(long *)kp->km_data = atol(av[1]); + break; + case NSC_STRING: + if (kp->km_flags & KM_ALLOC) + free(*(char **)kp->km_data); + *(char **)kp->km_data = strdup(av[1]); + kp->km_flags |= KM_ALLOC; + break; + case NSC_NOTYPE: + for (i = 1; av[i]; ++i) { + if (set_option(av[i], kp->km_key[0] != 'n') < 0) { + fprintf(stderr, "%s:%d: Unknown option %s\n", + file, lno, av[i]); + errors = 1; + } + } + break; + default: + assert(0); + } + if (av[i] != NULL) { + fprintf(stderr, "%s:%d: Junk after value of config key %s\n", + file, lno, av[0]); + errors = 1; } } fclose(fp); fixup_files(); + WORLD_X &= ~1; /* make even */ - return RET_OK; + return -errors; } struct otherfiles { - s_char **files; + char **files; char *name; }; @@ -184,188 +234,66 @@ keylookup(register s_char *command, struct keymatch *tbl) return NULL; } -/* worldx int setting function */ -static void -worldxset(struct keymatch *kp, s_char **av) -{ - int *intptr = (int *)kp->km_data; - - if (*av == NULL || intptr == NULL) - return; - *intptr = atoi(*av); - if (!((*intptr % 2) == 0)) { - /* Must be div / 2, so subtract one */ - *intptr = *intptr - 1; - } -} - -/* generic int setting function */ -static void -intset(struct keymatch *kp, s_char **av) -{ - int *intptr = (int *)kp->km_data; - - if (*av == NULL || intptr == NULL) - return; - *intptr = atoi(*av); -} - -/* generic float set function */ -static void -floatset(struct keymatch *kp, s_char **av) -{ - float *floatptr = (float *)kp->km_data; - - if (*av == NULL || floatptr == NULL) - return; - *floatptr = atof(*av); -} - - - -/* generic string set function */ -static void -optstrset(struct keymatch *kp, s_char **av) -{ - s_char **confstrp = (s_char **)kp->km_data; - - if (*av == NULL || confstrp == NULL) - return; - if (kp->km_flags & KM_ALLOC) - free(*confstrp); - *confstrp = strdup(*av); - kp->km_flags |= KM_ALLOC; -} - -/* generic double set function */ -static void -doubleset(struct keymatch *kp, s_char **av) -{ - double *doublep = (double *)kp->km_data; - - if (*av == NULL || doublep == NULL) - return; - *doublep = atof(*av); -} - -/* generic long set function */ -static void -longset(struct keymatch *kp, s_char **av) -{ - long int *longp = (long int *)kp->km_data; - - if (*av == NULL || longp == NULL) - return; - *longp = atol(*av); -} - void -print_config(FILE * fp) +print_config(FILE *fp) { struct empfile *ep; - struct otherfiles *op; + struct option_list *op; + struct otherfiles *ofp; struct keymatch *kp; fprintf(fp, "# Empire Configuration File:\n"); for (kp = configkeys; kp->km_key; kp++) { - /* We print a few special things here */ - if (kp->km_comment) { - if (kp->km_comment[0]) { - if (kp->km_comment[0] != '\n') - fprintf(fp, "\n# "); - fprintf(fp, "%s\n", kp->km_comment); - } - } + if (kp->km_comment) + fprintf(fp, "\n# %s\n", kp->km_comment); if (!kp->km_key[0]) continue; - if (kp->km_func == optstrset) { - fprintf(fp, "%s \"%s\"\n", kp->km_key, - *(s_char **)kp->km_data); - } else if (kp->km_func == intset) { + switch (kp->km_type) { + case NSC_STRING: + fprintf(fp, "%s \"%s\"\n", kp->km_key, *(char **)kp->km_data); + break; + case NSC_INT: fprintf(fp, "%s %d\n", kp->km_key, *(int *)kp->km_data); - } else if (kp->km_func == worldxset) { - fprintf(fp, "%s %d\n", kp->km_key, *(int *)kp->km_data); - } else if (kp->km_func == floatset) { + break; + case NSC_FLOAT: fprintf(fp, "%s %g\n", kp->km_key, *(float *)kp->km_data); - } else if (kp->km_func == doubleset) { + break; + case NSC_DOUBLE: fprintf(fp, "%s %g\n", kp->km_key, *(double *)kp->km_data); - } else if (kp->km_func == longset) { + break; + case NSC_LONG: fprintf(fp, "%s %ld\n", kp->km_key, *(long *)kp->km_data); - } else if (kp->km_func == optionset) { - struct option_list *op; - - for (op = Options; op->opt_key; op++) { - if (*op->opt_valuep) + break; + case NSC_NOTYPE: + for (op = Options; op->opt_key; op++) + if (*op->opt_valuep != (kp->km_key[0] == 'n')) fprintf(fp, "%s %s\n", kp->km_key, op->opt_key); - } - } else if (kp->km_func == optiondel) { - struct option_list *op; - - for (op = Options; op->opt_key; op++) { - if (*op->opt_valuep == 0) - fprintf(fp, "%s %s\n", kp->km_key, op->opt_key); - } - } else - fprintf(fp, "# Unknown format %s\n", kp->km_key); + break; + default: + assert(0); + } } fprintf(fp, "\n"); for (ep = empfile; ep < &empfile[EF_MAX]; ep++) fprintf(fp, "# File %s -> %s\n", ep->name, ep->file); - for (op = ofiles; op->files; op++) - fprintf(fp, "# File %s -> %s\n", op->name, *(op->files)); + for (ofp = ofiles; ofp->files; ofp++) + fprintf(fp, "# File %s -> %s\n", ofp->name, *(ofp->files)); } -/* add an option to the list */ -static void -set_option(const char *s) +/* Set option S to value VAL; return 0 on success, -1 on failure. */ +static int +set_option(const char *s, int val) { struct option_list *op; for (op = Options; op->opt_key; op++) { if (strcmp(op->opt_key, s) == 0) { - *op->opt_valuep = 1; - return; + *op->opt_valuep = val; + return 0; } } - fprintf(stderr, "Unknown option %s\n", s); -} - -/* delete an option from the list */ -static void -delete_option(const char *s) -{ - struct option_list *op; - - for (op = Options; op->opt_key; op++) { - if (strcmp(op->opt_key, s) == 0) { - *op->opt_valuep = 0; - return; - } - } - fprintf(stderr, "Unknown option %s\n", s); -} - -/* config interface */ -static void -optionset(struct keymatch *kp, s_char **av) - /* unused - we have a well known global */ -{ - char **cpp; - - for (cpp = (char **)av; *cpp; cpp++) - set_option(*cpp); -} - -/* config interface */ -static void -optiondel(struct keymatch *kp, s_char **av) - /* unused - we have a well known global */ -{ - char **cpp; - - for (cpp = (char **)av; *cpp; cpp++) - delete_option(*cpp); + return -1; } diff --git a/src/lib/global/constants.c b/src/lib/global/constants.c index 46bc2cb5..4cd8964a 100644 --- a/src/lib/global/constants.c +++ b/src/lib/global/constants.c @@ -38,8 +38,8 @@ #include "misc.h" #include "xy.h" -s_char *privname = PRVNAM; /* name of priv user */ -s_char *privlog = PRVLOG; /* logname of priv user */ +char *privname = PRVNAM; /* name of priv user */ +char *privlog = PRVLOG; /* logname of priv user */ int WORLD_X = DEF_WORLD_X; /* World size - x */ int WORLD_Y = DEF_WORLD_Y; /* World size - y */ @@ -53,15 +53,15 @@ int etu_per_update = ETUS; /* # of etu's per update, from misc.h */ int adj_update = 0; /* update time adjustment */ int update_window = 0; /* update window adjustment */ int hourslop = 5; /* amount of slop to match update times */ -s_char *update_times = ""; /* times regular update is allowed */ +char *update_times = ""; /* times regular update is allowed */ int update_policy = 0; /* update policy for regular updates */ int update_demandpolicy = 2; /* update policy for demand updates */ int update_missed = 999; /* demand updates missed before veto */ int update_wantmin = 0; /* number of votes required for demand update */ int blitz_time = 10; /* number of minutes between blitz updates */ -s_char *update_demandtimes = ""; /* times demand update is allowed */ -s_char *game_days = ""; /* days game is running */ -s_char *game_hours = ""; /* hours game is running */ +char *update_demandtimes = ""; /* times demand update is allowed */ +char *game_days = ""; /* days game is running */ +char *game_hours = ""; /* hours game is running */ int max_idle = 15; /* session dies after max_idle minutes idle */ int sect_mob_max = 127; /* sector mobility limits */ diff --git a/src/lib/global/path.c b/src/lib/global/path.c index 3f2ec903..77c7e733 100644 --- a/src/lib/global/path.c +++ b/src/lib/global/path.c @@ -35,17 +35,17 @@ #include "gamesdef.h" #include "misc.h" -s_char *infodir = EMPDIR "/info.nr"; -s_char *datadir = EMPDIR "/data"; -s_char *teldir = EMPDIR "/data/tel"; +char *infodir = EMPDIR "/info.nr"; +char *datadir = EMPDIR "/data"; +char *teldir = EMPDIR "/data/tel"; -s_char *upfil = EMPDIR "/data/up"; -s_char *downfil = EMPDIR "/data/down"; -s_char *disablefil = EMPDIR "/data/disable"; -s_char *telfil = EMPDIR "/data/tel/tel"; -s_char *annfil = EMPDIR "/data/ann"; -s_char *banfil = EMPDIR "/data/ban"; -s_char *authfil = EMPDIR "/data/auth"; -s_char *timestampfil = EMPDIR "/data/timestamp"; +char *upfil = EMPDIR "/data/up"; +char *downfil = EMPDIR "/data/down"; +char *disablefil = EMPDIR "/data/disable"; +char *telfil = EMPDIR "/data/tel/tel"; +char *annfil = EMPDIR "/data/ann"; +char *banfil = EMPDIR "/data/ban"; +char *authfil = EMPDIR "/data/auth"; +char *timestampfil = EMPDIR "/data/timestamp"; -s_char *loginport = EMP_PORT; +char *loginport = EMP_PORT;