Update of /cvsroot/monetdb/sql/src/backends/monet5/merovingian
In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv13338
Modified Files:
ChangeLog monetdb.c
Log Message:
Use qsort to sort output, since we have it buffered locally anyway. Makes
output predictable and less messy at times.
Index: monetdb.c
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/merovingian/monetdb.c,v
retrieving revision 1.72
retrieving revision 1.73
diff -u -d -r1.72 -r1.73
--- monetdb.c 22 Jan 2010 07:57:28 -0000 1.72
+++ monetdb.c 7 Apr 2010 13:43:07 -0000 1.73
@@ -39,7 +39,7 @@
#include "glob.h"
#include "database.h"
#include "control.h"
-#include <stdlib.h> /* exit, getenv */
+#include <stdlib.h> /* exit, getenv, qsort */
#include <stdarg.h> /* variadic stuff */
#include <stdio.h> /* fprintf, rename */
#include <string.h> /* strerror */
@@ -285,6 +285,15 @@
simple_argv_cmd(argc, argv, merocmd, successmsg, NULL);
}
+static int
+cmpsabdb(const void *p1, const void *p2)
+{
+ const sabdb *q1 = *(sabdb* const*)p1;
+ const sabdb *q2 = *(sabdb* const*)p2;
+
+ return strcmp(q1->dbname, q2->dbname);
+}
+
/**
* Helper function to perform the equivalent of
* SABAOTHgetStatus(&stats, x) but over the network.
@@ -295,6 +304,9 @@
sabdb *orig;
sabdb *stats;
sabdb *w = NULL;
+ size_t swlen = 50;
+ size_t swpos = 0;
+ sabdb **sw = malloc(sizeof(sabdb *) * swlen);
char *p;
char *buf;
char *e;
@@ -314,7 +326,7 @@
free(buf);
return(p);
}
- while ((p = strtok(NULL, "\n")) != NULL) {
+ for (swpos = 0; (p = strtok(NULL, "\n")) != NULL; swpos++) {
e = SABAOTHdeserialise(&stats, &p);
if (e != NULL) {
printf("WARNING: failed to parse response from "
@@ -322,16 +334,26 @@
GDKfree(e);
continue;
}
- if (orig == NULL) {
- orig = w = stats;
- } else {
- w = w->next = stats;
- }
+ if (swpos == swlen)
+ sw = realloc(sw, sizeof(sabdb *) * (swlen =
swlen * 2));
+ sw[swpos] = stats;
}
}
free(buf);
+ if (swpos > 1) {
+ qsort(sw, swpos, sizeof(sabdb *), cmpsabdb);
+ orig = w = sw[0];
+ for (swlen = 1; swlen < swpos; swlen++)
+ w = w->next = sw[swlen];
+ } else if (swpos == 1) {
+ orig = sw[0];
+ orig->next = NULL;
+ }
+
+ free(sw);
+
*ret = orig;
return(NULL);
}
@@ -704,6 +726,19 @@
SABAOTHfreeStatus(&orig);
}
+static int
+cmpurl(const void *p1, const void *p2)
+{
+ const char *q1 = *(char* const*)p1;
+ const char *q2 = *(char* const*)p2;
+
+ if (strncmp("mapi:monetdb://", q1, 15) == 0)
+ q1 += 15;
+ if (strncmp("mapi:monetdb://", q2, 15) == 0)
+ q2 += 15;
+ return strcmp(q1, q2);
+}
+
static void
command_discover(int argc, char *argv[])
{
@@ -775,7 +810,7 @@
if (posloc > 0) {
printf("%*slocation\n",
(int)(loclen - 8 /* "location" */ - ((loclen -
8) / 2)), "");
- /* could qsort the array here but we don't :P */
+ qsort(locations, posloc, sizeof(char *), cmpurl);
for (loclen = 0; loclen < posloc; loclen++) {
printf("%s\n", locations[loclen]);
free(locations[loclen]);
Index: ChangeLog
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/merovingian/ChangeLog,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- ChangeLog 29 Mar 2010 18:04:41 -0000 1.38
+++ ChangeLog 7 Apr 2010 13:43:07 -0000 1.39
@@ -1,5 +1,9 @@
-# ChangeLog file for sql/src/backends/monet5
-# This file is updated with mchangelog (Gentoo echangelog bastard script)
+# ChangeLog file for sql/src/backends/monet5/merovingian
+# This file is updated with mchangelog
+
+ 07 Apr 2010; Fabian Groffen <[email protected]> monetdb.c:
+ Sort output returned by discover, status and get commands based on url
+ or dbname.
24 Mar 2010; Fabian Groffen <[email protected]> merovingian.c,
merovingian_client.c:
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins