The below program takes the inputted string from commandline and parses it and calls the corresponding function. Commands are either single word or multiple words.
For example:
-#version //single word cmd
-#show input pressure
-#show input temp
The above 2 commands can fall under "show input."
In the current algorithm, on splitting the input string to tokens, I determine if it's a single word or double word.
If the number of token (strings) are more than 2 then based on the second token (here "input") it searches the second table show_input_command_list[]
and calls the appropriate function.
Some of the other commands are like:
show network ipaddress
show network ipsubnet
show network abcd<#>
set network ipaddress <#>
set network ipsubnet <#>
set network abcd <#> <#>
So I have to add ShowNetwork
to table 1 and create a new table show_network_command_list[]
and add the three other commands.
How could I improve this algorithm?
This code is not fully complete. I'm looking for a better algorithm.
header.h
#define CLI_PROMPT "CMD> "
#define CLI_NOT_FOUND "Command not found\"%s\"\n"
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
void CLI();
uint8 strsplit(const char *s, char **array, char *separator);
int16 strcontains(const char *s, char c);
/* COMMANDS DECLARATIONS */
uint8 clear(uint8 argn, const char **argv);
uint8 version(uint8 argn, const char **argv);
void quit(uint8 argn, const char **argv);
uint8 run(uint8 argn, const char **argv);
//void help(uint8 argn, const char **argv);
int help(int argn, char **argv);
int ShowInput(char argn,const char **argv);
int SystemRun(char argn,const char **argv);
int ShowInputPressure(char argn,const char **argv);
int ShowInputTemp(char argn,const char **argv);