caudium-commits AT caudium.net
Caudium CVS Commits list

CVS: caudium/server/modules/tags xmlparse.pike,1.47,1.48


chronological Thread 
  • From: "Bill Welliver" <hww3 AT cvs.caudiumforge.net>
  • To: caudium-commits AT caudium.net
  • Subject: CVS: caudium/server/modules/tags xmlparse.pike,1.47,1.48
  • Date: Thu, 12 May 2005 02:20:05 +0000

Update of /cvs/caudium/caudium/server/modules/tags
In directory cvs.caudiumforge.net:/tmp/cvs-serv90190

Modified Files:
        xmlparse.pike 
Log Message:
fixes for emit


Index: xmlparse.pike
===================================================================
RCS file: /cvs/caudium/caudium/server/modules/tags/xmlparse.pike,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -r1.47 -r1.48
--- xmlparse.pike       3 Jan 2005 17:04:50 -0000       1.47
+++ xmlparse.pike       12 May 2005 02:20:02 -0000      1.48
@@ -1,6 +1,6 @@
 /*
  * Caudium - An extensible World Wide Web server
- * Copyright © 2000-2005 The Caudium Group
+ * Copyright © 2000-2004 The Caudium Group
  * Copyright © 1994-2001 Roxen Internet Software
  * 
  * This program is free software; you can redistribute it and/or
@@ -27,10 +27,10 @@
 //!  strict, in the XML-sense. Please note that although this parser
 //!  handles XML-syntax, it never requires it. For example you can still
 //!  use unquoted arguments.
-//! cvs_version: $Id: xmlparse.pike,v 1.47 2005/01/03 17:04:50 kiwi Exp $
+//! cvs_version: $Id: xmlparse.pike,v 1.48 2005/05/12 02:20:02 hww3 Exp $
 //
 
-constant cvs_version = "$Id: xmlparse.pike,v 1.47 2005/01/03 17:04:50 kiwi 
Exp $";
+constant cvs_version = "$Id: xmlparse.pike,v 1.48 2005/05/12 02:20:02 hww3 
Exp $";
 constant thread_safe=1;
 
 #include <config.h>
@@ -460,6 +460,7 @@
 string container_emit(string t, mapping args, string contents, object id,  
   object f)
 {
+  function sort;
   function plugin;
   int rowinfo;
   CDEBUG("container_emit called for source: " + args->source);
@@ -471,6 +472,12 @@
   if(!plugin || !functionp(plugin))
     return "emit: no plugin " + args->source;
 
+   if(args->sort_function)
+   {
+     sort = master()->resolv(args->sort_function);
+     if(!sort) return sprintf("emit: invalid sort function %s", 
args->sort_function); 
+   }
+
   array dataset;
   mixed e;
 #ifdef HTML_DEBUG
@@ -492,6 +499,16 @@
   // changes the dataset).
   //
 
+  if(sort && args->sort_key)
+  {
+    dataset = emit_sort_array(dataset, sort, args->sort_key);
+  }
+
+  if(args->reverse)
+  {
+    dataset = reverse(dataset);
+  }
+
   int datasetsize= sizeof(dataset);
   int remainder;
 
@@ -499,8 +516,8 @@
   if(args->maxrows)
   {
       
-     if(sizeof(dataset)> args->maxrows)
-        dataset = dataset[0..(args->maxrows-1)];
+     if(sizeof(dataset)> (int)(args->maxrows))
+        dataset = dataset[0..((int)(args->maxrows)-1)];
 
      remainder = datasetsize - sizeof(dataset);
   }
@@ -508,8 +525,8 @@
   // args->skiprows
   if(args->skiprows)
   {
-     if(sizeof(dataset)> args->skiprows)
-        dataset = dataset[-(args->skiprows)..];
+     if(sizeof(dataset)> (int)(args->skiprows))
+        dataset = dataset[-((int)(args->skiprows))..];
   }
 
   rowinfo = sizeof(dataset);
@@ -558,6 +575,87 @@
   return retval->get();
 }
 
+array emit_sort_array(array foo, function|void cmp, string key, mixed ... 
args)
+{
+  array bar,tmp;
+  int len,start;
+  int length;
+  int foop, fooend, barp, barend;
+
+  if(!cmp || cmp==`>)
+  {
+    array x = allocate(sizeof(foo));
+    for(int q = 0; q < sizeof(foo); q++)
+      x[q] = foo[q][key];
+    foo+=({});
+    sort(x, foo);
+    return foo;
+  }
+
+  if(cmp == `<)
+  {
+    array x = allocate(sizeof(foo));
+    for(int q = 0; q < sizeof(foo); q++)
+      x[q] = foo[q][key];
+    foo+=({});
+    sort(x, foo);
+    return reverse(foo);
+  }
+
+  length=sizeof(foo);
+
+  foo+=({});
+  bar=allocate(length);
+
+  for(len=1;len<length;len*=2)
+  {
+    start=0;
+    while(start+len < length)
+    {
+      foop=start;
+      barp=start+len;
+      fooend=barp;
+      barend=barp+len;
+      if(barend > length) barend=length;
+
+      while(1)
+      {
+        
+        
if(([function(mixed,mixed,mixed...:int)]cmp)(foo[foop][key],foo[barp][key],@args)
+            <= 0)
+        {
+          bar[start++]=foo[foop++];
+          if(foop == fooend)
+          {
+            while(barp < barend) {
+               bar[start++]=foo[barp++];
+               }
+            break;
+          }
+         }else{
+          bar[start++]=foo[barp++];
+          if(barp == barend)
+          {
+            while(foop < fooend) {
+               bar[start++]=foo[foop++];
+               }
+            break;
+          }
+        }
+      }
+    }
+    while(start < length) {
+       bar[start]=foo[start++];
+       }
+    tmp=foo;
+    foo=bar;
+    bar=tmp;
+  }
+
+  return foo;
+}
+
+
 // This function is used to know if we have a xml document and thus
 // we'll try to output XML tags and containers with make_tag, 
 // make_container defaulting to make_xml_tag and make_xml_container



  • CVS: caudium/server/modules/tags xmlparse.pike,1.47,1.48, Bill Welliver

Archive powered by MhonArc 2.6.10.

§