Fell asleep before committing these, oops.

Cut menu entry return type down to int8_t, make menu command checks case-insensitive.

Fixes issue #135

git-svn-id: https://arducopter.googlecode.com/svn/trunk@553 f9c3cf11-9bcb-44bc-f272-b75c42450872
This commit is contained in:
DrZiplok@gmail.com 2010-09-25 18:02:41 +00:00
parent 8708675b1f
commit 4b09c9fade
2 changed files with 8 additions and 7 deletions

View File

@ -19,7 +19,7 @@ public:
/// menu command function
///
typedef int (*func)(uint8_t argc, const struct arg *argv);
typedef int8_t (*func)(uint8_t argc, const struct arg *argv);
/// menu pre-prompt function
///
@ -42,7 +42,7 @@ public:
/// name will always be in argv[0].
/// Commands may return -2 to cause the menu itself to exit.
/// The "?", "help" and "exit" commands are always defined.
int (*func)(uint8_t argc, const struct arg *argv); ///< callback function
int8_t (*func)(uint8_t argc, const struct arg *argv); ///< callback function
};
/// constructor
@ -66,7 +66,7 @@ private:
/// @param n Index for the menu item to call
/// @param argc Number of arguments prepared for the menu item
///
int _call(uint8_t n, uint8_t argc);
int8_t _call(uint8_t n, uint8_t argc);
const char *_prompt; ///< prompt to display
const command *_commands; ///< array of commands

View File

@ -75,6 +75,7 @@ Menu::run(void)
// split the input line into tokens
argc = 0;
_argv[argc++].str = strtok(_inbuf, " ");
// XXX should an empty line by itself back out of the current menu?
while (argc <= MENU_ARGS_MAX) {
_argv[argc].str = strtok(NULL, " ");
if ('\0' == _argv[argc].str)
@ -86,7 +87,7 @@ Menu::run(void)
// look for a command matching the first word (note that it may be empty)
for (i = 0; i < _entries; i++) {
if (!strcmp_P(_argv[0].str, _commands[i].command)) {
if (!strcasecmp_P(_argv[0].str, _commands[i].command)) {
ret = _call(i, argc);
if (-2 == ret)
return;
@ -96,9 +97,9 @@ Menu::run(void)
// implicit commands
if (i == _entries) {
if (!strcmp(_argv[0].str, "?") || (!strcmp_P(_argv[0].str, PSTR("help")))) {
if (!strcmp(_argv[0].str, "?") || (!strcasecmp_P(_argv[0].str, PSTR("help")))) {
_help();
} else if (!strcmp_P(_argv[0].str, PSTR("exit"))) {
} else if (!strcasecmp_P(_argv[0].str, PSTR("exit"))) {
return;
}
}
@ -117,7 +118,7 @@ Menu::_help(void)
}
// run the n'th command in the menu
int
int8_t
Menu::_call(uint8_t n, uint8_t argc)
{
func fn;