finish implementing pmatchregex

I started out cleaning up a bit of lint in the recent run-time options
handling and discovered that pmatchregex wasn't finished.  Finish it and
also deal with the version lint.  Argument declarations for function
definitions in pmatchregex.c have been switched to K&R style.  (The ones
in posixregex.c have been left in ANSI style.)

There wasn't any build rule for pmatchregex.o; now there is (for Unix).
posixregex.o is still the default.

There isn't any build rule for cppregex.o (again, for Unix); the change
to cppregex.cpp is untested.
This commit is contained in:
PatR
2015-06-16 02:29:22 -07:00
parent 666e4976b5
commit 1547e676f3
5 changed files with 54 additions and 37 deletions

View File

@@ -1,4 +1,4 @@
/* 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. */
@@ -130,9 +130,9 @@ doextversion()
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[] = " ";
@@ -150,7 +150,7 @@ char *buf;
{
char rtbuf[BUFSZ];
char *pd;
int l, i = 0, j = 0;
int l, i = 0;
if (strlen(buf) >= BUFSZ - 3)
return;

View File

@@ -10,7 +10,7 @@
extern "C" {
#include <hack.h>
char regex_id[] = "cppregex";
const char regex_id[] = "cppregex";
struct nhregex {
std::unique_ptr<std::regex> re;
@@ -25,7 +25,9 @@ extern "C" {
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) {

View File

@@ -1,10 +1,11 @@
/* 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,
@@ -12,56 +13,61 @@
* 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);
}
}

View File

@@ -1,4 +1,4 @@
/* 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. */
@@ -44,7 +44,7 @@
* Deallocate a regex object.
*/
char regex_id[] = "posixregex";
const char regex_id[] = "posixregex";
struct nhregex {
regex_t re;

View File

@@ -1,5 +1,5 @@
# 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=..
@@ -167,6 +167,11 @@ CXX=g++
#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
@@ -337,7 +342,9 @@ 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/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
@@ -391,14 +398,14 @@ 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 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)
@@ -599,12 +606,14 @@ pctty.o: ../sys/share/pctty.c $(HACK_H)
$(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