User Tools

Site Tools


docs:cli_parser

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
docs:cli_parser [2020/10/01 11:19] rootdocs:cli_parser [2020/10/01 11:34] (current) root
Line 25: Line 25:
 void process_cmd( arg_node *cfg_cur, const char* command, size_t offset=0;) void process_cmd( arg_node *cfg_cur, const char* command, size_t offset=0;)
 { {
 +    size_t kwd_len=0;
     size_t arg_len=0;     size_t arg_len=0;
-    char* arg = command+offset;+    char* keyword = command+offset
 +    char* arg = null;
          
     // Search the next argument boundary     // Search the next argument boundary
-    while( arg[arg_len] != '\0' && arg[arg_len] != ' ') +    while( keyword[kwd_len] != '\0' && keyword[kwd_len] != ' ') 
-        ++arg_len;+        ++kwd_len;
          
     // If we don't have an argument, attempt to call the node's callback method.     // If we don't have an argument, attempt to call the node's callback method.
-    if( arg_len == 0 )+    if( kwd_len == 0 )
     {     {
-        if( cfg_cur->callback != null)+        if( cfg_cur->callback != null && cfg_cur->has_arg == false)
         {         {
             cfg_cur->callback( command);             cfg_cur->callback( command);
Line 45: Line 47:
  
         return;         return;
 +    }
 +    
 +    if ( cfg_cur->has_arg == true )
 +    {
 +        // This node has an argument.
 +        
 +        arg = command+offset+kwd_len+1;
 +        
 +        // Attempt to get the size of the argument
 +        while( arg[kwd_len] != '\0' && arg[kwd_len] != ' ' )
 +            ++arg_len;
 +        
 +        if( arg_len == 0 )
 +        {
 +            Serial.print( F("Incomplete command.\r\n"));
 +            return;
 +        }
     }     }
          
Line 51: Line 70:
         for( size_t i=0; i<cfg_cur->nb_leaves; ++i)         for( size_t i=0; i<cfg_cur->nb_leaves; ++i)
         {         {
-            if( strncmp( cfg_cur->leaves[i]->quick_name, argarg_len) == 0)+            if( strncmp( cfg_cur->leaves[i]->quick_name, keywordkwd_len) == 0)
             {             {
                 // Positive match                 // Positive match
-                process_cmd( cfg_cur->leaves[i], command, offset+arg_len+1)+                process_cmd( cfg_cur->leaves[i], command, offset+kwd_len+1)
                 return;                 return;
             }             }
docs/cli_parser.1601543981.txt.gz · Last modified: 2020/10/01 11:19 by root

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki