[rtems commit] libmisc/shell: Make some internal shell functions public.

Chris Johns chrisj at rtems.org
Tue Aug 15 01:38:18 UTC 2017


Module:    rtems
Branch:    master
Commit:    2465c0130b861c013afa44145e7d2019f05f2bc0
Changeset: http://git.rtems.org/rtems/commit/?id=2465c0130b861c013afa44145e7d2019f05f2bc0

Author:    Chris Johns <chrisj at rtems.org>
Date:      Mon Aug 14 14:50:55 2017 +1000

libmisc/shell: Make some internal shell functions public.

- Add 'rtems_shell_init_environment()' so a user can create the
  shell environment without needing to run a shell.
- Move 'rtems_shell_lookup_topic', 'rtems_shell_can_see_cmd',
  and 'rtems_shell_execute_cmd' from the internal interface to
  the public interface.

Closes #3096.

---

 cpukit/libmisc/shell/internal.h | 15 ---------------
 cpukit/libmisc/shell/shell.c    | 11 +++++++----
 cpukit/libmisc/shell/shell.h    | 28 ++++++++++++++++++++++++++++
 3 files changed, 35 insertions(+), 19 deletions(-)

diff --git a/cpukit/libmisc/shell/internal.h b/cpukit/libmisc/shell/internal.h
index 56b1bb6..31df89d 100644
--- a/cpukit/libmisc/shell/internal.h
+++ b/cpukit/libmisc/shell/internal.h
@@ -11,24 +11,9 @@
 
 #include "shell.h"
 
-struct rtems_shell_topic_tt;
-typedef struct rtems_shell_topic_tt rtems_shell_topic_t;
-
-struct rtems_shell_topic_tt {
-  const char          *topic;
-  rtems_shell_topic_t *next;
-};
-
-
 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(const char *topic);
-
-bool rtems_shell_can_see_cmd(const rtems_shell_cmd_t *shell_cmd);
-
-int rtems_shell_execute_cmd(const char *cmd, int argc, char *argv[]);
-
 extern void rtems_shell_register_monitor_commands(void);
 
 extern void rtems_shell_print_heap_info(
diff --git a/cpukit/libmisc/shell/shell.c b/cpukit/libmisc/shell/shell.c
index e7e5793..5f042f5 100644
--- a/cpukit/libmisc/shell/shell.c
+++ b/cpukit/libmisc/shell/shell.c
@@ -147,6 +147,12 @@ static void rtems_shell_init_once(void)
                           "running on %m\n");
 
   rtems_shell_init_commands();
+  rtems_shell_register_monitor_commands();
+}
+
+void rtems_shell_init_environment(void)
+{
+  assert(pthread_once(&rtems_shell_once, rtems_shell_init_once) == 0);
 }
 
 /*
@@ -721,10 +727,7 @@ bool rtems_shell_main_loop(
   FILE              *stdinToClose = NULL;
   FILE              *stdoutToClose = NULL;
 
-  eno = pthread_once(&rtems_shell_once, rtems_shell_init_once);
-  assert(eno == 0);
-
-  rtems_shell_register_monitor_commands();
+  rtems_shell_init_environment();
 
   shell_env = rtems_shell_init_env(shell_env_arg);
   if (shell_env == NULL) {
diff --git a/cpukit/libmisc/shell/shell.h b/cpukit/libmisc/shell/shell.h
index 4d545d6..98ddf0a 100644
--- a/cpukit/libmisc/shell/shell.h
+++ b/cpukit/libmisc/shell/shell.h
@@ -94,6 +94,14 @@ typedef struct {
   const char *alias;
 } rtems_shell_alias_t;
 
+struct rtems_shell_topic_tt;
+typedef struct rtems_shell_topic_tt rtems_shell_topic_t;
+
+struct rtems_shell_topic_tt {
+  const char          *topic;
+  rtems_shell_topic_t *next;
+};
+
 /*
  * The return value has RTEMS_SHELL_KEYS_EXTENDED set if the key
  * is extended, ie a special key.
@@ -125,6 +133,26 @@ extern int rtems_shell_make_args(
   int    max_args
 );
 
+extern rtems_shell_topic_t * rtems_shell_lookup_topic(
+  const char *topic
+);
+
+extern bool rtems_shell_can_see_cmd(
+  const rtems_shell_cmd_t *shell_cmd
+);
+
+extern int rtems_shell_execute_cmd(
+  const char *cmd, int argc, char *argv[]
+);
+
+/*
+ * Call to set up the shell environment if you need to execute commands before
+ * running a shell.
+ */
+extern void rtems_shell_init_environment(
+  void
+);
+
 extern int rtems_shell_cat_file(
   FILE *out,
   const char *name




More information about the vc mailing list