aboutsummaryrefslogtreecommitdiff
path: root/src/helper
AgeCommit message (Collapse)Author
2009-11-28remove redundant 'rm' command handlerZachary T Welch
Two 'rm' commands were implemented and registered. This removes the version that would have never been called prior to refactoring the command registration.
2009-11-28add error checking in command_newZachary T Welch
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.
2009-11-28include mode information in help text.Zachary T Welch
Extends the help output to list the valid modes for each commands. Fixes a memory leak of the returned command_name() string.
2009-11-28refactor command mode detectionZachary T Welch
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.
2009-11-28add command private data setter/accessorZachary T Welch
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.
2009-11-28add 'command mode' introspective handlerZachary T Welch
Allows scripts to behave different depending on the current mode. Also allows introspection of the mode required for commands.
2009-11-28remove unknown handlerZachary T Welch
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.
2009-11-28improve command handler wrapper scriptZachary T Welch
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.
2009-11-28add 'command type' introspective handlerZachary T Welch
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).
2009-11-27fix regression causing duplicated outputZachary T Welch
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.
2009-11-25support OPENOCD_DEBUG_LEVEL environment settingZachary T Welch
Detect the OPENOCD_DEBUG_LEVEL setting in log_init(), allowing the very early startup phases to be debugged.
2009-11-25log: improve initializationZachary T Welch
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.
2009-11-25add script_command_run helperZachary T Welch
Eliminates duplicated code in script_command and handle_unknown_command. Fixes bug with duplicated help output generated by placeholder commands.
2009-11-25encapsulate and re-use log capture, retval setupZachary T Welch
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.
2009-11-25combine help and usage command handlersZachary T Welch
Remove duplicated handler code by checking the running command name.
2009-11-24improve usage and help command outputZachary T Welch
Rewrite formatting code in C, removing last remenants of TCL help code. Sinificantly improves the readability by using smarter indent and wrap.
2009-11-24allow scripts to update usage informationZachary T Welch
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'.
2009-11-24add jim_handler to command_registrationZachary T Welch
Adding jim_handler field to command_registration allows removing the register_jim helper. All command registrations now go through the register_command{,s}() functions.
2009-11-24refactor command_new to use command_registrationZachary T Welch
Save stack space: use a struct. Makes it easier to add new parameters.
2009-11-24log: use register_commands()Zachary T Welch
Use register_commands() for logging callbacks. Improve help and add proper usage.
2009-11-24ioutil: use register_commands()Zachary T Welch
Use table instead of individual calls. Add proper usage information.
2009-11-24rewrite 'unknown' command dispatching in CZachary T Welch
Rewrite the magical 'unknown' command in C as a Jim handler, allowing it to dispatch commands to any level in the tree.
2009-11-24add public API for locating commandsZachary T Welch
Allow other modules to find a command, primarily for the purpose of registering and unregistering subcommands.
2009-11-24refactor script_command context grabbingZachary T Welch
Move command context acquisition to current_command_context() for re-use.
2009-11-24add command registration chainingZachary T Welch
Adds the ability to chain registration structures. Modules can define a command with the 'chain' and 'num_chain' fields defined in their registration table, and the register_commands() function will initialize these commands. If the registration record creates a new command, then the chained commands are created under it; otherwise, they are created in the same context as the other commands (i.e. the parent argument).
2009-11-24more command registration refactoringZachary T Welch
Split out the handler registration into its own function, and add a few obviously missing NULL pointer error checking.
2009-11-24command: use register_commands for handlersZachary T Welch
Use register_commands() to register low-level command handlers, adding a builtin_command_handlers declaration that is easy to understand. Splits help and usage information into their appropriate fields.
2009-11-24add command usage, separate from helpZachary T Welch
Adds the usage command, to display usage information for commands. The output for this command will remain erronenously empty until commands are updated to use these new coventions.
2009-11-24add register_commands for batch registrationZachary T Welch
The register_commands API takes multiple commands in one call, allowing modules to declare and pass a much simpler (and more explicit) array of command_registration records.
2009-11-24add struct command_registrationZachary T Welch
Add a structure to encapsulate command registration information, rather than passing them all as parameters. Enables further API changes that require additional required or optional parameters. Updates the register_command API and COMMAND_REGISTER macro to use it, along with their documentation.
2009-11-24use COMMAND_REGISTER macroZachary T Welch
Replaces direct calls to register_command() with a macro, to allow its parameters to be changed and callers updated in phases.
2009-11-24add COMMAND_REGISTER macroZachary T Welch
Provides a migration path for the widely used register_command API, which needs to be updated to provide new functionality. This macro allows the API to change without having to update all of its callers at the same time.
2009-11-24improve startup tcl scriptsZachary T Welch
Fix a couple of layering violations missed in the last round. Add missing comment headers.
2009-11-24improve alloc_vprintfAndreas Fritiofson
The previous implementation was unnecessarily complex. Get rid of the loops, let vsnprintf() tell us directly how much storage we need and allocate that. A second pass writes the actual string. Also add a va_end() that was missing. This should be much faster for large strings and less wasteful for small ones. A quirk that has been retained is that some callers patch in a newline at the end of the returned string and depend on alloc_vprintf to allocate at least one byte extra. Signed-off-by: Andreas Fritiofson <andreas.fritiofson@gmail.com> Signed-off-by: Zachary T Welch <zw@superlucidity.net>
2009-11-24support for scripts in $HOME/.openocdAndreas Fritiofson
Add $HOME/.openocd as the first default script search directory, allowing the user to override the standard scripts. Update the user guide with information on where OpenOCD expects to find configuration files and scripts. Also fixed some minor formatting issues. Add entry to NEWS as well. Signed-off-by: Andreas Fritiofson <andreas.fritiofson@gmail.com> Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
2009-11-22embedded: reduce stack usageØyvind Harboe
Allocate working structures on stack to avoid issues with path lengths + reduce stack usage. Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
2009-11-21show script search dirs in debug logAndreas Fritiofson
Add this to ease debugging why the standard scripts aren't found on the default script search path in some build/install enviroments. Especially on Windows it's not straight forward where openocd actually looks for the scripts. Signed-off-by: Andreas Fritiofson <andreas.fritiofson@gmail.com> Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
2009-11-20maintain command lists in sorted orderZachary T Welch
Use insertion sort to the command link lists. The only practical effect of this is to order the output of the new 'help' command.
2009-11-20add add_help_text command handlerZachary T Welch
Rewrite means for scripts to register help text for commands. These cause the new commands to be stored in the command heirarchy, with built-in commands; however, they will never be invoked there because they do not receive a command handler. The same trick is used for the Jim commands. Remove the old helpers that were used to register commands.
2009-11-20provide command context during cmd_initZachary T Welch
For the startup.tcl code to use built-in commands, the context must be associated with the interpreter temporarily. This will be required to add help text.
2009-11-20improve 'help' commandZachary T Welch
Rewrites 'help' command in C, using new 'cmd_help' for display. Adds the built-in 'help' COMMAND_HANDLER to provide better output than the TCL-based script command (e.g. heirarchical listing of commands). The help string is stored in the command structure, though it conitnues to be pushed into the Jim environment. The current idiomatic usage suggests the addition of a usage field as well, to provide two levels of detail for users to consume (i.e. terse usage list, or verbose help).
2009-11-20factor help script command into partsZachary T Welch
Creates a helper function, cmd_help, which displays the help string for a single command. Presently, it is called from the loop in help. The routine has been extended to allow indentation of command groups, so an improved help command can improve the display of information.
2009-11-20refactor command registrationZachary T Welch
Refactors the command registration to use helpers to simplify the code. The unregistration routines were made more flexible by allowing them to operate on a single command, such that one can remove all of a commands children in one step (perhaps before adding back a 'config' subcommand that allows getting the others back). Eliminates a bit of duplicated code and adds full API documentation for these routines.
2009-11-20change command_find helper interfaceZachary T Welch
Avoid requiring double pointers where a single would suffice.
2009-11-20factor script_command argv allocationZachary T Welch
Splits argument allocation out from script command, reusing free() code.
2009-11-18remove fast command and jim_global_longZachary T Welch
Removing the fast command eliminates the fast_and_dangerous global, which was used only by arm7_9_common as an initializer. The command is not called in the tree; instead, more explicit commands are used. The jim_global_long function was not used anywhere in the tree.
2009-11-18change all bool parsers to accept any valueZachary T Welch
This patch changes the behavior of all boolean parsing callers to accept any one of "true/enable/on/yes/1" or "false/disable/off/no/0". Since one particular pair will be most appropriate in any given situation, the specific macros should continue to be used in order to display the most informative error messages possible.
2009-11-18add handle_command_parse_bool command helperZachary T Welch
Rewrite arm11_handle_bool to provide a generic on/off command helper. Refactors COMMAND_PARSE_BOOL to use new command_parse_bool helper, which gets reused by the new command_parse_bool_any helper. This later helper is called by the new command helper function to accepts any on/off, enable/disable, true/false, yes/no, or 0/1 parameter.
2009-11-18add COMMAND_PARSE_BOOL macro and friendsZachary T Welch
Adds several macros similar to COMMAND_PARSE_NUMBER, but for parsing boolean command arguments. Two flavors are provided to provide drop-in compatibility with existing code, allow for the elimination of a lot of code bloat while improving the error checking and reporting. COMMAND_PARSE_ON_OFF parses "on"/"off" command parameters. COMMAND_PARSE_ENABLE parses "enable"/"disable" command parameters. Both print the error and return an error out of the calling function.
2009-11-18pass startup_tcl to command_initZachary T Welch
Removes external linkage from helper module, making the startup code a parameter to a new command context's initialization routine.