Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 2 Jul 2007 01:22:40 GMT
From:      Marko Zec <zec@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 122687 for review
Message-ID:  <200707020122.l621MeIU035459@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=122687

Change 122687 by zec@zec_tpx32 on 2007/07/02 01:21:52

	Sort command lists in DDB before printing them out on console.

Affected files ...

.. //depot/projects/vimage/src/sys/ddb/db_command.c#3 edit

Differences ...

==== //depot/projects/vimage/src/sys/ddb/db_command.c#3 (text+ko) ====

@@ -262,24 +262,40 @@
 	return (result);
 }
 
+/*
+ * Print out a sorted command table.
+ */
 static void
 db_cmd_list(table)
 	struct command_table *table;
 {
-	register struct command *cmd;
-	register struct command **aux_cmdp;
+	struct command *cmd;
+	struct command **aux_cmdp;
+	char *last;
+	char *next = "";
 
-	for (cmd = table->table; cmd->name != 0; cmd++) {
-	    db_printf("%-12s", cmd->name);
-	    db_end_line(12);
-	}
-	if (table->aux_tablep == NULL)
-	    return;
-	for (aux_cmdp = table->aux_tablep; aux_cmdp < table->aux_tablep_end;
-	     aux_cmdp++) {
-	    db_printf("%-12s", (*aux_cmdp)->name);
-	    db_end_line(12);
-	}
+	do {
+		last = next;
+		for (cmd = table->table; cmd->name != 0; cmd++) {
+			if (strcmp(cmd->name, last) > 0 &&
+			    (last == next || strcmp(cmd->name, next) < 0))
+				next = cmd->name;
+		}
+		if (table->aux_tablep != NULL) {
+			for (aux_cmdp = table->aux_tablep;
+			     aux_cmdp < table->aux_tablep_end; aux_cmdp++) {
+				cmd = *aux_cmdp;
+				if (strcmp(cmd->name, last) > 0 &&
+				    (last == next ||
+				     strcmp(cmd->name, next) < 0))
+					next = cmd->name;
+			}
+		}
+		if (next != last) {
+			db_printf("%-12s", next);
+			db_end_line(12);
+		}
+	} while (next != last);
 }
 
 static void



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200707020122.l621MeIU035459>