Update of /cvsroot/monetdb/sql/src/backends/monet5
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv13325

Modified Files:
        monetdb.1 monetdb.mx 
Log Message:
Add -s option that orders the output on state, defaulting to running,
stopped, crashed, locked order.


U monetdb.1
Index: monetdb.1
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/monetdb.1,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- monetdb.1   7 Apr 2008 18:42:25 -0000       1.8
+++ monetdb.1   28 Aug 2008 14:05:47 -0000      1.9
@@ -64,7 +64,7 @@
 Use the
 .B lock
 command to take a database under maintenance.
-.IP "status [\-lc] [database ...]"
+.IP "status [\-lc] [\-s<state>...] [database ...]"
 Shows the state of the given database(s) or, when none given, all known
 databases.  Three modes control the level of detail in the displayed
 output.  By default a condensed one-line output per database format is
@@ -86,6 +86,21 @@
 flag, a long listing is used.  This listing spans many rows with on each
 row one property and its value separated by a colon (`:').  The long
 listing includes all information that is available.
+.IP \-s
+The
+.I \-s
+flag controls which databases are being shown, matching their state.
+The required argument to this flag can be a combination of any of the
+following characters.  Note that the order in which they are put also
+controls the order in which the databases are printed.
+.I r, s, c
+and
+.I l
+are used to print a started (running), stopped, crashed and locked
+database respectively.  The default order which is used when the
+.I \-s
+flag is absent, is
+.I rscl.
 .IP "start [\-aw] database [database ...]"
 .IP "stop [\-aw] database [database ...]"
 .IP "kill [\-aw] database [database ...]"

U monetdb.mx
Index: monetdb.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/monetdb.mx,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- monetdb.mx  28 Aug 2008 13:02:51 -0000      1.21
+++ monetdb.mx  28 Aug 2008 14:05:48 -0000      1.22
@@ -119,6 +119,9 @@
                printf("Options:\n");
                printf("  -l  extended information listing\n");
                printf("  -c  crash statistics listing\n");
+               printf("  -s  only show databases matching a state, 
combination\n");
+               printf("      possible from r (running), s (stopped), c 
(crashed)\n");
+               printf("      and l (locked).\n");
        } else if (strcmp(argv[1], "start") == 0) {
                printf("Usage: monetdb start [-aw] database [database ...]\n");
                printf("  Starts the given database, if the MonetDB Database 
Server\n");
@@ -390,10 +393,12 @@
 {
        int doall = 1; /* we default to showing all */
        int mode = 1;  /* 0=crash, 1=short, 2=long */
+       char *state = "rscl"; /* contains states to show */
        int i;
        char *p;
        str e;
        sabdb *stats;
+       sabdb *orig;
 
        if (argc == 0) {
                exit(2);
@@ -410,6 +415,32 @@
                                        case 'l':
                                                mode = 2;
                                        break;
+                                       case 's':
+                                               if (*(p + 1) != '\0') {
+                                                       state = ++p;
+                                               } else if (i + 1 < argc && 
argv[i + 1][0] != '-') {
+                                                       state = argv[++i];
+                                               } else {
+                                                       fprintf(stderr, 
"status: -s needs an argument\n");
+                                                       command_help(2, 
&argv[-1]);
+                                                       exit(1);
+                                               }
+                                               for (p = state; *p != '\0'; 
p++) {
+                                                       switch (*p) {
+                                                               case 'r': /* 
running (started) */
+                                                               case 's': /* 
stopped */
+                                                               case 'c': /* 
crashed */
+                                                               case 'l': /* 
locked */
+                                                               break;
+                                                               default:
+                                                                       
fprintf(stderr, "status: unknown flag for -s: -%c\n", *p);
+                                                                       
command_help(2, &argv[-1]);
+                                                                       exit(1);
+                                                               break;
+                                                       }
+                                               }
+                                               p--;
+                                       break;
                                        case '-':
                                                if (p[1] == '\0') {
                                                        if (argc - 1 > i) 
@@ -432,49 +463,75 @@
                }
        }
 
-       if (mode == 1) {
-               /* print header for short mode */
-               /* demo | state uptime | crash lastcrash */
-               printf("      name       state     uptime       health       
last crash\n");
-       }
-
        if (doall == 1) {
-               sabdb *orig;
                /* don't even look at the arguments, because we are instructed
                 * to list all known databases */
-               if ((e = SABAOTHgetStatus(&stats, NULL)) != MAL_SUCCEED) {
+               if ((e = SABAOTHgetStatus(&orig, NULL)) != MAL_SUCCEED) {
                        fprintf(stderr, "status: internal error: %s\n", e);
                        GDKfree(e);
                        exit(2);
                }
-       
-               orig = stats;
-               while (stats != NULL) {
-                       printStatus(stats, mode);
-                       stats = stats->next;
-               }
+       } else {
+               sabdb *w = NULL;
+               orig = NULL;
+               for (i = 1; i < argc; i++) {
+                       if (argv[i] != NULL) {
+                               if ((e = SABAOTHgetStatus(&stats, argv[i])) != 
MAL_SUCCEED) {
+                                       fprintf(stderr, "status: internal 
error: %s\n", e);
+                                       GDKfree(e);
+                                       exit(2);
+                               }
 
-               if (orig != NULL)
-                       SABAOTHfreeStatus(&orig);
-               return;
+                               if (stats == NULL) {
+                                       fprintf(stderr, "status: no such 
database: %s\n", argv[i]);
+                                       argv[i] = NULL;
+                               } else {
+                                       if (orig == NULL) {
+                                               orig = stats;
+                                               w = stats;
+                                       } else {
+                                               w = w->next = stats;
+                                       }
+                               }
+                       }
+               }
        }
 
-       for (i = 1; i < argc; i++) {
-               if (argv[i] != NULL) {
-                       if ((e = SABAOTHgetStatus(&stats, argv[i])) != 
MAL_SUCCEED) {
-                               fprintf(stderr, "status: internal error: %s\n", 
e);
-                               GDKfree(e);
-                               exit(2);
-                       }
+       if (mode == 1) {
+               /* print header for short mode */
+               /* demo | state uptime | crash lastcrash */
+               printf("      name       state     uptime       health       
last crash\n");
+       }
 
-                       if (stats == NULL) {
-                               fprintf(stderr, "status: no such database: 
%s\n", argv[i]);
-                       } else {
+       for (p = state; *p != '\0'; p++) {
+               int curLock = 0;
+               SABdbState curMode = SABdbIllegal;
+               switch (*p) {
+                       case 'r':
+                               curMode = SABdbRunning;
+                       break;
+                       case 's':
+                               curMode = SABdbInactive;
+                       break;
+                       case 'c':
+                               curMode = SABdbCrashed;
+                       break;
+                       case 'l':
+                               curLock = 1;
+                       break;
+               }
+               stats = orig;
+               while (stats != NULL) {
+                       if (stats->locked == curLock &&
+                                       (curLock == 1 || 
+                                        (curLock == 0 && stats->state == 
curMode)))
                                printStatus(stats, mode);
-                               SABAOTHfreeStatus(&stats);
-                       }
+                       stats = stats->next;
                }
        }
+
+       if (orig != NULL)
+               SABAOTHfreeStatus(&orig);
 }
 
 typedef enum {


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins

Reply via email to