Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

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);
share|improve this question

closed as unclear what you're asking by Jamal Dec 10 '13 at 0:06

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
I think its a mistake to have two word commands. No other shell I know of has gone in this direction. I would have the "show" command whose first parameter is what it is showing. –  Loki Astari Jan 8 '13 at 23:01