Commit graph

144 commits

Author SHA1 Message Date
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
8b6549519b (ef_open): Portability fix: malloc(0) may return null, which is not a
failure.  fillcache() chokes on null cache, so don't call it for empty
files.
2005-10-24 20:36:17 +00:00
3eb3607f0d (ef_open): Failed to reset empfile member fd on failure, and leaked
file descriptors.

(ef_flush, ef_close): Rely on negative fd instead of null cache to
detect unopened file.  This is more logical and consistent with the
use of cache by the new tables that are not file-backed (rev. 1.22).
Use CANT_HAPPEN().

(ef_close): Failed to report cash flush failure.

(ef_close): Clear all EFF_OPEN flags.  Should have been done in
rev. 1.27.
2005-10-24 20:18:04 +00:00
1c4fb67911 (do_write): New.
(ef_flush, ef_write): Use it.  Old code couldn't cope with interrupted
or short writes (mostly harmless, as disk reads commonly complete).

(ef_write): Use CANT_HAPPEN() for catching unimplemented table
extensions.
2005-10-24 19:17:05 +00:00
ab03d83ce1 (fillcache): Rewrite. Old version failed to check success of lseek(),
couldn't cope with interrupted or short reads (mostly harmless, as
disk reads commonly complete), and left an empty cache after a failed
read.
(ef_open): Use fillcache() instead of read().
(ef_read): Fail if fillcache() fails to read at least one element.
Old version copied garbage to its caller and claimed success.
2005-10-24 19:02:39 +00:00
3ea02e2519 (ef_open): Fail if file size is not a multiple of record size. 2005-10-24 18:40:13 +00:00
64d8f6babe (ef_open, EFF_RDONLY, EFF_CREATE, EFF_OPEN): Replace mode parameter
(really open flags, not mode) by new flags EFF_RDONLY, EFF_CREATE.
Open flags were needlessly general.  Callers changed.
(empfile): Member mode now unused, remove.
2005-10-24 18:18:59 +00:00
bfd14661c5 (ef_close): Reset member fd.
(ef_open): Catch attempt to open open file.
2005-10-23 06:24:08 +00:00
a3dd70f8c0 (EFF_OPEN): New.
(ef_open): Restrict HOW to EFF_OPEN.
2005-10-23 06:17:14 +00:00
290e759998 (ef_open): Remove code killed by the previous revision. 2005-10-22 19:59:56 +00:00
2802ce1863 (ef_open): Don't assume blksize() is the same for all files.
(ef_open): Ensure the cache has at least one slot.
2005-10-22 19:12:27 +00:00
0ab9260151 (empfile, chr_camap): Merge chr_camap[] into empfile[]. No existing
user sees the new elements of empfile[].
(EF_SECTOR_CHR, EF_SHIP_CHR, EF_PLANE_CHR, EF_LAND_CHR, EF_NUKE_CHR)
(EF_TREATY_CHR, EF_ITEM, EF_INFRASTRUCTURE, EF_PRODUCT): New.  Not yet
used.
(my_ef_byname): Replacement for ef_byname() that sees the new
elements.
(xdchr): Work with empfile[] instead of chr_camap[].
(xdump): Use my_ef_byname() instead of ef_byname() and
chridx_by_name().
(camap, chr_camap, chridx_by_name): Remove.
2005-10-21 19:38:37 +00:00
380b063f9c Remove some redundant parenthesis; no functional change. 2005-07-23 19:48:35 +00:00
a127869da2 (ef_write): Don't call log_last_commands() directly, use oops(). If
it's worth logging commands, then it's worth dumping core.
2005-05-28 15:52:29 +00:00
345ad3dfe0 Update copyright notice. 2005-03-16 22:03:16 +00:00
Ron Koenderink
55e6aca9e0 (wrmakesrc,wripglob,wrgamesdef,info,apro,mobupdate,rea,turn
upda,ef_open,logerror,emp_config,match_user,show_motd,gamedown,
typed_wu,delete_old_announcements,mobility_check,mobility_init,
allocate_memory,write_newcap_script,main,files,fairland,doconfig,)
[_WIN32]: Switchback to default mode of text.
"t" (text) is not included the ISO/ANSI C standard but "b" (binary)
is included.
2005-03-02 12:47:15 +00:00
Ron Koenderink
1a8488bc45 (main,mobility_check,upda,turn,rea,mobupdate,ef_open,logerror,
emp_config,gamedown,show_motd,match_user,typed_wu,
delete_old_announcements) [_WIN32]: switch the default file mode to
binary to match POSIX.  Remove the now unneccessary ifdef for
the open/fopen. Add text mode for user files (econfig/auth).
2004-12-30 01:31:03 +00:00
Marc Olzheim
d3396821f0 (ef_extend): free allocated tmpobj before early returns as well. 2004-12-16 12:29:41 +00:00
Marc Olzheim
e94b16b024 (EFF_COM,ef_items): No longer in use after removal of 'variables'. Removed.
Clean 'register' and s_char on the way. Remove dead code.
Rename some variables to better reflect their meaning.
Add function comments.
2004-12-16 12:25:56 +00:00
Marc Olzheim
c6ef918f3a Cleanup #includes of (mostly a long time) unused header files.
No functional changes.
2004-12-13 16:47:13 +00:00
7d34832100 (fldoff): Use offsetof() instead. Rest of struct.h is unused, remove. 2004-09-10 18:41:58 +00:00
fac342ed49 Update copyright notice. 2004-09-07 15:07:16 +00:00
dcfd251f95 caddr_t is obsolete. Replace by void *, except for struct empfile
member cache, which becomes char * to keep pointer arithmetic simple.
2004-08-23 18:29:44 +00:00
e7d75b2279 Use gcc function attribute `format' to catch bad format strings. Fix
them.  From Marc Olzheim.
Type modifier 'l' was missing in many places, probably rendering the
server useless on 64-bit hosts.
(ef_flush, ef_write, ef_extend, lwpCreate, lwpDestroy): Use conversion
specifier 'p' to print pointers.
(check_market): Fix display of loan amount.
(doland): Fix unescaped '%' (undefined behavior).
(ldump, ndump, pdump, sdump): Don't use flag '0' with conversion
specifier 's' (undefined behavior).
(dump, ldump, lost, ndump, pdump, sdump, empth_create, update_sched):
Cast time_t and pthread_t to long for printing.
(lwpStackCheck, lwpStackCheckUsed, finish_sects): Insert cast to fix
argument type on all platforms.
(prod): Remove extra argument.
(perform_mission, airdamage, retreat_land1, lwpReschedule): Format
string missed arguments.
2004-03-09 12:27:40 +00:00
eccc5cb7d7 Sectors need space for items, deliveries and distribution thresholds.
To save space, the ancients invented `variables': a collection of
key-value pairs, missing means zero value, space for `enough' keys.
This complicates the code, as assigning to a `variable' can fail for
lack of space.  Over time, `enough' increased, and for quite some time
now `variables' have been *wasting* space.  This changeset replaces
them, except in struct mchrstr, struct lchrstr and struct pchrstr,
where they are read-only, and will be replaced later.  It is only a
first step; further cleanup is required.  To simplify and minimize
this necessarily huge changeset, the new item[] arrays have an unused
slot 0, and the old variable types V_CIVIL, ... are still defined, but
must have the same values as the item types I_CIVIL, ...
2004-03-03 16:54:22 +00:00
e67dca9d29 Indentation fixes; suspect indent-emp is to blame. 2004-02-28 18:06:11 +00:00
c53438e7a0 (ef_ensure_space): New.
(edit): Use it to to fix copying to virgin unit slot.  Closes #896475.
From Ron Koenderink.
2004-02-24 18:19:57 +00:00
b5401d9dd4 <string.h> is ISO C, no need to #if it. 2004-02-19 10:05:53 +00:00
237baffca9 Supply prototypes where possible. This uncovered type errors with
thread entrypoints:
(lwpSelect, shutdown_sequence): Parameters didn't match thread entry
point prototype.
(lwpEntryPoint): Arguments didn't match thread entry point prototype.

Change linkage of functions without prototype declaration to static
where possible.

Remove some superflous declarations, replace others by suitable
includes.
2004-02-17 17:59:30 +00:00
beba530119 (file_lock, file_unlock, ef_lock, ef_unlock, commlock, communlock):
File locking doesn't make sense, must be a leftover from the distant
past.  Remove.  Callers changed.
2004-01-29 17:07:26 +00:00
4ae9c417b3 (bzero, bcopy): Obsolete BSDisms; remove. Remove some calls without
effect.  Replace calls by struct assignment where possible.  Replace
clear buffer, copy string to buffer by strncpy().  Use assignment to
clear when that's clearer.  Replace overlapping copy through bounce
buffer by memmove().  Replace rest by standard memset() and memcpy().
Also use sizeof() instead of literal array sizes for robustness, and
instead of symbolic array sizes for clarity.
2004-01-08 17:54:28 +00:00
9b7adfbecc Indented with src/scripts/indent-emp. 2003-09-02 20:48:48 +00:00
d8b7fdfae1 Import of Empire 4.2.12 2003-08-23 12:23:04 +00:00