Jim Tcl
Check-in [a181b7fe80]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:tcl::prefix: respect -message when no valid options

Signed-off-by: Steve Bennett <steveb@workware.net.au>

Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: a181b7fe8082318cf68961bb90248943d4e92aef
User & Date: steveb@workware.net.au 2017-09-21 06:30:55
Context
2017-09-21
06:31
tcltest: Support 'needs package xxx'

Makes it easy to skip all tests if the package isn't available

Signed-off-by: Steve Bennett <steveb@workware.net.au> check-in: c4f990b209 user: steveb@workware.net.au tags: trunk

06:30
tcl::prefix: respect -message when no valid options

Signed-off-by: Steve Bennett <steveb@workware.net.au> check-in: a181b7fe80 user: steveb@workware.net.au tags: trunk

06:30
jim.c: minor code cleanups in [switch]

Signed-off-by: Steve Bennett <steveb@workware.net.au> check-in: cdedd1ab2a user: steveb@workware.net.au tags: trunk

Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to jim-tclprefix.c.

    49     49           case OPT_MATCH:{
    50     50               int i;
    51     51               int ret;
    52     52               int tablesize;
    53     53               const char **table;
    54     54               Jim_Obj *tableObj;
    55     55               Jim_Obj *errorObj = NULL;
    56         -            Jim_Obj *messageObj = NULL;
           56  +            const char *message = "option";
    57     57               static const char * const matchoptions[] = { "-error", "-exact", "-message", NULL };
    58     58               enum { OPT_MATCH_ERROR, OPT_MATCH_EXACT, OPT_MATCH_MESSAGE };
    59     59               int flags = JIM_ERRMSG | JIM_ENUM_ABBREV;
    60     60   
    61     61               if (argc < 4) {
    62     62                   Jim_WrongNumArgs(interp, 2, argv, "?options? table string");
    63     63                   return JIM_ERR;
................................................................................
    87     87                           break;
    88     88   
    89     89                       case OPT_MATCH_MESSAGE:
    90     90                           if (++i == argc) {
    91     91                               Jim_SetResultString(interp, "missing message", -1);
    92     92                               return JIM_ERR;
    93     93                           }
    94         -                        messageObj = argv[i];
           94  +                        message = Jim_String(argv[i]);
    95     95                           break;
    96     96                   }
    97     97               }
    98     98               /* Do the match */
    99     99               tablesize = Jim_ListLength(interp, tableObj);
   100    100               table = Jim_Alloc((tablesize + 1) * sizeof(*table));
   101    101               for (i = 0; i < tablesize; i++) {
   102    102                   Jim_ListIndex(interp, tableObj, i, &objPtr, JIM_NONE);
   103    103                   table[i] = Jim_String(objPtr);
   104    104               }
   105    105               table[i] = NULL;
   106    106   
   107         -            ret = Jim_GetEnum(interp, stringObj, table, &i, messageObj ? Jim_String(messageObj) : NULL, flags);
          107  +            ret = Jim_GetEnum(interp, stringObj, table, &i, message, flags);
   108    108               Jim_Free(table);
   109    109               if (ret == JIM_OK) {
   110    110                   Jim_ListIndex(interp, tableObj, i, &objPtr, JIM_NONE);
   111    111                   Jim_SetResult(interp, objPtr);
   112    112                   return JIM_OK;
   113    113               }
   114    114               if (tablesize == 0) {
   115         -                Jim_SetResultFormatted(interp, "bad option \"%#s\": no valid options", stringObj);
          115  +                Jim_SetResultFormatted(interp, "bad %s \"%#s\": no valid options", message, stringObj);
   116    116                   return JIM_ERR;
   117    117               }
   118    118               if (errorObj) {
   119    119                   if (Jim_Length(errorObj) == 0) {
   120    120                       Jim_SetEmptyResult(interp);
   121    121                       return JIM_OK;
   122    122                   }