diff --git a/Files b/Files index b898e19e4..658cfc3ee 100644 --- a/Files +++ b/Files @@ -86,7 +86,7 @@ windows.c wizard.c worm.c worn.c write.c zap.c sys/amiga: -(files for Amiga versions) +(files for Amiga versions - untested for 3.6.0) Build.ami Install.ami Makefile.agc Makefile.ami NetHack.cnf amidos.c amidos.p amifont.uu amifont8.uu amigst.c amii.hlp amimenu.c amirip.c amisnd.c amistack.c @@ -97,12 +97,12 @@ winfuncs.c winkey.c winmenu.c winproto.h winreq.c winstr.c xpm2iff.c sys/atari: -(files for Atari version) +(files for Atari version - untested for 3.6.0) Install.tos atarifnt.uue nethack.mnu setup.g tos.c unx2atar.sed sys/be: -(files for BeOS version) +(files for BeOS version - untested for 3.6.0) README bemain.c sys/mac: @@ -115,7 +115,7 @@ macwin.c mgetline.c mmodal.c mrecover.c mrecover.hqx mttymain.c sys/msdos: -(files for MSDOS version) +(files for MSDOS version - untested for 3.6.0) Install.dos Makefile.BC Makefile.GCC Makefile.MSC moveinit.pat msdos.c msdoshlp.txt ovlinit.c pckeys.c pctiles.c pctiles.h pcvideo.h portio.h schema1.BC schema2.BC @@ -125,7 +125,7 @@ vidtxt.c vidvga.c nhico.uu nhpif.uu sys/os2: -(files for OS/2 version) +(files for OS/2 version - untested for 3.6.0) Install.os2 Makefile.os2 nhpmico.uu os2.c sys/share: @@ -152,6 +152,10 @@ termcap (lex/yacc output for special level and dungeon compilers) dgn_comp.h dgn_lex.c dgn_yacc.c lev_comp.h lev_lex.c lev_yacc.c +(posix regex for versions that include regex in their C library) +posixregex.c +(c++ regex code for versions that can build a C++ module and link it in) +cppregex.cpp sys/share/sounds: (files for Amiga and Macintosh versions) @@ -174,14 +178,14 @@ sys/unix/hints: linux linux-x11 macosx macos-x11 unix sys/vms: -(files for VMS version) +(files for VMS version - untested for 3.6.0) Install.vms Makefile.dat Makefile.doc Makefile.src Makefile.top Makefile.utl install.com lev_lex.h nethack.com oldcrtl.c spec_lev.com vmsbuild.com vmsfiles.c vmsmail.c vmsmain.c vmsmisc.c vmstty.c vmsunix.c sys/wince: -(files for Windows CE and PocketPC) +(files for Windows CE and PocketPC - untested for 3.6.0) Install.ce bootstrp.mak celib.c cesetup.bat cesound.c defaults.nh keypad.uu menubar.uu mhaskyn.c mhaskyn.h mhcmd.c mhcmd.h mhcolor.c mhcolor.h mhdlg.c diff --git a/doc/fixes35.0 b/doc/fixes35.0 index 5f5abf250..27c9aca0d 100644 --- a/doc/fixes35.0 +++ b/doc/fixes35.0 @@ -1117,6 +1117,9 @@ options to create the character blind or nudist moving clouds on the plane of air disclose extinct species alongside genocided ones tribute to Terry Pratchett +Some levels in Gehennom now use the old corridor-style maze instead of + the new room-style. Beelzebub's level always does this and the + "beetle legs" are restored. Platform- and/or Interface-Specific New Features diff --git a/include/color.h b/include/color.h index f7bec4a08..a772dd84c 100644 --- a/include/color.h +++ b/include/color.h @@ -1,4 +1,4 @@ -/* NetHack 3.5 color.h $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.5 color.h $NHDT-Date: 1428088106 2015/04/03 19:08:26 $ $NHDT-Branch: scshunt-regex $:$NHDT-Revision: 1.8 $ */ /* NetHack 3.5 color.h $Date: 2009/05/06 10:44:34 $ $Revision: 1.5 $ */ /* SCCS Id: @(#)color.h 3.5 1992/02/02 */ /* Copyright (c) Steve Linhart, Eric Raymond, 1989. */ @@ -7,10 +7,6 @@ #ifndef COLOR_H #define COLOR_H -#ifdef MENU_COLOR_REGEX -#include -#endif - /* * The color scheme used is tailored for an IBM PC. It consists of the * standard 8 colors, folowed by their bright counterparts. There are @@ -56,15 +52,7 @@ #define HI_ZAP CLR_BRIGHT_BLUE struct menucoloring { -# ifdef MENU_COLOR_REGEX -# ifdef MENU_COLOR_REGEX_POSIX - regex_t match; -# else - struct re_pattern_buffer match; -# endif -# else - char *match; -# endif + struct nhregex *match; int color, attr; struct menucoloring *next; }; diff --git a/include/config.h b/include/config.h index dbeecbccd..5fc3d0d8f 100644 --- a/include/config.h +++ b/include/config.h @@ -1,4 +1,5 @@ -/* NetHack 3.5 config.h $NHDT-Date: 1428706053 2015/04/10 22:47:33 $ $NHDT-Branch: win32-x64-working $:$NHDT-Revision: 1.77 $ */ +/* NetHack 3.5 config.h $NHDT-Date: 1428084467 2015/04/03 18:07:47 $ $NHDT-Branch: scshunt-regex $:$NHDT-Revision: 1.76 $ */ +/* NetHack 3.5 config.h $Date: 2012/01/27 20:15:26 $ $Revision: 1.37 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -435,18 +436,6 @@ typedef unsigned char uchar; * bugs left here. */ -/* Menucolors */ -/* HACK: this is being added to fix the builds temporarily. - * Remove it whenever we finally get a real regex for Win32 */ -#ifdef UNIX -# define MENU_COLOR_REGEX /* use GNU regex */ -/*# define MENU_COLOR_REGEX_POSIX*/ /* use POSIX regex */ -#endif -/* if neither is defined, uses pmatch() - * pmatch() provides basic globbing: '*' and '?' wildcards. - */ - - #define STATUS_VIA_WINDOWPORT /* re-work of the status line updating process */ #define STATUS_HILITES /* support hilites of status fields */ /* #define WINCHAIN*/ /* stacked window systems */ diff --git a/include/extern.h b/include/extern.h index 84f02e0dd..997885882 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1487,6 +1487,13 @@ E void NDECL(init_lan_features); E char *NDECL(lan_username); #endif +/* ### nhregex.c ### */ +E struct nhregex * NDECL(regex_init); +E boolean FDECL(regex_compile, (const char *, struct nhregex *)); +E const char *FDECL(regex_error_desc, (struct nhregex *)); +E boolean FDECL(regex_match, (const char *, struct nhregex*)); +E void FDECL(regex_free, (struct nhregex *)); + /* ### nttty.c ### */ #ifdef WIN32CON diff --git a/src/options.c b/src/options.c index 25e1407bf..755c9e754 100644 --- a/src/options.c +++ b/src/options.c @@ -1,4 +1,4 @@ -/* NetHack 3.5 options.c $NHDT-Date: 1427073746 2015/03/23 01:22:26 $ $NHDT-Branch: master $:$NHDT-Revision: 1.164 $ */ +/* NetHack 3.5 options.c $NHDT-Date: 1428088105 2015/04/03 19:08:25 $ $NHDT-Branch: scshunt-regex $:$NHDT-Revision: 1.182 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -1169,11 +1169,6 @@ char *str; int i, c = NO_COLOR, a = ATR_NONE; struct menucoloring *tmp; char *tmps, *cs = strchr(str, '='); -#ifdef MENU_COLOR_REGEX_POSIX - int errnum; - char errbuf[80]; -#endif - const char *err = (char *)0; if (!cs || !str) return FALSE; @@ -1216,28 +1211,9 @@ char *str; } tmp = (struct menucoloring *)alloc(sizeof(struct menucoloring)); -#ifdef MENU_COLOR_REGEX -#ifdef MENU_COLOR_REGEX_POSIX - errnum = regcomp(&tmp->match, tmps, REG_EXTENDED | REG_NOSUB); - if (errnum != 0) - { - regerror(errnum, &tmp->match, errbuf, sizeof(errbuf)); - err = errbuf; - } -#else - tmp->match.translate = 0; - tmp->match.fastmap = 0; - tmp->match.buffer = 0; - tmp->match.allocated = 0; - tmp->match.regs_allocated = REGS_FIXED; - err = re_compile_pattern(tmps, strlen(tmps), &tmp->match); -#endif -#else - tmp->match = (char *)alloc(strlen(tmps)+1); - (void) memcpy((genericptr_t)tmp->match, (genericptr_t)tmps, strlen(tmps)+1); -#endif - if (err) { - raw_printf("\nMenucolor regex error: %s\n", err); + tmp->match = regex_init(); + if (!regex_compile(tmps, tmp->match)) { + raw_printf("\nMenucolor regex error: %s\n", regex_error_desc(tmp->match)); wait_synch(); free(tmp); return FALSE; @@ -1258,15 +1234,7 @@ int *color, *attr; struct menucoloring *tmpmc; if (iflags.use_menu_color) for (tmpmc = menu_colorings; tmpmc; tmpmc = tmpmc->next) -#ifdef MENU_COLOR_REGEX -# ifdef MENU_COLOR_REGEX_POSIX - if (regexec(&tmpmc->match, str, 0, NULL, 0) == 0) { -# else - if (re_search(&tmpmc->match, str, strlen(str), 0, 9999, 0) >= 0) { -# endif -#else - if (pmatch(tmpmc->match, str)) { -#endif + if (regex_match(str, tmpmc->match)) { *color = tmpmc->color; *attr = tmpmc->attr; return TRUE; @@ -1281,11 +1249,7 @@ free_menu_coloring() while (tmp) { struct menucoloring *tmp2 = tmp->next; -#ifdef MENU_COLOR_REGEX - (void) regfree(&tmp->match); -#else - free(tmp->match); -#endif + regex_free(tmp->match); free(tmp); tmp = tmp2; } diff --git a/sys/share/cppregex.cpp b/sys/share/cppregex.cpp new file mode 100644 index 000000000..a0a1bbdc8 --- /dev/null +++ b/sys/share/cppregex.cpp @@ -0,0 +1,56 @@ +/* NetHack 3.5 cppregex.cpp $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* Copyright (c) Sean Hunt 2015. */ +/* NetHack may be freely redistributed. See license for details. */ + +#include +#include + +/* nhregex interface documented in sys/share/posixregex.c */ + +extern "C" { + #include + + struct nhregex { + std::unique_ptr re; + std::unique_ptr err; + }; + + struct nhregex *regex_init(void) { + return new nhregex; + } + + boolean regex_compile(const char *s, struct nhregex *re) { + if (!re) + return FALSE; + try { + re->re.reset(new std::regex(s, std::regex::extended | std::regex::nosubs | std::regex::optimize)); + re->err.reset(nullptr); + return TRUE; + } catch (const std::regex_error& err) { + re->err.reset(new std::regex_error(err)); + re->re.reset(nullptr); + return FALSE; + } + } + + const char *regex_error_desc(struct nhregex *re) { + if (re->err) + return re->err->what(); + else + return nullptr; + } + + boolean regex_match(const char *s, struct nhregex *re) { + if (!re->re) + return false; + try { + return regex_search(s, *re->re, std::regex_constants::match_any); + } catch (const std::regex_error& err) { + return false; + } + } + + void regex_free(struct nhregex *re) { + delete re; + } +} diff --git a/sys/share/posixregex.c b/sys/share/posixregex.c new file mode 100644 index 000000000..17cb2841e --- /dev/null +++ b/sys/share/posixregex.c @@ -0,0 +1,92 @@ +/* NetHack 3.5 posixregex.c $NHDT-Date: 1428590280 2015/04/09 14:38:00 $ $NHDT-Branch: scshunt-regex $:$NHDT-Revision: 1.0 $ */ +/* Copyright (c) Sean Hunt 2015. */ +/* NetHack may be freely redistributed. See license for details. */ + +#include + +#include + +/* The nhregex interface is implemented by several source files. The + * file to be used can be linked in by the build. + * + * The regex standard implemented should be POSIX extended regular + * expressions, see: + * http://pubs.opengroup.org/onlinepubs/009696899/basedefs/xbd_chap09.html + * If an implementation uses an alternate expression format, this should + * be clearly noted; this will result in incompatibility of config files + * when NetHack is compiled with that implementation. + * + * struct nhregex + * The nhregex structure is an opaque structure type containing the + * information about a compiled regular expression. + * + * struct nhregex *regex_init(void) + * Used to create a new instance of the nhregex structure. It is + * uninitialized and can only safely be passed to regex_compile. + * + * boolean regex_compile(const char *s, struct nhregex *re) + * Used to compile s into a regex and store it in re. Returns TRUE if + * successful and FALSE otherwise. re is invalidated regardless of + * success. + * + * const char *regex_error_desc(struct nhregex *re) + * Used to retrieve an error description from an error created involving + * re. Returns NULL if no description can be retrieved. The returned + * string may be a static buffer and so is only valid until the next + * call to regex_error_desc. + * + * boolean regex_match(const char *s, struct nhregex *re) + * Used to determine if s (or any substring) matches the regex compiled + * into re. Only valid if the most recent call to regex_compile on re + * succeeded. + * + * void regex_free(struct nhregex *re) + * Deallocate a regex object. + */ + +struct nhregex { + regex_t re; + int err; +}; + +struct nhregex *regex_init() { + return malloc (sizeof (struct nhregex)); +} + +boolean regex_compile(const char *s, struct nhregex *re) { + if (!re) + return FALSE; + if ((re->err = regcomp(&re->re, s, REG_EXTENDED | REG_NOSUB))) + return FALSE; + return TRUE; +} + +const char *regex_error_desc(struct nhregex *re) { + static char buf[BUFSZ]; + + if (!re || !re->err) + return NULL; + + /* FIXME: Using a static buffer here is not ideal, but avoids memory + * leaks. Consider the allocation more carefully. */ + regerror(re->err, &re->re, buf, BUFSZ); + + return buf; +} + +boolean regex_match(const char *s, struct nhregex *re) { + if (!re) + return FALSE; + + int result; + if ((result = regexec(&re->re, s, 0, NULL, 0))) { + if (result != REG_NOMATCH) + re->err = result; + return FALSE; + } + return TRUE; +} + +void regex_free(struct nhregex *re) { + free(re); +} diff --git a/sys/unix/Makefile.src b/sys/unix/Makefile.src index b64a838c9..79d34fc64 100644 --- a/sys/unix/Makefile.src +++ b/sys/unix/Makefile.src @@ -1,5 +1,5 @@ # NetHack Makefile. -# NetHack 3.5 Makefile.src $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ +# NetHack 3.5 Makefile.src $NHDT-Date: 1428590253 2015/04/09 14:37:33 $ $NHDT-Branch: scshunt-regex $:$NHDT-Revision: 1.38 $ # NetHack 3.5 Makefile.src $Date: 2012/01/20 03:41:33 $ $Revision: 1.37 $ # Root of source tree: @@ -338,7 +338,7 @@ HACKCSRC = allmain.c alloc.c apply.c artifact.c attrib.c ball.c bones.c \ # all operating-system-dependent .c (for dependencies and such) SYSCSRC = ../sys/atari/tos.c ../sys/share/pcmain.c ../sys/share/pcsys.c \ - ../sys/share/pctty.c ../sys/share/pcunix.c ../sys/share/random.c \ + ../sys/share/pctty.c ../sys/share/pcunix.c ../sys/share/posixregex.c ../sys/share/random.c \ ../sys/share/ioctl.c ../sys/share/unixtty.c ../sys/unix/unixmain.c \ ../sys/unix/unixunix.c ../sys/unix/unixres.c ../sys/be/bemain.c @@ -391,7 +391,7 @@ HOBJ = $(FIRSTOBJ) allmain.o alloc.o apply.o artifact.o attrib.o ball.o \ minion.o mklev.o mkmap.o \ mkmaze.o mkobj.o mkroom.o mon.o mondata.o monmove.o monstr.o \ mplayer.o mthrowu.o muse.o music.o o_init.o objnam.o options.o \ - pager.o pickup.o pline.o polyself.o potion.o pray.o priest.o \ + pager.o pickup.o pline.o polyself.o posixregex.o potion.o pray.o priest.o \ quest.o questpgr.o read.o rect.o region.o restore.o rip.o rnd.o \ role.o rumors.o save.o shk.o shknam.o sit.o sounds.o sp_lev.o spell.o \ sys.o \ @@ -603,6 +603,8 @@ random.o: ../sys/share/random.c $(HACK_H) $(CC) $(CFLAGS) -c ../sys/share/random.c ioctl.o: ../sys/share/ioctl.c $(HACK_H) ../include/tcap.h $(CC) $(CFLAGS) -c ../sys/share/ioctl.c +posixregex.o: ../sys/share/posixregex.c $(HACK_H) + $(CC) $(CFLAGS) -c ../sys/share/posixregex.c unixtty.o: ../sys/share/unixtty.c $(HACK_H) $(CC) $(CFLAGS) -c ../sys/share/unixtty.c unixmain.o: ../sys/unix/unixmain.c $(HACK_H) ../include/dlb.h diff --git a/win/win32/vs2010/NetHackW.vcxproj b/win/win32/vs2010/NetHackW.vcxproj index 9305e23b9..c90ff1112 100644 --- a/win/win32/vs2010/NetHackW.vcxproj +++ b/win/win32/vs2010/NetHackW.vcxproj @@ -636,6 +636,7 @@ copy ..\sys\winnt\defaults.nh ..\binary\defaults.nh %(PreprocessorDefinitions) %(PreprocessorDefinitions) + %(AdditionalIncludeDirectories) %(AdditionalIncludeDirectories) @@ -1776,4 +1777,4 @@ copy ..\sys\winnt\defaults.nh ..\binary\defaults.nh - \ No newline at end of file + diff --git a/win/win32/vs2013/NetHack.vcxproj b/win/win32/vs2013/NetHack.vcxproj index 81fcb2382..70138dcc2 100644 --- a/win/win32/vs2013/NetHack.vcxproj +++ b/win/win32/vs2013/NetHack.vcxproj @@ -418,6 +418,7 @@ +