Commit graph

82 commits

Author SHA1 Message Date
55ff4f8e3a Clean up initialization of empfile[]
Split ef_init() into two functions: empfile_init() for initialization,
and empfile_fixup() to fix it up for configuration.  Put them next to
empfile[].  Move the call to empfile_init() from behind emp_config()
to before it.
2008-02-10 11:40:57 +01:00
db02dda32f Update copyright notice 2008-01-19 10:15:37 +01:00
404095d2fa Trim system includes. 2007-08-18 17:03:14 +00:00
Ron Koenderink
4bbc3f4286 Simple POSIX I/O emulation layer to work around Windows's defective
Unix I/O:
[_WIN32] (socklen_t, accept, posix_accept, bind. posix_bind, listen)
(posix_listen, setsockopt, posix_setsockopt, shutdown, posix_shutdown)
(socket, posix_socket, close, posix_close, creat, fstat, posix_fstat)
(lseek, posix_lseek, open, posix_open, read, posix_read, write)
(posix_write, fileno, posix_fileno, fcntl, O_NONBLOCK, F_RDLCK)
(F_WRLCK, F_GETFL, F_SETFL, F_SETLK, EWOULDBLOCK, ENOTSOCK)
(flock, fsync, posix_fsync):
New.
(ef_open, io_close, io_input, io_output, io_shutdown, io_noblocking)
(player_accept): Use them to simplify.
[_WIN32] (posix_fd2socket): New.
(empth_select): Use it.
(gen_power): Use it.
2007-08-14 03:33:28 +00:00
e1926d9ce9 (ef_open): Leaked file descriptor when fcntl() failed. 2007-07-31 05:03:25 +00:00
56de7a2151 (WORLD_SZ): New.
(isok, ef_init, bmaps_intersect, bp_init, player_accept)
(finish_sects, main): Use it.

(bp_neighbors, bp_lbcost, pathcost): Use XYOFFSET().  No
functional change.
2007-07-28 12:12:17 +00:00
Ron Koenderink
c97d79c0ee (add, disa, ef_open, logerror, main): Switch permissions to
standard defines instead of magic numbers to improve portability.
Also define WIN32 equivalents to the standard defines.
2007-03-10 16:29:51 +00:00
Ron Koenderink
7356da4775 (add.c, disa.c, log.c, new.c, wantupd.c, wu.c) [_WIN32,__GNUC__]:
Remove the !defined(__GNUC__) for <io.h>.
Not required for VC8.
2007-02-23 22:35:50 +00:00
7db3523f62 Update known contributors comment. 2007-01-13 10:16:43 +00:00
63bdc89835 Update copyright notice. 2007-01-09 19:09:31 +00:00
Ron Koenderink
ce63991c9f (ef_open) [_WIN32]: Fix to get a read lock instead of a write lock for
EFF_RDONLY and to get a write lock instead of a total file lock for
file opened for writing.
2006-11-29 12:16:43 +00:00
Ron Koenderink
2742a2db62 (ef_open) [_WIN32]: Add shared.h for MinGW environment,
needed for WIN32 file locking. Broken (missed) in rev 1.70.
2006-08-08 22:43:18 +00:00
Ron Koenderink
a89e21037e (ef_open) [_WIN32]: Provide file locking for WIN32. 2006-08-07 17:15:04 +00:00
de124108de (ef_open): Lock the file. This prevents two programs (servers in
particular) running on the same game state.  fairland does not use
ef_open() at this time, and thus ignores the lock.
2006-08-02 18:05:04 +00:00
Ron Koenderink
d413884a37 [_WIN32, __GNUC__]: Reorganize the include files for WIN32 to
separate the MinGW environment from the MSVC environment and
WIN32 environment.  Reorganize the order of the includes so
the system files are always loaded first to prevent with misc.h defines.
Remove system file includes from misc.h.
2006-07-13 21:14:16 +00:00
Ron Koenderink
e55198f2c3 [_WIN32]: Add missing include sys/types.h to get off_t. 2006-07-11 03:16:02 +00:00
e42053d928 Break inclusion cycle: prototypes.h and commands.h included each
other.  Ensure headers in include/ can be included in any order
(except for econfig-spec.h, which is special).  New header types.h to
help avoid inclusion cycles.  Sort include directives.  Remove some
superflous includes.
2006-07-10 06:37:23 +00:00
211a56489b (ef_open): Zero cache size (empty EFF_MEM file) can lead to null cache
on some systems, which confuses assertions.  Force non-zero size.
2006-03-06 18:23:41 +00:00
6bd0eabb21 (ef_init): Remove superflous size initialization for tables that are
initialized from builtin config files.
(ef_init_chr): Unused, remove.
2006-02-19 17:07:04 +00:00
4ff857507e Doc fix. 2006-02-12 23:01:47 +00:00
4515b84c59 COPYING duplicates information from README. Remove. Move GPL from
LICENSE to COPYING, because that's where it usually is.  Update all
the references to these files.
2006-01-21 19:48:41 +00:00
Ron Koenderink
04a8b84592 (ship_bomb, deli, do_demo, fuel, grin, look_ship)
(ltend, multifire, quite_bigdef, mine, landmine)
(do_loan, prod, printdiff, sell, sona, stre)
(tend, fire_dchrg, vers, work, ac_planedamage)
(ac_shipflak, ask_off, get_mine_dsupport, att_fight)
(ask_move_in_off, detonate, sd, land_gun)
(land_unitgun, lnd_fort_interdiction, lnd_fortify)
(perform_mission, pln_mine, pln_mobcost)
(retreat_ship1, retreat_land1, shp_sweep)
(shp_fort_interdiction, shp_missle_defense)
(new_work, growfood, upd_land, land_repair)
(get_materials, do_mob_ship, do_mob_land)
(load_it, unload_it, prod_plane, produce)
(guerrilla, upd_buildeff, spread_fallout)
(upd_ship, ship_repair, min, dmin, MIN):
Remove min() and dmin() functions and replace
with a MIN macro in misc.h.  Remove local MIN
macros and use the new one in misc.h.  This
change removes the need for the special
case for _WIN32.

(fuel, look_ship, multifire, mission, sona)
(plane_sona, ef_open, player_accept, player_main)
(ac_dog, att_get_combat, calc_mobcost)
(ask_move_in_off, intelligence_report)
(build_mission_list_type, perform_mission)
(show_mission, use_supply, dodistribute)
(allocate_memory, max, dmax, MAX):
Remove max() and dmax() functions and replace
with a MAX macro in misc.h.  Remove local MAX
macros and use the new one in misc.h.  This
change removes the need for the special
case for _WIN32.
2006-01-12 14:23:55 +00:00
3e400c018c Update copyright notice. 2006-01-05 13:36:57 +00:00
c3900f8424 (empfile, fileinit, lnd_init, lnd_postread, lnd_prewrite, nuk_init)
(nuk_postread, nuk_prewrite, pln_init, pln_postread, pln_prewrite)
(sct_postread, sct_prewrite, shp_init, shp_postread, shp_prewrite)
(ef_extend): Use void * for generic pointer parameter.
2005-12-31 12:52:18 +00:00
3aebb68ee7 Include config.h. 2005-12-27 18:04:19 +00:00
803009d0ce (fillcache, do_write): Revert the previous revision. The portability
issue applies only to sockets, and EWOULDBLOCK isn't defined on all
systems.
2005-11-26 18:36:48 +00:00
edaa05b8cb (fillcache, do_write, io_input, io_output): Portability fix: always
check both EAGAIN and EWOULDBLOCK.  These are distinct on some
systems, e.g. HP-UX.
(io_output) [hpux]: Used to treat all errors as EWOULDBLOCK.  This
looks like a inept attempt to `fix' the above.  Remove.
2005-11-22 20:28:18 +00:00
661b650c1a (ef_write): Don't memcpy() onto itself; behavior's undefined. 2005-11-19 15:41:37 +00:00
d575d779ad (ef_ptr, ef_read): Undo rev. 1.52 for these two, because there are
callers that rely on these functions to fail for bad ID.
2005-11-19 11:20:13 +00:00
4fb17a62c0 (ef_init_chr): Sentinel names are now null, simplify sentinel check. 2005-11-07 07:54:16 +00:00
5173f8cd07 (ef_ptr, ef_read): Oops on bad ID. Some callers rely on these
functions to fail at the end of the table.  To support that, the first
ID beyond the end is not considered bad.

(ef_ensure_space): Oops on bad ID.
2005-11-06 11:01:37 +00:00
41bf5be715 (UNMAPPED_INIT, UNMAPPED_CACHE, ARRAY_INIT, ARRAY_TABLE, PTR_INIT)
(PTR_CACHE): Rename.

(ARRAY_CACHE): New.
(empfile): Use it to set csize of elements EF_SHIP_CHR, EF_PLANE_CHR,
EF_LAND_CHR, EF_NUKE_CHR.
(ef_init_chr): Now that empfile[]'s initializer sets csize, remove the
temporary csize initialization here.  The value wasn't correct, but
better than nothing.
2005-11-03 18:25:26 +00:00
ae9e7dad43 (ef_ptr): Null cache can't happen. 2005-10-31 21:26:16 +00:00
4cbb45d0e0 (ef_open): EFF_STATIC and cache not null can't happen.
(ef_open): Leave check of fd to do_write().
2005-10-30 18:48:55 +00:00
b2ae3257ca (empfile): Rename member ef_uid to uid for consistency with other
members.

(empfile): Reorder members for clearer documentation.

(EFF_IMMUTABLE): New.
(EFF_OPEN): Remove, use ~EFF_IMMUTABLE.

(empfile): Don't initialize member size to a useless value for EF_MAP
and EF_BMAP.  ef_init() writes the real value.
2005-10-30 12:50:13 +00:00
Ron Koenderink
bb79c64b92 (ef_init_chr): Add a NULL check to sentinel check. 2005-10-29 20:38:59 +00:00
6c849f0334 (ef_init): Fix check for sentinel. 2005-10-29 16:50:07 +00:00
ae81dade53 (ef_init, ef_init_srv): Rename old ef_init() ef_init_srv(), call new
ef_init().  Move initialization of map sizes to ef_init().
(main): Don't initialize map sizes by hand, call ef_init().

(fileinit): Internal linkage.
2005-10-29 15:16:50 +00:00
6be5ba5d40 (ef_byname): Old version didn't work when a table name was followed by
one of its prefixes.  src/lib/global/file.c rev. 1.18 added such table
entries, and file.h rev. 1.34 made them visible to ef_byname().
Simply use stmtch().  This also rejects ambiguous abbreviations: "s"
used to return EF_SECTOR, it now returns M_NOTUNIQUE.
2005-10-29 06:18:41 +00:00
2fc1e74a72 (ef_byname_from): New.
(set, mission, multifire, fuel, cons_choose, cede): Use it instead of
ef_byname().  Remove the hacks to map unwanted results to wanted
results.  The hacks in set() were broken: bad input made the code cast
arbitrary items to union trdgenstr, with potentially disastrous
consequences.  Closes #906483 and #906486.

(set): Less cryptic prompt and diagnostics.
2005-10-27 21:33:17 +00:00
71908018ec (ef_open): Implement EFF_STATIC.
(ef_open): Simplify dynamic buffer allocation.
2005-10-26 16:49:52 +00:00
babf467e15 (EFF_STATIC): New.
(empfile): Use it.
(ef_open): Oops on it (not implemented).
(ef_close): Implement it (trivial).
2005-10-24 23:35:18 +00:00
889dfebaad (ef_nameof, ef_ensure_space): Oops on bad argument.
(ef_check): Use CANT_HAPPEN().
2005-10-24 23:27:18 +00:00
12b1427693 (ef_zapcache): Clearing the cache doesn't make sense. No harm done if
the next user can't use the cache, it gets automatically zapped then.
Remove.
2005-10-24 23:23:53 +00:00
ecab7c4f2f (ef_read): Catch null cache.
(ef_read): Used to get the file size again some circumstances; doesn't
make sense, as no other process may be writing this file.

(ef_write): Don't refuse to write beyond record 65536.  This module
can cope with that.  Some users have trouble long before that (short
record numbers), but that should be handled there.

(ef_write): Catch table not file-backed.
2005-10-24 23:16:13 +00:00
880a3e399b (ef_extend): Use do_write() & simplify. Catch table not file-backed.
Catch negative count; used to have no effect with EFF_MEM, and
confusion otherwise.  Try to recover from partially successful
extension.  Need help from ef_write() to do a better job; to be done.
2005-10-24 22:47:16 +00:00
62264f8ada (ef_extend): Fix rev. 1.25. 2005-10-24 22:44:29 +00:00
e29369fadb Clean up rev. 1.30. 2005-10-24 21:57:20 +00:00
f2e6d6b232 (ef_ptr): Change return type to void *.
(ef_ptr): Use CANT_HAPPEN() to ensure EFF_MEM; check it before less
serious index out of range failure.
2005-10-24 21:43:47 +00:00
5030d124a1 (ef_open): Fix fatal typo. 2005-10-24 20:42:27 +00:00