]> git.sur5r.net Git - openocd/commitdiff
work in progress to improve help
authoroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Fri, 11 Jul 2008 15:07:58 +0000 (15:07 +0000)
committeroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Fri, 11 Jul 2008 15:07:58 +0000 (15:07 +0000)
git-svn-id: svn://svn.berlios.de/openocd/trunk@792 b42882b7-edfa-0310-969c-e2dbd0fdcd60

src/helper/Makefile.am
src/helper/command.c
src/helper/configuration.c
src/openocd.c
src/startup.tcl

index 1f3d76b6ec76d35d14fdd645daeffd1c702b1dc7..8a2d472e9057a0ec5d5c752aff9b408b9a90bed2 100644 (file)
@@ -1,4 +1,4 @@
-INCLUDES = $(all_includes)
+INCLUDES = -I$(top_srcdir)/src $(all_includes)
 METASOURCES = AUTO
 AM_CPPFLAGS = -DPKGDATADIR=\"$(pkgdatadir)\" -DPKGLIBDIR=\"$(pkglibdir)\" @CPPFLAGS@
 noinst_LIBRARIES = libhelper.a
index d2abb0c2ab43de4900667606f523f6d14785a6d6..e536cca511ec0dbcef548521eb3414c6fa0bb36a 100644 (file)
@@ -38,6 +38,8 @@
 #include <stdio.h>
 #include <unistd.h>
 
+#include <openocd_tcl.h>
+
 int fast_and_dangerous = 0;
 
 void command_print_help_line(command_context_t* context, struct command_s *command, int indent);
@@ -65,10 +67,9 @@ command_t* register_command(command_context_t *context, command_t *parent, char
        c->children = NULL;
        c->handler = handler;
        c->mode = mode;
-       if (help)
-               c->help = strdup(help);
-       else
-               c->help = NULL;
+       if (!help)
+               help="";
+       c->help = strdup(help);
        c->next = NULL;
        
        /* place command in tree */
@@ -100,7 +101,22 @@ command_t* register_command(command_context_t *context, command_t *parent, char
                        context->commands = c;
                }
        }
+       /* accumulate help text in Tcl helptext list.  */
+    Jim_Obj *helptext=Jim_GetGlobalVariableStr(interp, "ocd_helptext", JIM_ERRMSG);
+       Jim_Obj *cmd_entry=Jim_NewListObj(interp, NULL, 0);
+       
+       Jim_Obj *cmd_list=Jim_NewListObj(interp, NULL, 0);
+
+       /* maximum of two levels :-) */
+       if (c->parent!=NULL)
+       {
+               Jim_ListAppendElement(interp, cmd_list, Jim_NewStringObj(interp, c->parent->name, -1));
+       } 
+       Jim_ListAppendElement(interp, cmd_list, Jim_NewStringObj(interp, c->name, -1));
        
+       Jim_ListAppendElement(interp, cmd_entry, cmd_list);
+       Jim_ListAppendElement(interp, cmd_entry, Jim_NewStringObj(interp, c->help, -1));
+       Jim_ListAppendElement(interp, helptext, cmd_entry);
        return c;
 }
 
index ff8b0272e98137e2fab21a249898453115f91b46..e9a13ead1bb986d5cb3911176efa5a13d56e6cb3 100644 (file)
@@ -106,6 +106,7 @@ FILE *open_file_from_path (char *file, char *mode)
 
 int parse_config_file(struct command_context_s *cmd_ctx)
 {
+       int retval;
        char **cfg;
 
        if (!config_file_names)
@@ -115,7 +116,9 @@ int parse_config_file(struct command_context_s *cmd_ctx)
 
        while (*cfg)
        {
-               command_run_line(cmd_ctx, *cfg);
+               retval=command_run_line(cmd_ctx, *cfg);
+               if (retval!=ERROR_OK)
+                       return retval;
                cfg++;
        }
 
index 1dfe5515ceb577580d3fa88739e192c145ea7849..8cac5530a48b49c1836531d5e1047da48b5dcd99 100644 (file)
@@ -697,10 +697,22 @@ static char* openocd_jim_fgets(char *s, int size, void *cookie)
 void add_jim(const char *name, int (*cmd)(Jim_Interp *interp, int argc, Jim_Obj *const *argv), const char *help)
 {
        Jim_CreateCommand(interp, name, cmd, NULL, NULL);
-       /* FIX!!! add scheme to accumulate help! */
        
+       /* FIX!!! it would be prettier to invoke add_help_text... 
+       accumulate help text in Tcl helptext list.  */
+    Jim_Obj *helptext=Jim_GetGlobalVariableStr(interp, "ocd_helptext", JIM_ERRMSG);
+       Jim_Obj *cmd_entry=Jim_NewListObj(interp, NULL, 0);
+       
+       Jim_Obj *cmd_list=Jim_NewListObj(interp, NULL, 0);
+       Jim_ListAppendElement(interp, cmd_list, Jim_NewStringObj(interp, name, -1));
+       
+       Jim_ListAppendElement(interp, cmd_entry, cmd_list);
+       Jim_ListAppendElement(interp, cmd_entry, Jim_NewStringObj(interp, help, -1));
+       Jim_ListAppendElement(interp, helptext, cmd_entry);
 }
 
+extern const unsigned char filedata_startup[];
+
 void initJim(void)
 {
        Jim_CreateCommand(interp, "openocd", Jim_Command_openocd, NULL, NULL);
@@ -719,13 +731,9 @@ void initJim(void)
        interp->cb_vfprintf = openocd_jim_vfprintf;
        interp->cb_fflush = openocd_jim_fflush;
        interp->cb_fgets = openocd_jim_fgets;
-}
-
-extern const unsigned char filedata_startup[];
-
-/* after command line parsing */
-void initJim2(void)
-{
+       
+       add_default_dirs();
+       
        if (Jim_Eval(interp, filedata_startup)==JIM_ERR)
        {
                LOG_ERROR("Failed to run startup.tcl (embedded into OpenOCD compile time)");
@@ -735,6 +743,7 @@ void initJim2(void)
 }
 
 
+
 int handle_script_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
 {
        FILE *script_file;
@@ -752,7 +761,7 @@ command_context_t *setup_command_handler(void)
        command_context_t *cmd_ctx;
        
        cmd_ctx = command_init();
-
+       
        register_command(cmd_ctx, NULL, "version", handle_version_command,
                                         COMMAND_EXEC, "show OpenOCD version");
        register_command(cmd_ctx, NULL, "daemon_startup", handle_daemon_startup_command, COMMAND_CONFIG, 
@@ -825,10 +834,7 @@ int openocd_main(int argc, char *argv[])
        
        active_cmd_ctx=cfg_cmd_ctx;
        
-       add_default_dirs();
 
-       initJim2();
-       
        if (parse_cmdline_args(cfg_cmd_ctx, argc, argv) != ERROR_OK)
                return EXIT_FAILURE;
        
index acf93be4cf4156731215aaacb1bec28ee4713f81..029c4e4b2964fff661aec9425eedd1bc2ba87faf 100644 (file)
@@ -5,6 +5,20 @@
 # Embedded into OpenOCD executable
 #
 
+
+# Help text list. A list of command + help text pairs.
+#
+# Commands can be more than one word and they are stored
+# as "flash banks" "help text x x x"
+
+global ocd_helptext
+set ocd_helptext {}
+
+proc add_help_text {cmd cmd_help} {
+       global ocd_helptext
+       lappend ocd_helptext [list $cmd $cmd_help]
+}
+
 # Production command
 # FIX!!! need to figure out how to feed back relevant output
 # from e.g. "flash banks" command...
@@ -48,6 +62,20 @@ proc flash args {
        openocd_throw "flash $args"
 }
 
+#Print help text for a command
+proc tcl_help {args} {
+       global ocd_helptext
+       set cmd $args
+       foreach a [lsort $ocd_helptext] {
+               if {[string length $cmd]==0||[string first $cmd $a]!=-1} {
+                       puts [format "%18s - %s" [lindex $a 0] [lindex $a 1]]
+               }
+       }
+}
+
+add_help_text tcl_help "Tcl implementation of help command"
+
+
 # If a fn is unknown to Tcl, we try to execute it as an OpenOCD command
 proc unknown {args} {
        if {[string length $args]>0} {