Files
nethack/sys/share/pmatchregex.c
nhmall 37f0eafa93 support for link-time option in #version
Changes to be committed:
	modified:   src/version.c
	modified:   sys/share/cppregex.cpp
	modified:   sys/share/pmatchregex.c
	modified:   sys/share/posixregex.c
	modified:   util/makedefs.c

Some options in 3.6.0 are determined by what you link with.
The choice of regex support is one.
Let #version show that linked option along with the compile-time options.
2015-06-12 19:23:18 -04:00

68 lines
1.4 KiB
C

/* NetHack 3.6 posixregex.c $NHDT-Date: 1434151360 2015/06/12 23:22:40 $ $NHDT-Branch: master $:$NHDT-Revision: 1.0 $ */
/* Copyright (c) Sean Hunt 2015. */
/* NetHack may be freely redistributed. See license for details. */
#include "hack.h"
/* Implementation of the regex engine using pmatch().
*
* 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,
* configuration files for NetHacks built with this engine will not be
* portable to ones built with an alternate regex engine.
*/
/*
* NOTE: This file is untested.
*/
char regex_id[] = "pmatchregex";
struct nhregex {
const char *pat;
};
struct nhregex *
regex_init()
{
return (struct nhregex *) alloc(sizeof(struct nhregex));
}
boolean
regex_compile(const char *s, struct nhregex *re)
{
if (!re)
return FALSE;
if (re->pat);
free(re->path);
re->pat = alloc(strlen(s) + 1);
strcpy(re->pat, s);
return TRUE;
}
const char *
regex_error_desc(struct nhregex *re)
{
return "pattern match compilation error";
}
boolean
regex_match(const char *s, struct nhregex *re)
{
if (!re || !re->pat || !s)
return FALSE;
return pmatch(re->pat, s);
}
void
regex_free(struct nhregex *re)
{
if (!re)
return FALSE;
if (re->pat)
free(re->pat);
free(re);
}