]> git.donarmstrong.com Git - kiibohd-controller.git/commitdiff
Added help command and function'ized the arugmentIsolator.
authorJacob Alexander <haata@kiibohd.com>
Wed, 22 Jan 2014 09:58:34 +0000 (01:58 -0800)
committerJacob Alexander <haata@kiibohd.com>
Sat, 22 Mar 2014 21:10:52 +0000 (14:10 -0700)
Debug/cli/cli.c
Debug/cli/cli.h

index ce843d6d6b492efc52681f25664e15ced5a0347e..8bc3ab031b1533f482a8f852b24f315b3304a174 100644 (file)
@@ -34,7 +34,7 @@
 
 // Basic command dictionary
 CLIDictItem basicCLIDict[] = {
-       { "help",    "This command :P", cliFunc_help },
+       { "help",    "You're looking at it :P", cliFunc_help },
        { "version", "Version information about this firmware.", cliFunc_version },
        { 0, 0, 0 } // Null entry for dictionary end
 };
@@ -172,18 +172,15 @@ void process_cli()
        }
 }
 
-void commandLookup_cli()
+// Takes a string, returns two pointers
+//  One to the first non-space character
+//  The second to the next argument (first NULL if there isn't an argument). delimited by a space
+//  Places a NULL at the first space after the first argument
+inline void argumentIsolation_cli( char* string, char** first, char** second )
 {
-       // Ignore command if buffer is 0 length
-       if ( CLILineBufferCurrent == 0 )
-               return;
-
-       // Set the last+1 character of the buffer to NULL for string processing
-       CLILineBuffer[CLILineBufferCurrent] = '\0';
-
        // Mark out the first argument
        // This is done by finding the first space after a list of non-spaces and setting it NULL
-       char* cmdPtr = CLILineBuffer - 1;
+       char* cmdPtr = string - 1;
        while ( *++cmdPtr == ' ' ); // Skips leading spaces, and points to first character of cmd
 
        // Locates first space delimiter
@@ -194,6 +191,26 @@ void commandLookup_cli()
        // Point to the first character of args or a NULL (no args) and set the space delimiter as a NULL
        (++argPtr)[-1] = '\0';
 
+       // Set return variables
+       *first = cmdPtr;
+       *second = argPtr;
+}
+
+void commandLookup_cli()
+{
+       // Ignore command if buffer is 0 length
+       if ( CLILineBufferCurrent == 0 )
+               return;
+
+       // Set the last+1 character of the buffer to NULL for string processing
+       CLILineBuffer[CLILineBufferCurrent] = '\0';
+
+       // Retrieve pointers to command and beginning of arguments
+       // Places a NULL at the first space after the command
+       char* cmdPtr;
+       char* argPtr;
+       argumentIsolation_cli( CLILineBuffer, &cmdPtr, &argPtr );
+
        // Scan array of dictionaries for a valid command match
        for ( uint8_t dict = 0; dict < CLIDictionariesUsed; dict++ )
        {
@@ -214,10 +231,10 @@ void commandLookup_cli()
 
        // No match for the command...
        print( NL );
-       erro_dPrint("\"", CLILineBuffer, "\" is not a valid command...try help");
+       erro_dPrint("\"", CLILineBuffer, "\" is not a valid command...type \033[35mhelp\033[0m");
 }
 
-void registerDictionary_cli( CLIDictItem *cmdDict )
+inline void registerDictionary_cli( CLIDictItem *cmdDict )
 {
        // Make sure this max limit of dictionaries hasn't been reached
        if ( CLIDictionariesUsed >= CLIMaxDictionaries )
@@ -236,9 +253,20 @@ void registerDictionary_cli( CLIDictItem *cmdDict )
 
 void cliFunc_help( char* args )
 {
-       print( NL );
-       print("Help!");
-       dPrint( args );
+       // Scan array of dictionaries and print every description
+       //  (no alphabetical here, too much processing/memory to sort...)
+       for ( uint8_t dict = 0; dict < CLIDictionariesUsed; dict++ )
+       {
+               print( NL "\033[1;32mCOMMAND SET\033[0m " );
+               printInt8( dict + 1 );
+               print( NL );
+
+               // Parse each cmd/description until a null command entry is found
+               for ( uint8_t cmd = 0; CLIDict[dict][cmd].name != 0; cmd++ )
+               {
+                       dPrintStrs( " \033[35m", CLIDict[dict][cmd].name, NL, "\033[0m    ", CLIDict[dict][cmd].description, NL );
+               }
+       }
 }
 
 void cliFunc_version( char* args )
index 081f372688bd2f253d815ab961294726dcc13eb8..399f26f20750630fa4245c113acec38d4ad9e9c6 100644 (file)
@@ -69,6 +69,7 @@ uint8_t CLIDictionariesUsed;
 void init_cli();
 void process_cli();
 void registerDictionary_cli( CLIDictItem *cmdDict );
+void argumentIsolation_cli( char* string, char** first, char** second );
 
 void commandLookup_cli();