diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2008-12-19 14:59:35 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2008-12-19 14:59:35 +0000 |
commit | eb961961837bd288fb57799c189326fc944047b5 (patch) | |
tree | e857eea22b553b5288811467a2089ab87ad368ad /cpukit/libmisc/monitor | |
parent | 2008-12-18 Joel Sherrill <joel.sherrill@oarcorp.com> (diff) | |
download | rtems-eb961961837bd288fb57799c189326fc944047b5.tar.bz2 |
2008-12-19 Sebastian Huber <sebastian.huber@embedded-brains.de>
* libblock/src/ide_part_table.c: Fixed NULL pointer access.
* libmisc/monitor/mon-command.c, libmisc/monitor/mon-editor.c,
libmisc/monitor/mon-monitor.c, libmisc/monitor/monitor.h,
libmisc/shell/cmds.c: The list of registered monitor commands is now
private and only accessible via a lookup and iterate function.
Diffstat (limited to 'cpukit/libmisc/monitor')
-rw-r--r-- | cpukit/libmisc/monitor/mon-command.c | 95 | ||||
-rw-r--r-- | cpukit/libmisc/monitor/mon-editor.c | 10 | ||||
-rw-r--r-- | cpukit/libmisc/monitor/mon-monitor.c | 26 | ||||
-rw-r--r-- | cpukit/libmisc/monitor/monitor.h | 8 |
4 files changed, 83 insertions, 56 deletions
diff --git a/cpukit/libmisc/monitor/mon-command.c b/cpukit/libmisc/monitor/mon-command.c index e5ee6aee53..bd4a6a8277 100644 --- a/cpukit/libmisc/monitor/mon-command.c +++ b/cpukit/libmisc/monitor/mon-command.c @@ -24,49 +24,6 @@ #include <rtems.h> #include <rtems/monitor.h> -/* - * Look up a command in a command table - * - */ - -const rtems_monitor_command_entry_t *rtems_monitor_command_lookup( - const rtems_monitor_command_entry_t *table, - const char *command_name -) -{ - const rtems_monitor_command_entry_t *found_it = NULL; - size_t command_length = 0; - - if (command_name == NULL) { - return NULL; - } - - command_length = strlen(command_name); - - while (table != NULL) { - if (table->command != NULL) { - /* Check for ambiguity */ - if (!strncmp(table->command, command_name, command_length)) { - if (found_it == NULL) { - found_it = table; - } else { - return NULL; - } - } - } - table = table->next; - } - - /* No ambiguity (the possible partial command was unique after all) */ - - /* Ignore empty commands */ - if (found_it == NULL || found_it->command_function == NULL) { - return NULL; - } - - return found_it; -} - static void rtems_monitor_show_help ( const rtems_monitor_command_entry_t *help_cmd, @@ -173,7 +130,7 @@ rtems_monitor_command_usage( if (command_name && (*command_name != '\0')) { - command = rtems_monitor_command_lookup (table, command_name); + command = rtems_monitor_command_lookup (command_name); if (command) rtems_monitor_show_help (command, strlen (command_name)); @@ -231,3 +188,53 @@ void rtems_monitor_help_cmd( rtems_monitor_command_usage(command, argv[arg]); } } + +typedef struct { + const char *name; + size_t length; + const rtems_monitor_command_entry_t *match; +} rtems_monitor_command_lookup_entry; + +static bool rtems_monitor_command_lookup_routine( + const rtems_monitor_command_entry_t *e, + void *arg +) +{ + rtems_monitor_command_lookup_entry *le = + (rtems_monitor_command_lookup_entry *) arg; + + /* Check name */ + if (strncmp(e->command, le->name, le->length) == 0) { + /* Check for ambiguity */ + if (le->match == NULL) { + le->match = e; + } else { + return false; + } + } + + return true; +} + +/** + * @brief Looks for a command with the name @a name in the list of registered + * commands. + * + * The parameter @a name must not be NULL. + * + * Returns the corresponding command entry or NULL if no command is found. + */ +const rtems_monitor_command_entry_t *rtems_monitor_command_lookup( + const char *name +) +{ + rtems_monitor_command_lookup_entry e = { + .name = name, + .length = strlen( name), + .match = NULL + }; + + rtems_monitor_command_iterate(rtems_monitor_command_lookup_routine, &e); + + return e.match; +} diff --git a/cpukit/libmisc/monitor/mon-editor.c b/cpukit/libmisc/monitor/mon-editor.c index c204e2716c..de10a02317 100644 --- a/cpukit/libmisc/monitor/mon-editor.c +++ b/cpukit/libmisc/monitor/mon-editor.c @@ -597,12 +597,10 @@ rtems_monitor_task( if (0 == rtems_monitor_command_read(command_buffer, &argc, argv)) continue; if (argc < 1 - || (command = rtems_monitor_command_lookup(rtems_monitor_commands, - argv [0])) == 0) - { - /* no command */ - fprintf(stdout,"Unrecognised command; try 'help'\n"); - continue; + || (command = rtems_monitor_command_lookup(argv [0])) == 0) { + /* no command */ + fprintf(stdout,"Unrecognised command; try 'help'\n"); + continue; } command->command_function(argc, argv, &command->command_arg, verbose); diff --git a/cpukit/libmisc/monitor/mon-monitor.c b/cpukit/libmisc/monitor/mon-monitor.c index 06f72e0f04..f60c9a33ed 100644 --- a/cpukit/libmisc/monitor/mon-monitor.c +++ b/cpukit/libmisc/monitor/mon-monitor.c @@ -60,7 +60,7 @@ rtems_symbol_table_t *rtems_monitor_symbols; * The top-level commands */ -const rtems_monitor_command_entry_t rtems_monitor_commands[] = { +static const rtems_monitor_command_entry_t rtems_monitor_commands[] = { { "config", "Show the system configuration.", 0, @@ -480,3 +480,27 @@ rtems_monitor_insert_cmd ( return 1; } + +/** + * @brief Iterates through all registerd commands. + * + * For each command the interation routine @a routine is called with the + * command entry and the user provided argument @a arg. It is guaranteed that + * the command name and function are not NULL. + */ +void rtems_monitor_command_iterate( + rtems_monitor_per_command_routine routine, + void *arg +) +{ + const rtems_monitor_command_entry_t *e = rtems_monitor_registered_commands; + + while (e != NULL) { + if (e->command != NULL && e->command_function != NULL) { + if (!routine(e, arg)) { + break; + } + } + e = e->next; + } +} diff --git a/cpukit/libmisc/monitor/monitor.h b/cpukit/libmisc/monitor/monitor.h index 28e6831834..bb7d5aafd7 100644 --- a/cpukit/libmisc/monitor/monitor.h +++ b/cpukit/libmisc/monitor/monitor.h @@ -368,6 +368,7 @@ typedef struct { rtems_monitor_object_dump_fn dump; } rtems_monitor_object_info_t; +typedef bool (*rtems_monitor_per_command_routine)(const rtems_monitor_command_entry_t *, void *); /* monitor.c */ void rtems_monitor_pause_cmd(int, char **, const rtems_monitor_command_arg_t*, bool); @@ -377,8 +378,8 @@ void rtems_monitor_debugger_cmd(int, char **, const rtems_monitor_command_arg void rtems_monitor_node_cmd(int, char **, const rtems_monitor_command_arg_t*, bool); void rtems_monitor_symbols_loadup(void); int rtems_monitor_insert_cmd(rtems_monitor_command_entry_t *); -int rtems_monitor_erase_cmd(rtems_monitor_command_entry_t *); void rtems_monitor_wakeup(void); +void rtems_monitor_command_iterate(rtems_monitor_per_command_routine routine, void *arg); rtems_status_code rtems_monitor_suspend(rtems_interval timeout); /* editor.c */ @@ -395,9 +396,9 @@ void rtems_monitor_server_init(uint32_t ); /* command.c */ int rtems_monitor_make_argv(char *, int *, char **); int rtems_monitor_command_read(char *, int *, char **); -const rtems_monitor_command_entry_t *rtems_monitor_command_lookup(const rtems_monitor_command_entry_t *table, const char *command_name); void rtems_monitor_command_usage(const rtems_monitor_command_entry_t *, const char *); void rtems_monitor_help_cmd(int, char **, const rtems_monitor_command_arg_t *, bool); +const rtems_monitor_command_entry_t *rtems_monitor_command_lookup(const char *name); /* prmisc.c */ void rtems_monitor_separator(void); @@ -519,9 +520,6 @@ const rtems_monitor_object_info_t *rtems_monitor_object_lookup( /* shared data */ extern rtems_symbol_table_t *rtems_monitor_symbols; -/* FIXME: This should not be here */ -extern const rtems_monitor_command_entry_t rtems_monitor_commands[]; - #define MONITOR_WAKEUP_EVENT RTEMS_EVENT_0 #ifdef __cplusplus |