The following skeletal version of GeneralCommand may be copied and pasted directly from your web-browser into a .cpp program being edited with pico or vi:
int GeneralCommand(char *command, char *arg1, char *arg2, char *arg3) { if (strcmp(command, "ECHO")==0) { printf("command='%s'\n", command); if (arg1!=NULL) printf("arg1='%s'\n", arg1); if (arg2!=NULL) printf("arg2='%s'\n", arg2); if (arg3!=NULL) printf("arg3='%s'\n", arg3); return 1; } return 0; }You do not need to do anything with that function if you don't want to. Adding it should mean that you never have to add anything else to your .cpp files because of any future changes.
Before defining your own command, make sure it is one that the system does not already understand, otherwise it will not work. There are two exceptions. if the SET or SHOW commands are typed with options or parameters that the system does not understand, they too will be passed on to GeneralCommand.
If this function recognises and processes the command it should return 1. If this function can not understand the command, return 0, and the system will do whatever it can with it, probably printing an error message.
The "echo" command is added in the sample below, just so that you see that there is nothing tricky to it.
This function is called for all unrecognised commands, and also if the main option to SET or SHOW is not recognised. So for example if the user types the command "set bedtime=7pm tomorrow", this function will be called with command="SET", arg1="bedtime=7pm", arg3="tomorrow", and arg3="".
If you need to convert any of the arguments from strings to integers,
you can #include
Example of its use:
{ int ok, value;
char *str="0x100";
ok=strtoint(str, value);
if (!ok)
printf("'%s' is not a valid number\n", str);
else
printf("'%s' = %d as a decimal int\n", str, value); }
That program would print 0x100 = 256 as a decimal int.