summaryrefslogtreecommitdiff
path: root/src/helper
Commit message (Collapse)AuthorAgeFilesLines
* streamline and document helptext mode displaysDavid Brownell2010-01-021-10/+22
| | | | | | | | | | | | | | | | | | | Most commands are usable only at runtime; so don't bother saying that, it's noise. Moreover, tokens like EXEC are cryptic. Be more clear: highlight only the commands which may (also) be used during the config stage, thus matching the docs more closely. There are - Configuration commands (per documentation) - And also some commands that valid at *any* time. Update the docs to note that "help" now shows this mode info. This also highlighted a few mistakes in command configuration, mostly commands listed as "valid at any time" which shouldn't have been. This just fixes ones I noted when sanity testing. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
* Fix usage/help search for subcommands.Dean Glazeski2010-01-021-7/+34
| | | | | | | | This makes it so that the usage/help command properly uses the whole command, including subcommand, in the search for help information. This previously caused erroneous output from the usage command handler. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
* Add the current command to the command informationDean Glazeski2010-01-021-0/+1
| | | | | | | | | | | I wanted to make it so I can be ignorant of a commands invocation string, so I tried to use CMD_CURRENT (aka cmd->current) which is supposed to house a pointer to the current command.  It turns out that this wasn't being set. This patch adds the current command structure to the command invocation structure before sending it along to the command handler. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
* cygwin 1.7 build fixesDavid Brownell2009-12-261-3/+3
| | | | | | | | | | | It's less accepting of signed char ... insisting that e.g. tolower() not receive one as a parameter. It's probably good to phase out such usage, given the number of bugs that lurk in the vicinity (assumptions that char is unsigned), so fix these even though such usage is actually legal. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
* help: list all commands that match stringOyvind Harboe2009-12-211-21/+35
| | | | | | | Restore behavior where help lists all commands that match string passed to help. Signed-off-by: Oyvind Harboe <oyvind.harboe@zylin.com>
* ecos: crisper implementation of timeval_ms()Øyvind Harboe2009-12-164-13/+87
| | | | | | | A crisper/faster implementation under eCos that makes profiling a tad easier. Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
* command: retire obsolete macroØyvind Harboe2009-12-151-11/+0
| | | | | | | COMMAND_REGISTER() was only used transiently during code conversion. Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
* build: add build/src to include pathØyvind Harboe2009-12-081-0/+1
| | | | | | This allows including generated include files. Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
* misc code review updatesDavid Brownell2009-12-051-4/+3
| | | | | | | | | More updates from the code review by Steve Grubb <sgrubb@redhat.com>. The Jim float-comparision bug just gets a comment not a fix, though. Cc: Steve Grubb <sgrubb@redhat.com>. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
* switch 'rm' command away from using JimZachary T Welch2009-12-041-18/+11
| | | | | Commands that do not need to use Jim should be registered as high-level command handlers.
* doxygen: remove some warningsDavid Brownell2009-12-031-1/+1
| | | | Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
* remove tertiary include pathsZachary T Welch2009-12-031-2/+0
| | | | | With all #include directives converted, we only need to have the top-level src/ directory in the search path.
* change #include "server.h" to <server/server.h>Zachary T Welch2009-12-032-2/+2
| | | | | | | | | | | | Changes from the flat namespace to heirarchical one. Instead of writing: #include "server.h" the following form should be used. #include <server/server.h> The exception is from .c files in the same directory.
* change #include "target.h" to <target/target.h>Zachary T Welch2009-12-031-1/+1
| | | | | | | | | | | | Changes from the flat namespace to heirarchical one. Instead of writing: #include "target.h" the following form should be used. #include <target/target.h> The exception is from .c files in the same directory.
* change #include "types.h" to <helper/types.h>Zachary T Welch2009-12-034-4/+4
| | | | | | | | | | | | Changes from the flat namespace to heirarchical one. Instead of writing: #include "types.h" the following form should be used. #include <helper/types.h> The exception is from .c files in the same directory.
* change #include "jim.h" to <helper/jim.h>Zachary T Welch2009-12-031-1/+1
| | | | | | | | | | | | Changes from the flat namespace to heirarchical one. Instead of writing: #include "jim.h" the following form should be used. #include <helper/jim.h> The exception is from .c files in the same directory.
* change #include "command.h" to <helper/command.h>Zachary T Welch2009-12-032-2/+2
| | | | | | | | | | | | Changes from the flat namespace to heirarchical one. Instead of writing: #include "command.h" the following form should be used. #include <helper/command.h> The exception is from .c files in the same directory.
* allow #include directives to use module nameZachary T Welch2009-12-031-0/+1
| | | | | | | | | | | | Includes the src directory in the search path, so header files may be migrated from: #include "foo.h" to #include <module/foo.h> which is more conducive for installation.
* stubs: buildfixDavid Brownell2009-12-021-0/+1
| | | | | | | | | | | | | | The new stubs for httpd and ioutil gave errors like: ioutil_stubs.c: In function ‘ioutil_init’: ioutil_stubs.c:27: error: implicit declaration of function ‘LOG_DEBUG’ ioutil_stubs.c:28: error: ‘ERROR_OK’ undeclared (first use in this function) ioutil_stubs.c:28: error: (Each undeclared identifier is reported only once ioutil_stubs.c:28: error: for each function it appears in.) Fix. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
* remove BUILD_IOUTIL symbolZachary T Welch2009-12-023-0/+59
| | | | | | | | | | Add ioutil_stubs.c to provide an empty ioutil_init() routine. Add ioutil.h to prevent applications from needing to declare it. Allows unconditionally calling that function during startup, and the resulting libocdhelper library API is now more stable. Prints a DEBUG message when the stub implementation is included.
* command: the Jim interpreter can now be provided rather than createdØyvind Harboe2009-12-012-9/+15
| | | | | | | In embedded hosts, the Jim interpreter can come from the existing context rather than be created by OpenOCD. Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
* improve command prohibition error reportZachary T Welch2009-11-301-2/+10
| | | | | | Ensures that the correct information gets displayed, depending on the mode of the command being denied. Fixes misreporting all commands as needing to run "before 'init'".
* remove interp global variable!Zachary T Welch2009-11-302-19/+21
| | | | | | | Finish removing references to the 'interp' global variable from the command module, encapsulating all reference via command_context. Eliminates use of the global entirely, so it can be removed. Hurrah!
* command output capture: do not use interp globalZachary T Welch2009-11-301-15/+34
| | | | | | Adds a log_capture_state structure to pass to the log capture callback used by the command module. Ensures that the capture occurs in the proper context.
* do not extern 'interp' from command.cZachary T Welch2009-11-302-3/+2
| | | | | Adds 'interp' field to command_context, chasing the few remaining references to the global variable outside of the command module.
* make syntax errors respond with 'usage'Zachary T Welch2009-11-302-4/+4
| | | | | | The 'help' text will become more verbose, so its entire text will be far more than desired when you only borked your syntax. The usage still allows the commands to be looked up for more help.
* move improperly located documentationZachary T Welch2009-11-301-15/+17
| | | | | Somehow, the comment block for command handlers ended up associated with the output_handler. Move it to the command_handler_t declaration.
* improve command_done() API and docsZachary T Welch2009-11-302-6/+19
| | | | | | | | | | | | | | | | | | command_done() does not need to return an error, but it needed Doxygen comment. Provide some for copy_command_context as well. Note: this audit revealed some potential bugs with the command context implementation. There was a reason that commands were added at the end of the list. Shallow copying of command_context means that the list is shared between them. And commands added at the top-level before the pre-existing commands will not be available in the shared context as they were before. Yikes! Fortunately, this does not seem to occur in general use, as 'add_help_text' gets registered in startup.tcl and claims the first slot in my own test cases. Thus, it seems that we have been masking the issue for now, but it shows the need for further architectural improvement in the core command module.
* only display usable commands in helpZachary T Welch2009-11-301-0/+3
| | | | | | | With the ability to defer 'init', users can access the help system while still in CONFIG mode. This patch omits commands from the help and usage list when they cannot be run in the current command mode, making it much easier to see what can be done at a given time.
* remove redundant 'rm' command handlerZachary T Welch2009-11-281-27/+0
| | | | | | Two 'rm' commands were implemented and registered. This removes the version that would have never been called prior to refactoring the command registration.
* add error checking in command_newZachary T Welch2009-11-281-20/+30
| | | | | | Adds checks for memory allocation failures. Started to use calloc() instead of malloc()/memset(), but I got carried away. This kind of work should be done throughout the tree, but it's almost hopeless at present.
* include mode information in help text.Zachary T Welch2009-11-281-3/+27
| | | | | Extends the help output to list the valid modes for each commands. Fixes a memory leak of the returned command_name() string.
* refactor command mode detectionZachary T Welch2009-11-281-2/+7
| | | | | | | | | | | Splits the check for a command's ability to run into a helper. This also fixes a bug whereby commands that specified COMMAND_EXEC were allowed to run during the configuration stage. This allowed problematic commands to be called before 'init', defeating the intention of specifying that command mode. With this change, the run_command() helper denies access to handlers that should run only after 'init' during the configuration stage.
* add command private data setter/accessorZachary T Welch2009-11-282-0/+31
| | | | | | | | | | Presently, commands registration taks a static handler data pointer. This patch adds support for commands that require a dynamic pointer, such as those registered in a dynamic context (e.g. subcommands for a user-created 'foo.cpu' command). The command_set_handler_data will update a command (group) to use a new context pointer, while the CMD_DATA macro allows command handlers to access the value. Jim handlers should find this value in interp->cmdPrivData.
* add 'command mode' introspective handlerZachary T Welch2009-11-281-0/+39
| | | | | Allows scripts to behave different depending on the current mode. Also allows introspection of the mode required for commands.
* remove unknown handlerZachary T Welch2009-11-282-36/+38
| | | | | | | | | | | | | | Updates command registration to provide top-level handlers for all commands, rather than falling back onto the 'unknown' command. Instead, that same handler is registered for placeholders, providing the same functionality under the root verb command name instead. This permits users to implement their own 'unknown' function, and it resolves some mind-bending breakage related to function object lookup while recursing. Changes 'ocd_bounce' to call 'ocd_command' and 'ocd_help' from the wrapper directly, rather than bouncing through their wrappers. This prevents endless recursion caused by the above changes, whereby the 'command' wrapper's type check would blow the stack to hell and gone.
* improve command handler wrapper scriptZachary T Welch2009-11-282-3/+26
| | | | | | | | | | Adds 'ocd_bouncer' in startup.tcl that is called as a helper for all command handlers, shrinking the embedded C wrapper to a mere stub. Jim handlers are called directly, simple handlers get called with the wrapper to capture and discard their output on error, and placeholders call help directly (though the unknown handler still does this too). It attempts to improve the quality of the error messages as well.
* add 'command type' introspective handlerZachary T Welch2009-11-281-0/+43
| | | | | | | | Adds the 'command' group handler, with the 'type' command producing a string that tells whether the given command is 'native' (for Jim-based command handlers), 'simple' (for simple built-in commands), 'group' for command group placeholders, and 'unknown' if not found in the command registration tables (e.g. core built-ins functions).
* fix regression causing duplicated outputZachary T Welch2009-11-271-13/+28
| | | | | | | | | | | | | | | | | | | | | | | | The command refactoring caused subcommand handlers to produce duplicate output when run. The problem was introduced by failing to ensure all such invocations went through a top-level "catcher" script, prefixing the command name with the 'ocd_' prefix and consuming its results. The fix is to ensure such a top-level "catcher" script gets created for each top-level command, regardless of whether it has a handler. Indeed, this patch removes all command registrations for sub-commands, which would not have worked in the new registration scheme anyway. For now, dispatch of subcommands continues to be handled by the new 'unknown' command handler, which gets fixed here to strip the 'ocd_' prefix if searching for the top-level command name fails initially. Some Jim commands may be registered with this prefix, and that situation seems to require the current fallback approach. Otherwise, that prefix could be stripped unconditionally and the logic made a little simpler. The same problem must be handled by the 'help' command handler too, so its lookup process works as intended. Overall, the command dispatching remains more complicated than desired, but this patch fixes the immediate regressions.
* support OPENOCD_DEBUG_LEVEL environment settingZachary T Welch2009-11-251-0/+13
| | | | | Detect the OPENOCD_DEBUG_LEVEL setting in log_init(), allowing the very early startup phases to be debugged.
* log: improve initializationZachary T Welch2009-11-252-9/+7
| | | | | | Removes redundant assignment of start_ms from log_register_commands(). Eliminates command_context parameter and return value. Adds Doxygen comment block for this API call.
* add script_command_run helperZachary T Welch2009-11-251-26/+19
| | | | | Eliminates duplicated code in script_command and handle_unknown_command. Fixes bug with duplicated help output generated by placeholder commands.
* encapsulate and re-use log capture, retval setupZachary T Welch2009-11-251-49/+43
| | | | | | | | | Factors log capture while running script commands, eliminating duplicated code between script_command and jim_capture. Factors setting a command's Jim "retval" into a new helper as well. Using these new helpers in the new unknown command handler's fixes possible regressions caused by these bits being missing.
* combine help and usage command handlersZachary T Welch2009-11-251-20/+8
| | | | Remove duplicated handler code by checking the running command name.
* improve usage and help command outputZachary T Welch2009-11-242-44/+38
| | | | | Rewrite formatting code in C, removing last remenants of TCL help code. Sinificantly improves the readability by using smarter indent and wrap.
* allow scripts to update usage informationZachary T Welch2009-11-242-7/+36
| | | | | | The add_usage_text command uses the same C handler, which was updated to support its new polymorphic role. This patch updates the two script commands that needed this support: 'find' and 'script'.
* add jim_handler to command_registrationZachary T Welch2009-11-243-41/+68
| | | | | | Adding jim_handler field to command_registration allows removing the register_jim helper. All command registrations now go through the register_command{,s}() functions.
* refactor command_new to use command_registrationZachary T Welch2009-11-241-12/+10
| | | | Save stack space: use a struct. Makes it easier to add new parameters.
* log: use register_commands()Zachary T Welch2009-11-241-5/+19
| | | | | Use register_commands() for logging callbacks. Improve help and add proper usage.
* ioutil: use register_commands()Zachary T Welch2009-11-241-17/+45
| | | | Use table instead of individual calls. Add proper usage information.