work in progress to improve help
git-svn-id: svn://svn.berlios.de/openocd/trunk@792 b42882b7-edfa-0310-969c-e2dbd0fdcd60__archive__
parent
c5b718f5e8
commit
69c6f1f7ea
|
@ -1,4 +1,4 @@
|
||||||
INCLUDES = $(all_includes)
|
INCLUDES = -I$(top_srcdir)/src $(all_includes)
|
||||||
METASOURCES = AUTO
|
METASOURCES = AUTO
|
||||||
AM_CPPFLAGS = -DPKGDATADIR=\"$(pkgdatadir)\" -DPKGLIBDIR=\"$(pkglibdir)\" @CPPFLAGS@
|
AM_CPPFLAGS = -DPKGDATADIR=\"$(pkgdatadir)\" -DPKGLIBDIR=\"$(pkglibdir)\" @CPPFLAGS@
|
||||||
noinst_LIBRARIES = libhelper.a
|
noinst_LIBRARIES = libhelper.a
|
||||||
|
|
|
@ -38,6 +38,8 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <openocd_tcl.h>
|
||||||
|
|
||||||
int fast_and_dangerous = 0;
|
int fast_and_dangerous = 0;
|
||||||
|
|
||||||
void command_print_help_line(command_context_t* context, struct command_s *command, int indent);
|
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->children = NULL;
|
||||||
c->handler = handler;
|
c->handler = handler;
|
||||||
c->mode = mode;
|
c->mode = mode;
|
||||||
if (help)
|
if (!help)
|
||||||
c->help = strdup(help);
|
help="";
|
||||||
else
|
c->help = strdup(help);
|
||||||
c->help = NULL;
|
|
||||||
c->next = NULL;
|
c->next = NULL;
|
||||||
|
|
||||||
/* place command in tree */
|
/* place command in tree */
|
||||||
|
@ -100,7 +101,22 @@ command_t* register_command(command_context_t *context, command_t *parent, char
|
||||||
context->commands = c;
|
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;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -106,6 +106,7 @@ FILE *open_file_from_path (char *file, char *mode)
|
||||||
|
|
||||||
int parse_config_file(struct command_context_s *cmd_ctx)
|
int parse_config_file(struct command_context_s *cmd_ctx)
|
||||||
{
|
{
|
||||||
|
int retval;
|
||||||
char **cfg;
|
char **cfg;
|
||||||
|
|
||||||
if (!config_file_names)
|
if (!config_file_names)
|
||||||
|
@ -115,7 +116,9 @@ int parse_config_file(struct command_context_s *cmd_ctx)
|
||||||
|
|
||||||
while (*cfg)
|
while (*cfg)
|
||||||
{
|
{
|
||||||
command_run_line(cmd_ctx, *cfg);
|
retval=command_run_line(cmd_ctx, *cfg);
|
||||||
|
if (retval!=ERROR_OK)
|
||||||
|
return retval;
|
||||||
cfg++;
|
cfg++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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)
|
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);
|
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)
|
void initJim(void)
|
||||||
{
|
{
|
||||||
Jim_CreateCommand(interp, "openocd", Jim_Command_openocd, NULL, NULL);
|
Jim_CreateCommand(interp, "openocd", Jim_Command_openocd, NULL, NULL);
|
||||||
|
@ -719,13 +731,9 @@ void initJim(void)
|
||||||
interp->cb_vfprintf = openocd_jim_vfprintf;
|
interp->cb_vfprintf = openocd_jim_vfprintf;
|
||||||
interp->cb_fflush = openocd_jim_fflush;
|
interp->cb_fflush = openocd_jim_fflush;
|
||||||
interp->cb_fgets = openocd_jim_fgets;
|
interp->cb_fgets = openocd_jim_fgets;
|
||||||
}
|
|
||||||
|
|
||||||
extern const unsigned char filedata_startup[];
|
add_default_dirs();
|
||||||
|
|
||||||
/* after command line parsing */
|
|
||||||
void initJim2(void)
|
|
||||||
{
|
|
||||||
if (Jim_Eval(interp, filedata_startup)==JIM_ERR)
|
if (Jim_Eval(interp, filedata_startup)==JIM_ERR)
|
||||||
{
|
{
|
||||||
LOG_ERROR("Failed to run startup.tcl (embedded into OpenOCD compile time)");
|
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)
|
int handle_script_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
|
||||||
{
|
{
|
||||||
FILE *script_file;
|
FILE *script_file;
|
||||||
|
@ -825,9 +834,6 @@ int openocd_main(int argc, char *argv[])
|
||||||
|
|
||||||
active_cmd_ctx=cfg_cmd_ctx;
|
active_cmd_ctx=cfg_cmd_ctx;
|
||||||
|
|
||||||
add_default_dirs();
|
|
||||||
|
|
||||||
initJim2();
|
|
||||||
|
|
||||||
if (parse_cmdline_args(cfg_cmd_ctx, argc, argv) != ERROR_OK)
|
if (parse_cmdline_args(cfg_cmd_ctx, argc, argv) != ERROR_OK)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
|
@ -5,6 +5,20 @@
|
||||||
# Embedded into OpenOCD executable
|
# 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
|
# Production command
|
||||||
# FIX!!! need to figure out how to feed back relevant output
|
# FIX!!! need to figure out how to feed back relevant output
|
||||||
# from e.g. "flash banks" command...
|
# from e.g. "flash banks" command...
|
||||||
|
@ -48,6 +62,20 @@ proc flash args {
|
||||||
openocd_throw "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
|
# If a fn is unknown to Tcl, we try to execute it as an OpenOCD command
|
||||||
proc unknown {args} {
|
proc unknown {args} {
|
||||||
if {[string length $args]>0} {
|
if {[string length $args]>0} {
|
||||||
|
|
Loading…
Reference in New Issue