new .h files: hacklib.h selvar.h stairs.h
new .c files: calendar.c, getpos.c, report.c, selvar.c, stairs.c,
strutil.c, wizcmds.c
cleanup of hacklib.c and mdlib.c
hacklib contains functions that do not have to link with the core
relocate wiz commands from cmd.c to wizcmds.c
relocate CRASHREPORT stuff to report.c
relocate getpos stuff from do_name.c to getpos.c
remove temporary struct definition from extern.h
cross-compile PRE-section split into cross-pre1.370 and cross-pre2.370
Windows sys/windows/Makefile.nmake and sys/windows/Makefile.mingw32 and
visual studio project file updates
Unix sys/unix/Makefile.src, sys/unix/Makefile.utl
populate selvar.c and selvar.h
build on MS-DOS (not cross-compile) Makefile updates
for sys/msdos/Makefile.GCC (untested)
vms updates for above (untested)
89 lines
1.9 KiB
C++
89 lines
1.9 KiB
C++
/* NetHack 3.7 cppregex.cpp */
|
|
/* $NHDT-Date: 1596498279 2020/08/03 23:44:39 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.9 $ */
|
|
/* Copyright (c) Sean Hunt 2015. */
|
|
/* NetHack may be freely redistributed. See license for details. */
|
|
|
|
#include <regex>
|
|
#include <memory>
|
|
#include <cstring>
|
|
|
|
extern "C" {
|
|
#include "config.h"
|
|
#define CPPREGEX_C
|
|
//#include "extern.h"
|
|
} // extern "C"
|
|
|
|
|
|
extern "C" { // rest of file
|
|
|
|
/* nhregex interface documented in sys/share/posixregex.c */
|
|
|
|
extern const char regex_id[] = "cppregex";
|
|
|
|
struct nhregex {
|
|
std::unique_ptr<std::regex> re;
|
|
std::unique_ptr<std::regex_error> 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;
|
|
}
|
|
}
|
|
|
|
char *
|
|
regex_error_desc(struct nhregex *re, char *errbuf)
|
|
{
|
|
if (!re) {
|
|
Strcpy(errbuf, "no regexp");
|
|
} else if (!re->err) {
|
|
Strcpy(errbuf, "no explanation");
|
|
} else {
|
|
errbuf[0] = '\0';
|
|
(void) strncat(errbuf, re->err->what(), BUFSZ - 1);
|
|
if (!errbuf[0])
|
|
Strcpy(errbuf, "unspecified regexp error");
|
|
}
|
|
return errbuf;
|
|
}
|
|
|
|
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;
|
|
}
|
|
#undef CPPREGEX_C
|
|
} // extern "C"
|
|
|
|
/*cppregex.cpp*/
|