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

@@ -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;