Commit Graph

52 Commits

Author SHA1 Message Date
Bart House
c67f7e5122 globals from files.c moved to instance globals. 2018-12-25 12:56:27 -08:00
Bart House
576eece500 More globals moved to instance_globals. 2018-12-19 21:26:35 -08:00
Bart House
74caa8d8e4 Moved pray.c globals to instance_globals. 2018-12-19 20:00:35 -08:00
Bart House
912886a73f First set of changes to move globals to instance_globals. 2018-12-19 20:00:35 -08:00
PatR
5d2686e7c1 lev_comp int vs long
Fix lev_comp's variable argument usage by changing it to make
add_opvars() expect an int rather than a long when given the "i"
indicator, and add "l" for really passing a long.  The ints are
conveted to longs when setting up the interpreter.  I think I changed
just about all the integer opvars to int, although there is one use
of "l" in lev_main.c just to make sure it works.  There could be
arguments that really do need to be 'long'; if so, the add_opvars()
calls for them will have to have its indicator string updated and
possibly add or remove some casts.

There's a lot of reformatting included but it's not consistent about
tab replacement.  Some of the changes are due to renaming long-named
'variable_definitions' to 'vardefs' to shorten a bunch of lines.

Updated sys/share/*_yacc.c will be checked in separately.  The ones
currently in the repository won't work with patched lev_main.c due to
that renamed variable.
2018-11-27 18:21:58 -08:00
PatR
64f284dd61 USE_OLDARGS update (1 of 2)
Files modified:
    include/tradstdc.h, sp_lev.h, system.h
    util/lev_main.c

Silence a bunch of warnings generated by recent gcc which weren't there
with whatever version I had when 3.6.0 was being readied for release.
For lev_main, there were two basic types:  not enough arguments in calls
to lc_pline, lc_warning, and lc_error (since we weren't passing dummy
arguments as is done for add_opvars), and conversion from 'int' or
narrower to 'char *' (from -Wint-to-pointer-cast, which either wasn't
there yet in the older gcc, or wasn't included in -Wall back then).
[Note that for any configuration decrepit enough to actually need
USE_OLDARGS, such conversions will either work fine or else nethack
simply won't be viable.]

src/pline.c generates a bunch of warnings (for USE_OLDARGS).  The fix
for that will be (2 of 2).

To test, instead of mucking about with CFLAGS or sys/unix/hints, I've
been temporarily adding unconditional
|#undef USE_STDARG
|#undef USE_VARARGS
|#define USE_OLDARGS
to the end of config1.h and then doing my normal build--which is why
-Wall (or possibly -W) is drawing -Wint-to-pointer-cast warnings.
2017-08-02 18:23:42 -07:00
PatR
e3c4ac730d util updates: lev_main.c and recover.c
Change lev_comp's add_opvars() to be like pline(), where there's a
single visible opening brace and a second one hidden in VA_DECL2
that introduces a nested block, plus a single visible closing brace
with a hidden one in VA_END() to close the nested block.  This
addresses the erroneous report (sent directly to devteam, so no #H
number, subject "missing '{' in util/lev_main.c:634") that the code
for !USE_STDARG/!USE_VARARGS in add_opvars() wouldn't compile.

Also, fix the part of "#H5778: file descriptor leaks" dealing with
util/recover.c -- an open file not being closed after various errors.
I didn't take responsibility for this entry in the bugzilla list
since the report includes similar problems in other code that's not
addressed here.

And a blast from the past:  some reformatting fixups in recover.c.
The most interesting bit is for a block of dead code....
2017-07-30 17:34:52 -07:00
PatR
7482be39e8 lev_comp update for older Unix system
Increase the lex paramaters in lev_comp.l and replace use of snprintf
with sprintf in lev_comp.y and lev_main.c.

Also some reformatting for lev_comp.y, but I gave up pretty quickly:
some early tab replacement and adjusting of the spacing for casts.
2016-01-19 16:27:39 -08:00
Pasi Kallinen
50359a3552 Fix possible lev_comp segfault when map was too tall 2016-01-06 19:49:38 +02:00
PatR
63dc6b3a31 lev_main cleanup
Use an alternate fix for the complaint from clang's static analyzer
(about potentially derefencing a null pointer, which can't happen
here because alloc() panics and quits rather than return Null), plus
some reformatting and removal of a chunk of unused code (strncmpi).

Also a formatting bit for lev_comp.y, making sys/share/lev_yacc.c
be out of date.  However, the generated code will be the same--except
for line numbers--so this shouldn't inhibit anybody's planned testing
waiting for the generated copy to be updated.
2015-11-20 18:58:48 -08:00
Pasi Kallinen
9518e74c93 Fix segfault if lev_comp could not alloc memory for opcode 2015-11-20 12:27:46 +02:00
Sean Hunt
1c081b1647 Remove stale version control lines. 2015-05-25 09:21:31 +09:00
Sean Hunt
26ee7dc370 Convert the vibrating square to a trap
Patch due to ais523 in NetHack 4.

This is not ready to be merged yet; the vibrating square needs a tile
image for tiles builds.
2015-05-25 09:19:20 +09:00
PatR
fabf9cd901 VA_DECL/VA_END usage
Make the variadic functions look more like ordinary code rather than
have the function opening brace be hidden inside the VA_DECL() macro.
That brace is still there, but VA_DECL() now needs to be followed by
a visible brace (which introduces a nested block rather than the
start of the funciton).  VA_END() now provides a hidden closing brace
to end the nested block, and the existing closing brace still matches
the one in VA_DECL().

Sample usage:
void foo VA_DECL(int, arg)  --macro expansion has a hidden opening brace
{  --new, explicit opening brace (actually introduces a nested block)
  VA_START(bar);
  ...code for foo...
  VA_END();  --expansion now provides a closing brace for the nested block
}  --existing closing brace, still pairs with the hidden one in VA_DECL()

This should help if/when another round of reformatting ever takes place,
and also with editors or other tools that do brace/bracket/parenthesis
matching.

I had forgotten that there were variadic functions in sys/* and ended
up modifying a lot more files than intended.  The majority of changes
to those just inserted a new '{' line so that revised VA_END()'s '}'
won't introduce a syntax error.  A couple of them needed VA_END() moved
so that local variables wouldn't go out of scope too soon.  Only the
Unix ones have been tested.
2015-05-15 17:45:21 -07:00
Sean Hunt
97d6fade74 Reformat all C files.
I'll push a formatting guide at some point. There may still be
outstanding changes, but please feel free to resolve those as you arrive
a them.

To the best of my knowledge, there is no changes to the actual code
content, but the formatter does have the occasional bug. If you run into
an issue, please fix it!
2015-05-09 13:43:16 -04:00
karnov
2a907f894e Version number increment 2015-05-06 22:04:27 -04:00
Pasi Kallinen
c266d05680 Minor special level and compiler tweakage
Fix allowed map characters.
Make some predefined MAPs blend in better with randomly
generated parts.
2015-04-10 16:47:32 +03:00
PatR
71d7eff0a7 revisit variable arguments in new lev_comp
The previous USE_OLDARGS worked with gcc on Intel, but was inherently
unsafe.  This method is completely safe, just obnoxiously intrusive.
It you disliked debugpline*(), you're bound to hate this....
2015-04-10 01:39:55 -07:00
PatR
9072e80085 support pre-ansi varargs in new lev_comp
Remove the requirement for <stdarg.h> that was introduced to lev_comp.
USE_STDARG still works.  USE_OLDARGS required hackery but has been
tested and actually works, although I wouldn't trust it on platforms
where 'long' and 'char *' aren't the same size.  USE_VARARGS didn't
require any hackery--aside from the conversion to core's pline code--
but has not been tested:  <varargs.h> supplied with OSX won't compile,
with an #error directive that basically says "switch to <stdarg.h>".

I changed several printf formats of %i and %li to %d and %ld because
I'm not sure how widespread the 'i' variant was back in days of yore.
[TODO:  avoid use of snprintf since pre-ANSI systems won't have it.]
2015-04-09 03:09:00 -07:00
Pasi Kallinen
68a39aeab4 Fix GCC warnings caused by new lev_comp 2015-04-03 17:40:54 +03:00
Pasi Kallinen
0a9248c7f1 Merge branch 'master' of https://rodney.nethack.org:20040/git/NHsource into paxed-new_lev_comp
Conflicts:
	doc/fixes35.0
	include/extern.h
	include/ntconf.h
	include/obj.h
	include/patchlevel.h
	src/dig.c
	src/do.c
	src/files.c
	src/fountain.c
	src/mklev.c
	src/objnam.c
	src/options.c
	src/potion.c
	src/rumors.c
	src/save.c
	src/topten.c
	src/trap.c
	src/wield.c
	sys/share/pcmain.c
	sys/unix/unixmain.c
	sys/winnt/Makefile.msc
	util/lev_main.c
	util/makedefs.c
2015-03-24 19:46:38 +02:00
Pasi Kallinen
8785f73b7f Use the correct declaration macro 2015-03-24 19:28:27 +02:00
nhmall
b1547c4770 include header file <ctype.h> in lev_main.c
options.c depends on ctype.h  and uses tolower()
so no sense getting into a discussion about
use of _that_
2015-03-24 19:26:01 +02:00
nhmall
c4009b781c Actually use the new routines in lev_main 2015-03-24 19:25:54 +02:00
nhmall
f9d22e02cd lev_main's own internal case-insensitive compare
TEST SUITE

int case_insensitive_comp(const char *, const char *);

/* define your built-in compiler library variation here */

/* #define BUILTIN(a,b) strcasecmp(a,b) */
/* #define BUILTIN(a,b) stricmp(a,b) */

int main(int argc, char *argv[])
{
	const char *t1 = "NetHack";
	const char *t2 = "nethack";
	const char *t3 = "Fred";
	const char *t4 = "Barney lived next door";

	/* try the results with built-in strcmpi first */

	printf("builtin:\tcompare <%s> to <%s>, result %d.\n",
		t1, t2, BUILTIN(t1,t2));
	printf("builtin:\tcompare <%s> to <%s>, result %d.\n",
		t3, t4, BUILTIN(t3,t4));

	/* try the results with case_insensitive_comp 2nd */

	printf("ours:\tcompare <%s> to <%s>, result %d.\n",
		t1, t2, case_insensitive_comp(t1,t2));
	printf("ours:\tcompare <%s> to <%s>, result %d.\n",
		t3, t4, case_insensitive_comp(t3,t4));

}

int
case_insensitive_comp(s1, s2)
const char *s1;
const char *s2;
{
    unsigned char u1, u2;

    for ( ; ; s1++, s2++) {
	u1 = tolower((unsigned char) *s1);
	u2 = tolower((unsigned char) *s2);
	if ((u1 == '\0') || (u1 != u2)) {
	    break;
	}
    }
    return u1-u2;
}

======================== END TEST SUITE ===========================
2015-03-24 19:25:45 +02:00
nhmall
c49dbcc5b3 include this also 2015-03-24 19:16:29 +02:00
nhmall
4c2df285b4 an easy fix for strcmpi and we move on
Here in branch paxed-new_lev_comp-B (branched
from paxed-new_lev_comp) is a simple fix
for the strcmpi issue.

The bottom section of lev_main.c has a bunch
of forced linkages to names from NetHack etc.
	#ifdef STRICT_REF_DEF
	bunch of stuff
	#endif

This change to lev_main should make everything
work for those that don't supply a compiler
library version of strcmpi()

With this patch, those people can just
add a -DSTRICT_REF_DEF to their compile line
for lev_main.c.

This would close the issue in a simple way,
and doesn't require linking in anything new to
the level compiler, or modifying any port's Makefiles etc.
2015-03-24 19:06:01 +02:00
Pasi Kallinen
47bb9abace New level compiler: code changes 2015-03-17 18:52:42 +02:00
Sean Hunt
44ca9fc16a Make SINKS unconditional. 2015-03-17 18:45:58 +02:00
keni
25cd007c48 Bulk recovery of file CVS headers and addition of NHDT- headers. 2015-03-17 18:45:12 +02:00
Sean Hunt
5ee71d2757 Make SINKS unconditional. 2015-02-27 19:33:06 -05:00
keni
03140969ee Bulk recovery of file CVS headers and addition of NHDT- headers. 2015-02-26 09:19:03 -05:00
nethack.rankin
eec34e4144 supress lev_main.c diagnostic (trunk only)
gcc warned about comparing signed with unsigned for one particular
write() that used an expression for the size argument, and there was already
conditional code to try to handle it for a couple of other compilers.  But
this simpler fix should handle it for everybody.
2012-01-12 04:48:12 +00:00
keni
4036a6727c Add RCS version lines 2009-05-06 10:55:43 +00:00
keni
c7858a6d37 more warning cleanup, makedefs grep bits (trunk only)
drop -Wcast-qual
warning cleanup (lev_comp)
comment bits
makedefs grep cleanup: drop magic constant, add --grep-define, --grep-undef,
 #ifdef out code not needed yet, update mdgrep.h, mdgrep.pl
2008-04-22 23:20:44 +00:00
nethack.rankin
697ec97812 hangup hangup bit (trunk only)
Accidentally left out  of the previous patch.
2007-01-18 05:12:36 +00:00
nethack.rankin
2ca87d8a5e more health food shops (trunk only)
Allow health food stores to carry eggs and tins of veggy contents in
their stock.  The tins will almost always contain spinach because random
tins containing meat are converted into that.

     Also, allow health food stores to be placed with the level compiler
(not tested) and to be forcibly placed in wizard mode via SHOPTYPE setting
of "V".  Increments EDITLEVEL in patchlevel.h because lighting store in
Minetown got renumbered and the special level for it needs to be rebuilt.
2005-03-13 05:29:01 +00:00
nethack.allison
e9b022d579 housekeeping: mark trunk sources 3.5 (misc) 2005-01-02 17:21:18 +00:00
nethack.allison
aa6f3df889 new context_info struct in compat checks (trunk only)
lev_main needed to reflect the change too.
2004-02-02 12:44:58 +00:00
kmhugo
1282e5c623 Synch recent 3.4.2 changes to main trunk
This is merely a synchronization of recent changes for the
Macintosh Carbon port, which were committed to the 3.4.2
branch, to the main trunk.
2003-08-30 00:45:58 +00:00
dean
78ae08d384 Place finished .lev files in the MPW build's destination directory. 2002-04-03 05:40:29 +00:00
nethack.allison
51f9892b3b Allow MICRO and WIN32 code paths to diverge
There's still a lot of overlap for 3.4.1, but not
100% any longer and it facilitates some improvements
- Allow error save files on WIN32
2002-03-30 19:09:56 +00:00
nethack.rankin
e835e2f420 lev_comp,dgn_comp vs CRLF style input
Allow the special level and dungeon compilers to handle input
files which have CR+LF delimited lines.  Apparently Cygwin doesn't
convert MSDOS style line ends into newlines the way stdio should
do for text I/O.  The resulting unexpected CR characters result in
syntax errors.

     And explicitly using '\n' on both the lex and yacc sides of
MAP processing allows removal of the old NEWLINE hack for Mac MPW.
It won't matter what numeric value that character escape sequence
has internally.
2002-03-28 01:37:39 +00:00
dean
007ddef858 Fix a typo. 2002-03-01 05:26:36 +00:00
nethack.allison
4b0dab0d0e <Someone> bit
in util/lev_main.c:write_maze(), line which reads
"Write(fd, &(pt->ngold), sizeof(pt->naltar));"

should read
"Write(fd, &(pt->ngold), sizeof(pt->ngold));"
2002-02-19 13:25:06 +00:00
nethack.allison
7d1e6f7d57 from Yitzhak
Add absent prototypes to some core routines.
Also add some port function() to function(void) in some win32 routines.
Also updates the Borland C Makefile for win32.
2002-02-05 13:21:43 +00:00
nethack.allison
742e1e8c90 3.3.2 to 3.4.0 2002-02-04 16:11:00 +00:00
kmhugo
263b6c06b1 Line numbering in lev_comp files
This patch allows the digits 0-9 to be used to indicate line numbers
in the MAP...ENDMAP arrays of level files.  This makes it a wee
bit easier to place features.  The digits get stripped out before
the map is interpreted.
2002-01-19 06:06:16 +00:00
nethack.allison
8ef53b7e30 Get rid of a compiler warning that has been there forever.
This finally gets the entire build process warning-free
under MSVC.
2002-01-15 03:37:36 +00:00
nethack.allison
e02ab47597 Changes to existing files by the win32 port additions. 2002-01-13 05:53:39 +00:00