Update of /cvsroot/monetdb/MonetDB4/src/modules/plain
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv26644/src/modules/plain
Modified Files:
arith.mx mmath.mx pcre.mx str.mx
Log Message:
propagated changes of Friday Nov 30 2007 - Tuesday Dec 18 2007
from the MonetDB_4-20 branch to the development trunk
Index: mmath.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB4/src/modules/plain/mmath.mx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- mmath.mx 20 Feb 2007 11:32:13 -0000 1.3
+++ mmath.mx 18 Dec 2007 10:45:13 -0000 1.4
@@ -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: arith.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB4/src/modules/plain/arith.mx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- arith.mx 20 Feb 2007 11:32:12 -0000 1.3
+++ arith.mx 18 Dec 2007 10:45:13 -0000 1.4
@@ -251,6 +251,7 @@
@= mel_unary_ops
.COMMAND abs(@1) : @1 = @1_unary_ABS; "absolute value"
.OPERATOR "-" (@1) : @1 = @1_unary_NEG; "negative value"
+ .COMMAND sign(@1) : @1 = @1_unary_SIGN; "Returns +1, 0, -1 based on the
sign of the given expression"
@= unary_ops
@:@1_unary_ops(chr)@
@:@1_unary_ops(bte)@
@@ -411,9 +412,11 @@
#define arith_abs(s) ((s)<0)?-(s):(s)
#define arith_neg(s) (-(s))
+#define arith_sign(s) ((s)<0)?-1:((s)==0)?0:1
@= c_unary_ops
@:arith_unop(_ABS,arith_abs,@1)@
@:arith_unop(_NEG,arith_neg,@1)@
+@:arith_unop(_SIGN,arith_sign,@1)@
@c
@:unary_ops(c)@
Index: str.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB4/src/modules/plain/str.mx,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- str.mx 4 Oct 2007 10:35:25 -0000 1.4
+++ str.mx 18 Dec 2007 10:45:15 -0000 1.5
@@ -206,10 +206,10 @@
proc stringlength( str s) : int {
return length(rtrim(s));
}
-proc stringinsert( str s, int start, int l, str s2 ) : str {
+proc insert( str s, int start, int l, str s2 ) : str {
return substring(s,start,l) + s2 + substring(s,start+l);
}
-proc stringreplace( str s1, str s2, str s3 ) : str {
+proc replace( str s1, str s2, str s3 ) : str {
return substitute(s1,s2,s3, true);
}
# string of c times s
@@ -1585,24 +1585,24 @@
int
strSubString(str *res, str s, wrd *offset, wrd *length)
{
- wrd len, off = *offset;
+ wrd len, off = *offset, l = *length;
- RETURN_NIL_IF(strNil(s) || off == wrd_nil || *length == wrd_nil,
TYPE_str);
+ RETURN_NIL_IF(strNil(s) || off == wrd_nil || l == wrd_nil, TYPE_str);
if (off < 0) {
len = UTF8_strlen(s);
RETURN_NIL_IF(len == wrd_nil, TYPE_str);
off = len + off;
if (off < 0) {
- *length += off;
+ l += off;
off = 0;
}
}
- if (*length < 0) {
+ if (l < 0) {
*res = GDKstrdup("");
return GDK_SUCCEED;
}
s = UTF8_strtail(s, MAX(0, off));
- len = UTF8_strtail(s, *length) - s;
+ len = UTF8_strtail(s, l) - s;
if (off < 0) {
len += off;
off = 0;
@@ -1630,9 +1630,9 @@
/* 64bit: should have wrd arg */
unsigned char *s = (unsigned char *) val;
- RETURN_NIL_IF(strNil(val) || *at == int_nil || *at < 0, TYPE_chr);
+ RETURN_NIL_IF(strNil(val) || *at == int_nil || *at < 0, TYPE_int);
s = (unsigned char *) UTF8_strtail((str) s, *at);
- RETURN_NIL_IF(*s == 0, TYPE_chr);
+ RETURN_NIL_IF(*s == 0, TYPE_int);
@:UTF8_GETCHAR(*res,s)@
return GDK_SUCCEED;
}
Index: pcre.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB4/src/modules/plain/pcre.mx,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- pcre.mx 14 Nov 2007 21:54:10 -0000 1.5
+++ pcre.mx 18 Dec 2007 10:45:15 -0000 1.6
@@ -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)
{
BATiter strsi = bat_iterator(strs);
@@ -775,6 +803,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
@@ -811,3 +870,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