summaryrefslogtreecommitdiffstats
path: root/generic/tclIO.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2022-09-22 11:26:44 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2022-09-22 11:26:44 (GMT)
commit606baf39a5ea4daea70730647a6c5e435db9df03 (patch)
tree7a5e866964e12224281eb3845e93b012abe20352 /generic/tclIO.c
parente473aab63f856841f45c1477e5dd887d9d2938e0 (diff)
downloadtcl-606baf39a5ea4daea70730647a6c5e435db9df03.zip
tcl-606baf39a5ea4daea70730647a6c5e435db9df03.tar.gz
tcl-606baf39a5ea4daea70730647a6c5e435db9df03.tar.bz2
Add -strictencoding option to channels. Thanks to Harald Oehlman for his example (largely copied). No testcases yet
Diffstat (limited to 'generic/tclIO.c')
-rw-r--r--generic/tclIO.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c
index e00b99b..04c3b1b 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -4342,6 +4342,14 @@ Write(
}
/*
+ * Transfer encoding strict option to the encoding flags
+ */
+
+ if (statePtr->flags & CHANNEL_ENCODING_STRICT) {
+ statePtr->outputEncodingFlags |= TCL_ENCODING_STRICT;
+ }
+
+ /*
* Write the terminated escape sequence even if srcLen is 0.
*/
@@ -4657,6 +4665,14 @@ Tcl_GetsObj(
}
/*
+ * Transfer encoding strict option to the encoding flags
+ */
+
+ if (statePtr->flags & CHANNEL_ENCODING_STRICT) {
+ statePtr->inputEncodingFlags |= TCL_ENCODING_STRICT;
+ }
+
+ /*
* Object used by FilterInputBytes to keep track of how much data has been
* consumed from the channel buffers.
*/
@@ -5412,6 +5428,15 @@ FilterInputBytes(
*gsPtr->dstPtr = dst;
}
gsPtr->state = statePtr->inputEncodingState;
+
+ /*
+ * Transfer encoding strict option to the encoding flags
+ */
+
+ if (statePtr->flags & CHANNEL_ENCODING_STRICT) {
+ statePtr->inputEncodingFlags |= TCL_ENCODING_STRICT;
+ }
+
result = Tcl_ExternalToUtf(NULL, gsPtr->encoding, raw, rawLen,
statePtr->inputEncodingFlags | TCL_ENCODING_NO_TERMINATE,
&statePtr->inputEncodingState, dst, spaceLeft, &gsPtr->rawRead,
@@ -6185,6 +6210,14 @@ ReadChars(
}
/*
+ * Transfer encoding strict option to the encoding flags
+ */
+
+ if (statePtr->flags & CHANNEL_ENCODING_STRICT) {
+ statePtr->inputEncodingFlags |= TCL_ENCODING_STRICT;
+ }
+
+ /*
* This routine is burdened with satisfying several constraints. It cannot
* append more than 'charsToRead` chars onto objPtr. This is measured
* after encoding and translation transformations are completed. There is
@@ -7920,6 +7953,16 @@ Tcl_GetChannelOption(
return TCL_OK;
}
}
+ if (len == 0 || HaveOpt(1, "-strictencoding")) {
+ if (len == 0) {
+ Tcl_DStringAppendElement(dsPtr, "-strictencoding");
+ }
+ Tcl_DStringAppendElement(dsPtr,
+ (flags & CHANNEL_ENCODING_STRICT) ? "1" : "0");
+ if (len > 0) {
+ return TCL_OK;
+ }
+ }
if (len == 0 || HaveOpt(1, "-translation")) {
if (len == 0) {
Tcl_DStringAppendElement(dsPtr, "-translation");
@@ -8173,6 +8216,16 @@ Tcl_SetChannelOption(
ResetFlag(statePtr, CHANNEL_EOF|CHANNEL_STICKY_EOF|CHANNEL_BLOCKED);
statePtr->inputEncodingFlags &= ~TCL_ENCODING_END;
return TCL_OK;
+ } else if (HaveOpt(1, "-strictencoding")) {
+ int newMode;
+
+ if (Tcl_GetBoolean(interp, newValue, &newMode) == TCL_ERROR) {
+ return TCL_ERROR;
+ }
+ if (newMode) {
+ statePtr->flags |= CHANNEL_ENCODING_STRICT;
+ }
+ return TCL_OK;
} else if (HaveOpt(1, "-translation")) {
const char *readMode, *writeMode;