Update of /cvsroot/monetdb/MonetDB5/src/modules/mal
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv18233/src/modules/mal
Modified Files:
Tag: MonetDB_5-2
pcre.mx
Log Message:
added cotangent and fixed implementation of patindex
Index: pcre.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/modules/mal/pcre.mx,v
retrieving revision 1.49
retrieving revision 1.49.2.1
diff -u -d -r1.49 -r1.49.2.1
--- pcre.mx 16 Aug 2007 07:01:57 -0000 1.49
+++ pcre.mx 14 Dec 2007 07:51:32 -0000 1.49.2.1
@@ -44,6 +44,10 @@
address PCREexec_wrap
comment "match a pattern";
+command index(pat:pcre, s:str) :int
+address PCREindex
+comment "match a pattern, return matched position (or 0 when not found)";
+
command select(pat:str, strs:bat[:any_1,:str]) :bat[:any_1,:str]
address PCREselect
comment "Select tuples based on the pattern";
@@ -56,7 +60,7 @@
address PCREmatch
comment "POSIX pattern matching against a string";
-command patindex(s:str, pat:str):int
+command patindex(pat:str, s:str) :int
address PCREpatindex
comment "Location of the first POSIX pattern matching against a string"
@@ -133,7 +137,8 @@
pcre_export str PCREselect(int *res, str *pattern, int *bid);
pcre_export str PCREuselect(int *res, str *pattern, int *bid);
pcre_export str PCREmatch(bit *ret, str *val, str *pat);
-pcre_export str PCREpatindex(int *ret, str *val, str *pat);
+pcre_export str PCREindex(int *ret, pcre *pat, str *val);
+pcre_export str PCREpatindex(int *ret, str *pat, str *val);
pcre_export str PCREfromstr(str instr, int *l, pcre ** val);
pcre_export str PCREreplace_wrap(str *res, str *or, str *pat, str *repl, str
*flags);
@@ -176,6 +181,15 @@
}
str
+pcre_index_wrap(int *res, pcre * pattern, str s)
+{
+ (void) res;
+ (void) pattern;
+ (void) s;
+ throw(MAL, "pcre_index", "not available as required version of libpcre
was not found by configure.\n");
+}
+
+str
pcre_select(BAT **res, str pattern, BAT *strs)
{
(void) res, (void) pattern;
@@ -226,23 +240,26 @@
{
}
-str
-pcre_match(bit *ret, str val, str pat)
+int
+pcre_match_with_flags(bit *ret, str val, str pat, str flags)
{
(void) ret;
(void) val;
(void) pat;
- throw(MAL, "pcre_match", "not available as required version of libpcre
was not found by configure.\n");
+ (void)flags;
+ GDKerror("pcre_match_with_flags() not available as required version of
libpcre was not found by configure.\n");
+ return GDK_FAIL;
}
str
-pcre_patindex(int *ret, str val, str pat)
+pcre_match(bit *ret, str val, str pat)
{
(void) ret;
(void) val;
(void) pat;
- throw(MAL, "pcre_patindexmatch", "not available as required version of
libpcre was not found by configure.\n");
+ throw(MAL, "pcre_match", "not available as required version of libpcre
was not found by configure.\n");
}
+
#else
#include <pcre.h>
@@ -296,6 +313,18 @@
}
str
+pcre_index(int *res, pcre * pattern, str s)
+{
+ int v[2];
+
+ v[0] = v[1] = *res = 0;
+ if (pcre_exec(pattern, NULL, s, strlen(s), 0, 0, v, 2) >= 0) {
+ *res = v[1];
+ }
+ return MAL_SUCCEED;
+}
+
+str
pcre_select(BAT **res, str pattern, BAT *strs)
{
const char err[BUFSIZ], *err_p = err;
@@ -639,11 +668,6 @@
return msg;
}
-str
-pcre_patindex(int *ret, str val, str pat)
-{
- return pcre_match_with_flags(ret, val, pat, "");
-}
#endif
static int
@@ -813,6 +837,37 @@
}
return 0;
}
+
+/* change SQL PATINDEX pattern into PCRE pattern */
+int
+pat2pcre(str *r, str pat)
+{
+ int len = (int) strlen(pat);
+ char *ppat = GDKmalloc(len*2+3 /* 3 = "^'the translated regexp'$0" */);
+ int start = 0;
+
+ *r = ppat;
+ while (*pat) {
+ int c = *pat++;
+
+ if (strchr( ".+*()\\", c) != NULL) {
+ *ppat++ = '\\';
+ *ppat++ = c;
+ } else if (c == '%') {
+ if (start && *pat) {
+ *ppat++ = '.';
+ *ppat++ = '*';
+ }
+ start++;
+ } else if (c == '_') {
+ *ppat++ = '.';
+ } else {
+ *ppat++ = c;
+ }
+ }
+ *ppat = 0;
+ return GDK_SUCCEED;
+}
@+ Wrapping
@c
#include "mal.h"
@@ -928,9 +983,26 @@
}
str
-PCREpatindex(int *ret, str *val, str *pat)
+PCREindex(int *res, pcre * pattern, str *s)
{
- return pcre_patindex(ret, *val, *pat);
+ return pcre_index(res, m2p(pattern), *s);
+}
+
+
+str
+PCREpatindex(int *ret, str *pat, str *val)
+{
+ pcre *re;
+ char *ppat, *msg;
+
+ if (pat2pcre(&ppat, *pat) <0)
+ throw(MAL, "pcre.sql2pcre", "Pattern convert failed");
+ if ((msg = pcre_compile_wrap(&re, ppat)) != NULL)
+ return msg;
+ GDKfree(ppat);
+ msg = PCREindex(ret, re, val);
+ GDKfree(re);
+ return msg;
}
str
-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Monetdb-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-checkins