Commit Graph

402 Commits

Author SHA1 Message Date
nhmall
b4f578495c more pointer style consistency 2024-02-20 13:04:32 -05:00
nhmall
688ac6ffbe remove register from variable declarations 2024-02-19 16:30:07 -05:00
nhkeni
c02220499b Add CROSSCOMPILE to mdgrep, then use it to stop CRASHREPORT when cross-compiling 2024-02-15 19:37:43 -05:00
PatR
1c08982d56 Strlen_()
Restore its ability to reject a string longer than will fit within
size_t that was lost by moving away from strnlen().  Determine the
length inline rather than using strlen().

Move it from hacklib.c to alloc.c so that utility programs have easy
access, and remove the copy of it from dlb_main.c.

Fix a logic bug in str_start_is().  If a string was considered to
be too long, it exited the loop when n was 0 but also performed
post-decrement.  So after the loop, n would be -1 and the 'if (n==0)'
test would fail.  panic() would occur if the initial string matched
and happened to be LARGEST_INT-1 characters long.
2024-01-25 12:16:39 -08:00
PatR
77d7c449e0 build fix for dlb 2024-01-22 13:31:48 -08:00
PatR
7c1512fa99 avoid strnlen()
Replace the single strnlen() use with strlen() so as not to require
something from posix.1 (2008) when we supposedly only require c99.

If someone manages to produce a string that's longer than will fit
within size_t, strlen()'s length count will wrap and Strlen_() might
not notice.  Since size_t has to be at least 32 bits, that doesn't
seem like something to worry about.

If checking for size_t overflow is considered essential, we should
just switch to counting the length via an in-line loop that imposes
a similar limit to strnlen().
2024-01-22 12:59:51 -08:00
nhmall
d292ad7d17 update util/.gitignore 2023-12-20 18:48:17 -05:00
PatR
5e9358b331 makedefs: check input files for non-ASCII chars
If MAKEDEFS_FILTER_NONASCII is defined (which config.h now does by
default), it will check data.base, rumors.*, and {various}.txt for
characters outside the range of ' ' through '~'.  If it finds any, it
will warn about them and change them to '#'.

Tab handling is incomplete; the files that use tabs for indentation
will allow tabs anywhere, even though that's not wanted.  That could
be fixed but doesn't seem particularly urgent.  This is more about
spotting and repairing the special 3-char punctuation characters that
crept into data.base fairly recently.
2023-12-18 17:16:33 -08:00
nhmall
a8313d47e5 rearrange some code in makedefs.c
This was a part of an earlier change that was reverted.
Get all the obsolete parts of makedefs arranged so that
they can be disabled simply by not defining
OLD_MAKEDEFS_OPTIONS.

Right now OLD_MAKEDEFS_OPTIONS is defined.
2023-12-02 14:22:18 -05:00
nhmall
04082a2033 Remove TEXTCOLOR build option 2023-11-22 16:01:58 -05:00
nhmall
5c8b36e95a Revert "don't build in support for obsolete makedefs options"
This reverts commit 13f49bdd92.
2023-11-19 17:36:25 -05:00
nhmall
a42d3dadce Revert "remove pasted comment"
This reverts commit c33c49295d.
2023-11-19 17:36:00 -05:00
nhmall
2cbbfbe648 Revert "comment typo"
This reverts commit bca8720c6e.
2023-11-19 17:35:30 -05:00
nhmall
bca8720c6e comment typo 2023-11-19 10:56:26 -05:00
nhmall
c33c49295d remove pasted comment 2023-11-19 10:10:27 -05:00
nhmall
13f49bdd92 don't build in support for obsolete makedefs options
unless OLD_MAKEDEFS_OPTIONS is defined during the compile of makedefs.c
2023-11-19 10:05:01 -05:00
PatR
d8bd1ddec0 github pull request #1106 - invent action: lookup
Pull request from NullCGT:  add '/' to look up selected item in its
context-sensitive inventory action menu.

The whatis_item branch added an extraneous file: util/tileset.bmp;
this commit removes it.

Closes #1106
2023-10-12 23:14:18 -07:00
Kestrel Gregorich-Trevor
880b7e3eef Object lookup via inventory menu.
Adds an option to the inventory item menu which allows a user to
look up an item in the database. This uses the existing whatis
command.

A minor secondary change is switching the failed database lookup
message to second person. The use of a first person pronoun here
has always been very strange, and switching to second person centers
the player in the action.
2023-10-12 23:11:35 -07:00
nhkeni
8c095b009a Add CRASHREPORT, show contact form on panic/impossible
When calling panic() or impossible(), create the option
of opening a browser window with most of the fields
already populated.  Code for MacOS and linux is included;
other ports are affected by argument change to early_init
which are done but not tested.

To enable, define CRASHREPORT in config.h and set
CRASHREPORTURL in sysconf to (for the moment at least)
http[s]://www.nethack.org/common/contactcr.html

Adds --grep-defined option to makedefs for Makefiles.

Adds "bid" (binary identifier), an MD4 of the main nethack
binary.  This is ONLY for helping (in the future) contact.html
to set the "NetHack from" field automatically for our own
binaries.  This can be faked, but the user can lie so nothing
lost.  There's nothing magic about MD4; other ports can use
anything that prodcues a long apparently random string we can
match against.

- new option --bidshow for us to get the MD4 of a
  released binary so I can add it to the website.
  Only available in wizard mode and not in nethack.6.
- typo macos -> macosx in hints file

No support for packaging builds as I'm not sure what that
would look like.

Adds a javascript helper for MacOS.
Adds a lua helper for linux (and builds and installs
 nhlua).
2023-09-06 12:27:13 -04:00
PatR
ef534e053d basename() for util/*.c
Update dlb_main to use the revised vms_basename() for #if VMS in
case it issues a usage message.

Change recover to use similar setup, but the vms-specific bit is
commented out because I'm not sure whether the necessary routine
is being linked with it.
2023-06-23 12:10:38 -07:00
nhmall
86368148bf soundlib in the Makefile hints updated
Move pieces of the Makefile hints sound-related changes that
are not macOS-specific from sys/unix/hints/macOS.370 to some new
include files. The WANT_MACSOUND block stays in
sys/unix/hints/macOS.370 because it is system-specific.

Before this change, the various Makefiles were assembled via
hints files macOS.370 or linux.370. Both were using included
portions from the following files in the sys/unix/hints/include
directory, in this sequence:

    -INCLUDE multiw-1.370
    -INCLUDE multiw-2.370
    -INCLUDE compiler.370
    -INCLUDE multiw-3.370
    -INCLUDE cross-pre.370
    -INCLUDE gbdates-pre.370
    -INCLUDE gbdates-post.370
    -INCLUDE cross-post.370

After this change, the various Makefiles will still be assembled
via hints files macOS.370 or linux.370. They will continue to use
included portions from the following files in the
sys/unix/hints/include directory, but with three additional
include files related to sound and soundlibs. This is the new
sequence:

    -INCLUDE multiw-1.370
    -INCLUDE multiw-2.370
    -INCLUDE compiler.370
    -INCLUDE multiw-3.370
+   -INCLUDE multisnd1-pre.370
    -INCLUDE cross-pre.370
    -INCLUDE gbdates-pre.370
+   -INCLUDE multisnd2-pre.370
    -INCLUDE gbdates-post.370
+   -INCLUDE multisnd-post.370
    -INCLUDE cross-post.370

The include mechanism continues to allow common portions that can
be shared between macOS and Linux to be maintained in a single
place only, with minimal duplication. Now, that has been extended
to include Makefile lines related to sounds and soundlib.
2023-01-28 22:43:48 -05:00
nhmall
6e136c6f7d more ATTNORETURN
A recent commit to alloc.c by Keni drew attention to the fact that
there are extern prototypes scattered around in various .c files.
Those can make use of ATTRNORETURN (non-gcc compilers and C23) the
same way the prototypes in extern.h can, and they were overlooked
when ATTRNORETURN was first added.
2023-01-12 15:38:15 -05:00
nhmall
2fc0d25d45 introduce support for coloring the frame behind a map location
Also includes support by paxed for polearm targeting using the
frame color.

Also renames USE_TILES to TILES_IN_GLYPHMAP which is a more
accurate description.

Not all window interfaces have full support for the color framing
of the background square yet.

MS-DOS needs further work (to bring it to both VESA and VGA, with
and without tiles.

Windows GUI is missing support.

X11 and Qt have been started, but may require further refinement.
2023-01-01 19:55:02 -05:00
nhmall
71c26361ff follow-up: make the ifdef logic a bit clearer 2022-12-12 14:37:40 -05:00
nhmall
9e91064659 makedefs temp files issue with mingw
The unlink call wasn't operating the same on a makedefs built
on mingw, and dat/mdXXXX files were being left behind post-build.

Provide an alternative way of doing the temporary files if
MD_USE_TMPFILE_S is defined during the compile of makedefs.c
2022-12-12 12:53:51 -05:00
nhmall
937355038d some coordxy and other conversion warnings
When dist2() got changed to use coordxy parameters, a macro that uses
it in its definition was overlooked and it had (int) casts in it.
That caused a warning about possible data loss when the int
then got converted to coordxy for the dist2() call.

Give online2() coordxy parameters instead of int, like its bretheren.

Avoid a couple of implicit conversion warnings where ints were being assigned
to smaller uchar or ints being assigned to smaller short.

A couple of signed vs unsigned warnings on some rumor processing.

Avoid some signed vs unsigned warnings in mdlib/makedefs where a signed int
param eventually got used in an external call that took size_t.
Eliminate all of it by just having the outer NetHack routine also take
a size_t.

Lastly, insert some default C99 alternative time-related code
in mdlib/makedefs since asctime() and ctime() are being flagged as
deprecated in the upcoming C23 standard and will now start to trigger
warnings for anyone using a C23-compliant compiler.
2022-11-23 17:49:55 -05:00
nhmall
6b804c0e84 warning resolution
makedefs.c:100:6: warning: unused variable 'Dont_Edit_Code' [-Wunused-variable]
    *Dont_Edit_Code =
     ^
1 warning generated.
2022-11-05 19:36:46 -04:00
nhmall
185322421a relocate mstrength() and supporting function again
Also, purge the code for makedefs -m
2022-11-05 18:40:57 -04:00
SHIRAKATA Kentaro
79927d70a0 remove the code for embedding SCCS ID
This code is for UNIXy build, but current UNIXy builds define GCC_WARN,
so this is never used.

(After all, embedding SCCS ID itself is out of date.)
2022-10-31 15:57:28 +09:00
nhmall
99a93fe50b some C99 changes
Instead of using index() macro defined to strchr, use C99 strchr.
Instead of using rindex() macro defined to strrchr, use C99 strrchr.

If you want to try building on a platform that doesn't offer those
two functions, these are available:
    define NOT_C99       /* to make some non-C99 code available */
    define NEED_INDEX    /* to define a macro for index()  */
    define NEED_RINDX    /* to define a macro for rindex() */
2022-10-29 10:54:25 -04:00
nhmall
26d13f6656 just the one mstrength() for makedefs and game 2022-10-07 11:00:15 -04:00
nhmall
83f64ee2b6 a couple of warnings 2022-09-30 08:59:57 -04:00
nhmall
8df41a6ba2 Revert "NEED_VARARGS followup"
This reverts commit 4d34e153e0.
2022-09-17 15:57:52 -04:00
nhmall
4d34e153e0 NEED_VARARGS followup 2022-09-17 14:22:20 -04:00
PatR
70b8bc04e7 fix recover
I tried to reproduce #812 so that I could check whether the suggested
fix worked but I discovered that external 'recover' was broken by the
coordxy changes.

The fix is trivial but I haven't gone back to #812.
2022-07-17 14:25:51 -07:00
nhmall
30b557f7d5 change xchar to other typedefs
One of the drivers of this change was that screen coordinates require a
type that can hold values greater than 127. Parameters to the window
port routines require a large type in order to be able to have values
a fair bit larger than COLNO and ROWNO passed to them, particularly for
their use to the right of the map window.

This splits the uses of xchar into 3 different situations, and adjusts
their type and size:

                        xchar
                          |
               -----------------------
               |          |          |
            coordxy     xint16     xint8

coordxy: Actual x or y coordinates for various things (moved to 16-bits).

xint16:  Same data size as coordxy, but for non-coordinate use (16-bits).

xint8:   There are only a few use cases initially, where it was very
         plain to see that the variable could remain as 8-bits, rather
         than be bumped to 16-bits.  There are probably more such cases
         that could be changed after additional review.

Note: This first changed all xchar variables to coordxy. Some were
reviewed and got changed to xint16 or xint8 when it became apparent that
their usage was not for coordinates.

This increments EDITLEVEL in patchlevel.h
2022-06-30 23:48:18 -04:00
PatR
3806dae153 ignoring features when checking version compat
The nomakedefs stuff for cross-compiling support broke the code to
treat enabling or disabling some optional features as not breaking
save and bones file compatibility.  It was relying on a macro whose
definition was local to mdlib.c rather than propagated among files.
makedefs still constructs date.h with a value indicating the ignored
features but the actual compatability check doesn't use that anymore.
Toggling SCORE_ON_BOTL shouldn't have caused existing files to be
rejected but they were.
2022-06-16 11:00:53 -07:00
PatR
687e7c12f7 implement realloc() for MONITOR_HEAP or vice versa
Add new routine 're_alloc()' that functions as MONITOR_HEAP-aware
libc realloc().  'nhrealloc()' is the version that passes source
file and line info if built with MONITOR_HEAP enabled.  The heaplog
data might now contain '<' (freed by realloc), '>' (replacement
allocation by realloc), and '*' (resized by realloc) entries in
addition to the previous '+' (allocated) and '-' (freed) entries.
heaputil has already been updated in the NHinternal repository.

Move FITSint_() and FITSuint_() from hacklib.c to alloc.c so that
they can be accessed by miscellaneous utility programs.

Remove three or four copies of FITSint_() that were duplicated in
utility programs like dlb and tile2bmp due to those not having
access to src/hacklib.o.  They do have access to src/alloc.o (and
util/panic.o).
2022-05-30 23:19:35 -07:00
nhmall
303e34e5c6 clear a warning: variable set but not used
makedefs.c:2125:12: warning: variable 'sum' set but not used
[-Wunused-but-set-variable]
    int i, sum = 0;
           ^
    1 warning generated.
2022-04-04 10:35:43 -04:00
nhkeni
3cc0043dfe Fix dlb_main type issues. 2022-03-17 18:12:40 -04:00
nhkeni
7dba4f1236 Add FITSint() and FITSuint(),
which cast long long to int while panicking on overflow
2022-03-17 18:10:38 -04:00
PatR
cca90a061c makedefs exit control
Have makedefs do through a common point when exiting, in case it ever
needs extra memory or scratch file cleanup.

While testing, I discovered that the reference use of 'makedefs -o' to
build obsolete onames.h didn't work anymore because of the change to
not require object probabilities to add up to 1000 within classes.
I think fixing that is the only change besides new 'makedefs_exit()'.
2022-02-20 13:52:18 -08:00
nhmall
a71d5e3cb3 remove some obsolete file references 2022-02-04 15:43:21 -05:00
PatR
7205d9a417 makedefs revision
This started out as fix for a comment but ended up redoing 'limit()'
and its 'temp[]' because they seemed likely to someday interfere with
other uses of such generic names.

No change to observable behavior.
2022-01-05 12:50:21 -08:00
PatR
3536ede5bd makedefs.c comment typo 2021-12-29 03:16:31 -08:00
PatR
459b1c1c8d switch makedefs from malloc() to alloc()
Avoids any need for MONITOR_HEAP hackery.  Link src/alloc.o and
util/panic.o into util/makedefs.

When replacing the realloc() call in fgetline(), I noticed that
fgetline() would miss the last line of an input file if it lacked a
terminating newline.  This was hard to test because OSX seems to be
supplying one when it is missing (VMS would do that too).  I had to
modify epitaph (my test bed) to take off the final character, run
'makedefs -s' under debugger control and strip away final newline
that stdio added back, build new nhdat and move it into place, then
run nethack and execute #wizrumorcheck all multiple times before
the fix and once more after it.  Much effort for little gain...

Plus some of the recent reformatting:  indent labels one space,
replace tabs with spaces, shorten or split wide lines.
2021-12-22 00:18:37 -08:00
PatR
0a0ee2d1e6 date.c vs MONITOR_HEAP
I tried building with MONITOR_HEAP defined for the first time in a
while.  It wasn't pretty.

date.c was calling libc's strdup() instead of our dupstr() so alloc.c
wasn't tracking those allocations when/if MONITOR_HEAP is enabled.
Then it called free() which is actually a call to nhfree() in that
situation.  If the file of allocations and releases was subsequently
fed to heaputil, it would complain about freeing pointers that hadn't
been allocated.

Worse, makedefs and tilemap wouldn't link.  For MONITOR_HEAP,
makedefs was undefining free() in order to avoid nhfree() but it now
links with date.o so got nhfree() calls anyway.  And it wouldn't link
because that routine isn't available without alloc.o.  tilemap
doesn't link with date.o but it does call malloc() and free() and it
wasn't undefining free(), so looked for nhfree() when linking and got
the same no-such-routine failure.
2021-12-15 18:39:29 -08:00
PatR
35ac9a09e2 miscellaneous tweaks
Simplify a glob handling bit in a recent shrink_glob change used when
catching for lost time upon returning to a level.

Revise a clumsily worded fixes entry.

Fix a comment typo in makedefs that's been there for a bunch of years
now.  It's been within the diff context for several recent patches
and I still hadn't noticed it until just now.
2021-11-30 14:04:00 -08:00
PatR
03476a7c78 get_rnd_text() for rumors and other stuff
Solve the uneven distribution situation that has been present for
picking random rumors for a long time and for random engravings,
epitaphs, and hallucinatory monster names since 3.6.0.  This relies
on the previous partial solution where short lines have been padded
to a longer length.  When that length is N and random seek lands in
a long line of length L, retry if the position is in the first L-N
characters.  Put differently, it if takes more than N characters to
reach the next newline, reject that random seek and try again.  This
effectively makes long lines behave as if they had the same length
of N as the short lines have been padded to and when all lines are
the same length, all entries have the same chance to be chosen.
2021-11-27 12:23:01 -08:00
PatR
59beebcbcc get_rnd_text() selection distribution
While testing 'the("Capitalized Hallucinatory Monster")' I noticed that
some hallucinatory monsters showed up more often than others.  When
the random engravings, epitaphs, and bogus monsters were converted from
hard-coded arrays to data files accessed by random seek (3.6.0), they
became subject to the same distribution irregularites that rumors suffer
from.  The chance that an entry will be chosen depends upon the chance
that a random seek will hit somewhere in the line which precedes it, so
entries that follow long lines are more likely to be chosen and entries
that follow short lines are less likely.  We improved that for rumors
by having makedefs pad the shortest lines.  Distribution still isn't
uniform but is much better than it was (and could be further improved
with a longer padding length at the cost of making data files bigger so
possibly slower to access; both overall size and access speed mattered
back when floppy discs were supported but are probably irrelevant now).

Start doing the same thing for the newer files:  pad the shortest lines
to increase the chance that seek will find them.  The tradeoff is that
the data files become bigger.  Rumors, engravings, and epitaphs lines
are all at least 60 characters now; bogus monsters are at least 20.
These are the data file sizes I see (in bytes:  old, new; padding for
rumors was already in use so its size hasn't changed):
  bogusmon    4449    7211
  engrave     1326    2894
  epitaph    14159   24075
  rumors     49173   49173

The only place that padding is noticeable in-game is #wizrumorcheck.
2021-11-25 17:57:37 -08:00