#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);
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 */
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;
}
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);
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)");
}
+
int handle_script_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
{
FILE *script_file;
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,
active_cmd_ctx=cfg_cmd_ctx;
- add_default_dirs();
- initJim2();
-
if (parse_cmdline_args(cfg_cmd_ctx, argc, argv) != ERROR_OK)
return EXIT_FAILURE;
# 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...
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} {