Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
soc:fredrikhultin [2006/07/11 23:33] noname |
soc:fredrikhultin [2006/07/12 00:24] (current) noname |
||
---|---|---|---|
Line 7: | Line 7: | ||
===== Design ===== | ===== Design ===== | ||
+ | |||
==== User interface ==== | ==== User interface ==== | ||
Line 12: | Line 13: | ||
<file> | <file> | ||
+ | Welcome to Etherboot | ||
+ | |||
?>help | ?>help | ||
Line 80: | 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 94: | 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 106: | 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 116: | Line 119: | ||
/* Add the three list sets to the parameter list */ | /* Add the three list sets to the parameter list */ | ||
- | cmdl_param_list_add(ipv4); | + | cmdl_param_list_add(param_list, ipv4); |
- | cmdl_param_list_add(ipv6); | + | cmdl_param_list_add(param_list, ipv6); |
- | cmdl_param_list_add(view); | + | cmdl_param_list_add(param_list, view); |
/* Return the parameter list to the command line */ | /* Return the parameter list to the command line */ | ||
Line 167: | Line 170: | ||
} | } | ||
</code> | </code> | ||
+ | |||
+ | Observe that the output of "help ip" is generated from this implementation. | ||
==== Structures ==== | ==== Structures ==== | ||
Line 198: | 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 210: | 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 223: | 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 249: | 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 260: | 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 278: | Line 285: | ||
typedef struct{ | typedef struct{ | ||
- | unsigned short int part[8]; | + | unsigned short int part[ |
+ | |||
+ | 8]; | ||
}cmdl_ipv6; | }cmdl_ipv6; | ||
Line 291: | 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 327: | Line 336: | ||
<code> | <code> | ||
- | void cmdl_param_list_add(cmdl_param_list* param_list, cmdl_parameter_list_set* list_set); | + | void cmdl_param_list_add(cmdl_param_list* param_list, cmdl_param |
</code> | </code> | ||
+ | === cmdl_printf === | ||
+ | Prints formated text to a given command line. | ||
+ | |||
+ | <code> | ||
+ | int cmdl_printf(cmd_line* cmd, const char *format, ...); | ||
+ | </code> | ||
+ | |||
+ | === cmdl_param_get_TYPE === | ||
+ | Returns the given parameter from a cmdl_params as TYPE. | ||
+ | Rturns NULL if the parameter isn't a TYPE. | ||
+ | |||
+ | <code> | ||
+ | int *cmdl_param_get_int(cmdl_params* params, int param_num); | ||
+ | cmdl_ipv4 *cmdl_param_get_ipv4(cmdl_params* params, int param_num); | ||
+ | ... | ||
+ | </code> | ||
+ | ==== Concerns ==== | ||
+ | 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... | ||
===== 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. |