CVS: libraries/commandline help.c,1.1,1.2

Chris Liechti <[email protected]>
Newsgroups gmane.comp.hardware.texas-instruments.msp430.gcc.cvs
Message-ID <[email protected]>
Update of /cvsroot/mspgcc/libraries/commandline
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3794/libraries/commandline

Modified Files:
	help.c 
Log Message:
enhance help function:
- short help: first line of help text
- "help command" -> print full help text, indented

Index: help.c
===================================================================
RCS file: /cvsroot/mspgcc/libraries/commandline/help.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -d -r1.1 -r1.2
--- help.c	22 Aug 2005 11:25:26 -0000	1.1
+++ help.c	4 Oct 2005 09:37:41 -0000	1.2
@@ -1,16 +1,46 @@
 #include <stdio.h>
+#include <string.h>
 
 #include "commandline.h"
 
 //the help commands expect that there is a global command table
 extern const COMMANDLINE_TABLE commandline_table[];
 
+// "help" -> write a list of commands, with the first line of the help text
+// "help cmd" -> print the commands entire help text
 int command_help(int argc, char *argv[]) {
     const COMMANDLINE_TABLE *table_entry = commandline_table;
-    puts("Commands:");
+    if (argc == 2) {
     while (table_entry->name) {
-        printf("%-10s %s\n", table_entry->name, table_entry->help);
+            if (strcmp(table_entry->name, argv[1]) == 0) {
+                printf("%s: ", argv[1]);
+                const char * help_text = table_entry->help;
+                while (*help_text) {
+                    putchar(*help_text);
+                    if (*help_text == '\n' && help_text[1] != '\0') {
+                        printf("    ");
+                    }
+                    help_text++;
+                }
+                putchar('\n');
+                return 0;
+            }
         table_entry++;
     }
+        printf("no such command: \"%s\"\n", argv[1]);
+        return 1;
+    } else {
+        puts("List of commands:");
+        while (table_entry->name) {
+            printf("%-12s", table_entry->name);
+            // show first line of help text
+            const char * help_text = table_entry->help;
+            while (*help_text && *help_text != '\n') {
+                putchar(*help_text++);
+            }
+            putchar('\n');
+            table_entry++;
+        }
+    }
     return 0;
 }



-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.