summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorshmuz <shmuz>2008-07-30 17:30:02 +0000
committershmuz <shmuz>2008-07-30 17:30:02 +0000
commit09205eea30e1dfa3c8c309dd221ae1ab3c2590a8 (patch)
tree7e2b4b89f9f8193e7d8f7bf2ea865764dcf42695 /src
parent54a8e5ff8ba5b24bae3a56d33091703074545b39 (diff)
downloadlrexlib-09205eea30e1dfa3c8c309dd221ae1ab3c2590a8.tar.gz
Moving files: each binding to its dedicated directory.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/lpcre.c439
-rwxr-xr-xsrc/lpcre_f.c189
-rwxr-xr-xsrc/lposix.c295
-rwxr-xr-xsrc/ltre.c358
-rwxr-xr-xsrc/rex_pcre.mak38
-rwxr-xr-xsrc/rex_posix.mak48
-rwxr-xr-xsrc/rex_tre.mak42
-rwxr-xr-xsrc/scite.properties21
8 files changed, 0 insertions, 1430 deletions
diff --git a/src/lpcre.c b/src/lpcre.c
deleted file mode 100755
index 01541b0..0000000
--- a/src/lpcre.c
+++ /dev/null
@@ -1,439 +0,0 @@
-/* lpcre.c - Lua binding of PCRE library */
-/* See Copyright Notice in the file LICENSE */
-
-#include <stdlib.h>
-#include <string.h>
-#include <locale.h>
-#include <ctype.h>
-#include <pcre.h>
-
-#include "lua.h"
-#include "lauxlib.h"
-#include "common.h"
-
-extern int Lpcre_get_flags (lua_State *L);
-extern int Lpcre_config (lua_State *L);
-extern flag_pair pcre_error_flags[];
-
-/* These 2 settings may be redefined from the command-line or the makefile.
- * They should be kept in sync between themselves and with the target name.
- */
-#ifndef REX_LIBNAME
-# define REX_LIBNAME "rex_pcre"
-#endif
-#ifndef REX_OPENLIB
-# define REX_OPENLIB luaopen_rex_pcre
-#endif
-
-#define REX_TYPENAME REX_LIBNAME"_regex"
-
-#define ALG_CFLAGS_DFLT 0
-#define ALG_EFLAGS_DFLT 0
-
-static int getcflags (lua_State *L, int pos);
-#define ALG_GETCFLAGS(L,pos) getcflags(L, pos)
-
-static void optlocale (TArgComp *argC, lua_State *L, int pos);
-#define ALG_OPTLOCALE(a,b,c) optlocale(a,b,c)
-
-#define ALG_NOMATCH PCRE_ERROR_NOMATCH
-#define ALG_ISMATCH(res) ((res) >= 0)
-#define ALG_SUBBEG(ud,n) ud->match[n+n]
-#define ALG_SUBEND(ud,n) ud->match[n+n+1]
-#define ALG_SUBLEN(ud,n) (ALG_SUBEND(ud,n) - ALG_SUBBEG(ud,n))
-#define ALG_SUBVALID(ud,n) (ALG_SUBBEG(ud,n) >= 0)
-#define ALG_NSUB(ud) ((int)ud->ncapt)
-
-#define ALG_PUSHSUB(L,ud,text,n) \
- lua_pushlstring (L, (text) + ALG_SUBBEG(ud,n), ALG_SUBLEN(ud,n))
-
-#define ALG_PUSHSUB_OR_FALSE(L,ud,text,n) \
- (ALG_SUBVALID(ud,n) ? ALG_PUSHSUB (L,ud,text,n) : lua_pushboolean (L,0))
-
-#define ALG_PUSHSTART(L,ud,offs,n) lua_pushinteger(L, (offs) + ALG_SUBBEG(ud,n) + 1)
-#define ALG_PUSHEND(L,ud,offs,n) lua_pushinteger(L, (offs) + ALG_SUBEND(ud,n))
-#define ALG_PUSHOFFSETS(L,ud,offs,n) \
- (ALG_PUSHSTART(L,ud,offs,n), ALG_PUSHEND(L,ud,offs,n))
-
-#define ALG_BASE(st) 0
-#define ALG_PULL
-#define ALG_USERETRY
-
-typedef struct {
- pcre * pr;
- pcre_extra * extra;
- int * match;
- int ncapt;
- const unsigned char * tables;
- int freed;
-} TPcre;
-
-#define TUserdata TPcre
-
-#if PCRE_MAJOR >= 4
-static void do_named_subpatterns (lua_State *L, TPcre *ud, const char *text);
-# define DO_NAMED_SUBPATTERNS do_named_subpatterns
-#endif
-
-#include "algo.h"
-
-/* Locations of the 2 permanent tables in the function environment */
-#define INDEX_CHARTABLES_META 1 /* chartables type's metatable */
-#define INDEX_CHARTABLES_LINK 2 /* link chartables to compiled regex */
-
-const char chartables_typename[] = "chartables";
-
-/* Functions
- ******************************************************************************
- */
-
-static void push_chartables_meta (lua_State *L) {
- lua_pushinteger (L, INDEX_CHARTABLES_META);
- lua_rawget (L, LUA_ENVIRONINDEX);
-}
-
-static int getcflags (lua_State *L, int pos) {
- switch (lua_type (L, pos)) {
- case LUA_TNONE:
- case LUA_TNIL:
- return ALG_CFLAGS_DFLT;
- case LUA_TNUMBER:
- return lua_tointeger (L, pos);
- case LUA_TSTRING: {
- const char *s = lua_tostring (L, pos);
- int res = 0, ch;
- while ((ch = *s++) != '\0') {
- if (ch == 'i') res |= PCRE_CASELESS;
- else if (ch == 'm') res |= PCRE_MULTILINE;
- else if (ch == 's') res |= PCRE_DOTALL;
- else if (ch == 'x') res |= PCRE_EXTENDED;
- else if (ch == 'U') res |= PCRE_UNGREEDY;
- else if (ch == 'X') res |= PCRE_EXTRA;
- }
- return res;
- }
- default:
- return luaL_typerror (L, pos, "number or string");
- }
-}
-
-static int generate_error (lua_State *L, const TPcre *ud, int errcode) {
- const char *key = get_flag_key (pcre_error_flags, errcode);
- (void) ud;
- if (key)
- return luaL_error (L, "error PCRE_%s", key);
- else
- return luaL_error (L, "PCRE error code %d", errcode);
-}
-
-#if PCRE_MAJOR >= 6
-/* method r:dfa_exec (s, [st], [ef], [ovecsize], [wscount]) */
-static void checkarg_dfa_exec (lua_State *L, TArgExec *argE, TPcre **ud) {
- *ud = check_ud (L);
- argE->text = luaL_checklstring (L, 2, &argE->textlen);
- argE->startoffset = get_startoffset (L, 3, argE->textlen);
- argE->eflags = luaL_optint (L, 4, ALG_EFLAGS_DFLT);
- argE->ovecsize = luaL_optint (L, 5, 100);
- argE->wscount = luaL_optint (L, 6, 50);
-}
-#endif
-
-static int Lpcre_maketables (lua_State *L) {
- *(const void**)lua_newuserdata (L, sizeof(void*)) = pcre_maketables();
- push_chartables_meta (L);
- lua_setmetatable (L, -2);
- return 1;
-}
-
-static void **check_chartables (lua_State *L, int pos) {
- void **q;
- /* Compare the metatable against the C function environment. */
- if (lua_getmetatable(L, pos)) {
- push_chartables_meta (L);
- if (lua_rawequal(L, -1, -2) &&
- (q = (void **)lua_touserdata(L, pos)) != NULL) {
- lua_pop(L, 2);
- return q;
- }
- }
- luaL_argerror(L, pos, lua_pushfstring (L, "not a %s", chartables_typename));
- return NULL;
-}
-
-static int chartables_gc (lua_State *L) {
- void **ud = check_chartables (L, 1);
- if (*ud) {
- pcre_free (*ud);
- *ud = NULL;
- }
- return 0;
-}
-
-static void optlocale (TArgComp *argC, lua_State *L, int pos) {
- argC->locale = NULL;
- argC->tables = NULL;
- if (!lua_isnoneornil (L, pos)) {
- if (lua_isstring (L, pos))
- argC->locale = lua_tostring (L, pos);
- else {
- argC->tablespos = pos;
- argC->tables = *check_chartables (L, pos);
- }
- }
-}
-
-static int compile_regex (lua_State *L, const TArgComp *argC, TPcre **pud) {
- const char *error;
- int erroffset;
- TPcre *ud;
- const unsigned char *tables = NULL;
-
- ud = (TPcre*)lua_newuserdata (L, sizeof (TPcre));
- memset (ud, 0, sizeof (TPcre)); /* initialize all members to 0 */
- lua_pushvalue (L, LUA_ENVIRONINDEX);
- lua_setmetatable (L, -2);
-
- if (argC->locale) {
- char old_locale[256];
- strcpy (old_locale, setlocale (LC_CTYPE, NULL)); /* store the locale */
- if (NULL == setlocale (LC_CTYPE, argC->locale)) /* set new locale */
- return luaL_error (L, "cannot set locale");
- ud->tables = tables = pcre_maketables (); /* make tables with new locale */
- setlocale (LC_CTYPE, old_locale); /* restore the old locale */
- }
- else if (argC->tables) {
- tables = argC->tables;
- lua_pushinteger (L, INDEX_CHARTABLES_LINK);
- lua_rawget (L, LUA_ENVIRONINDEX);
- lua_pushvalue (L, -2);
- lua_pushvalue (L, argC->tablespos);
- lua_rawset (L, -3);
- lua_pop (L, 1);
- }
-
- ud->pr = pcre_compile (argC->pattern, argC->cflags, &error, &erroffset, tables);
- if (!ud->pr)
- return luaL_error (L, "%s (pattern offset: %d)", error, erroffset + 1);
-
- ud->extra = pcre_study (ud->pr, 0, &error);
- if (error) return luaL_error (L, "%s", error);
-
- pcre_fullinfo (ud->pr, ud->extra, PCRE_INFO_CAPTURECOUNT, &ud->ncapt);
- /* need (2 ints per capture, plus one for substring match) * 3/2 */
- ud->match = (int *) Lmalloc (L, (ALG_NSUB(ud) + 1) * 3 * sizeof (int));
-
- if (pud) *pud = ud;
- return 1;
-}
-
-#if PCRE_MAJOR >= 4
-/* the target table must be on lua stack top */
-static void do_named_subpatterns (lua_State *L, TPcre *ud, const char *text) {
- int i, namecount, name_entry_size;
- unsigned char *name_table, *tabptr;
-
- /* do named subpatterns - NJG */
- pcre_fullinfo (ud->pr, ud->extra, PCRE_INFO_NAMECOUNT, &namecount);
- if (namecount <= 0)
- return;
- pcre_fullinfo (ud->pr, ud->extra, PCRE_INFO_NAMETABLE, &name_table);
- pcre_fullinfo (ud->pr, ud->extra, PCRE_INFO_NAMEENTRYSIZE, &name_entry_size);
- tabptr = name_table;
- for (i = 0; i < namecount; i++) {
- int n = (tabptr[0] << 8) | tabptr[1]; /* number of the capturing parenthesis */
- if (n > 0 && n <= ALG_NSUB(ud)) { /* check range */
- lua_pushstring (L, (char *)tabptr + 2); /* name of the capture, zero terminated */
- ALG_PUSHSUB_OR_FALSE (L, ud, text, n);
- lua_rawset (L, -3);
- }
- tabptr += name_entry_size;
- }
-}
-#endif /* #if PCRE_MAJOR >= 4 */
-
-#if PCRE_MAJOR >= 6
-static int Lpcre_dfa_exec (lua_State *L)
-{
- TArgExec argE;
- TPcre *ud;
- int res;
- int *buf, *ovector, *wspace;
-
- checkarg_dfa_exec (L, &argE, &ud);
- buf = (int*) Lmalloc (L, (argE.ovecsize + argE.wscount) * sizeof(int));
- ovector = buf;
- wspace = buf + argE.ovecsize;
-
- res = pcre_dfa_exec (ud->pr, ud->extra, argE.text, (int)argE.textlen,
- argE.startoffset, argE.eflags, ovector, argE.ovecsize, wspace, argE.wscount);
-
- if (ALG_ISMATCH (res) || res == PCRE_ERROR_PARTIAL) {
- int i;
- int max = (res>0) ? res : (res==0) ? (int)argE.ovecsize/2 : 1;
- lua_pushinteger (L, ovector[0] + 1); /* 1-st return value */
- lua_newtable (L); /* 2-nd return value */
- for (i=0; i<max; i++) {
- lua_pushinteger (L, ovector[i+i+1]);
- lua_rawseti (L, -2, i+1);
- }
- lua_pushinteger (L, res); /* 3-rd return value */
- free (buf);
- return 3;
- }
- else {
- free (buf);
- if (res == ALG_NOMATCH)
- return lua_pushnil (L), 1;
- else
- return generate_error (L, ud, res);
- }
-}
-#endif /* #if PCRE_MAJOR >= 6 */
-
-#ifdef ALG_USERETRY
- static int gmatch_exec (TUserdata *ud, TArgExec *argE, int retry) {
- int eflags = retry ? (argE->eflags|PCRE_NOTEMPTY|PCRE_ANCHORED) : argE->eflags;
- return pcre_exec (ud->pr, ud->extra, argE->text, argE->textlen,
- argE->startoffset, eflags, ud->match, (ALG_NSUB(ud) + 1) * 3);
- }
-#else
- static int gmatch_exec (TUserdata *ud, TArgExec *argE) {
- return pcre_exec (ud->pr, ud->extra, argE->text, argE->textlen,
- argE->startoffset, argE->eflags, ud->match, (ALG_NSUB(ud) + 1) * 3);
- }
-#endif
-
-static void gmatch_pushsubject (lua_State *L, TArgExec *argE) {
- lua_pushlstring (L, argE->text, argE->textlen);
-}
-
-static int findmatch_exec (TPcre *ud, TArgExec *argE) {
- return pcre_exec (ud->pr, ud->extra, argE->text, argE->textlen,
- argE->startoffset, argE->eflags, ud->match, (ALG_NSUB(ud) + 1) * 3);
-}
-
-#ifdef ALG_USERETRY
- static int gsub_exec (TPcre *ud, TArgExec *argE, int st, int retry) {
- int eflags = retry ? (argE->eflags|PCRE_NOTEMPTY|PCRE_ANCHORED) : argE->eflags;
- return pcre_exec (ud->pr, ud->extra, argE->text, argE->textlen,
- st, eflags, ud->match, (ALG_NSUB(ud) + 1) * 3);
- }
-#else
- static int gsub_exec (TPcre *ud, TArgExec *argE, int st) {
- return pcre_exec (ud->pr, ud->extra, argE->text, argE->textlen,
- st, argE->eflags, ud->match, (ALG_NSUB(ud) + 1) * 3);
- }
-#endif
-
-static int split_exec (TPcre *ud, TArgExec *argE, int offset) {
- return pcre_exec (ud->pr, ud->extra, argE->text, argE->textlen, offset,
- argE->eflags, ud->match, (ALG_NSUB(ud) + 1) * 3);
-}
-
-static int Lpcre_gc (lua_State *L) {
- TPcre *ud = check_ud (L);
- if (ud->freed == 0) { /* precaution against "manual" __gc calling */
- ud->freed = 1;
- if (ud->pr) pcre_free (ud->pr);
- if (ud->extra) pcre_free (ud->extra);
- if (ud->tables) pcre_free ((void *)ud->tables);
- if (ud->match) free (ud->match);
- }
- return 0;
-}
-
-static int Lpcre_tostring (lua_State *L) {
- TPcre *ud = check_ud (L);
- if (ud->freed == 0)
- lua_pushfstring (L, "%s (%p)", REX_TYPENAME, (void*)ud);
- else
- lua_pushfstring (L, "%s (deleted)", REX_TYPENAME);
- return 1;
-}
-
-static int chartables_tostring (lua_State *L) {
- void **ud = check_chartables (L, 1);
- lua_pushfstring (L, "%s (%p)", chartables_typename, ud);
- return 1;
-}
-
-static int Lpcre_version (lua_State *L) {
- lua_pushstring (L, pcre_version ());
- return 1;
-}
-
-static const luaL_reg chartables_meta[] = {
- { "__gc", chartables_gc },
- { "__tostring", chartables_tostring },
- { NULL, NULL }
-};
-
-static const luaL_reg regex_meta[] = {
- { "exec", ud_exec },
- { "tfind", ud_tfind }, /* old name: match */
- { "find", ud_find },
- { "match", ud_match },
-#if PCRE_MAJOR >= 6
- { "dfa_exec", Lpcre_dfa_exec },
-#endif
- { "__gc", Lpcre_gc },
- { "__tostring", Lpcre_tostring },
- { NULL, NULL }
-};
-
-static const luaL_reg rexlib[] = {
- { "match", match },
- { "find", find },
- { "gmatch", gmatch },
- { "gsub", gsub },
- { "split", split },
- { "new", ud_new },
- { "plainfind", plainfind_func },
- { "flags", Lpcre_get_flags },
- { "version", Lpcre_version },
- { "maketables", Lpcre_maketables },
-#if PCRE_MAJOR >= 4
- { "config", Lpcre_config },
-#endif
- { NULL, NULL }
-};
-
-/* Open the library */
-REX_API int REX_OPENLIB (lua_State *L) {
- if (PCRE_MAJOR > atoi (pcre_version ())) {
- return luaL_error (L, "%s requires at least version %d of PCRE library",
- REX_LIBNAME, (int)PCRE_MAJOR);
- }
- /* create a new function environment to serve as a metatable for methods */
- lua_newtable (L);
- lua_pushvalue (L, -1);
- lua_replace (L, LUA_ENVIRONINDEX);
- lua_pushvalue(L, -1); /* mt.__index = mt */
- lua_setfield(L, -2, "__index");
- luaL_register (L, NULL, regex_meta);
-
- /* register functions */
- luaL_register (L, REX_LIBNAME, rexlib);
- lua_pushliteral (L, REX_VERSION" (for PCRE)");
- lua_setfield (L, -2, "_VERSION");
-
- /* create a table and register it as a metatable for "chartables" userdata */
- lua_pushinteger (L, INDEX_CHARTABLES_META);
- lua_newtable (L);
- lua_pushliteral (L, "access denied");
- lua_setfield (L, -2, "__metatable");
- luaL_register (L, NULL, chartables_meta);
- lua_rawset (L, LUA_ENVIRONINDEX);
-
- /* create a table for connecting "chartables" userdata to "regex" userdata */
- lua_pushinteger (L, INDEX_CHARTABLES_LINK);
- lua_newtable (L);
- lua_pushliteral (L, "k"); /* weak keys */
- lua_setfield (L, -2, "__mode");
- lua_pushvalue (L, -1); /* setmetatable (tb, tb) */
- lua_setmetatable (L, -2);
- lua_rawset (L, LUA_ENVIRONINDEX);
-
- return 1;
-}
-
diff --git a/src/lpcre_f.c b/src/lpcre_f.c
deleted file mode 100755
index c7e93da..0000000
--- a/src/lpcre_f.c
+++ /dev/null
@@ -1,189 +0,0 @@
-/* lpcre.c - PCRE regular expression library */
-/* See Copyright Notice in the file LICENSE */
-
-#include <pcre.h>
-#include "lua.h"
-#include "lauxlib.h"
-#include "common.h"
-
-#define VERSION_PCRE (PCRE_MAJOR*100 + PCRE_MINOR)
-
-static flag_pair pcre_flags[] = {
- { "MAJOR", PCRE_MAJOR },
- { "MINOR", PCRE_MINOR },
-/*---------------------------------------------------------------------------*/
- { "CASELESS", PCRE_CASELESS },
- { "MULTILINE", PCRE_MULTILINE },
- { "DOTALL", PCRE_DOTALL },
- { "EXTENDED", PCRE_EXTENDED },
- { "ANCHORED", PCRE_ANCHORED },
- { "DOLLAR_ENDONLY", PCRE_DOLLAR_ENDONLY },
- { "EXTRA", PCRE_EXTRA },
- { "NOTBOL", PCRE_NOTBOL },
- { "NOTEOL", PCRE_NOTEOL },
- { "UNGREEDY", PCRE_UNGREEDY },
- { "NOTEMPTY", PCRE_NOTEMPTY },
- { "UTF8", PCRE_UTF8 },
-#if VERSION_PCRE >= 400
- { "NO_AUTO_CAPTURE", PCRE_NO_AUTO_CAPTURE },
- { "NO_UTF8_CHECK", PCRE_NO_UTF8_CHECK },
-#endif
-#if VERSION_PCRE >= 500
- { "AUTO_CALLOUT", PCRE_AUTO_CALLOUT },
- { "PARTIAL", PCRE_PARTIAL },
-#endif
-#if VERSION_PCRE >= 600
- { "DFA_SHORTEST", PCRE_DFA_SHORTEST },
- { "DFA_RESTART", PCRE_DFA_RESTART },
- { "FIRSTLINE", PCRE_FIRSTLINE },
-#endif
-#if VERSION_PCRE >= 607
- { "DUPNAMES", PCRE_DUPNAMES },
- { "NEWLINE_CR", PCRE_NEWLINE_CR },
- { "NEWLINE_LF", PCRE_NEWLINE_LF },
- { "NEWLINE_CRLF", PCRE_NEWLINE_CRLF },
-#endif
-#if VERSION_PCRE >= 700
- { "NEWLINE_ANY", PCRE_NEWLINE_ANY },
-#endif
-#if VERSION_PCRE >= 701
- { "NEWLINE_ANYCRLF", PCRE_NEWLINE_ANYCRLF },
-#endif
-#if VERSION_PCRE >= 704
- { "BSR_ANYCRLF", PCRE_BSR_ANYCRLF },
- { "BSR_UNICODE", PCRE_BSR_UNICODE },
-#endif
-#if VERSION_PCRE >= 707
- { "JAVASCRIPT_COMPAT", PCRE_JAVASCRIPT_COMPAT },
-#endif
-/*---------------------------------------------------------------------------*/
- { "INFO_OPTIONS", PCRE_INFO_OPTIONS },
- { "INFO_SIZE", PCRE_INFO_SIZE },
- { "INFO_CAPTURECOUNT", PCRE_INFO_CAPTURECOUNT },
- { "INFO_BACKREFMAX", PCRE_INFO_BACKREFMAX },
-#if VERSION_PCRE >= 400
- { "INFO_FIRSTBYTE", PCRE_INFO_FIRSTBYTE },
-#endif
- { "INFO_FIRSTCHAR", PCRE_INFO_FIRSTCHAR },
- { "INFO_FIRSTTABLE", PCRE_INFO_FIRSTTABLE },
- { "INFO_LASTLITERAL", PCRE_INFO_LASTLITERAL },
-#if VERSION_PCRE >= 400
- { "INFO_NAMEENTRYSIZE", PCRE_INFO_NAMEENTRYSIZE },
- { "INFO_NAMECOUNT", PCRE_INFO_NAMECOUNT },
- { "INFO_NAMETABLE", PCRE_INFO_NAMETABLE },
- { "INFO_STUDYSIZE", PCRE_INFO_STUDYSIZE },
-#endif
-#if VERSION_PCRE >= 500
- { "INFO_DEFAULT_TABLES", PCRE_INFO_DEFAULT_TABLES },
-#endif
-#ifdef PCRE_INFO_OKPARTIAL
- { "INFO_OKPARTIAL", PCRE_INFO_OKPARTIAL },
-#endif
-#ifdef PCRE_INFO_JCHANGED
- { "INFO_JCHANGED", PCRE_INFO_JCHANGED },
-#endif
-#ifdef PCRE_INFO_HASCRORLF
- { "INFO_HASCRORLF", PCRE_INFO_HASCRORLF },
-#endif
-/*---------------------------------------------------------------------------*/
-#if VERSION_PCRE >= 400
- { "EXTRA_STUDY_DATA", PCRE_EXTRA_STUDY_DATA },
- { "EXTRA_MATCH_LIMIT", PCRE_EXTRA_MATCH_LIMIT },
- { "EXTRA_CALLOUT_DATA", PCRE_EXTRA_CALLOUT_DATA },
-#endif
-#if VERSION_PCRE >= 500
- { "EXTRA_TABLES", PCRE_EXTRA_TABLES },
-#endif
-#ifdef PCRE_EXTRA_MATCH_LIMIT_RECURSION
- { "EXTRA_MATCH_LIMIT_RECURSION", PCRE_EXTRA_MATCH_LIMIT_RECURSION },
-#endif
-/*---------------------------------------------------------------------------*/
- { NULL, 0 }
-};
-
-flag_pair pcre_error_flags[] = {
- { "ERROR_NOMATCH", PCRE_ERROR_NOMATCH },
- { "ERROR_NULL", PCRE_ERROR_NULL },
- { "ERROR_BADOPTION", PCRE_ERROR_BADOPTION },
- { "ERROR_BADMAGIC", PCRE_ERROR_BADMAGIC },
-#if VERSION_PCRE >= 700
- { "ERROR_UNKNOWN_OPCODE", PCRE_ERROR_UNKNOWN_OPCODE },
-#endif
- { "ERROR_UNKNOWN_NODE", PCRE_ERROR_UNKNOWN_NODE },
- { "ERROR_NOMEMORY", PCRE_ERROR_NOMEMORY },
- { "ERROR_NOSUBSTRING", PCRE_ERROR_NOSUBSTRING },
-#if VERSION_PCRE >= 400
- { "ERROR_MATCHLIMIT", PCRE_ERROR_MATCHLIMIT },
- { "ERROR_CALLOUT", PCRE_ERROR_CALLOUT },
- { "ERROR_BADUTF8", PCRE_ERROR_BADUTF8 },
- { "ERROR_BADUTF8_OFFSET", PCRE_ERROR_BADUTF8_OFFSET },
-#endif
-#if VERSION_PCRE >= 500
- { "ERROR_PARTIAL", PCRE_ERROR_PARTIAL },
- { "ERROR_BADPARTIAL", PCRE_ERROR_BADPARTIAL },
- { "ERROR_INTERNAL", PCRE_ERROR_INTERNAL },
- { "ERROR_BADCOUNT", PCRE_ERROR_BADCOUNT },
-#endif
-#if VERSION_PCRE >= 600
- { "ERROR_DFA_UITEM", PCRE_ERROR_DFA_UITEM },
- { "ERROR_DFA_UCOND", PCRE_ERROR_DFA_UCOND },
- { "ERROR_DFA_UMLIMIT", PCRE_ERROR_DFA_UMLIMIT },
- { "ERROR_DFA_WSSIZE", PCRE_ERROR_DFA_WSSIZE },
- { "ERROR_DFA_RECURSE", PCRE_ERROR_DFA_RECURSE },
-#endif
-#if VERSION_PCRE >= 607
- { "ERROR_RECURSIONLIMIT", PCRE_ERROR_RECURSIONLIMIT },
-#endif
-#if VERSION_PCRE >= 700
- { "ERROR_BADNEWLINE", PCRE_ERROR_BADNEWLINE },
-#endif
-#ifdef PCRE_ERROR_NULLWSLIMIT
- { "ERROR_NULLWSLIMIT", PCRE_ERROR_NULLWSLIMIT },
-#endif
-/*---------------------------------------------------------------------------*/
- { NULL, 0 }
-};
-
-#if VERSION_PCRE >= 400
-static flag_pair pcre_config_flags[] = {
- { "CONFIG_UTF8", PCRE_CONFIG_UTF8 },
- { "CONFIG_NEWLINE", PCRE_CONFIG_NEWLINE },
- { "CONFIG_LINK_SIZE", PCRE_CONFIG_LINK_SIZE },
- { "CONFIG_POSIX_MALLOC_THRESHOLD", PCRE_CONFIG_POSIX_MALLOC_THRESHOLD },
- { "CONFIG_MATCH_LIMIT", PCRE_CONFIG_MATCH_LIMIT },
- { "CONFIG_STACKRECURSE", PCRE_CONFIG_STACKRECURSE },
-#if VERSION_PCRE >= 500
- { "CONFIG_UNICODE_PROPERTIES", PCRE_CONFIG_UNICODE_PROPERTIES },
-#endif
-#if VERSION_PCRE >= 650
- { "CONFIG_MATCH_LIMIT_RECURSION", PCRE_CONFIG_MATCH_LIMIT_RECURSION },
-#endif
-#if VERSION_PCRE >= 704
- { "CONFIG_BSR", PCRE_CONFIG_BSR },
-#endif
-/*---------------------------------------------------------------------------*/
- { NULL, 0 }
-};
-
-int Lpcre_config (lua_State *L) {
- int val;
- flag_pair *fp;
- if (lua_istable (L, 1))
- lua_settop (L, 1);
- else
- lua_newtable (L);
- for (fp = pcre_config_flags; fp->key; ++fp) {
- if (0 == pcre_config (fp->val, &val)) {
- lua_pushinteger (L, val);
- lua_setfield (L, -2, fp->key);
- }
- }
- return 1;
-}
-#endif /* #if VERSION_PCRE >= 400 */
-
-int Lpcre_get_flags (lua_State *L) {
- const flag_pair* fps[] = { pcre_flags, pcre_error_flags, NULL };
- return get_flags (L, fps);
-}
-
diff --git a/src/lposix.c b/src/lposix.c
deleted file mode 100755
index a0fa152..0000000
--- a/src/lposix.c
+++ /dev/null
@@ -1,295 +0,0 @@
-/* lposix.c - Lua binding of POSIX regular expressions library */
-/* See Copyright Notice in the file LICENSE */
-
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include "lua.h"
-#include "lauxlib.h"
-#include "common.h"
-
-#ifndef REX_POSIX_INCLUDE
-# include <regex.h>
-#else
-# include REX_POSIX_INCLUDE
-#endif
-
-/* These 2 settings may be redefined from the command-line or the makefile.
- * They should be kept in sync between themselves and with the target name.
- */
-#ifndef REX_LIBNAME
-# define REX_LIBNAME "rex_posix"
-#endif
-#ifndef REX_OPENLIB
-# define REX_OPENLIB luaopen_rex_posix
-#endif
-
-#define REX_TYPENAME REX_LIBNAME"_regex"
-
-/* Test if regex.h corresponds to the extended POSIX library, i.e. H.Spencer's.
- This test may not work as intended if regex.h introduced REG_BASIC, etc.
- via enum rather than #define.
- If that's the case, add -DREX_POSIX_EXT in the makefile/command line.
-*/
-#ifndef REX_POSIX_EXT
-# if defined(REG_BASIC) && defined(REG_STARTEND)
-# define REX_POSIX_EXT
-# endif
-#endif
-
-#define ALG_CFLAGS_DFLT REG_EXTENDED
-#ifdef REX_POSIX_EXT
-# define ALG_EFLAGS_DFLT REG_STARTEND
-#else
-# define ALG_EFLAGS_DFLT 0
-#endif
-
-#define ALG_NOMATCH REG_NOMATCH
-#define ALG_ISMATCH(res) ((res) == 0)
-#define ALG_SUBBEG(ud,n) ud->match[n].rm_so
-#define ALG_SUBEND(ud,n) ud->match[n].rm_eo
-#define ALG_SUBLEN(ud,n) (ALG_SUBEND(ud,n) - ALG_SUBBEG(ud,n))
-#define ALG_SUBVALID(ud,n) (ALG_SUBBEG(ud,n) >= 0)
-#ifdef REX_NSUB_BASE1
-# define ALG_NSUB(ud) ((int)ud->r.re_nsub - 1)
-#else
-# define ALG_NSUB(ud) ((int)ud->r.re_nsub)
-#endif
-
-#define ALG_PUSHSUB(L,ud,text,n) \
- lua_pushlstring (L, (text) + ALG_SUBBEG(ud,n), ALG_SUBLEN(ud,n))
-
-#define ALG_PUSHSUB_OR_FALSE(L,ud,text,n) \
- (ALG_SUBVALID(ud,n) ? ALG_PUSHSUB (L,ud,text,n) : lua_pushboolean (L,0))
-
-#define ALG_PUSHSTART(L,ud,offs,n) lua_pushinteger(L, (offs) + ALG_SUBBEG(ud,n) + 1)
-#define ALG_PUSHEND(L,ud,offs,n) lua_pushinteger(L, (offs) + ALG_SUBEND(ud,n))
-#define ALG_PUSHOFFSETS(L,ud,offs,n) \
- (ALG_PUSHSTART(L,ud,offs,n), ALG_PUSHEND(L,ud,offs,n))
-
-#define ALG_BASE(st) (st)
-#define ALG_GETCFLAGS(L,pos) luaL_optint(L, pos, ALG_CFLAGS_DFLT)
-
-typedef struct {
- regex_t r;
- regmatch_t * match;
- int freed;
-} TPosix;
-
-#define TUserdata TPosix
-
-#include "algo.h"
-
-/* Functions
- ******************************************************************************
- */
-
-static int generate_error (lua_State *L, const TPosix *ud, int errcode) {
- char errbuf[80];
- regerror (errcode, &ud->r, errbuf, sizeof (errbuf));
- return luaL_error (L, "%s", errbuf);
-}
-
-static int compile_regex (lua_State *L, const TArgComp *argC, TPosix **pud) {
- int res;
- TPosix *ud;
-
- ud = (TPosix *)lua_newuserdata (L, sizeof (TPosix));
- memset (ud, 0, sizeof (TPosix)); /* initialize all members to 0 */
-
-#ifdef REX_POSIX_EXT
- if (argC->cflags & REG_PEND)
- ud->r.re_endp = argC->pattern + argC->patlen;
-#endif
-
- res = regcomp (&ud->r, argC->pattern, argC->cflags);
- if (res != 0)
- return generate_error (L, ud, res);
-
- if (argC->cflags & REG_NOSUB)
- ud->r.re_nsub = 0;
- ud->match = (regmatch_t *) Lmalloc (L, (ALG_NSUB(ud) + 1) * sizeof (regmatch_t));
- lua_pushvalue (L, LUA_ENVIRONINDEX);
- lua_setmetatable (L, -2);
-
- if (pud) *pud = ud;
- return 1;
-}
-
-#ifdef REX_POSIX_EXT
-static void CheckStartEnd (TArgExec *argE, TPosix *ud) {
- if (argE->eflags & REG_STARTEND) {
- ud->match[0].rm_so = argE->startoffset;
- ud->match[0].rm_eo = argE->textlen;
- argE->startoffset = 0;
- }
- else
- argE->text += argE->startoffset;
-}
-#endif
-
-static int gmatch_exec (TUserdata *ud, TArgExec *argE) {
- if (argE->startoffset > 0)
- argE->eflags |= REG_NOTBOL;
-
-#ifdef REX_POSIX_EXT
- if (argE->eflags & REG_STARTEND) {
- ALG_SUBBEG(ud,0) = 0;
- ALG_SUBEND(ud,0) = argE->textlen - argE->startoffset;
- }
-#endif
-
- argE->text += argE->startoffset;
- return regexec (&ud->r, argE->text, ALG_NSUB(ud) + 1, ud->match, argE->eflags);
-}
-
-static void gmatch_pushsubject (lua_State *L, TArgExec *argE) {
-#ifdef REX_POSIX_EXT
- if (argE->eflags & REG_STARTEND)
- lua_pushlstring (L, argE->text, argE->textlen);
- else
- lua_pushlstring (L, argE->text, strlen (argE->text));
-#else
- lua_pushlstring (L, argE->text, strlen (argE->text));
-#endif
-}
-
-static int findmatch_exec (TPosix *ud, TArgExec *argE) {
-#ifdef REX_POSIX_EXT
- CheckStartEnd (argE, ud);
-#else
- argE->text += argE->startoffset;
-#endif
- return regexec (&ud->r, argE->text, ALG_NSUB(ud) + 1, ud->match, argE->eflags);
-}
-
-static int gsub_exec (TPosix *ud, TArgExec *argE, int st) {
-#ifdef REX_POSIX_EXT
- if(argE->eflags & REG_STARTEND) {
- ALG_SUBBEG(ud,0) = 0;
- ALG_SUBEND(ud,0) = argE->textlen - st;
- }
-#endif
- if (st > 0)
- argE->eflags |= REG_NOTBOL;
- return regexec (&ud->r, argE->text+st, ALG_NSUB(ud)+1, ud->match, argE->eflags);
-}
-
-static int split_exec (TPosix *ud, TArgExec *argE, int offset) {
-#ifdef REX_POSIX_EXT
- if (argE->eflags & REG_STARTEND) {
- ALG_SUBBEG(ud,0) = 0;
- ALG_SUBEND(ud,0) = argE->textlen - offset;
- }
-#endif
- if (offset > 0)
- argE->eflags |= REG_NOTBOL;
-
- return regexec (&ud->r, argE->text + offset, ALG_NSUB(ud) + 1, ud->match, argE->eflags);
-}
-
-static int Posix_gc (lua_State *L) {
- TPosix *ud = check_ud (L);
- if (ud->freed == 0) { /* precaution against "manual" __gc calling */
- ud->freed = 1;
- regfree (&ud->r);
- if (ud->match)
- free (ud->match);
- }
- return 0;
-}
-
-static int Posix_tostring (lua_State *L) {
- TPosix *ud = check_ud (L);
- if (ud->freed == 0)
- lua_pushfstring (L, "%s (%p)", REX_TYPENAME, (void*)ud);
- else
- lua_pushfstring (L, "%s (deleted)", REX_TYPENAME);
- return 1;
-}
-
-static flag_pair posix_flags[] =
-{
-#ifdef REX_POSIX_EXT
- { "BASIC", REG_BASIC },
- { "NOSPEC", REG_NOSPEC },
- { "PEND", REG_PEND },
- { "STARTEND", REG_STARTEND },
-#endif
- { "EXTENDED", REG_EXTENDED },
- { "ICASE", REG_ICASE },
- { "NOSUB", REG_NOSUB },
- { "NEWLINE", REG_NEWLINE },
- { "NOTBOL", REG_NOTBOL },
- { "NOTEOL", REG_NOTEOL },
-/*---------------------------------------------------------------------------*/
- { NULL, 0 }
-};
-
-static flag_pair posix_error_flags[] = {
- { "NOMATCH", REG_NOMATCH },
- { "BADPAT", REG_BADPAT },
- { "ECOLLATE", REG_ECOLLATE },
- { "ECTYPE", REG_ECTYPE },
- { "EESCAPE", REG_EESCAPE },
- { "ESUBREG", REG_ESUBREG },
- { "EBRACK", REG_EBRACK },
- { "EPAREN", REG_EPAREN },
- { "EBRACE", REG_EBRACE },
- { "BADBR", REG_BADBR },
- { "ERANGE", REG_ERANGE },
- { "ESPACE", REG_ESPACE },
- { "BADRPT", REG_BADRPT },
-#ifdef REX_POSIX_EXT
- { "EMPTY", REG_EMPTY },
- { "ASSERT", REG_ASSERT },
- { "INVARG", REG_INVARG },
-#endif
-/*---------------------------------------------------------------------------*/
- { NULL, 0 }
-};
-
-static int Posix_get_flags (lua_State *L) {
- const flag_pair* fps[] = { posix_flags, posix_error_flags, NULL };
- return get_flags (L, fps);
-}
-
-static const luaL_reg posixmeta[] = {
- { "exec", ud_exec },
- { "tfind", ud_tfind }, /* old match */
- { "find", ud_find },
- { "match", ud_match },
- { "__gc", Posix_gc },
- { "__tostring", Posix_tostring },
- { NULL, NULL}
-};
-
-static const luaL_reg rexlib[] = {
- { "match", match },
- { "find", find },
- { "gmatch", gmatch },
- { "gsub", gsub },
- { "split", split },
- { "new", ud_new },
- { "flags", Posix_get_flags },
- { "plainfind", plainfind_func },
- { NULL, NULL }
-};
-
-/* Open the library */
-REX_API int REX_OPENLIB (lua_State *L)
-{
- /* create a new function environment to serve as a metatable for methods */
- lua_newtable (L);
- lua_pushvalue (L, -1);
- lua_replace (L, LUA_ENVIRONINDEX);
- lua_pushvalue(L, -1); /* mt.__index = mt */
- lua_setfield(L, -2, "__index");
- luaL_register (L, NULL, posixmeta);
-
- /* register functions */
- luaL_register (L, REX_LIBNAME, rexlib);
- lua_pushliteral (L, REX_VERSION" (for POSIX regexes)");
- lua_setfield (L, -2, "_VERSION");
- return 1;
-}
diff --git a/src/ltre.c b/src/ltre.c
deleted file mode 100755
index dd9846f..0000000
--- a/src/ltre.c
+++ /dev/null
@@ -1,358 +0,0 @@
-/* ltre.c - Lua binding of TRE regular expressions library */
-/* See Copyright Notice in the file LICENSE */
-
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include "lua.h"
-#include "lauxlib.h"
-#include "common.h"
-
-#include <tre/regex.h>
-
-/* These 2 settings may be redefined from the command-line or the makefile.
- * They should be kept in sync between themselves and with the target name.
- */
-#ifndef REX_LIBNAME
-# define REX_LIBNAME "rex_tre"
-#endif
-#ifndef REX_OPENLIB
-# define REX_OPENLIB luaopen_rex_tre
-#endif
-
-#define REX_TYPENAME REX_LIBNAME"_regex"
-
-#define ALG_CFLAGS_DFLT REG_EXTENDED
-#define ALG_EFLAGS_DFLT 0
-
-#define ALG_NOMATCH REG_NOMATCH
-#define ALG_ISMATCH(res) ((res) == 0)
-#define ALG_SUBBEG(ud,n) ud->match[n].rm_so
-#define ALG_SUBEND(ud,n) ud->match[n].rm_eo
-#define ALG_SUBLEN(ud,n) (ALG_SUBEND(ud,n) - ALG_SUBBEG(ud,n))
-#define ALG_SUBVALID(ud,n) (ALG_SUBBEG(ud,n) >= 0)
-#define ALG_NSUB(ud) ((int)ud->r.re_nsub)
-
-#define ALG_PUSHSUB(L,ud,text,n) \
- lua_pushlstring (L, (text) + ALG_SUBBEG(ud,n), ALG_SUBLEN(ud,n))
-
-#define ALG_PUSHSUB_OR_FALSE(L,ud,text,n) \
- (ALG_SUBVALID(ud,n) ? ALG_PUSHSUB (L,ud,text,n) : lua_pushboolean (L,0))
-
-#define ALG_PUSHSTART(L,ud,offs,n) lua_pushinteger(L, (offs) + ALG_SUBBEG(ud,n) + 1)
-#define ALG_PUSHEND(L,ud,offs,n) lua_pushinteger(L, (offs) + ALG_SUBEND(ud,n))
-#define ALG_PUSHOFFSETS(L,ud,offs,n) \
- (ALG_PUSHSTART(L,ud,offs,n), ALG_PUSHEND(L,ud,offs,n))
-
-#define ALG_BASE(st) (st)
-#define ALG_GETCFLAGS(L,pos) luaL_optint(L, pos, ALG_CFLAGS_DFLT)
-
-typedef struct {
- regex_t r;
- regmatch_t * match;
- int freed;
-} TPosix;
-
-#define TUserdata TPosix
-
-#include "algo.h"
-
-/* Functions
- ******************************************************************************
- */
-
-static void checkarg_regaparams (lua_State *L, int stackpos, regaparams_t *argP) {
- if (lua_type (L, stackpos) != LUA_TTABLE) /* allow for userdata? */
- luaL_argerror (L, stackpos, "table expected");
- lua_pushvalue (L, stackpos);
- argP->cost_ins = get_int_field (L, "cost_ins");
- argP->cost_del = get_int_field (L, "cost_del");
- argP->cost_subst = get_int_field (L, "cost_subst");
- argP->max_cost = get_int_field (L, "max_cost");
- argP->max_ins = get_int_field (L, "max_ins");
- argP->max_del = get_int_field (L, "max_del");
- argP->max_subst = get_int_field (L, "max_subst");
- argP->max_err = get_int_field (L, "max_err");
- lua_pop (L, 1);
-}
-
-/* method r:atfind (s, params, [st], [ef]) */
-/* method r:aexec (s, params, [st], [ef]) */
-static void checkarg_atfind (lua_State *L, TArgExec *argE, TPosix **ud,
- regaparams_t *argP) {
- *ud = check_ud (L);
- argE->text = luaL_checklstring (L, 2, &argE->textlen);
- checkarg_regaparams (L, 3, argP);
- argE->startoffset = get_startoffset (L, 4, argE->textlen);
- argE->eflags = luaL_optint (L, 5, ALG_EFLAGS_DFLT);
-}
-
-static int generate_error (lua_State *L, const TPosix *ud, int errcode) {
- char errbuf[80];
- regerror (errcode, &ud->r, errbuf, sizeof (errbuf));
- return luaL_error (L, "%s", errbuf);
-}
-
-static int compile_regex (lua_State *L, const TArgComp *argC, TPosix **pud) {
- int res;
- TPosix *ud;
-
- ud = (TPosix *)lua_newuserdata (L, sizeof (TPosix));
- memset (ud, 0, sizeof (TPosix)); /* initialize all members to 0 */
-
- res = regncomp (&ud->r, argC->pattern, argC->patlen, argC->cflags);
- if (res != 0)
- return generate_error (L, ud, res);
-
- if (argC->cflags & REG_NOSUB)
- ud->r.re_nsub = 0;
- ud->match = (regmatch_t *) Lmalloc (L, (ALG_NSUB(ud) + 1) * sizeof (regmatch_t));
- lua_pushvalue (L, LUA_ENVIRONINDEX);
- lua_setmetatable (L, -2);
-
- if (pud) *pud = ud;
- return 1;
-}
-
-static int generic_atfind (lua_State *L, int tfind) {
- int res;
- TArgExec argE;
- TPosix *ud;
- regaparams_t argP;
- regamatch_t res_match;
-
- checkarg_atfind (L, &argE, &ud, &argP);
- if (argE.startoffset > (int)argE.textlen)
- return lua_pushnil(L), 1;
-
- argE.text += argE.startoffset;
- res_match.nmatch = ALG_NSUB(ud) + 1;
- res_match.pmatch = ud->match;
-
- /* execute the search */
- res = reganexec (&ud->r, argE.text, argE.textlen - argE.startoffset,
- &res_match, argP, argE.eflags);
- if (ALG_ISMATCH (res)) {
- ALG_PUSHOFFSETS (L, ud, argE.startoffset, 0);
- if (tfind)
- push_substring_table (L, ud, argE.text);
- else
- push_offset_table (L, ud, argE.startoffset);
- /* set values in the dictionary part of the table */
- set_int_field (L, "cost", res_match.cost);
- set_int_field (L, "num_ins", res_match.num_ins);
- set_int_field (L, "num_del", res_match.num_del);
- set_int_field (L, "num_subst", res_match.num_subst);
- return 3;
- }
- else if (res == ALG_NOMATCH)
- return lua_pushnil (L), 1;
- else
- return generate_error (L, ud, res);
-}
-
-static int Ltre_atfind (lua_State *L) {
- return generic_atfind (L, 1);
-}
-
-static int Ltre_aexec (lua_State *L) {
- return generic_atfind (L, 0);
-}
-
-static int gmatch_exec (TUserdata *ud, TArgExec *argE) {
- if (argE->startoffset > 0)
- argE->eflags |= REG_NOTBOL;
- argE->text += argE->startoffset;
- return regnexec (&ud->r, argE->text, argE->textlen - argE->startoffset,
- ALG_NSUB(ud) + 1, ud->match, argE->eflags);
-}
-
-static void gmatch_pushsubject (lua_State *L, TArgExec *argE) {
- lua_pushlstring (L, argE->text, argE->textlen);
-}
-
-static int findmatch_exec (TPosix *ud, TArgExec *argE) {
- argE->text += argE->startoffset;
- return regnexec (&ud->r, argE->text, argE->textlen - argE->startoffset,
- ALG_NSUB(ud) + 1, ud->match, argE->eflags);
-}
-
-static int gsub_exec (TPosix *ud, TArgExec *argE, int st) {
- if (st > 0)
- argE->eflags |= REG_NOTBOL;
- return regnexec (&ud->r, argE->text+st, argE->textlen-st, ALG_NSUB(ud)+1,
- ud->match, argE->eflags);
-}
-
-static int split_exec (TPosix *ud, TArgExec *argE, int offset) {
- if (offset > 0)
- argE->eflags |= REG_NOTBOL;
- return regnexec (&ud->r, argE->text + offset, argE->textlen - offset,
- ALG_NSUB(ud) + 1, ud->match, argE->eflags);
-}
-
-static int Ltre_have_backrefs (lua_State *L) {
- TPosix *ud = check_ud (L);
- lua_pushboolean (L, tre_have_backrefs (&ud->r));
- return 1;
-}
-
-static int Ltre_have_approx (lua_State *L) {
- TPosix *ud = check_ud (L);
- lua_pushboolean (L, tre_have_approx (&ud->r));
- return 1;
-}
-
-static int Ltre_gc (lua_State *L) {
- TPosix *ud = check_ud (L);
- if (ud->freed == 0) { /* precaution against "manual" __gc calling */
- ud->freed = 1;
- regfree (&ud->r);
- if (ud->match)
- free (ud->match);
- }
- return 0;
-}
-
-static int Ltre_tostring (lua_State *L) {
- TPosix *ud = check_ud (L);
- if (ud->freed == 0)
- lua_pushfstring (L, "%s (%p)", REX_TYPENAME, (void*)ud);
- else
- lua_pushfstring (L, "%s (deleted)", REX_TYPENAME);
- return 1;
-}
-
-static flag_pair tre_flags[] =
-{
- { "BASIC", REG_BASIC },
- { "NOSPEC", REG_NOSPEC },
- { "EXTENDED", REG_EXTENDED },
- { "ICASE", REG_ICASE },
- { "NOSUB", REG_NOSUB },
- { "NEWLINE", REG_NEWLINE },
- { "NOTBOL", REG_NOTBOL },
- { "NOTEOL", REG_NOTEOL },
- /* TRE-specific flags */
- { "LITERAL", REG_LITERAL },
- { "RIGHT_ASSOC", REG_RIGHT_ASSOC },
- { "UNGREEDY", REG_UNGREEDY },
- { "APPROX_MATCHER", REG_APPROX_MATCHER },
- { "BACKTRACKING_MATCHER", REG_BACKTRACKING_MATCHER },
-/*---------------------------------------------------------------------------*/
- { NULL, 0 }
-};
-
-static flag_pair tre_error_flags[] = {
- { "OK", REG_OK }, /* TRE-specific */
- { "NOMATCH", REG_NOMATCH },
- { "BADPAT", REG_BADPAT },
- { "ECOLLATE", REG_ECOLLATE },
- { "ECTYPE", REG_ECTYPE },
- { "EESCAPE", REG_EESCAPE },
- { "ESUBREG", REG_ESUBREG },
- { "EBRACK", REG_EBRACK },
- { "EPAREN", REG_EPAREN },
- { "EBRACE", REG_EBRACE },
- { "BADBR", REG_BADBR },
- { "ERANGE", REG_ERANGE },
- { "ESPACE", REG_ESPACE },
- { "BADRPT", REG_BADRPT },
-/*---------------------------------------------------------------------------*/
- { NULL, 0 }
-};
-
-/* config. flags with integer value */
-static flag_pair tre_config_flags_int[] = {
- { "CONFIG_APPROX", TRE_CONFIG_APPROX },
- { "CONFIG_WCHAR", TRE_CONFIG_WCHAR },
- { "CONFIG_MULTIBYTE", TRE_CONFIG_MULTIBYTE },
- { "CONFIG_SYSTEM_ABI", TRE_CONFIG_SYSTEM_ABI },
- { NULL, 0 }
-};
-
-/* config. flags with string value */
-static flag_pair tre_config_flags_str[] = {
- { "CONFIG_VERSION", TRE_CONFIG_VERSION },
- { NULL, 0 }
-};
-
-static int Ltre_get_flags (lua_State *L) {
- const flag_pair* fps[] = { tre_flags, tre_error_flags, NULL };
- return get_flags (L, fps);
-}
-
-static int Ltre_config (lua_State *L) {
- int intval;
- const char *strval;
- flag_pair *fp;
- if (lua_istable (L, 1))
- lua_settop (L, 1);
- else
- lua_newtable (L);
- for (fp = tre_config_flags_int; fp->key; ++fp) {
- if (0 == tre_config (fp->val, &intval)) {
- lua_pushinteger (L, intval);
- lua_setfield (L, -2, fp->key);
- }
- }
- for (fp = tre_config_flags_str; fp->key; ++fp) {
- if (0 == tre_config (fp->val, &strval)) {
- lua_pushstring (L, strval);
- lua_setfield (L, -2, fp->key);
- }
- }
- return 1;
-}
-
-static int Ltre_version (lua_State *L) {
- lua_pushstring (L, tre_version ());
- return 1;
-}
-
-static const luaL_reg posixmeta[] = {
- { "exec", ud_exec },
- { "tfind", ud_tfind },
- { "find", ud_find },
- { "match", ud_match },
- { "aexec", Ltre_aexec },
- { "atfind", Ltre_atfind },
- { "have_backrefs", Ltre_have_backrefs },
- { "have_approx", Ltre_have_approx },
- { "__gc", Ltre_gc },
- { "__tostring", Ltre_tostring },
- { NULL, NULL}
-};
-
-static const luaL_reg rexlib[] = {
- { "match", match },
- { "find", find },
- { "gmatch", gmatch },
- { "gsub", gsub },
- { "split", split },
- { "new", ud_new },
- { "flags", Ltre_get_flags },
- { "plainfind", plainfind_func },
- { "config", Ltre_config },
- { "version", Ltre_version },
- { NULL, NULL }
-};
-
-/* Open the library */
-REX_API int REX_OPENLIB (lua_State *L)
-{
- /* create a new function environment to serve as a metatable for methods */
- lua_newtable (L);
- lua_pushvalue (L, -1);
- lua_replace (L, LUA_ENVIRONINDEX);
- lua_pushvalue(L, -1); /* mt.__index = mt */
- lua_setfield(L, -2, "__index");
- luaL_register (L, NULL, posixmeta);
-
- /* register functions */
- luaL_register (L, REX_LIBNAME, rexlib);
- lua_pushliteral (L, REX_VERSION" (for TRE regexes)");
- lua_setfield (L, -2, "_VERSION");
- return 1;
-}
-
diff --git a/src/rex_pcre.mak b/src/rex_pcre.mak
deleted file mode 100755
index c03fa33..0000000
--- a/src/rex_pcre.mak
+++ /dev/null
@@ -1,38 +0,0 @@
-# makefile for rex_pcre library
-
-include defaults.mak
-
-# === USER SETTINGS ===
-# ===========================================================================
-
-# These are default values.
-INC =
-LIB = -lpcre
-
-# If the default settings don't work for your system,
-# try to uncomment and edit the settings below.
-#INC =
-#LIB = -lpcre
-
-# Target name
-TRG = rex_pcre
-
-# ===========================================================================
-# === END OF USER SETTINGS ===
-
-OBJ = lpcre.o lpcre_f.o common.o
-
-include common.mak
-
-# static PCRE regexp library binding
-ar_pcre: $(TRG_AR)
-
-# dynamic PCRE regexp library binding
-so_pcre: $(TRG_SO)
-
-# Dependencies
-lpcre.o: lpcre.c common.h algo.h
-lpcre_f.o: lpcre_f.c common.h
-common.o: common.c common.h
-
-# (End of Makefile)
diff --git a/src/rex_posix.mak b/src/rex_posix.mak
deleted file mode 100755
index 1930c99..0000000
--- a/src/rex_posix.mak
+++ /dev/null
@@ -1,48 +0,0 @@
-# makefile for rex_posix library
-
-include defaults.mak
-
-# === USER SETTINGS ===
-# ===========================================================================
-
-# These are default values.
-INC =
-LIB =
-
-# If the default settings don't work for your system,
-# try to uncomment and edit the settings below.
-#INC =
-#LIB = -lc
-
-# WARNING:
-# If you want to use a POSIX regex library that is not the system
-# default, make sure you set both the INC and LIB variables correctly,
-# as if a header file and library are used which do not match, you may
-# well get segmentation faults (or worse).
-
-# The following lines work for the rxspencer library, when installed
-# under /usr (note the above warning!)
-#INC = -I/usr/include/rxspencer
-#LIB = -lrxspencer
-
-# Target name
-TRG = rex_posix
-
-# ===========================================================================
-# === END OF USER SETTINGS ===
-
-OBJ = lposix.o common.o
-
-include common.mak
-
-# static POSIX regexp library binding
-ar_posix: $(TRG_AR)
-
-# dynamic POSIX regexp library binding
-so_posix: $(TRG_SO)
-
-# Dependencies
-lposix.o: lposix.c common.h algo.h
-common.o: common.c common.h
-
-# (End of Makefile)
diff --git a/src/rex_tre.mak b/src/rex_tre.mak
deleted file mode 100755
index e7aed80..0000000
--- a/src/rex_tre.mak
+++ /dev/null
@@ -1,42 +0,0 @@
-# makefile for rex_tre library
-
-include defaults.mak
-
-# === USER SETTINGS ===
-# ===========================================================================
-
-# These are default values.
-INC =
-LIB = -ltre
-
-# If the default settings don't work for your system,
-# try to uncomment and edit the settings below.
-#INC = -I/usr/include
-#LIB = -lc
-
-# WARNING:
-# Make sure you set both the INC and LIB variables correctly, as
-# otherwise you risk using a header file and library that do not
-# match, and you may well get segmentation faults (or worse).
-
-# Target name
-TRG = rex_tre
-
-# ===========================================================================
-# === END OF USER SETTINGS ===
-
-OBJ = ltre.o common.o
-
-include common.mak
-
-# static TRE regexp library binding
-ar_tre: $(TRG_AR)
-
-# dynamic TRE regexp library binding
-so_tre: $(TRG_SO)
-
-# Dependencies
-ltre.o: ltre.c common.h algo.h
-common.o: common.c common.h
-
-# (End of Makefile)
diff --git a/src/scite.properties b/src/scite.properties
deleted file mode 100755
index 35287aa..0000000
--- a/src/scite.properties
+++ /dev/null
@@ -1,21 +0,0 @@
-eol.mode=LF
-
-cc=bcc32
-dir_lib=\Progr\lib
-dir_lua=$(dir_lib)\lua\lua_5.1
-dir_pcre=$(dir_lib)\pcre\pcre_7.0
-dir_posix=$(dir_lib)\henry_spencer
-dir_tre=$(dir_lib)
-
-command.compile.lposix.c=cl.bat -A -I$(dir_lua) -I$(dir_posix) -c "$(FileNameExt)"
-
-command.compile.ltre.c=$(cc) -A -I$(dir_lua);$(dir_tre) -c "$(FileNameExt)"
-
-command.compile.*.c=$(cc) -A -I$(dir_lua);$(dir_pcre);$(dir_posix) -c \
- "$(FileNameExt)"
-
-command.compile.*.cpp=$(cc) -A -I$(dir_lua);$(dir_pcre);$(dir_posix) -c \
- "$(FileNameExt)"
-
-command.build.*.c=lrexlib.bat
-command.build.*.h=lrexlib.bat