CVS: libraries/commandline commandline_usage.c, NONE, 1.1 commandline.c, 1.3, 1.4 help.c, 1.2, 1.3 tabcomplete.c, 1.1, 1.2

Chris Liechti <[email protected]> Wed, 11 Oct 2006 11:47:30 -0700
Newsgroups gmane.comp.hardware.texas-instruments.msp430.gcc.cvs
Message-ID <[email protected]>
Update of /cvsroot/mspgcc/libraries/commandline
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv12454/libraries/commandline

Modified Files:
	commandline.c help.c tabcomplete.c 
Added Files:
	commandline_usage.c 
Log Message:
- commandline_usage helper function
- support for separator entries in command list
- switch to case insensitive string compares

--- NEW FILE: commandline_usage.c ---
#include <stdlib.h>
#include <stdbool.h>

#include "commandline.h"

bool commandline_usage(const char *s) {
    const COMMANDLINE_TABLE *table_entry = commandline_table;
    // find command with name
    while (table_entry->name) {
        if (strcasecmp(table_entry->name, command) == 0) {
            printf("%s: ", table_entry->name);
            const char * help_text = table_entry->help;
            // write help text line by line, indented.
            while (*help_text) {
                putchar(*help_text);
                if (*help_text == '\n' && help_text[1] != '\0') {
                    printf("    ");
                }
                help_text++;
            }
            putchar('\n');
            putchar('\n');
            return true;
        }
        table_entry++;
    }
    return false;
}

Index: commandline.c
===================================================================
RCS file: /cvsroot/mspgcc/libraries/commandline/commandline.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -w -d -r1.3 -r1.4
--- commandline.c	4 Apr 2006 22:25:05 -0000	1.3
+++ commandline.c	11 Oct 2006 18:47:28 -0000	1.4
@@ -53,7 +53,7 @@
     }
     //search table for command
     for (int i = 0;  command_table[i].name;  i++) {
-        if (strcmp(argv[0], command_table[i].name) == 0) {
+        if (strcasecmp(argv[0], command_table[i].name) == 0) {
             return command_table[i].function(argc, argv);
         }
     }

Index: help.c
===================================================================
RCS file: /cvsroot/mspgcc/libraries/commandline/help.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -w -d -r1.2 -r1.3
--- help.c	4 Oct 2005 09:37:41 -0000	1.2
+++ help.c	11 Oct 2006 18:47:28 -0000	1.3
@@ -11,27 +11,14 @@
 int command_help(int argc, char *argv[]) {
     const COMMANDLINE_TABLE *table_entry = commandline_table;
     if (argc == 2) {
-        while (table_entry->name) {
-            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++;
+        if (!commandline_usage(argv[1])) {
+            printf("No such command: \"%s\"\n", argv[1]);
+            return COMMANDLINE_ERROR_PARAMETER;
         }
-        printf("no such command: \"%s\"\n", argv[1]);
-        return 1;
     } else {
-        puts("List of commands:");
         while (table_entry->name) {
+            // check for separators
+            if (table_entry->name[0] != '\0') {
             printf("%-12s", table_entry->name);
             // show first line of help text
             const char * help_text = table_entry->help;
@@ -39,8 +26,11 @@
                 putchar(*help_text++);
             }
             putchar('\n');
+            } else {
+                printf("\n[%s]\n", table_entry->help);
+            }
             table_entry++;
         }
     }
-    return 0;
+    return COMMANDLINE_SUCCESS;
 }

Index: tabcomplete.c
===================================================================
RCS file: /cvsroot/mspgcc/libraries/commandline/tabcomplete.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -d -r1.1 -r1.2
--- tabcomplete.c	4 Apr 2006 22:25:05 -0000	1.1
+++ tabcomplete.c	11 Oct 2006 18:47:28 -0000	1.2
@@ -16,7 +16,7 @@
     bool append_space = false;
     // scan command table for a command that starts with the text from the current command line
     for (const COMMANDLINE_TABLE *entry=commandline_table; entry->name; entry++) {
-        if (strncmp(lineeditor->line, entry->name, lineeditor->position) == 0) {
+        if (strncasecmp(lineeditor->line, entry->name, lineeditor->position) == 0) {
             if (match == NULL) {
                 // save first match
                 match = entry;


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642