Update of /cvsroot/monetdb/MonetDB4/src/modules/plain
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv18087/src/modules/plain
Modified Files:
Tag: MonetDB_4-20
mmath.mx pcre.mx
Log Message:
added missing cotangent and patindex
Index: mmath.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB4/src/modules/plain/mmath.mx,v
retrieving revision 1.3
retrieving revision 1.3.6.1
diff -u -d -r1.3 -r1.3.6.1
--- mmath.mx 20 Feb 2007 11:32:13 -0000 1.3
+++ mmath.mx 14 Dec 2007 07:48:22 -0000 1.3.6.1
@@ -14,10 +14,9 @@
@' Portions created by CWI are Copyright (C) 1997-2007 CWI.
@' All Rights Reserved.
-@' Alex van Ballegooij <[EMAIL PROTECTED]>
-
@f mmath
[EMAIL PROTECTED] N.J. Nes
[EMAIL PROTECTED] N.J. Nes, Alex van Ballegooij
+
@d 07/01/1996
@t The math module
@@ -59,6 +58,9 @@
.COMMAND tan(dbl) : dbl = math_unary_TAN;
"The tan(x) function returns the tangent of x,
where x is given in radians"
+ .COMMAND cot(dbl) : dbl = math_unary_COT;
+"The cot(x) function returns the cotangent of x,
+where x is given in radians"
.COMMAND cosh(dbl) : dbl = math_unary_COSH;
"The cosh() function returns the hyperbolic cosine of x,
@@ -132,6 +134,7 @@
proc sin(flt f) : flt {return flt(sin(dbl(f)));}
proc cos(flt f) : flt {return flt(cos(dbl(f)));}
proc tan(flt f) : flt {return flt(tan(dbl(f)));}
+proc cot(flt f) : flt {return flt(cot(dbl(f)));}
proc asin(flt f) : flt {return flt(asin(dbl(f)));}
proc acos(flt f) : flt {return flt(acos(dbl(f)));}
proc atan(flt f) : flt {return flt(atan(dbl(f)));}
@@ -171,6 +174,7 @@
#define cos_unary(x, z) *z = cos(*x)
#define sin_unary(x, z) *z = sin(*x)
#define tan_unary(x, z) *z = tan(*x)
+#define cot_unary(x, z) *z = (1/tan(*x))
#define cosh_unary(x, z) *z = cosh(*x)
#define sinh_unary(x, z) *z = sinh(*x)
@@ -243,6 +247,7 @@
@:unop(_COS,cos)@
@:unop(_SIN,sin)@
@:unop(_TAN,tan)@
+@:unop(_COT,cot)@
@:unop(_COSH,cosh)@
@:unop(_SINH,sinh)@
Index: pcre.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB4/src/modules/plain/pcre.mx,v
retrieving revision 1.3
retrieving revision 1.3.6.1
diff -u -d -r1.3 -r1.3.6.1
--- pcre.mx 20 Feb 2007 11:32:14 -0000 1.3
+++ pcre.mx 14 Dec 2007 07:48:22 -0000 1.3.6.1
@@ -49,6 +49,9 @@
.COMMAND pcre_match(pcre pattern, str s) : bit = pcre_exec_wrap;
"match a pattern"
+.COMMAND pcre_index(pcre pattern, str s) : int = pcre_index_wrap;
+ "match a pattern, return matched position (or 0 when not found)"
+
.COMMAND pcre_select(str pattern, BAT[any::1,str] strs) : BAT[any::1,str] =
pcre_select;
"Select tuples based on the pattern"
@@ -91,6 +94,9 @@
.COMMAND sql2pcre(str pat, str esc) : str = sql2pcre;
"Convert a SQL like pattern with the given escape character into a PCRE
pattern."
+.COMMAND pat2pcre(str pat) : str = pat2pcre;
+ "Convert a SQL patindex pattern into a PCRE pattern."
+
.PRELUDE = pcre_init;
.EPILOGUE = pcre_exit;
@@ -132,6 +138,16 @@
}
int
+pcre_index_wrap(int *res, pcre * pattern, str s)
+{
+ (void) res;
+ (void) pattern;
+ (void) s;
+ GDKerror("pcre_index_wrap() not available as required version of
libpcre was not found by configure.\n");
+ return GDK_FAIL;
+}
+
+int
pcre_select(BAT **res, str pattern, BAT *strs)
{
(void) res, (void) pattern;
@@ -259,6 +275,18 @@
}
int
+pcre_index_wrap(int *res, pcre * pattern, str s)
+{
+ int v[2];
+
+ v[0] = v[1] = *res = 0;
+ if (pcre_exec(m2p(pattern), NULL, s, strlen(s), 0, 0, v, 2) >= 0) {
+ *res = v[1];
+ }
+ return GDK_SUCCEED;
+}
+
+int
pcre_select(BAT **res, str pattern, BAT *strs)
{
const char err[BUFSIZ], *err_p = err;
@@ -566,7 +594,7 @@
{
const char err[BUFSIZ], *err_p = err;
int errpos = 0;
- int options = PCRE_UTF8, i;
+ int options = PCRE_UTF8, i;
pcre *re;
for (i = 0; i < (int)strlen(flags); i++) {
@@ -772,6 +800,37 @@
}
return GDK_SUCCEED;
}
+
+/* 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;
+}
@}
@mil
@@ -808,3 +867,14 @@
ADDHELP("like_uselect_pcre", "groffen", "Dec 19 2004",
"does SQL LIKE select with use of PCRE", "algebra");
+ proc patindex(str pat, str s) : int
+ {
+ var ppat := pat2pcre(pat);
+ if (isnil(ppat)) {
+ return 0;
+ } else {
+ return(pcre_index(pcre_compile(ppat), s));
+ }
+ }
+ ADDHELP("patindex", "niels", "Dec 13 2008",
+ "does SQL PATINDEX with use of PCRE", "algebra");
-------------------------------------------------------------------------
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