From a230afdc68bcad14a9dfd0f9c8c6955980669cd6 Mon Sep 17 00:00:00 2001 From: Steve Bennett Date: Sun, 24 Jan 2010 12:44:43 +1000 Subject: Many improvements, bug fixes *: Allow math functions to be enabled via configure *: Allow support for references to be removed *: Documentation updates *: Jim_ListLength() now returns the result directly *: Optimise list -> dict conversion *: Consistent capitalisation of some structures, functions *: Add support for abbreviations to Jim_GetEnum() *: The commands to 'info' may be abbreviated *: Use abbreviation support in parsing options to 'subst' *: Use Jim_GetEnum() to parse return code names *: Optimise 'array get', 'array set' if no conversion needed *: Import Tcl string.test *: string compare now returns -1,0,1 like Tcl *: Fix 'string last' with index=0 *: Add support for 'string reverse' *: Add -nocase option to 'string equal' *: Fix infinite loop in 'string repeat str -1' *: Support braced patterns in glob *: glob should not return dot files unless the pattern starts with . *: Simplify glob.tcl by using some new features *: When creating C extensions from Tcl, preserve newlines and invoke with Jim_Eval_Named() to produce more meaningful error messages. *: Also remove all comments, not just those starting in the first column *: Add support for 'n+n' and 'n-n' in string/list indexes (Tcl 8.5) *: Add a level to the stack trace for 'return -code error' *: 'return -code' should also affect the return from 'source' (see Tcl docs) *: Fix lsort -command *: Some systems don't have INFINITY --- jim-subcmd.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'jim-subcmd.c') diff --git a/jim-subcmd.c b/jim-subcmd.c index 24af265..e246941 100644 --- a/jim-subcmd.c +++ b/jim-subcmd.c @@ -70,6 +70,21 @@ static void show_full_usage(Jim_Interp *interp, const jim_subcmd_type *ct, int a } } +static void add_cmd_usage(Jim_Interp *interp, const jim_subcmd_type *command_table, int argc, Jim_Obj *const *argv) +{ + Jim_AppendStrings(interp, Jim_GetResult(interp), Jim_GetString(argv[0], NULL), NULL); + if (command_table->args && *command_table->args) { + Jim_AppendStrings(interp, Jim_GetResult(interp), " ", command_table->args, NULL); + } +} + +static void set_wrong_args(Jim_Interp *interp, const jim_subcmd_type *command_table, int argc, Jim_Obj *const *argv) +{ + Jim_SetResultString(interp, "wrong # args: must be \"", -1); + add_cmd_usage(interp, command_table, argc, argv); + Jim_AppendStrings(interp, Jim_GetResult(interp), "\"", NULL); +} + const jim_subcmd_type * Jim_ParseSubCmd(Jim_Interp *interp, const jim_subcmd_type *command_table, int argc, Jim_Obj *const *argv) { @@ -169,7 +184,7 @@ Jim_ParseSubCmd(Jim_Interp *interp, const jim_subcmd_type *command_table, int ar /* Check the number of args */ if (argc - 2 < ct->minargs || (ct->maxargs >= 0 && argc - 2> ct->maxargs)) { - Jim_SetResultString(interp, "wrong # args: should be \"", -1); + Jim_SetResultString(interp, "wrong # args: must be \"", -1); add_subcmd_usage(interp, ct, argc, argv); Jim_AppendStrings(interp, Jim_GetResult(interp), "\"", NULL); @@ -192,9 +207,7 @@ int Jim_CallSubCmd(Jim_Interp *interp, const jim_subcmd_type *ct, int argc, Jim_ ret = ct->function(interp, argc - 2, argv + 2); } if (ret < 0) { - Jim_SetResultString(interp, "wrong # args: should be \"", -1); - add_subcmd_usage(interp, ct, argc, argv); - Jim_AppendStrings(interp, Jim_GetResult(interp), "\"", NULL); + set_wrong_args(interp, ct, argc, argv); ret = JIM_ERR; } } @@ -209,14 +222,6 @@ int Jim_SubCmdProc(Jim_Interp *interp, int argc, Jim_Obj *const *argv) } /* The following two functions are for normal commands */ -static void add_cmd_usage(Jim_Interp *interp, const jim_subcmd_type *command_table, int argc, Jim_Obj *const *argv) -{ - Jim_AppendStrings(interp, Jim_GetResult(interp), Jim_GetString(argv[0], NULL), NULL); - if (command_table->args && *command_table->args) { - Jim_AppendStrings(interp, Jim_GetResult(interp), " ", command_table->args, NULL); - } -} - int Jim_CheckCmdUsage(Jim_Interp *interp, const jim_subcmd_type *command_table, int argc, Jim_Obj *const *argv) { @@ -266,9 +271,7 @@ Jim_CheckCmdUsage(Jim_Interp *interp, const jim_subcmd_type *command_table, int /* Check the number of args */ if (argc - 1 < command_table->minargs || (command_table->maxargs >= 0 && argc - 1> command_table->maxargs)) { - Jim_SetResultString(interp, "wrong # args: should be \"", -1); - add_cmd_usage(interp, command_table, argc, argv); - Jim_AppendStrings(interp, Jim_GetResult(interp), "\"", NULL); + set_wrong_args(interp, command_table, argc, argv); Jim_AppendStrings(interp, Jim_GetResult(interp), "\"\nUse \"", Jim_GetString(argv[0], NULL), " -help\" for help", NULL); return JIM_ERR; } -- cgit v1.1