Overview
| Artifact ID: | 0d521cf583e67909fe4abdcb1c4550b6252b8cb8e380d6ecc8e03de9fb088e5c |
|---|---|
| Ticket: | 2370575fffffffffffffffffffffffffffffffff |
| Date: | 2019-04-01 09:10:28 |
| User: | dkf |
| Artifact Attached: | 8b8de311982cb1acf4b89ed3ec1e44d082f6e4e980a0863ff6bfba3a2b89ce9b |
| Filename: | dict-getwithdefault.c |
| Description: | dict-getwithdefault.c: File extracted from SourceForge |
Content:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121/* * Table of dict subcommand names and implementations. */ static const EnsembleImplMap implementationMap[] = { {"append", DictAppendCmd, TclCompileDictAppendCmd }, {"create", DictCreateCmd }, {"exists", DictExistsCmd }, {"filter", DictFilterCmd }, {"for", DictForCmd, TclCompileDictForCmd, DictForNRCmd }, {"get", DictGetCmd, TclCompileDictGetCmd }, {"getwithdefault", DictGetWithDefaultCmd }, {"incr", DictIncrCmd, TclCompileDictIncrCmd }, {"info", DictInfoCmd }, {"keys", DictKeysCmd }, {"lappend", DictLappendCmd, TclCompileDictLappendCmd }, {"merge", DictMergeCmd }, {"remove", DictRemoveCmd }, {"replace", DictReplaceCmd }, {"set", DictSetCmd, TclCompileDictSetCmd }, {"size", DictSizeCmd }, {"unset", DictUnsetCmd }, {"update", DictUpdateCmd, TclCompileDictUpdateCmd }, {"values", DictValuesCmd }, {"with", DictWithCmd }, {NULL} }; /*********** * * * [snip] * * * ***********/ /* *---------------------------------------------------------------------- * * DictGetWithDefaultCmd -- * * This function implements the "dict getwithdefault" Tcl command. * See the user documentation for details on what it does, and * TIP#3?? for the formal specification. * * Results: * A standard Tcl result. * * Side effects: * The same as for DictExistsCmd. * *---------------------------------------------------------------------- */ static int DictGetWithDefaultCmd( ClientData dummy, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv) { Tcl_Obj *dictPtr, *valuePtr; int result; if (objc < 4) { Tcl_WrongNumArgs(interp, 1, objv, "dictionary key ?key ...? default"); return TCL_ERROR; } dictPtr = TclTraceDictPath(interp, objv[1], objc-4, objv+2, DICT_PATH_EXISTS); if (dictPtr == NULL) { return TCL_ERROR; } if (dictPtr == DICT_PATH_NON_EXISTENT) { Tcl_SetObjResult(interp, objv[objc-1]); return TCL_OK; } result = Tcl_DictObjGet(interp, dictPtr, objv[objc-2], &valuePtr); if (result != TCL_OK) { return result; } Tcl_SetObjResult(interp, valuePtr != NULL ? valuePtr : objv[objc-1]); return TCL_OK; } /* Material for dict.test: test dict-23.1 {dict getwithdefault command} -body { dict getwithdefault {a b} a c } -result b test dict-23.2 {dict getwithdefault command} -body { dict getwithdefault {a b} b c } -result c test dict-23.3 {dict getwithdefault command} -body { dict getwithdefault {a {b c}} a b d } -result c test dict-23.4 {dict getwithdefault command} -body { dict getwithdefault {a {b c}} a c d } -result d test dict-23.5 {dict getwithdefault command} -body { dict getwithdefault {a {b c}} b c d } -result d test dict-23.6 {dict getwithdefault command} -returnCodes error -body { dict getwithdefault {a {b c d}} a b d } -result {missing value to go with key} test dict-23.7 {dict getwithdefault command} -returnCodes error -body { dict getwithdefault } -result {wrong # args: should be\ "dict getwithdefault dictionary key ?key ...? default"} test dict-23.8 {dict getwithdefault command} -returnCodes error -body { dict getwithdefault {} } -result {wrong # args: should be\ "dict getwithdefault dictionary key ?key ...? default"} */
