From 4b09c9fadee1ceeb0f508bf103a8f0aeb17bcab8 Mon Sep 17 00:00:00 2001 From: "DrZiplok@gmail.com" Date: Sat, 25 Sep 2010 18:02:41 +0000 Subject: [PATCH] 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 --- libraries/AP_Common/include/menu.h | 6 +++--- libraries/AP_Common/menu.cpp | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/libraries/AP_Common/include/menu.h b/libraries/AP_Common/include/menu.h index e74803c786..1e2fdd0a52 100644 --- a/libraries/AP_Common/include/menu.h +++ b/libraries/AP_Common/include/menu.h @@ -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 diff --git a/libraries/AP_Common/menu.cpp b/libraries/AP_Common/menu.cpp index 1219a6ce45..56d7fd56e6 100644 --- a/libraries/AP_Common/menu.cpp +++ b/libraries/AP_Common/menu.cpp @@ -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;