diff options
| -rw-r--r-- | generic/tclCmdAH.c | 66 |
1 files changed, 48 insertions, 18 deletions
diff --git a/generic/tclCmdAH.c b/generic/tclCmdAH.c index 60a2c42..96bac4e 100644 --- a/generic/tclCmdAH.c +++ b/generic/tclCmdAH.c @@ -556,28 +556,59 @@ EncodingConvertfromObjCmd( int flags = TCL_ENCODING_NOCOMPLAIN; #endif size_t result; + Tcl_Obj *failVarObj = NULL; + int i, encodingSeen = 0; + /* + * Decode parameters: + * Possible combinations: + * 1) data -> objc = 2 + * 2) encoding data -> objc = 3 + * 3) -nocomplain data -> objc = 3 (8.7) + * 4) -nocomplain encoding data -> objc = 4 (8.7) + * 5) -failindex val data -> objc = 4 + * 6) -failindex val encoding data -> objc = 5 + * 7a) -nocomplain -failindex val data -> objc = 5 + * 7b) -failindex val -nocomplain data -> objc = 5 + * 8a) -nocomplain -failindex val encoding data -> objc = 6 + * 8b) -failindex val -nocomplain encoding data -> objc = 6 + */ - if (objc == 2) { - encoding = Tcl_GetEncoding(interp, NULL); - data = objv[1]; - } else if ((unsigned)(objc - 2) < 3) { + if (objc > 1 && objc < 7) { + int noComplaintSeen = 0; + int encodingSeen = 0; data = objv[objc - 1]; - bytesPtr = Tcl_GetString(objv[1]); - if (bytesPtr[0] == '-' && bytesPtr[1] == 'n' - && !strncmp(bytesPtr, "-nocomplain", strlen(bytesPtr))) { - flags = TCL_ENCODING_NOCOMPLAIN; - } else if (objc < 4) { - if (Tcl_GetEncodingFromObj(interp, objv[objc - 2], &encoding) != TCL_OK) { - return TCL_ERROR; + for(i = 1; i < objc-1 ; i++ ) { + bytesPtr = Tcl_GetString(objv[i]); + if (bytesPtr[0] == '-' && bytesPtr[1] == 'n' + && !strncmp(bytesPtr, "-nocomplain", strlen(bytesPtr))) { + if (noComplaintSeen) { + goto encConvFromError; + } + flags = TCL_ENCODING_NOCOMPLAIN; + noComplaintSeen = 1; + } else if (bytesPtr[0] == '-' && bytesPtr[1] == 'f' + && !strncmp(bytesPtr, "-failindex", strlen(bytesPtr))) { + /* at least two additional arguments needed */ + if (objc < i + 3) { + goto encConvFromError; + } + if (failVarObj != NULL) { + goto encConvFromError; + } + i++; + failVarObj = objv[i]; + flags = TCL_ENCODING_NOCOMPLAIN; + } else if (i == objc - 2) { + if (Tcl_GetEncodingFromObj(interp, objv[i], &encoding) != TCL_OK) { + return TCL_ERROR; + } + encodingSeen = 1; + } else { + goto encConvFromError; } - goto encConvFromOK; - } else { - goto encConvFromError; } - if (objc < 4) { + if (!encodingSeen) { encoding = Tcl_GetEncoding(interp, NULL); - } else if (Tcl_GetEncodingFromObj(interp, objv[objc - 2], &encoding) != TCL_OK) { - return TCL_ERROR; } } else { encConvFromError: @@ -585,7 +616,6 @@ EncodingConvertfromObjCmd( return TCL_ERROR; } -encConvFromOK: /* * Convert the string into a byte array in 'ds' */ |
