Commit Graph

419 Commits

Author SHA1 Message Date
nhmall
56ebf05324 convert some tabs to spaces in util 2025-02-26 21:51:44 -05:00
nhmall
0792e5fe9e expand implicit fallthrough detection to non-gcc compilers
gcc has recognized various "magic comments" for white-listing
occurrences of implicit fallthrough in switch statements for
a long time:

    The range and shape of "falls through" comments accepted are
    contingent upon the level of the warning. (The default level is =3.)

    -Wimplicit-fallthrough=0 disables the warning altogether.
    -Wimplicit-fallthrough=1 treats any kind of comment as a "falls through" comment.
    -Wimplicit-fallthrough=2 essentially accepts any comment that contains something
     that matches (case insensitively) "falls?[ \t-]*thr(ough|u)" regular expression.
    -Wimplicit-fallthrough=3 case sensitively matches a wide range of regular
     expressions, listed in the GCC manual. E.g., all of these are accepted:
        /* Falls through. */
        /* fall-thru */
        /* Else falls through. */
        /* FALLTHRU */
        /* ... falls through ... */
       etc.
    -Wimplicit-fallthrough=4 also, case sensitively matches a range of regular
     expressions but is much more strict than level =3.
    -Wimplicit-fallthrough=5 doesn't recognize any comments.

Plenty of other compilers did not recognize the gcc comment convention,
and up until now the compiler warning for detecting unintended
fallthrough had to be suppressed on other compilers. That's because the code
in NetHack has been relying on the gcc approach, and only the gcc approach.

The C23 standard introduces an attribute [[fallthrough]] for the
functionality, when implicit fallthrough warnings have been enabled.

Several popular compilers already support that, or a very similar attribute
style approach, today, even ahead of their C23 support:

       C compiler                       whitelist approach
       ---------------------------   -------------------------------------
       C23 conforming compilers         [[fallthrough]]

       clang versions supporting
       standards prior to
       C23                              __attribute__((__fallthrough__))

       Microsoft Visual Studio
       since VS 2022 17.4.
       The warning C5262 controls
       whether the implict
       fallthrough is detected and
       warned about with
       /std:clatest.                    [[fallthrough]]

This adds support to NetHack for the attribute approach by inserting a
macro FALLTHROUGH to the existing cases that require white-listing, so
other compilers can analyze things too.

The definition of the FALLTHROUGH macro is controlled in include/tradstdc.h.

The gcc comment approach has also been left in place at this time.
2024-11-30 14:16:27 -05:00
nhmall
fec99bfb86 follow-up: parameter UNUSED as in most of NetHack 2024-10-29 19:30:09 -04:00
Mika Kuoppala
9294239197 util: match fopen_datafile function prototype
The prototype for fopen_datafile() is different if
it is used for util/dlb. Add the missing integer parameter.
2024-10-28 21:40:50 +02:00
nhmall
fb70aadbb5 improve copy_bytes() maintenance
Remove the copy_bytes() function from files.c and util/recover.c
and place a single copy into hacklib.
2024-10-05 15:55:20 -04:00
nhmall
6f8c36df70 copy_bytes() recover function
The version of copy_bytes() in util/recover.c had fallen behind
the internal version in files.c which had received some
analyzer changes in 4bc5e26082 from
December 2022.

This synchronizes them, and addresses a couple of other static
analysis recommendations.
2024-10-05 10:54:54 -04:00
nhmall
5af723669e some static analyzer items 2024-10-04 12:34:09 -04:00
Keni
55eed7c19a Ignore lua .dll files. 2024-09-06 12:03:18 -07:00
nhmall
29bf3646e0 add makedefs options for producing individual files
This may be useful for some build environments to avoid parallel make
issues, and artificially-concocted order dependencies, leaving the ordering
up to that specified in the Makefile.

The related makedefs options are now:

       ‐s     Generate the bogusmon , engrave and epitaph files.

       ‐1     Generate the epitaph file.

       ‐2     Generate the engrave file.

       ‐3     Generate the bogusmon file.

Also resolves an existing issue encountered in doc/makedefs.6 where "and epitaphfiles"
was being produced in the result.
2024-05-13 08:45:11 -04:00
nhkeni
4786f82e73 Merge branch 'NetHack-3.7' of https://rodney.nethack.org:20040/git/NHsource into NetHack-3.7 2024-03-20 11:56:32 -04:00
nhkeni
41bdaa348a teach mdgrep.* about NH_DEVEL_STATUS 2024-03-20 11:51:55 -04:00
nhmall
295d6e257c used, unused variables
some variables marked as unused, are now actually used
some unused variables are eliminated or commented out
2024-03-16 12:53:58 -04:00
nhmall
79648c6ce2 some variables not referenced in another translation unit made static
Also adds some cross-refence comments for some variables that are
referenced in another translation unit.
2024-03-15 16:00:14 -04:00
nhmall
629badfbd9 more code cleanup
remove disabled code from makedefs.c because it uses a function in hacklib
now.
2024-03-12 16:18:23 -04:00
nhmall
a11898bef5 some code cleanup following recent code relocations 2024-03-12 16:13:33 -04:00
nhmall
50811037f3 split some code into separate files
new .h files: hacklib.h selvar.h stairs.h

new .c files: calendar.c, getpos.c, report.c, selvar.c, stairs.c,
              strutil.c, wizcmds.c

cleanup of hacklib.c and mdlib.c

hacklib contains functions that do not have to link with the core

relocate wiz commands from cmd.c to wizcmds.c

relocate CRASHREPORT stuff to report.c

relocate getpos stuff from do_name.c to getpos.c

remove temporary struct definition from extern.h

cross-compile PRE-section split into cross-pre1.370 and cross-pre2.370

Windows sys/windows/Makefile.nmake and sys/windows/Makefile.mingw32 and
visual studio project file updates

Unix sys/unix/Makefile.src, sys/unix/Makefile.utl

populate selvar.c and selvar.h

build on MS-DOS (not cross-compile) Makefile updates
for sys/msdos/Makefile.GCC (untested)

vms updates for above (untested)
2024-03-07 11:01:04 -05:00
RainRat
a3658f85ac fix typos 2024-02-28 20:15:56 -08:00
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