Update of /cvsroot/monetdb/MonetDB5/src/modules/atoms
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv6590/src/modules/atoms

Modified Files:
        xml.mx 
Log Message:
don't use strcat but simply array assignments

added some more missing functions for sql


Index: xml.mx
===================================================================
RCS file: /cvsroot/monetdb/MonetDB5/src/modules/atoms/xml.mx,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- xml.mx      31 Aug 2007 18:05:01 -0000      1.11
+++ xml.mx      1 Sep 2007 12:11:12 -0000       1.12
@@ -23,6 +23,13 @@
 @mal
 atom xml :str; 
 
+command fromstr():xml 
+address XMLfromString
+       comment "Convert a string to an xml. ";
+command tostr():str 
+address XMLtoString
+       comment "Convert xml to string equivalent";
+
 command xml(src:str):xml
 address XMLstr2xml
 comment "Cast the string to an xml compliant string";
@@ -67,7 +74,7 @@
 address XMLelementSmall
 comment "The basic building block for XML elements are namespaces, attributes 
and a sequence of xml elements. The name space and the attributes may be left 
unspecified(=nil:bat).";
 
-pattern concat(val:xml... ):xml
+command concat(val1:xml, val2:xml):xml
 address XMLconcat
 comment "Concatenate the xml values";
 
@@ -86,6 +93,8 @@
 
 module calc;
 command xml(src:str):xml address XMLstr2xml;
+command xml(src:xml):xml address XMLxml2xml;
+
 
 @{
 @- Implementation
@@ -115,8 +124,12 @@
 
 xml_export int TYPE_xml;
 
+xml_export int XMLfromString(str src, int *len, xml *x);
+xml_export int XMLtoString(str *s, int *len, str src);
+
 xml_export str XMLxml2str(str *s, xml *x);
 xml_export str XMLstr2xml(xml *x, str *s);
+xml_export str XMLxml2xml(xml *x, xml *s);
 xml_export str XMLdocument(xml *x, str *s);
 xml_export str XMLcontent(xml *x, str *s);
 xml_export str XMLisdcoument(bit *x, str *s);
@@ -146,34 +159,37 @@
 str
 XMLstr2xml(xml *x, str *val){
        str t= *val;
-       str buf= alloca(6*sizeof(*t)), s=buf;
+       str buf= alloca(6*strlen(t)), s=buf;
        
-       for(; *t; t++)
-       if (*t == '&'){
-               strcat(s,"&"); 
-               while(*s) s++;
+       for(*s = 0; *t; t++)
+       if (*t == '&') {
+               *s++ = '&'; *s++ = 'a'; *s++ = 'm'; *s++ = 'p'; *s++ = ';';
        } else if (*t == '<'){
-               strcat(s,"&lt;"); 
-               while(*s) s++;
+               *s++ = '&'; *s++ = 'l'; *s++ = 't'; *s++ = ';';
        } else if (*t == '>'){
-               strcat(s,"&gt;");
-               while(*s) s++;
+               *s++ = '&'; *s++ = 'g'; *s++ = 't'; *s++ = ';';
        }else if (*t == '"'){
-               strcat(s,"&quot;");
-               while(*s) s++;
+               *s++ = '&'; *s++ = 'q'; *s++ = 'u'; *s++ = 'o'; *s++ = 't'; 
+               *s++ = ';';
        } else if (*t == '\''){
-               strcat(s,"&apos;");
-               while(*s) s++;
+               *s++ = '&'; *s++ = 'a'; *s++ = 'p'; *s++ = 'o'; *s++ = 's'; 
+               *s++ = ';';
        } else if ((*t & 0xFF) < 0x20){
-               sprintf(s, "&#%d;", *t & 0xFF);
-               while(*s) s++;
-       } else
+               s += sprintf(s, "&#%d;", *t & 0xFF);
+       } else {
                *s++= *t;
+       }
        *s=0;
        *x= GDKstrdup(buf);
        return MAL_SUCCEED;
 }
 
+str 
+XMLxml2xml(xml *s, xml *x){
+       *s= GDKstrdup(*x);
+       return MAL_SUCCEED;
+}
+
 str
 XMLdocument(xml *x, str *val){
        /* call the libxml2 library to perform the test */
@@ -286,6 +302,7 @@
        *ret= buf;
        return MAL_SUCCEED;
 }
+
 str
 XMLforest(MalBlkPtr mb, MalStkPtr stk, InstrPtr p)
 {
@@ -314,6 +331,32 @@
        return MAL_SUCCEED;
 }
 
+int XMLfromString(str src, int *len, xml *x)
+{
+       if (*x)
+               GDKfree(*x);
+       XMLstr2xml(x, &src);
+       *len = strlen(*x);
+       return *len;
+}
+
+int XMLtoString(str *s, int *len, str src)
+{
+       int l;
+
+       if (GDK_STRNIL(src)) {
+               *s = GDKstrdup("nil");
+               return 0;
+       }
+       l = src == 0 ? 3 : strlen(src) + 1;
+       if (l >= *len) {
+               GDKfree(*s);
+               *s = (str) GDKmalloc(l);
+       }
+       snprintf(*s, l, "%s", src);
+       *len = l - 1;
+       return *len;
+}
 
 
 @sql


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Monetdb-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-checkins

Reply via email to