Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
soc:fredrikhultin [2006/07/11 23:44]
noname
soc:fredrikhultin [2006/07/12 00:24] (current)
noname
Line 83: Line 83:
   /* Name and describe the list set */   /* Name and describe the list set */
   cmdl_param_list_set_name(ipv4,​ "​ipv4"​);​   cmdl_param_list_set_name(ipv4,​ "​ipv4"​);​
-  ​cmdl_param_list_set_descr(ipv4, "Set the IP adress and netmask (IPv4)"​);​+  ​cmdl_param_list_set_desc(ipv4, "Set the IP adress and netmask (IPv4)"​);​
  
   /* Add the parameters with name, type and example value */   /* Add the parameters with name, type and example value */
Line 97: Line 97:
   /* Name and describe the list set */   /* Name and describe the list set */
   cmdl_param_list_set_name(ipv6,​ "​ipv6"​);​   cmdl_param_list_set_name(ipv6,​ "​ipv6"​);​
-  ​cmdl_param_list_set_descr(ipv6, "Set the IP adress (IPv6)"​);​+  ​cmdl_param_list_set_desc(ipv6, "Set the IP adress (IPv6)"​);​
  
   cmdl_param_list_set_add(ipv6,​ "​ip",​ CMDL_IPV6, "​2001:​0db8::​1428:​57ab"​);​   cmdl_param_list_set_add(ipv6,​ "​ip",​ CMDL_IPV6, "​2001:​0db8::​1428:​57ab"​);​
Line 109: Line 109:
   /* Name and describe the list set */   /* Name and describe the list set */
   cmdl_param_list_set_name(view,​ "​view"​);​   cmdl_param_list_set_name(view,​ "​view"​);​
-  ​cmdl_param_list_set_descr(view, "View the IP/​netmask"​);​+  ​cmdl_param_list_set_desc(view, "View the IP/​netmask"​);​
  
   /* (No parameters = view) */   /* (No parameters = view) */
Line 170: Line 170:
 } }
 </​code>​ </​code>​
 +
 +Observe that the output of "help ip" is generated from this implementation.
  
 ==== Structures ==== ==== Structures ====
Line 201: Line 203:
 <code c> <code c>
 typedef struct { typedef struct {
-  int num_sets; +  int num_sets; ​// The number of sets in the list 
-  cmdl_param_list_set* param_list_set;​+  cmdl_param_list_set** param_list_set; ​// An array of list set pointers
 } cmdl_param_list;​ } cmdl_param_list;​
 </​code>​ </​code>​
Line 213: Line 215:
 <code c> <code c>
 typedef struct { typedef struct {
-  char* name; +  char* name;  // Name of the list set (used for identification) 
-  char* desc; +  char* desc;  // Description of the list set (used for the automated help) 
-  int num_params;​ +  int num_params; ​  // The number of parameters 
-  cmdl_param_desc param;+  cmdl_param_desc** param; ​// An array of parameter description pointers
 } cmdl_param_list_set;​ } cmdl_param_list_set;​
 </​code>​ </​code>​
Line 226: Line 228:
 <code c> <code c>
 typedef struct { typedef struct {
-  int type; +  int type; // Parameter type 
-  char* name; +  char* name; // Parameter name 
-  char* example;+  char* example; ​// Example of possible value
 } cmdl_param_desc;​ } cmdl_param_desc;​
 </​code>​ </​code>​
Line 252: Line 254:
 <code c> <code c>
 typedef struct{ typedef struct{
-  char* set_name; +  char* set_name; ​// Name of the set 
-  int num_params;​ +  int num_params; ​// The number of parameters the set contains 
-  cmdl_param** param;+  cmdl_param** param; ​// An array of param pointers
 }cmdl_params;​ }cmdl_params;​
 </​code>​ </​code>​
Line 263: Line 265:
 <code c> <code c>
 typedef struct{ typedef struct{
-  int valid_type;+  int valid_type; ​// Defines the param type (which pointer is valid) 
 + 
 +  // Pointers to available types
  
   int* integer;   int* integer;
Line 296: Line 300:
  
 <​code>​ <​code>​
-cmdl_param_list_set* cmdl_param_list_set_create()+cmdl_param_list_set* cmdl_param_list_set_create();
 </​code>​ </​code>​
  
Line 352: Line 356:
 </​code>​ </​code>​
  
- +==== Concerns ==== 
-ter_list_setlist_set)+Perhaps this implementation would be a bit over the top. I got an email from Michael last week and he suggested, without reading this, that I should use ordinary C-style command structures (int argc, char** argv). That might not be as grandiose, and it would be harder to generate standardized automated help output, but it'd be much easier to implement. With some nice parse helper functions available to the command implementations,​ then perhaps it wouldn'​t be so bad. Hmm...
-</​code>​ +
- +
  
 ===== Status ===== ===== Status =====
  
 The command line is working and accepts input from the user, which it parses and then, at the moment, disregards. The command line is working and accepts input from the user, which it parses and then, at the moment, disregards.

QR Code
QR Code soc:fredrikhultin (generated for current page)