diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 2008-12-18 15:25:27 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 2008-12-18 15:25:27 +0000 |
commit | e41eaa881a1a0ba6645d4a23d1313088c8ccfb7f (patch) | |
tree | 01edbddc5c654a1fb474fbccf56654bf35eadf1b /cpukit/libmisc/shell | |
parent | 2008-12-17 Joel Sherrill <joel.sherrill@oarcorp.com> (diff) | |
download | rtems-e41eaa881a1a0ba6645d4a23d1313088c8ccfb7f.tar.bz2 |
2008-12-18 Sebastian Huber <sebastian.huber@embedded-brains.de>
* libmisc/serdbg/termios_printk.c, libmisc/serdbg/termios_printk.h:
Fixed incompatible return value.
* libmisc/cpuuse/cpuusagereport.c: Changed output format.
* libmisc/Makefile.am, libmisc/monitor/mon-editor.c: New file.
* libmisc/capture/capture-cli.c, libmisc/monitor/mon-command.c,
libmisc/monitor/mon-monitor.c, libmisc/monitor/mon-object.c,
libmisc/monitor/mon-prmisc.c, libmisc/monitor/mon-symbols.c,
libmisc/monitor/monitor.h, libmisc/shell/cat_file.c,
libmisc/shell/cmds.c, libmisc/shell/internal.h,
libmisc/shell/main_help.c, libmisc/shell/shell.c,
libmisc/shell/shell.h, libmisc/shell/shell_cmdset.c,
libmisc/shell/shell_getchar.c, libmisc/shell/str2int.c: Various global
data is now read only. Added 'const' qualifier to many pointer
parameters. It is no longer possible to remove monitor commands.
Moved monitor line editor into a separate file to avoid unnecessary
dependencies.
Diffstat (limited to '')
-rw-r--r-- | cpukit/libmisc/shell/cat_file.c | 2 | ||||
-rw-r--r-- | cpukit/libmisc/shell/cmds.c | 62 | ||||
-rw-r--r-- | cpukit/libmisc/shell/internal.h | 4 | ||||
-rw-r--r-- | cpukit/libmisc/shell/main_help.c | 2 | ||||
-rw-r--r-- | cpukit/libmisc/shell/shell.c | 12 | ||||
-rw-r--r-- | cpukit/libmisc/shell/shell.h | 42 | ||||
-rw-r--r-- | cpukit/libmisc/shell/shell_cmdset.c | 68 | ||||
-rw-r--r-- | cpukit/libmisc/shell/shell_getchar.c | 16 | ||||
-rw-r--r-- | cpukit/libmisc/shell/str2int.c | 2 |
9 files changed, 117 insertions, 93 deletions
diff --git a/cpukit/libmisc/shell/cat_file.c b/cpukit/libmisc/shell/cat_file.c index 91e719aec0..1a5efb4418 100644 --- a/cpukit/libmisc/shell/cat_file.c +++ b/cpukit/libmisc/shell/cat_file.c @@ -18,7 +18,7 @@ #include <stdio.h> -int rtems_shell_cat_file(FILE * out,char * name) { +int rtems_shell_cat_file(FILE * out,const char * name) { FILE * fd; int c; diff --git a/cpukit/libmisc/shell/cmds.c b/cpukit/libmisc/shell/cmds.c index aa63a46a3b..9cb48d9d76 100644 --- a/cpukit/libmisc/shell/cmds.c +++ b/cpukit/libmisc/shell/cmds.c @@ -29,40 +29,48 @@ * with this you can call at all the rtems monitor commands. * Not all work fine but you can show the rtems status and more. *-----------------------------------------------------------*/ -int rtems_shell_main_monitor(int argc,char * argv[]) { - rtems_monitor_command_entry_t *command; +static int rtems_shell_main_monitor(int argc, char **argv) { + const rtems_monitor_command_entry_t *command = NULL; - if ((command=rtems_monitor_command_lookup(rtems_monitor_commands,argc,argv))) - command->command_function(argc, argv, &command->command_arg, 0); + if (argc < 1) { + return 1; + } + + command = rtems_monitor_command_lookup(rtems_monitor_commands, argv [0]); + + if (command == NULL) { + return 1; + } + + command->command_function(argc, argv, &command->command_arg, 0); return 0; } void rtems_shell_register_monitor_commands(void) { - rtems_monitor_command_entry_t *command; - - /* monitor topic */ - command = rtems_monitor_commands; - - while (command) { - /* Exclude EXIT (alias quit)*/ - if (strcmp("exit",command->command)) { - rtems_shell_cmd_t *shell_cmd; - - shell_cmd = (rtems_shell_cmd_t *) malloc(sizeof(rtems_shell_cmd_t)); - shell_cmd->name = command->command; - shell_cmd->topic = "monitor"; - shell_cmd->usage = command->usage; - shell_cmd->command = rtems_shell_main_monitor; - shell_cmd->alias = (rtems_shell_cmd_t *) NULL; - shell_cmd->next = (rtems_shell_cmd_t *) NULL; + /* Monitor topic */ + const rtems_monitor_command_entry_t *e = rtems_monitor_commands; - if (rtems_shell_add_cmd_struct( shell_cmd ) == NULL) { - free( shell_cmd ); - shell_cmd = NULL; - } - } - command = command->next; + while (e != NULL) { + /* Exclude EXIT (alias quit)*/ + if (e->command != NULL && strcmp("exit", e->command) != 0) { + rtems_shell_cmd_t *shell_cmd = + (rtems_shell_cmd_t *) malloc(sizeof(rtems_shell_cmd_t)); + + if (shell_cmd != NULL) { + shell_cmd->name = e->command; + shell_cmd->topic = "monitor"; + shell_cmd->usage = e->usage; + shell_cmd->command = rtems_shell_main_monitor; + shell_cmd->alias = NULL; + shell_cmd->next = NULL; + + if (rtems_shell_add_cmd_struct(shell_cmd) == NULL) { + free(shell_cmd); + } + } + } + e = e->next; } } diff --git a/cpukit/libmisc/shell/internal.h b/cpukit/libmisc/shell/internal.h index c0a9908cdf..1855d0b080 100644 --- a/cpukit/libmisc/shell/internal.h +++ b/cpukit/libmisc/shell/internal.h @@ -15,7 +15,7 @@ struct rtems_shell_topic_tt; typedef struct rtems_shell_topic_tt rtems_shell_topic_t; struct rtems_shell_topic_tt { - char *topic; + const char *topic; rtems_shell_topic_t *next; }; @@ -23,7 +23,7 @@ struct rtems_shell_topic_tt { extern rtems_shell_cmd_t * rtems_shell_first_cmd; extern rtems_shell_topic_t * rtems_shell_first_topic; -rtems_shell_topic_t * rtems_shell_lookup_topic(char * topic); +rtems_shell_topic_t * rtems_shell_lookup_topic(const char *topic); void rtems_shell_register_monitor_commands(void); diff --git a/cpukit/libmisc/shell/main_help.c b/cpukit/libmisc/shell/main_help.c index 01dd35020f..5aa9dc759e 100644 --- a/cpukit/libmisc/shell/main_help.c +++ b/cpukit/libmisc/shell/main_help.c @@ -31,7 +31,7 @@ int rtems_shell_help_cmd( rtems_shell_cmd_t *shell_cmd ) { - char * pc; + const char * pc; int col,line; printf("%-10.10s - ",shell_cmd->name); diff --git a/cpukit/libmisc/shell/shell.c b/cpukit/libmisc/shell/shell.c index a320e46902..0a784ba712 100644 --- a/cpukit/libmisc/shell/shell.c +++ b/cpukit/libmisc/shell/shell.c @@ -939,10 +939,10 @@ bool rtems_shell_main_loop( /* ----------------------------------------------- */ static rtems_status_code rtems_shell_run ( - char *task_name, + const char *task_name, uint32_t task_stacksize, rtems_task_priority task_priority, - char *devname, + const char *devname, int forever, int wait, const char* input, @@ -957,7 +957,7 @@ static rtems_status_code rtems_shell_run ( rtems_shell_env_t *shell_env; rtems_name name; - if ( task_name ) + if ( task_name && strlen(task_name) >= 4) name = rtems_build_name( task_name[0], task_name[1], task_name[2], task_name[3]); else @@ -1010,10 +1010,10 @@ static rtems_status_code rtems_shell_run ( } rtems_status_code rtems_shell_init( - char *task_name, + const char *task_name, uint32_t task_stacksize, rtems_task_priority task_priority, - char *devname, + const char *devname, int forever, int wait ) @@ -1039,7 +1039,7 @@ rtems_status_code rtems_shell_init( } rtems_status_code rtems_shell_script ( - char *task_name, + const char *task_name, uint32_t task_stacksize, rtems_task_priority task_priority, const char* input, diff --git a/cpukit/libmisc/shell/shell.h b/cpukit/libmisc/shell/shell.h index 5509b365bc..fa3ad00cc5 100644 --- a/cpukit/libmisc/shell/shell.h +++ b/cpukit/libmisc/shell/shell.h @@ -54,23 +54,23 @@ extern "C" { #define RTEMS_SHELL_KEYS_F9 (16) #define RTEMS_SHELL_KEYS_F10 (17) -typedef int (*rtems_shell_command_t)(int argc,char * argv[]); +typedef int (*rtems_shell_command_t)(int argc, char **argv); struct rtems_shell_cmd_tt; typedef struct rtems_shell_cmd_tt rtems_shell_cmd_t; struct rtems_shell_cmd_tt { - char *name; - char *usage; - char *topic; + const char *name; + const char *usage; + const char *topic; rtems_shell_command_t command; rtems_shell_cmd_t *alias; rtems_shell_cmd_t *next; }; typedef struct { - char *name; - char *alias; + const char *name; + const char *alias; } rtems_shell_alias_t; /* @@ -79,22 +79,22 @@ typedef struct { */ unsigned int rtems_shell_getchar(FILE *in); -rtems_shell_cmd_t * rtems_shell_lookup_cmd(char * cmd); +rtems_shell_cmd_t * rtems_shell_lookup_cmd(const char *cmd); rtems_shell_cmd_t *rtems_shell_add_cmd_struct( rtems_shell_cmd_t *shell_cmd ); rtems_shell_cmd_t * rtems_shell_add_cmd( - char *cmd, - char *topic, - char *usage, + const char *cmd, + const char *topic, + const char *usage, rtems_shell_command_t command ); rtems_shell_cmd_t * rtems_shell_alias_cmd( - char *cmd, - char *alias + const char *cmd, + const char *alias ); int rtems_shell_make_args( @@ -113,7 +113,7 @@ int rtems_shell_scanline( int rtems_shell_cat_file( FILE *out, - char *name + const char *name ); void rtems_shell_write_file( @@ -122,8 +122,8 @@ void rtems_shell_write_file( ); int rtems_shell_script_file( - int argc, - char *argv[] + int argc, + char **argv ); /** @@ -138,10 +138,10 @@ int rtems_shell_script_file( * */ rtems_status_code rtems_shell_init( - char *task_name, + const char *task_name, uint32_t task_stacksize, /*0 default*/ rtems_task_priority task_priority, - char *devname, + const char *devname, int forever, int wait ); @@ -160,7 +160,7 @@ rtems_status_code rtems_shell_init( * @param wait Wait for the script to finish. */ rtems_status_code rtems_shell_script( - char *task_name, + const char *task_name, uint32_t task_stacksize, /*0 default*/ rtems_task_priority task_priority, const char *input, @@ -174,12 +174,12 @@ rtems_status_code rtems_shell_script( * Things that are useful to external entities developing commands and plugging * them in. */ -int rtems_shell_str2int(char * s); +int rtems_shell_str2int(const char * s); typedef struct { rtems_name magic; /* 'S','E','N','V': Shell Environment */ - char *devname; - char *taskname; + const char *devname; + const char *taskname; /* user extensions */ bool exit_shell; /* logout */ bool forever ; /* repeat login */ diff --git a/cpukit/libmisc/shell/shell_cmdset.c b/cpukit/libmisc/shell/shell_cmdset.c index 124296de0c..8f6aa4fdbf 100644 --- a/cpukit/libmisc/shell/shell_cmdset.c +++ b/cpukit/libmisc/shell/shell_cmdset.c @@ -50,7 +50,7 @@ rtems_shell_topic_t * rtems_shell_first_topic; /* * Find the topic from the set of topics registered. */ -rtems_shell_topic_t * rtems_shell_lookup_topic(char * topic) { +rtems_shell_topic_t * rtems_shell_lookup_topic(const char * topic) { rtems_shell_topic_t * shell_topic; shell_topic=rtems_shell_first_topic; @@ -65,7 +65,7 @@ rtems_shell_topic_t * rtems_shell_lookup_topic(char * topic) { /* * Add a new topic to the list of topics */ -rtems_shell_topic_t * rtems_shell_add_topic(char * topic) { +rtems_shell_topic_t * rtems_shell_add_topic(const char * topic) { rtems_shell_topic_t * current,*aux; if (!rtems_shell_first_topic) { @@ -93,7 +93,7 @@ rtems_shell_topic_t * rtems_shell_add_topic(char * topic) { /* * Find the command in the set */ -rtems_shell_cmd_t * rtems_shell_lookup_cmd(char * cmd) { +rtems_shell_cmd_t * rtems_shell_lookup_cmd(const char * cmd) { rtems_shell_cmd_t * shell_cmd; shell_cmd=rtems_shell_first_cmd; while (shell_cmd) { @@ -136,33 +136,49 @@ rtems_shell_cmd_t *rtems_shell_add_cmd_struct( * allocate the command structure on the fly. */ rtems_shell_cmd_t * rtems_shell_add_cmd( - char *cmd, - char *topic, - char *usage, + const char *name, + const char *topic, + const char *usage, rtems_shell_command_t command ) { - rtems_shell_cmd_t *shell_cmd; + rtems_shell_cmd_t *shell_cmd = NULL; + char *my_name = NULL; + char *my_topic = NULL; + char *my_usage = NULL; + + /* Reject empty commands */ + if (name == NULL || command == NULL) { + return NULL; + } + + /* Allocate command stucture */ + shell_cmd = (rtems_shell_cmd_t *) malloc(sizeof(rtems_shell_cmd_t)); + if (shell_cmd == NULL) { + return NULL; + } - if (!cmd) - return (rtems_shell_cmd_t *) NULL; - if (!command) - return (rtems_shell_cmd_t *) NULL; + /* Allocate strings */ + my_name = strdup(name); + my_topic = strdup(topic); + my_usage = strdup(usage); - shell_cmd = (rtems_shell_cmd_t *) malloc(sizeof(rtems_shell_cmd_t)); - shell_cmd->name = strdup( cmd ); - shell_cmd->topic = strdup( topic ); - shell_cmd->usage = strdup( usage ); + /* Assign values */ + shell_cmd->name = my_name; + shell_cmd->topic = my_topic; + shell_cmd->usage = my_usage; shell_cmd->command = command; - shell_cmd->alias = (rtems_shell_cmd_t *) NULL; - shell_cmd->next = (rtems_shell_cmd_t *) NULL; - - if (rtems_shell_add_cmd_struct( shell_cmd ) == NULL) { - free( shell_cmd->usage ); - free( shell_cmd->topic ); - free( shell_cmd->name ); - free( shell_cmd ); - shell_cmd = NULL; + shell_cmd->alias = NULL; + shell_cmd->next = NULL; + + if (rtems_shell_add_cmd_struct(shell_cmd) == NULL) { + /* Something is wrong, free allocated resources */ + free(my_usage); + free(my_topic); + free(my_name); + free(shell_cmd); + + return NULL; } return shell_cmd; @@ -189,8 +205,8 @@ void rtems_shell_initialize_command_set(void) * you can make an alias for every command. * ----------------------------------------------- */ rtems_shell_cmd_t *rtems_shell_alias_cmd( - char *cmd, - char *alias + const char *cmd, + const char *alias ) { rtems_shell_cmd_t *shell_cmd, *shell_aux; diff --git a/cpukit/libmisc/shell/shell_getchar.c b/cpukit/libmisc/shell/shell_getchar.c index 53b80dd953..b214a9511f 100644 --- a/cpukit/libmisc/shell/shell_getchar.c +++ b/cpukit/libmisc/shell/shell_getchar.c @@ -41,29 +41,29 @@ struct translation_table { char expecting; - struct translation_table *branch; + const struct translation_table *branch; unsigned int key; }; -static struct translation_table trans_one[] = +static const struct translation_table trans_one[] = { { '\x7e', 0, RTEMS_SHELL_KEYS_HOME }, { 0, 0, 0 } }; -static struct translation_table trans_two[] = +static const struct translation_table trans_two[] = { { '~', 0, RTEMS_SHELL_KEYS_INS }, { 0, 0, 0 } }; -static struct translation_table trans_three[] = +static const struct translation_table trans_three[] = { { '~', 0, RTEMS_SHELL_KEYS_DEL }, { 0, 0, 0 } }; -static struct translation_table trans_tab_csi[] = +static const struct translation_table trans_tab_csi[] = { { '1', trans_one, 0 }, { '2', trans_two, 0 }, @@ -77,7 +77,7 @@ static struct translation_table trans_tab_csi[] = { 0, 0, 0 } }; -static struct translation_table trans_tab_O[] = +static const struct translation_table trans_tab_O[] = { { '1', 0, RTEMS_SHELL_KEYS_F1 }, { '2', 0, RTEMS_SHELL_KEYS_F2 }, @@ -103,7 +103,7 @@ static struct translation_table trans_tab_O[] = { 0, 0, 0 } }; -static struct translation_table trans_tab[] = +static const struct translation_table trans_tab[] = { { '[', trans_tab_csi, 0 }, /* CSI command sequences */ { 'O', trans_tab_O, 0 }, /* O are the fuction keys */ @@ -120,7 +120,7 @@ static struct translation_table trans_tab[] = unsigned int rtems_shell_getchar (FILE *in) { - struct translation_table *translation = 0; + const struct translation_table *translation = 0; for (;;) { int c = fgetc (in); diff --git a/cpukit/libmisc/shell/str2int.c b/cpukit/libmisc/shell/str2int.c index a569772bb6..ee02f74bf3 100644 --- a/cpukit/libmisc/shell/str2int.c +++ b/cpukit/libmisc/shell/str2int.c @@ -21,7 +21,7 @@ /* * str to int "0xaffe" "0b010010" "0123" "192939" */ -int rtems_shell_str2int(char * s) { +int rtems_shell_str2int(const char * s) { int sign=1; int base=10; int value=0; |