diff --git a/.gitignore b/.gitignore index 9f9acde2..2e447e59 100644 --- a/.gitignore +++ b/.gitignore @@ -60,7 +60,3 @@ *.orig *.rej *~ - -# Visual Studio Directories for building -/.vs -/Empire diff --git a/Make.mk b/Make.mk index 19988c01..3416853c 100644 --- a/Make.mk +++ b/Make.mk @@ -81,8 +81,8 @@ edatadir := $(datadir)/empire builtindir := $(edatadir)/builtin einfodir := $(edatadir)/info.nr ehtmldir := $(edatadir)/info.html -client/w32 := arpa/inet.h getopt.c netdb.h netinet/in.h sys/time.h \ -sys/socket.h sys/uio.h unistd.h w32io.c w32sockets.c w32types.h +client/w32 := arpa/inet.h netdb.h netinet/in.h sys/time.h sys/socket.h \ +sys/uio.h unistd.h w32io.c w32sockets.c w32types.h # Abbreviate make output # Run make with a V=1 parameter for full output. diff --git a/include/item.h b/include/item.h index dcebcc6f..7466af6a 100644 --- a/include/item.h +++ b/include/item.h @@ -27,7 +27,7 @@ * item.h: Definitions for item characteristics stuff * * Known contributors to this file: - * Markus Armbruster, 2004-2020 + * Markus Armbruster, 2004-2016 */ #ifndef ITEM_H @@ -80,8 +80,7 @@ struct ichrstr { /* variables using this structure */ -#define ICHR_SZ (I_MAX + 2) -extern struct ichrstr ichr[ICHR_SZ]; +extern struct ichrstr ichr[I_MAX + 2]; /* procedures using/returning this struct */ diff --git a/include/land.h b/include/land.h index 3052a327..8d2581a2 100644 --- a/include/land.h +++ b/include/land.h @@ -124,8 +124,7 @@ struct lchrstr { #define putland(n, p) ef_write(EF_LAND, (n), (p)) #define getlandp(n) ((struct lndstr *)ef_ptr(EF_LAND, (n))) -#define LCHR_SZ 128 -extern struct lchrstr lchr[LCHR_SZ]; +extern struct lchrstr lchr[128]; enum { LND_AIROPS_EFF = 50 /* min. efficiency for air ops */ diff --git a/include/nuke.h b/include/nuke.h index 06622486..86a5ce7f 100644 --- a/include/nuke.h +++ b/include/nuke.h @@ -82,8 +82,7 @@ struct nchrstr { #define putnuke(n, p) ef_write(EF_NUKE, (n), (p)) #define getnukep(n) ((struct nukstr *)ef_ptr(EF_NUKE, (n))) -#define NCHR_SZ 64 -extern struct nchrstr nchr[NCHR_SZ]; +extern struct nchrstr nchr[64]; /* src/lib/common/cargo.c */ extern void nuk_carrier_change(struct nukstr *, int, int, int); diff --git a/include/plane.h b/include/plane.h index 35a807b1..db455577 100644 --- a/include/plane.h +++ b/include/plane.h @@ -134,8 +134,7 @@ struct plist { #define putplane(n, p) ef_write(EF_PLANE, (n), (p)) #define getplanep(n) ((struct plnstr *)ef_ptr(EF_PLANE, (n))) -#define PLCHR_SZ 128 -extern struct plchrstr plchr[PLCHR_SZ]; +extern struct plchrstr plchr[128]; struct shiplist { int uid; diff --git a/include/product.h b/include/product.h index 79d532dd..e1d2bbd9 100644 --- a/include/product.h +++ b/include/product.h @@ -58,7 +58,6 @@ struct pchrstr { char *p_sname; /* short (7 char or less) name of product */ }; -#define PCHR_SZ 32 -extern struct pchrstr pchr[PCHR_SZ]; +extern struct pchrstr pchr[32]; #endif diff --git a/include/sect.h b/include/sect.h index d003bbfe..0bb7d936 100644 --- a/include/sect.h +++ b/include/sect.h @@ -165,9 +165,7 @@ struct dchrstr { #define getsectp(x, y) ((struct sctstr *)ef_ptr(EF_SECTOR, sctoff((x), (y)))) #define getsectid(id) ((struct sctstr *)ef_ptr(EF_SECTOR, (id))) -#define DCHR_SZ 64 -extern struct dchrstr dchr[DCHR_SZ]; - +extern struct dchrstr dchr[64]; #define IS_BIG_CITY(type) (dchr[(type)].d_pkg == UPKG) /* Minimal efficiency of sectors that can be knocked down (bridges) */ @@ -223,8 +221,7 @@ struct sctintrins { unsigned char in_enable; /* enabled iff non-zero */ }; -#define INTRCHR_SZ INT_DEF + 2 -extern struct sctintrins intrchr[INTRCHR_SZ]; +extern struct sctintrins intrchr[INT_DEF + 2]; extern int fort_fire(struct sctstr *); extern int sct_rail_track(struct sctstr *); diff --git a/include/ship.h b/include/ship.h index 83db8c03..aa709876 100644 --- a/include/ship.h +++ b/include/ship.h @@ -126,8 +126,7 @@ struct mchrstr { #define putship(n, p) ef_write(EF_SHIP, (n), (p)) #define getshipp(n) ((struct shpstr *)ef_ptr(EF_SHIP, (n))) -#define MCHR_SZ 128 -extern struct mchrstr mchr[MCHR_SZ]; +extern struct mchrstr mchr[128]; enum { SHP_AIROPS_EFF = 50, /* min. efficiency for air ops */ diff --git a/info/Empire4.4.t b/info/Empire4.4.t index a64dffb0..f058551b 100644 --- a/info/Empire4.4.t +++ b/info/Empire4.4.t @@ -5,7 +5,7 @@ This document outlines the various changes to the game and how they will affect you, the player. These were coded as the Wolfpack project. .NF -Changes to Empire 4.4.1 - Sat Feb 21 2021 +Changes to Empire 4.4.1 - Sun Jan 17 2021 * Fix land unit casualties in guerrilla fighting. Broken in 4.4.0. * Changes to edit: - You can now edit bars on ships and land units, and missile @@ -61,7 +61,7 @@ Changes to Empire 4.4.1 - Sat Feb 21 2021 when it can't place all the islands the deity asks for. You can't fill the world with islands anymore by asking for impossibly many of them. - - Fix silent failure to place mountains. Fairness issue. + - Fix silent failure to place place mountains. Fairness issue. - Fix unfair mountain resources. Neglected when Empire 3 made mountains produce gold dust. - Drop undocumented, silent limit of 1000 mountains per island. @@ -74,8 +74,8 @@ Changes to Empire 4.4.1 - Sat Feb 21 2021 - Manual page improvements. - Code refactoring and cleanup. * Test suite improvements: - - Fix empdump-test for "make check-accept". Has been broken since - its addition in 4.3.33. + - Fix empdump-test for "make check-accept". Has been broken its + addition in 4.3.33. - Improve give and edit coverage. - Cover load and tend. There are known gaps. - Improve fairland coverage. @@ -97,8 +97,8 @@ Changes to Empire 4.4.1 - Sat Feb 21 2021 systems: read from standard input in canonical mode with echo turned off. Before, it commonly read from /dev/tty in noncanonical mode. - * The server crashed on some systems when bomb, launch and - interdiction missed the target. Fix that. + * The server crashed on systems when bomb, launch and interdiction + miss the target. Fix that. * Fix truncated "info Empire4.3" on systems with a losing nroff. * Make client's fancy line editing and persistent history work on more systems. @@ -118,14 +118,9 @@ Changes to Empire 4.4.1 - Sat Feb 21 2021 third more than before. * Fix crash when a deity runs neweff or production on a sea sector. Broken in 4.4.0. - * Don't let embarked engineers work. Screwed up when the work - command was added in Empire 2. - * Fix buy to handle concurrent lot change more robustly. The flawed - handling goes back to 4.0.0 and 4.0.2. - * Fix MOB_ACCESS mobility update for ships owned by countries with - even country number. Broken in 4.4.0. - * Journal entries for output are no longer flushed to disk right - away. + * Don't let embarked engineers work. Screwed up when the command was + added in Empire 2. + * Fix buy error messages on concurrent lot change. * Code refactoring and cleanup. * Info page, manual page and documentation fixes and clarifications. diff --git a/m4/my_windows_api.m4 b/m4/my_windows_api.m4 index 7bcabfc6..63a2af62 100644 --- a/m4/my_windows_api.m4 +++ b/m4/my_windows_api.m4 @@ -12,8 +12,6 @@ AC_DEFUN([MY_WINDOWS_API], AC_DEFINE([WINDOWS], 1, [Define if compiling for Windows API]) AC_DEFINE([WIN32_LEAN_AND_MEAN], 1, [Define to make Windows includes pull in less junk]) - AC_DEFINE([_WIN32_WINNT], 0x0601, - [Request Windows 7]) LIBS_SOCKETS="-lws2_32" else LIBS_SOCKETS= diff --git a/src/client/Makefile.in b/src/client/Makefile.in index 674d8834..f9350384 100644 --- a/src/client/Makefile.in +++ b/src/client/Makefile.in @@ -101,6 +101,5 @@ host.$O: w32/sys/socket.h w32/netinet/in.h w32/arpa/inet.h w32/netdb.h w32/unist main.$O: w32/sys/socket.h w32/unistd.h w32/w32types.h play.$O: w32/sys/socket.h w32/unistd.h w32/w32types.h ringbuf.$O: w32/sys/uio.h w32/w32types.h -w32/getopt.$O: w32/w32io.$O: misc.h w32/sys/uio.h w32/w32types.h w32/w32sockets.$O: w32/sys/socket.h w32/unistd.h w32/w32types.h diff --git a/src/lib/commands/arm.c b/src/lib/commands/arm.c index d1cbce96..9c7b220b 100644 --- a/src/lib/commands/arm.c +++ b/src/lib/commands/arm.c @@ -30,7 +30,7 @@ * Dave Pare, 1986 * Ken Stevens, 1995 * Steve McClure, 2000 - * Markus Armbruster, 2006-2018 + * Markus Armbruster, 2006-2021 */ #include diff --git a/src/lib/commands/buy.c b/src/lib/commands/buy.c index 45dbec50..d3088ff4 100644 --- a/src/lib/commands/buy.c +++ b/src/lib/commands/buy.c @@ -30,7 +30,7 @@ * Dave Pare, 1986 * Pat Loney, 1992 * Steve McClure, 1996-2000 - * Markus Armbruster, 2004-2021 + * Markus Armbruster, 2004-2018 */ #include diff --git a/src/lib/commands/info.c b/src/lib/commands/info.c index 0cac8d15..dd7069b5 100644 --- a/src/lib/commands/info.c +++ b/src/lib/commands/info.c @@ -40,9 +40,7 @@ #include #include #include -#ifdef _WIN32 -#include -#else +#if !defined(_WIN32) #include #include #endif @@ -273,7 +271,7 @@ c_apropos(void) #else /* _WIN32 */ int -c_info(void) +info(void) { char buf[255]; FILE *fp; @@ -386,7 +384,7 @@ c_info(void) } int -c_apropos(void) +apro(void) { HANDLE hDir; WIN32_FIND_DATA fData; diff --git a/src/lib/commands/laun.c b/src/lib/commands/laun.c index 15ba87a2..9e1466b5 100644 --- a/src/lib/commands/laun.c +++ b/src/lib/commands/laun.c @@ -263,8 +263,7 @@ launch_missile(struct plnstr *pp) target_ship.shp_x, target_ship.shp_y, target_ship.shp_own, &sublaunch) < 0) return RET_OK; - /* @target_ship may have expended shells defending */ - getship(target_ship.shp_uid, &target_ship); + getship(n, &target_ship); if (!msl_hit(pp, shp_hardtarget(&target_ship), EF_SHIP, N_SHP_MISS, N_SHP_SMISS, sublaunch, target_ship.shp_own)) { diff --git a/src/lib/commands/load.c b/src/lib/commands/load.c index 62847837..b3e9b60c 100644 --- a/src/lib/commands/load.c +++ b/src/lib/commands/load.c @@ -30,7 +30,7 @@ * David Sharnoff, 1987 * Ken Stevens, 1995 (rewritten) * Steve McClure, 1998-2000 - * Markus Armbruster, 2004-2021 + * Markus Armbruster, 2004-2018 */ #include @@ -79,12 +79,12 @@ c_load(void) "What commodity (or 'plane' or 'land')? ", buf); if (!p || !*p) return RET_SYN; - ich = item_by_name(p); + if (!strncmp(p, "plane", 5)) type = EF_PLANE; else if (!strncmp(p, "land", 4)) type = EF_LAND; - else if (ich) + else if (NULL != (ich = item_by_name(p))) type = EF_SECTOR; else { pr("Can't %sload '%s'\n", loading ? "" : "un", p); @@ -208,12 +208,11 @@ c_lload(void) "What commodity (or 'plane' or 'land')? ", buf); if (!p || !*p) return RET_SYN; - ich = item_by_name(p); if (!strncmp(p, "plane", 5)) type = EF_PLANE; else if (!strncmp(p, "land", 4)) type = EF_LAND; - else if (ich) + else if (NULL != (ich = item_by_name(p))) type = EF_SECTOR; else { pr("Can't %sload '%s'\n", loading ? "" : "un", p); diff --git a/src/lib/commands/mfir.c b/src/lib/commands/mfir.c index de2aa0a4..cb1eb9c5 100644 --- a/src/lib/commands/mfir.c +++ b/src/lib/commands/mfir.c @@ -393,7 +393,7 @@ c_fire(void) putsect(&vsect); break; default: - getship(vship.shp_uid, &vship); + getship(vshipno, &vship); shipdamage(&vship, dam); if (vship.shp_effic < SHIP_MINEFF) pr("%s sunk!\n", prsub(&vship)); diff --git a/src/lib/commands/tend.c b/src/lib/commands/tend.c index 3f037714..5bce7177 100644 --- a/src/lib/commands/tend.c +++ b/src/lib/commands/tend.c @@ -30,7 +30,7 @@ * Dave Pare, 1986 * Thomas Ruschak, 1992 * Steve McClure, 2000 - * Markus Armbruster, 2004-2021 + * Markus Armbruster, 2004-2017 */ #include @@ -70,10 +70,10 @@ c_tend(void) buf); if (!p || !*p) return RET_SYN; - ip = item_by_name(p); + if (!strncmp(p, "land", 4)) type = EF_LAND; - else if (ip) + else if (NULL != (ip = item_by_name(p))) type = EF_SECTOR; else { pr("Can't tend '%s'\n", p); diff --git a/src/lib/commands/work.c b/src/lib/commands/work.c index cd4cd7bb..870f6a73 100644 --- a/src/lib/commands/work.c +++ b/src/lib/commands/work.c @@ -27,7 +27,7 @@ * work.c: Implementation of the work command * * Known contributors to this file: - * Markus Armbruster, 2009-2021 + * Markus Armbruster, 2009-2016 */ #include diff --git a/src/lib/common/pathfind.c b/src/lib/common/pathfind.c index 4b3b75c9..7b1f13cb 100644 --- a/src/lib/common/pathfind.c +++ b/src/lib/common/pathfind.c @@ -42,7 +42,7 @@ #include "sect.h" #ifdef PATH_FIND_DEBUG -#define DPRINTF(...) ((void)fprintf(stdout, ## __VA_ARGS__)) +#define DPRINTF(...) ((void)printf(## __VA_ARGS__)) #else #define DPRINTF(...) ((void)0) #endif @@ -490,11 +490,12 @@ path_find_visualize(coord sx, coord sy, coord dx, coord dy) { int uid; int xmin, xmax, ymin, ymax, x, y, odd, ch; - double c, cost; + double c, u, cost; char buf[1024]; assert(pf_cost(XYOFFSET(sx, sy)) == 0.0); c = pf_cost(XYOFFSET(dx, dy)); + u = c / 10.0; /* find bounding box */ xmin = xmax = 0; diff --git a/src/lib/gen/chance.c b/src/lib/gen/chance.c index 35ed9824..c415c085 100644 --- a/src/lib/gen/chance.c +++ b/src/lib/gen/chance.c @@ -27,7 +27,7 @@ * chance.c: Roll dice * * Known contributors to this file: - * Markus Armbruster, 2006-2021 + * Markus Armbruster, 2006-2012 */ #include @@ -140,12 +140,11 @@ djb_hash(unsigned hash, void *buf, size_t sz) unsigned pick_seed(void) { + int fd; unsigned seed; int got_seed = 0; struct timeval tv; pid_t pid; -#ifndef _WIN32 - int fd; /* * Modern systems provide random number devices, but the details @@ -165,7 +164,6 @@ pick_seed(void) got_seed = read(fd, &seed, sizeof(seed)) == sizeof(seed); close(fd); } -#endif if (!got_seed) { /* Kernel didn't provide, fall back to hashing time and PID */ diff --git a/src/lib/global/item.c b/src/lib/global/item.c index 0f5d8092..ea59b2c6 100644 --- a/src/lib/global/item.c +++ b/src/lib/global/item.c @@ -38,4 +38,4 @@ * Table of item types * Initialized on startup from item.config and deity custom config (if any). */ -struct ichrstr ichr[ICHR_SZ]; +struct ichrstr ichr[I_MAX + 2]; diff --git a/src/lib/global/land.c b/src/lib/global/land.c index 3066d8d1..2b1bf9f6 100644 --- a/src/lib/global/land.c +++ b/src/lib/global/land.c @@ -43,7 +43,7 @@ * Initialized on startup from land.config and deity custom config (if any). * Terminated by a sentinel with null l_name. */ -struct lchrstr lchr[LCHR_SZ]; +struct lchrstr lchr[]; #define logx(a, b) (log((a)) / log((b))) #define LND_ATTDEF(b, t) (((b) * (1.0 + ((sqrt((t)) / 100.0) * 4.0))) \ diff --git a/src/lib/global/nuke.c b/src/lib/global/nuke.c index d61ee00c..e3e9df91 100644 --- a/src/lib/global/nuke.c +++ b/src/lib/global/nuke.c @@ -38,4 +38,4 @@ * Table of nuke types * Initialized on startup from nuke.config and deity custom config (if any). */ -struct nchrstr nchr[NCHR_SZ]; +struct nchrstr nchr[]; diff --git a/src/lib/global/plane.c b/src/lib/global/plane.c index bc1a6dd4..dd70a0f9 100644 --- a/src/lib/global/plane.c +++ b/src/lib/global/plane.c @@ -45,7 +45,7 @@ * Initialized on startup from plane.config and deity custom config (if any). * Terminated by a sentinel with null pl_name. */ -struct plchrstr plchr[PLCHR_SZ]; +struct plchrstr plchr[]; #define logx(a, b) (log((a)) / log((b))) #define PLN_ATTDEF(b, t) (b + ((b?1:0) * ((t/20)>10?10:(t/20)))) diff --git a/src/lib/global/product.c b/src/lib/global/product.c index 412abfab..ba49b8b5 100644 --- a/src/lib/global/product.c +++ b/src/lib/global/product.c @@ -38,4 +38,4 @@ * Table of product types * Initialized on startup from product.config and deity custom config (if any). */ -struct pchrstr pchr[PCHR_SZ]; +struct pchrstr pchr[]; diff --git a/src/lib/global/sect.c b/src/lib/global/sect.c index afafd80a..3adb58a4 100644 --- a/src/lib/global/sect.c +++ b/src/lib/global/sect.c @@ -43,10 +43,10 @@ * Initialized on startup from sect.config and deity custom config (if any). * Terminated by a sentinel with null d_name. */ -struct dchrstr dchr[DCHR_SZ]; +struct dchrstr dchr[]; /* * Table of infrastructure types * Initialized on startup from infra.config and deity custom config (if any). */ -struct sctintrins intrchr[INTRCHR_SZ]; +struct sctintrins intrchr[INT_DEF + 2]; diff --git a/src/lib/global/ship.c b/src/lib/global/ship.c index 39aa2984..4ed3361a 100644 --- a/src/lib/global/ship.c +++ b/src/lib/global/ship.c @@ -45,7 +45,7 @@ * Initialized on startup from ship.config and deity custom config (if any). * Terminated by a sentinel with null m_name. */ -struct mchrstr mchr[MCHR_SZ]; +struct mchrstr mchr[]; #define logx(a, b) (log((a)) / log((b))) #define SHP_DEF(b, t) (t ? (b * (logx(t, 40.0) < 1.0 ? 1.0 : \ diff --git a/src/lib/subs/journal.c b/src/lib/subs/journal.c index f98d2731..93ae6635 100644 --- a/src/lib/subs/journal.c +++ b/src/lib/subs/journal.c @@ -128,8 +128,7 @@ journal_entry_end(int newline, int flush) if (!newline) fputc('\\', journal); fputc('\n', journal); - if (flush) - fflush(journal); + fflush(journal); if (ferror(journal)) { logerror("Error writing journal (%s)", strerror(errno)); clearerr(journal); diff --git a/src/lib/subs/move.c b/src/lib/subs/move.c index 95ac4e82..e1b03632 100644 --- a/src/lib/subs/move.c +++ b/src/lib/subs/move.c @@ -111,7 +111,7 @@ move_ground(struct sctstr *start, struct sctstr *end, curx = start->sct_x; cury = start->sct_y; total_mcost = 0.0; - if (!getsect(curx, cury, §)) { + if (getsect(curx, cury, §) < 0) { logerror("move_path: getsect %d,%d", curx, cury); return -1; } @@ -191,7 +191,7 @@ move_ground(struct sctstr *start, struct sctstr *end, */ tmpx = curx + diroff[dir][0]; tmpy = cury + diroff[dir][1]; - if (!getsect(tmpx, tmpy, &next)) { + if (getsect(tmpx, tmpy, &next) < 0) { pr("You can't go there...\n"); *movstr = 0; continue; diff --git a/src/lib/subs/ship.c b/src/lib/subs/ship.c index fe63e69b..7b257941 100644 --- a/src/lib/subs/ship.c +++ b/src/lib/subs/ship.c @@ -56,7 +56,7 @@ shp_postread(int n, void *ptr) player->owner = (player->god || sp->shp_own == player->cnum); - if (opt_MOB_ACCESS && sp->shp_own && !update_running) + if (opt_MOB_ACCESS & sp->shp_own && !update_running) mob_inc_ship(sp, game_tick_to_now(&sp->shp_access)); } diff --git a/src/lib/subs/show.c b/src/lib/subs/show.c index 79ba622b..01241689 100644 --- a/src/lib/subs/show.c +++ b/src/lib/subs/show.c @@ -31,7 +31,7 @@ * Jeff Bailey, 1990 * Steve McClure, 1996 * Ron Koenderink, 2005-2009 - * Markus Armbruster, 2006-2021 + * Markus Armbruster, 2006-2020 */ #include @@ -615,10 +615,34 @@ static char * fmttime2822(time_t t) { static char buf[32]; - size_t n = strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S %z", +#if defined(_WIN32) + size_t n; + int nn; + TIME_ZONE_INFORMATION tzi; + long time_offset; + struct tm *time; + + time = localtime(&t); + + n = strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S", time); + if (CANT_HAPPEN(n == 0)) { + buf[0] = 0; + return buf; + } + GetTimeZoneInformation(&tzi); + time_offset = -(tzi.Bias + + (time->tm_isdst ? tzi.DaylightBias : tzi.StandardBias)); + + nn = _snprintf(buf + n, sizeof(buf) - n, " %+03ld%02ld", + time_offset / 60, labs(time_offset) % 60); + if (CANT_HAPPEN(nn <= 0 || nn + n >= sizeof(buf))) + buf[0] = 0; +#else + size_t n = strftime(buf, sizeof(buf), "%a, %d %b %Y %T %z", localtime(&t)); if (CANT_HAPPEN(n == 0)) buf[0] = 0; +#endif return buf; } diff --git a/src/lib/subs/takeover.c b/src/lib/subs/takeover.c index 6be81278..261e55f3 100644 --- a/src/lib/subs/takeover.c +++ b/src/lib/subs/takeover.c @@ -233,6 +233,7 @@ takeover_unit(struct empobj *unit, natid newown) struct shpstr *sp; struct plnstr *pp; struct lndstr *lp; + struct nukstr *np; int type; struct nstr_item ni; union empobj_storage cargo; @@ -261,6 +262,8 @@ takeover_unit(struct empobj *unit, natid newown) lp->lnd_harden = 0; break; case EF_NUKE: + np = (struct nukstr *)unit; + np->nuk_off = 1; break; default: CANT_REACH(); diff --git a/src/lib/subs/wu.c b/src/lib/subs/wu.c index 6bcaf000..355685ec 100644 --- a/src/lib/subs/wu.c +++ b/src/lib/subs/wu.c @@ -28,7 +28,7 @@ * * Known contributors to this file: * Steve McClure, 2000 - * Markus Armbruster, 2005-2021 + * Markus Armbruster, 2005-2016 */ #include @@ -110,16 +110,14 @@ typed_wu(natid from, natid to, char *message, int type) char box[1024]; struct player *other; - if (type == TEL_ANNOUNCE) { + if (type == TEL_ANNOUNCE) strcpy(box, annfil); - np = NULL; - } else { + else mailbox(box, to); - np = getnatp(to); - if (!np || np->nat_stat < STAT_SANCT) - return -1; - } + if (type != TEL_ANNOUNCE) + if (!(np = getnatp(to)) || np->nat_stat < STAT_SANCT) + return -1; #if !defined(_WIN32) if ((fd = open(box, O_WRONLY | O_APPEND, 0)) < 0) { #else diff --git a/src/lib/update/sect.c b/src/lib/update/sect.c index 9fcb21e4..8e6feba2 100644 --- a/src/lib/update/sect.c +++ b/src/lib/update/sect.c @@ -29,7 +29,7 @@ * Known contributors to this file: * Dave Pare, 1986 * Steve McClure, 1996 - * Markus Armbruster, 2004-2021 + * Markus Armbruster, 2004-2016 */ #include diff --git a/src/lib/w32/arpa/inet.h b/src/lib/w32/arpa/inet.h index de78f434..97a19a4c 100644 --- a/src/lib/w32/arpa/inet.h +++ b/src/lib/w32/arpa/inet.h @@ -33,6 +33,9 @@ #ifndef ARPA_INET_H #define ARPA_INET_H -#include "ws2tcpip.h" +#include "sys/socket.h" + +extern const char *inet_ntop(int af, const void *src, char *dst, + socklen_t cnt); #endif /* ARPA_INET_H */ diff --git a/src/lib/w32/getopt.c b/src/lib/w32/getopt.c deleted file mode 100644 index d0159750..00000000 --- a/src/lib/w32/getopt.c +++ /dev/null @@ -1,150 +0,0 @@ -#ifdef _MSC_VER -#define __UNCONST(a) ((void *)(a)) -#define _DIAGASSERT(cond) assert((cond)) -#define getprogname() ((const char *)nargv[0]) - -/* $NetBSD: getopt.c,v 1.29 2014/06/05 22:00:22 christos Exp $ */ - -/* - * Copyright (c) 1987, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if 0 -#include -__RCSID("$NetBSD: getopt.c,v 1.29 2014/06/05 22:00:22 christos Exp $"); - -#include "namespace.h" -#endif - -#include -#include -#include -#include -#include -#include - -#ifdef __weak_alias -__weak_alias(getopt,_getopt) -#endif - -int opterr = 1, /* if error message should be printed */ - optind = 1, /* index into parent argv vector */ - optopt, /* character checked for validity */ - optreset; /* reset getopt */ -char *optarg; /* argument associated with option */ - -#define BADCH (int)'?' -#define BADARG (int)':' -#define EMSG "" - -/* - * getopt -- - * Parse argc/argv argument vector. - */ -int -getopt(int nargc, char * const nargv[], const char *ostr) -{ - static const char *place = EMSG; /* option letter processing */ - char *oli; /* option letter list index */ - - _DIAGASSERT(nargv != NULL); - _DIAGASSERT(ostr != NULL); - - if (optreset || *place == 0) { /* update scanning pointer */ - optreset = 0; - place = nargv[optind]; - if (optind >= nargc || *place++ != '-') { - /* Argument is absent or is not an option */ - place = EMSG; - return (-1); - } - optopt = *place++; - if (optopt == '-' && *place == 0) { - /* "--" => end of options */ - ++optind; - place = EMSG; - return (-1); - } - if (optopt == 0) { - /* Solitary '-', treat as a '-' option - if the program (eg su) is looking for it. */ - place = EMSG; - if (strchr(ostr, '-') == NULL) - return -1; - optopt = '-'; - } - } else - optopt = *place++; - - /* See if option letter is one the caller wanted... */ - if (optopt == ':' || (oli = strchr(ostr, optopt)) == NULL) { - if (*place == 0) - ++optind; - if (opterr && *ostr != ':') - (void)fprintf(stderr, - "%s: unknown option -- %c\n", getprogname(), - optopt); - return (BADCH); - } - - /* Does this option need an argument? */ - if (oli[1] != ':') { - /* don't need argument */ - optarg = NULL; - if (*place == 0) - ++optind; - } else { - /* Option-argument is either the rest of this argument or the - entire next argument. */ - if (*place) - optarg = __UNCONST(place); - else if (oli[2] == ':') - /* - * GNU Extension, for optional arguments if the rest of - * the argument is empty, we return NULL - */ - optarg = NULL; - else if (nargc > ++optind) - optarg = nargv[optind]; - else { - /* option-argument absent */ - place = EMSG; - if (*ostr == ':') - return (BADARG); - if (opterr) - (void)fprintf(stderr, - "%s: option requires an argument -- %c\n", - getprogname(), optopt); - return (BADCH); - } - place = EMSG; - ++optind; - } - return (optopt); /* return option letter */ -} -#endif diff --git a/src/lib/w32/getrusage.c b/src/lib/w32/getrusage.c index 8c3a0bbc..4a657aa2 100644 --- a/src/lib/w32/getrusage.c +++ b/src/lib/w32/getrusage.c @@ -33,7 +33,7 @@ #include -#include +#include #include "sys/resource.h" int diff --git a/src/lib/w32/strptime.c b/src/lib/w32/strptime.c index 04b83eeb..123f4c7b 100644 --- a/src/lib/w32/strptime.c +++ b/src/lib/w32/strptime.c @@ -4,9 +4,6 @@ */ #include "w32misc.h" -#ifdef _MSC_VER -#define tzname _tzname -#endif typedef unsigned char u_char; typedef unsigned int uint; diff --git a/src/lib/w32/sys/time.h b/src/lib/w32/sys/time.h index 4e3c1244..cdc6b67b 100644 --- a/src/lib/w32/sys/time.h +++ b/src/lib/w32/sys/time.h @@ -33,15 +33,9 @@ #ifndef SYS_TIME_H #define SYS_TIME_H -#ifdef _MSC_VER - /* include winsock2.h thru sys/socket.h to get struct timeval */ #include "sys/socket.h" extern int gettimeofday(struct timeval *tv, void *tz); -#else /* !_MSC_VER */ -#include_next -#endif - #endif /* SYS_TIME_H */ diff --git a/src/lib/w32/unistd.h b/src/lib/w32/unistd.h index 6f401949..2e24d49e 100644 --- a/src/lib/w32/unistd.h +++ b/src/lib/w32/unistd.h @@ -27,7 +27,7 @@ * unistd.h: POSIX emulation for Windows * * Known contributors to this file: - * Ron Koenderink, 2007-2021 + * Ron Koenderink, 2007 * Markus Armbruster, 2007-2013 */ @@ -46,6 +46,7 @@ * here. Major name space pollution, can't be helped. */ #include +#include #include #include #include @@ -59,7 +60,6 @@ extern int w32_mkdir(const char *dirname, mode_t perm); /* Should be in sys/stat.h */ -#ifdef _MSC_VER #ifndef S_IRUSR #define S_IRUSR _S_IREAD #define S_IWUSR _S_IWRITE @@ -78,34 +78,22 @@ extern int w32_mkdir(const char *dirname, mode_t perm); #define S_IXOTH 0 #define S_IRWXO S_IROTH | S_IWOTH | S_IXOTH #endif -#endif /* Should be in fcntl.h */ -/* HACK, for use with fcntl() on a socket only, see w32sockets.c */ #define O_NONBLOCK 1 + #define F_GETFL 1 #define F_SETFL 2 + extern int fcntl(int fd, int cmd, ...); /* Stuff that actually belongs here */ #define close(fd) w32_close_function((fd)) extern int (*w32_close_function)(int); +#define ftruncate(fd, length) _chsize((fd), (length)) #define read(fd, buf, sz) w32_read_function((fd), (buf), (sz)) extern int (*w32_read_function)(int, void *, unsigned); #define write(fd, buf, sz) w32_write_function((fd), (buf), (sz)) extern int (*w32_write_function)(int, const void *, unsigned); -#ifdef _MSC_VER -#define ftruncate(fd, length) _chsize((fd), (length)) -#endif - -#ifdef _MSC_VER -extern int getopt(int, char * const [], const char *); -extern char *optarg; -extern int opterr; -extern int optind; -extern int optopt; -#else /* !_MSC_VER */ -#include_next -#endif #endif /* UNISTD_H */ diff --git a/src/lib/w32/w32misc.h b/src/lib/w32/w32misc.h index 92a900c8..8a27a384 100644 --- a/src/lib/w32/w32misc.h +++ b/src/lib/w32/w32misc.h @@ -28,7 +28,7 @@ * * Known contributors to this file: * Ron Koenderink, 2007 - * Markus Armbruster, 2007-2021 + * Markus Armbruster, 2007-2013 */ /* @@ -41,16 +41,30 @@ #include -/* strings.h */ #ifdef _MSC_VER +/* integral mismatch, due to misuse of sector short */ +#pragma warning (disable : 4761 ) + +/* strings.h */ #define strncasecmp(s1, s2, s3) _strnicmp((s1), (s2), (s3)) #endif /* _MSC_VER */ +/* errno.h */ +#ifndef EWOULDBLOCK +#define EWOULDBLOCK EAGAIN +#endif + /* fcntl.h */ #ifdef _MSC_VER #define O_ACCMODE (_O_RDONLY|_O_WRONLY|_O_RDWR) #endif +/* stdio.h */ +#ifdef _MSC_VER +#define snprintf _snprintf +#define vsnprintf _vsnprintf +#endif + /* time.h */ struct tm; extern char *strptime(const char *buf, const char *fmt, struct tm *tm); diff --git a/src/lib/w32/w32sockets.c b/src/lib/w32/w32sockets.c index f1c36cce..3d80a2da 100644 --- a/src/lib/w32/w32sockets.c +++ b/src/lib/w32/w32sockets.c @@ -232,6 +232,43 @@ w32_socket(int domain, int type, int protocol) return W32_SOCKET_TO_FD(sock); } +#ifdef HAVE_GETADDRINFO +const char * +inet_ntop(int af, const void *src, char *dst, socklen_t len) +{ + struct sockaddr *sa; + struct sockaddr_in sin; + struct sockaddr_in6 sin6; + size_t salen; + + if (af == AF_INET) { + memset(&sin, 0, sizeof(sin)); + sin.sin_family = af; + memcpy(&sin.sin_addr, src, sizeof(sin.sin_addr)); + sa = (struct sockaddr *)&sin; + salen = sizeof(sin); + } else if (af == AF_INET6) { + memset(&sin6, 0, sizeof(sin6)); + sin6.sin6_family = af; + memcpy(&sin6.sin6_addr, src, sizeof(sin6.sin6_addr)); + sa = (struct sockaddr *)&sin6; + salen = sizeof(sin6); + } else { + WSASetLastError(WSAEAFNOSUPPORT); + w32_set_winsock_errno(); + return NULL; + } + + if (getnameinfo(sa, salen, dst, len, NULL, 0, NI_NUMERICHOST)) { + WSASetLastError(WSAEAFNOSUPPORT); + w32_set_winsock_errno(); + return NULL; + } + + return dst; +} +#endif + /* * POSIX equivalent for fcntl(). * Horrible hacks, just good enough support Empire's use of fcntl(). diff --git a/src/util/fairland.c b/src/util/fairland.c index c9eb427a..68f8c956 100644 --- a/src/util/fairland.c +++ b/src/util/fairland.c @@ -193,6 +193,9 @@ struct resource_point uran_conf[] = { { 98, 0 }, { 127, 0 } }; +static void qprint(const char * const fmt, ...) + ATTRIBUTE((format (printf, 1, 2))); + /* * Program arguments and options */ @@ -302,26 +305,25 @@ static int bfs_queue_head, bfs_queue_tail; static const char *numletter = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; -static void print_vars(void); -static void qprint(const char * const fmt, ...) - ATTRIBUTE((format (printf, 1, 2))); static void help(char *); static void usage(void); static void parse_args(int argc, char *argv[]); static void allocate_memory(void); static void init(void); static int drift(void); -static int stable(int); -static void drift_capital(int); static int grow_continents(void); -static int grow_islands(void); static void create_elevations(void); -static void elevate_prep(void); -static void elevate_land(void); -static void elevate_sea(void); static void write_sects(void); static void output(void); static int write_newcap_script(void); +static int stable(int); +static void elevate_prep(void); +static void elevate_land(void); +static void elevate_sea(void); + +static void print_vars(void); +static void drift_capital(int); +static int grow_islands(void); /* Debugging aids: */ void print_own_map(void); @@ -1053,8 +1055,7 @@ add_sector(int c, int x, int y) adj_land_update(x, y); } -static int -grow_weight(int c, int x, int y, int spike) +static int grow_weight(int c, int x, int y, int spike) { int n, b;