diff options
author | Steve Bennett <steveb@workware.net.au> | 2017-09-16 13:03:52 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2017-09-16 15:37:57 +1000 |
commit | 59af8ac418343fb922ba602b3690707c07b8cdda (patch) | |
tree | f8049718938d9701fe01e5b0cd28a26127616176 | |
parent | 68125a71ad36e150ec4ca7c596064840a2fbc8ae (diff) | |
download | jimtcl-59af8ac418343fb922ba602b3690707c07b8cdda.zip jimtcl-59af8ac418343fb922ba602b3690707c07b8cdda.tar.gz jimtcl-59af8ac418343fb922ba602b3690707c07b8cdda.tar.bz2 |
Simplify error reporting in jim-subcmd
Make use of Jim_SetResultFormatted()
Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r-- | jim-subcmd.c | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/jim-subcmd.c b/jim-subcmd.c index c522830..1371dd4 100644 --- a/jim-subcmd.c +++ b/jim-subcmd.c @@ -41,18 +41,14 @@ static void add_commands(Jim_Interp *interp, const jim_subcmd_type * ct, const c static void bad_subcmd(Jim_Interp *interp, const jim_subcmd_type * command_table, const char *type, Jim_Obj *cmd, Jim_Obj *subcmd) { - Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); - Jim_AppendStrings(interp, Jim_GetResult(interp), Jim_String(cmd), ", ", type, - " command \"", Jim_String(subcmd), "\": should be ", NULL); + Jim_SetResultFormatted(interp, "%#s, %s command \"%#s\": should be ", cmd, type, subcmd); add_commands(interp, command_table, ", "); } static void show_cmd_usage(Jim_Interp *interp, const jim_subcmd_type * command_table, int argc, Jim_Obj *const *argv) { - Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); - Jim_AppendStrings(interp, Jim_GetResult(interp), "Usage: \"", Jim_String(argv[0]), - " command ... \", where command is one of: ", NULL); + Jim_SetResultFormatted(interp, "Usage: \"%#s command ... \", where command is one of: ", argv[0]); add_commands(interp, command_table, ", "); } @@ -82,16 +78,11 @@ const jim_subcmd_type *Jim_ParseSubCmd(Jim_Interp *interp, const jim_subcmd_type int cmdlen; Jim_Obj *cmd; const char *cmdstr; - const char *cmdname; int help = 0; - cmdname = Jim_String(argv[0]); - if (argc < 2) { - Jim_SetResult(interp, Jim_NewEmptyStringObj(interp)); - Jim_AppendStrings(interp, Jim_GetResult(interp), "wrong # args: should be \"", cmdname, - " command ...\"\n", NULL); - Jim_AppendStrings(interp, Jim_GetResult(interp), "Use \"", cmdname, " -help ?command?\" for help", NULL); + Jim_SetResultFormatted(interp, "wrong # args: should be \"%#s command ...\"\n" + "Use \"%#s -help ?command?\" for help", argv[0], argv[0]); return 0; } |