Tell me more ×
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. say for e.g.

-#version      //single word cmd

-#show input pressure  
-#show input temp

The above 2 cmds can fall under "show input"

In the current algorithm, on splitting the input string to tokens ,I see that if its 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 cmds 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 cmd .etc .

How to improve this algorithm ? Please suggest me if there is a better algorithm. Thanks. "This Code is not fully complete." Im 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
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 at 23:01

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.