-/* NetHack 3.6 version.c $NHDT-Date: 1434151385 2015/06/12 23:23:05 $ $NHDT-Branch: master $:$NHDT-Revision: 1.32 $ */
+/* NetHack 3.6 version.c $NHDT-Date: 1434446944 2015/06/16 09:29:04 $ $NHDT-Branch: master $:$NHDT-Revision: 1.33 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed. See license for details. */
return 0;
}
-extern char regex_id[];
+extern const char regex_id[];
-static char *rt_opts[] = {
+static const char *rt_opts[] = {
"pattern matching via", regex_id,
};
static const char indent[] = " ";
{
char rtbuf[BUFSZ];
char *pd;
- int l, i = 0, j = 0;
+ int l, i = 0;
if (strlen(buf) >= BUFSZ - 3)
return;
extern "C" {
#include <hack.h>
- char regex_id[] = "cppregex";
+ const char regex_id[] = "cppregex";
struct nhregex {
std::unique_ptr<std::regex> re;
if (!re)
return FALSE;
try {
- re->re.reset(new std::regex(s, std::regex::extended | std::regex::nosubs | std::regex::optimize));
+ 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) {
-/* NetHack 3.6 posixregex.c $NHDT-Date: 1434151360 2015/06/12 23:22:40 $ $NHDT-Branch: master $:$NHDT-Revision: 1.0 $ */
+/* NetHack 3.6 posixregex.c $NHDT-Date: 1434446946 2015/06/16 09:29:06 $ $NHDT-Branch: master $:$NHDT-Revision: 1.1 $ */
/* Copyright (c) Sean Hunt 2015. */
/* NetHack may be freely redistributed. See license for details. */
#include "hack.h"
/* Implementation of the regex engine using pmatch().
+ * [Switched to pmatchi() so as to ignore case.]
*
* This is a fallback ONLY and should be avoided where possible, as it results
* in regexes not behaving as POSIX extended regular expressions. As a result,
* portable to ones built with an alternate regex engine.
*/
-/*
- * NOTE: This file is untested.
- */
-
-char regex_id[] = "pmatchregex";
+const char regex_id[] = "pmatchregex";
struct nhregex {
- const char *pat;
+ const char *pat;
};
struct nhregex *
regex_init()
{
- return (struct nhregex *) alloc(sizeof(struct nhregex));
+ struct nhregex *re;
+
+ re = (struct nhregex *) alloc(sizeof (struct nhregex));
+ re->pat = (const char *) 0;
+ return re;
}
boolean
-regex_compile(const char *s, struct nhregex *re)
+regex_compile(s, re)
+const char *s;
+struct nhregex *re;
{
if (!re)
return FALSE;
- if (re->pat);
- free(re->path);
+ if (re->pat)
+ free((genericptr_t) re->pat);
- re->pat = alloc(strlen(s) + 1);
- strcpy(re->pat, s);
+ re->pat = dupstr(s);
return TRUE;
}
const char *
-regex_error_desc(struct nhregex *re)
+regex_error_desc(re)
+struct nhregex *re UNUSED;
{
return "pattern match compilation error";
}
boolean
-regex_match(const char *s, struct nhregex *re)
+regex_match(s, re)
+const char *s;
+struct nhregex *re;
{
if (!re || !re->pat || !s)
return FALSE;
- return pmatch(re->pat, s);
+
+ return pmatchi(re->pat, s);
}
void
-regex_free(struct nhregex *re)
+regex_free(re)
+struct nhregex *re;
{
- if (!re)
- return FALSE;
-
- if (re->pat)
- free(re->pat);
- free(re);
+ if (re) {
+ if (re->pat)
+ free((genericptr_t) re->pat);
+ free((genericptr_t) re);
+ }
}
-/* NetHack 3.6 posixregex.c $NHDT-Date: 1434151361 2015/06/12 23:22:41 $ $NHDT-Branch: master $:$NHDT-Revision: 1.4 $ */
+/* NetHack 3.6 posixregex.c $NHDT-Date: 1434446947 2015/06/16 09:29:07 $ $NHDT-Branch: master $:$NHDT-Revision: 1.5 $ */
/* Copyright (c) Sean Hunt 2015. */
/* NetHack may be freely redistributed. See license for details. */
* Deallocate a regex object.
*/
-char regex_id[] = "posixregex";
+const char regex_id[] = "posixregex";
struct nhregex {
regex_t re;
# NetHack Makefile.
-# NetHack 3.6 Makefile.src $NHDT-Date: 1432512789 2015/05/25 00:13:09 $ $NHDT-Branch: master $:$NHDT-Revision: 1.43 $
+# NetHack 3.6 Makefile.src $NHDT-Date: 1434446945 2015/06/16 09:29:05 $ $NHDT-Branch: master $:$NHDT-Revision: 1.44 $
# Root of source tree:
NHSROOT=..
#CXX=arm-linux-g++
#LINK=arm-linux-gcc
+# file for regular expression matching
+REGEXOBJ = posixregex.o
+#REGEXOBJ = pmatchregex.o
+#REGEXOBJ = cppregex.o
+
# Set the WINSRC, WINOBJ, and WINLIB lines to correspond to your desired
# combination of windowing systems. Also set windowing systems in config.h.
# Note that if you are including multiple tiled window systems, you don't
# 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/posixregex.c ../sys/share/random.c \
+ ../sys/share/pctty.c ../sys/share/pcunix.c \
+ ../sys/share/pmatchregex.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
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 posixregex.o potion.o pray.o priest.o \
+ pager.o pickup.o pline.o polyself.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 \
steal.o steed.o teleport.o timeout.o topten.o track.o trap.o u_init.o \
uhitm.o vault.o vision.o vis_tab.o weapon.o were.o wield.o windows.o \
wizard.o worm.o worn.o write.o zap.o \
- $(RANDOBJ) $(SYSOBJ) $(WINOBJ) $(HINTOBJ) version.o
+ $(REGEXOBJ) $(RANDOBJ) $(SYSOBJ) $(WINOBJ) $(HINTOBJ) version.o
# the .o files from the HACKCSRC, SYSSRC, and WINSRC lists
$(GAME): $(SYSTEM)
$(CC) $(CFLAGS) -c ../sys/share/pctty.c
pcunix.o: ../sys/share/pcunix.c $(HACK_H)
$(CC) $(CFLAGS) -c ../sys/share/pcunix.c
+pmatchregex.o: ../sys/share/pmatchregex.c $(HACK_H)
+ $(CC) $(CFLAGS) -c ../sys/share/pmatchregex.c
+posixregex.o: ../sys/share/posixregex.c $(HACK_H)
+ $(CC) $(CFLAGS) -c ../sys/share/posixregex.c
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