summaryrefslogtreecommitdiffstats
path: root/generic/tclIO.c
diff options
context:
space:
mode:
authorapnadkarni <apnmbx-wits@yahoo.com>2023-02-10 17:07:12 (GMT)
committerapnadkarni <apnmbx-wits@yahoo.com>2023-02-10 17:07:12 (GMT)
commite26214c28753b22c398ba4d7196a8afae999ab5a (patch)
tree4a414b531bf1f2880840f04b1a70eb6757a9b38a /generic/tclIO.c
parent9d1ba01f11c772a015e3edbfb1ea4ae8e9f148bf (diff)
downloadtcl-e26214c28753b22c398ba4d7196a8afae999ab5a.zip
tcl-e26214c28753b22c398ba4d7196a8afae999ab5a.tar.gz
tcl-e26214c28753b22c398ba4d7196a8afae999ab5a.tar.bz2
Phase out (almost) STRICT and NOCOMPLAIN flags.
Diffstat (limited to 'generic/tclIO.c')
-rw-r--r--generic/tclIO.c118
1 files changed, 28 insertions, 90 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c
index 0152740..49f4257 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -1700,8 +1700,12 @@ Tcl_CreateChannel(
}
statePtr->inputEncodingState = NULL;
statePtr->inputEncodingFlags = TCL_ENCODING_START;
+ TCL_ENCODING_PROFILE_SET(statePtr->inputEncodingFlags,
+ TCL_ENCODING_PROFILE_DEFAULT);
statePtr->outputEncodingState = NULL;
statePtr->outputEncodingFlags = TCL_ENCODING_START;
+ TCL_ENCODING_PROFILE_SET(statePtr->outputEncodingFlags,
+ TCL_ENCODING_PROFILE_DEFAULT);
/*
* Set the channel up initially in AUTO input translation mode to accept
@@ -4394,21 +4398,6 @@ Write(
}
/*
- * Transfer encoding nocomplain/strict option to the encoding flags
- */
-
- if (GotFlag(statePtr, CHANNEL_ENCODING_STRICT)) {
- statePtr->outputEncodingFlags |= TCL_ENCODING_STRICT;
-#ifdef TCL_NO_DEPRECATED
- } else if (GotFlag(statePtr, CHANNEL_ENCODING_NOCOMPLAIN)) {
- statePtr->outputEncodingFlags &= ~TCL_ENCODING_STRICT;
- statePtr->outputEncodingFlags |= TCL_ENCODING_NOCOMPLAIN;
-#endif
- } else {
- statePtr->outputEncodingFlags &= ~TCL_ENCODING_STRICT;
- }
-
- /*
* Write the terminated escape sequence even if srcLen is 0.
*/
@@ -4733,21 +4722,6 @@ Tcl_GetsObj(
}
/*
- * Transfer encoding nocomplain/strict option to the encoding flags
- */
-
- if (GotFlag(statePtr, CHANNEL_ENCODING_STRICT)) {
- statePtr->inputEncodingFlags |= TCL_ENCODING_STRICT;
-#ifdef TCL_NO_DEPRECATED
- } else if (GotFlag(statePtr, CHANNEL_ENCODING_NOCOMPLAIN)) {
- statePtr->inputEncodingFlags &= ~TCL_ENCODING_STRICT;
- statePtr->inputEncodingFlags |= TCL_ENCODING_NOCOMPLAIN;
-#endif
- } else {
- statePtr->inputEncodingFlags &= ~TCL_ENCODING_STRICT;
- }
-
- /*
* Object used by FilterInputBytes to keep track of how much data has been
* consumed from the channel buffers.
*/
@@ -5528,21 +5502,6 @@ FilterInputBytes(
}
gsPtr->state = statePtr->inputEncodingState;
- /*
- * Transfer encoding nocomplain/strict option to the encoding flags
- */
-
- if (GotFlag(statePtr, CHANNEL_ENCODING_STRICT)) {
- statePtr->inputEncodingFlags |= TCL_ENCODING_STRICT;
-#ifdef TCL_NO_DEPRECATED
- } else if (GotFlag(statePtr, CHANNEL_ENCODING_NOCOMPLAIN)) {
- statePtr->inputEncodingFlags &= ~TCL_ENCODING_STRICT;
- statePtr->inputEncodingFlags |= TCL_ENCODING_NOCOMPLAIN;
-#endif
- } else {
- 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,
@@ -6349,21 +6308,6 @@ ReadChars(
}
/*
- * Transfer encoding nocomplain/strict option to the encoding flags
- */
-
- if (GotFlag(statePtr, CHANNEL_ENCODING_STRICT)) {
- statePtr->inputEncodingFlags |= TCL_ENCODING_STRICT;
-#ifdef TCL_NO_DEPRECATED
- } else if (GotFlag(statePtr, CHANNEL_ENCODING_NOCOMPLAIN)) {
- statePtr->inputEncodingFlags &= ~TCL_ENCODING_STRICT;
- statePtr->inputEncodingFlags |= TCL_ENCODING_NOCOMPLAIN;
-#endif
- } else {
- 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
@@ -8065,16 +8009,18 @@ Tcl_GetChannelOption(
}
}
if (len == 0 || HaveOpt(1, "-encodingprofile")) {
+ int profile;
+ const char *profileName;
if (len == 0) {
Tcl_DStringAppendElement(dsPtr, "-encodingprofile");
}
- if (flags & CHANNEL_ENCODING_STRICT) {
- Tcl_DStringAppendElement(dsPtr, "strict");
- } else if (flags & CHANNEL_ENCODING_NOCOMPLAIN) {
- Tcl_DStringAppendElement(dsPtr, "tcl8");
- } else {
- Tcl_DStringAppendElement(dsPtr, "");
+ /* Note currently input and output profiles are same */
+ profile = TCL_ENCODING_PROFILE_GET(statePtr->inputEncodingFlags);
+ profileName = TclEncodingProfileIdToName(interp, profile);
+ if (profileName == NULL) {
+ return TCL_ERROR;
}
+ Tcl_DStringAppendElement(dsPtr, profileName);
if (len > 0) {
return TCL_OK;
}
@@ -8293,6 +8239,7 @@ Tcl_SetChannelOption(
return TCL_OK;
} else if (HaveOpt(2, "-encoding")) {
Tcl_Encoding encoding;
+ int profile;
if ((newValue[0] == '\0') || (strcmp(newValue, "binary") == 0)) {
encoding = NULL;
@@ -8317,9 +8264,12 @@ Tcl_SetChannelOption(
Tcl_FreeEncoding(statePtr->encoding);
statePtr->encoding = encoding;
statePtr->inputEncodingState = NULL;
+ profile = TCL_ENCODING_PROFILE_GET(statePtr->inputEncodingFlags);
statePtr->inputEncodingFlags = TCL_ENCODING_START;
+ TCL_ENCODING_PROFILE_SET(statePtr->inputEncodingFlags, profile);
statePtr->outputEncodingState = NULL;
statePtr->outputEncodingFlags = TCL_ENCODING_START;
+ TCL_ENCODING_PROFILE_SET(statePtr->outputEncodingFlags, profile); /* Same as input */
ResetFlag(statePtr, CHANNEL_NEED_MORE_DATA|CHANNEL_ENCODING_ERROR);
UpdateInterest(chanPtr);
return TCL_OK;
@@ -8380,28 +8330,11 @@ Tcl_SetChannelOption(
return TCL_OK;
} else if (HaveOpt(1, "-encodingprofile")) {
int profile;
- if (TclEncodingProfileParseName(interp, newValue, &profile) != TCL_OK) {
+ if (TclEncodingProfileNameToId(interp, newValue, &profile) != TCL_OK) {
return TCL_ERROR;
}
- switch (profile) {
- case TCL_ENCODING_PROFILE_TCL8:
- ResetFlag(statePtr, CHANNEL_ENCODING_STRICT);
- SetFlag(statePtr, CHANNEL_ENCODING_NOCOMPLAIN);
- break;
- case TCL_ENCODING_PROFILE_STRICT:
- ResetFlag(statePtr, CHANNEL_ENCODING_NOCOMPLAIN);
- SetFlag(statePtr, CHANNEL_ENCODING_STRICT);
- break;
- /* TODO - clean up this DEFAULT handling once channel flags fixed */
-#if TCL_ENCODING_PROFILE_DEFAULT != TCL_ENCODING_PROFILE_TCL8 \
- && TCL_ENCODING_PROFILE_DEFAULT != TCL_ENCODING_PROFILE_STRICT
- case TCL_ENCODING_PROFILE_DEFAULT: /* FALLTHRU */
-#endif
- default:
- ResetFlag(statePtr, CHANNEL_ENCODING_NOCOMPLAIN);
- ResetFlag(statePtr, CHANNEL_ENCODING_STRICT);
- break;
- }
+ TCL_ENCODING_PROFILE_SET(statePtr->inputEncodingFlags, profile);
+ TCL_ENCODING_PROFILE_SET(statePtr->outputEncodingFlags, profile);
ResetFlag(statePtr, CHANNEL_NEED_MORE_DATA|CHANNEL_ENCODING_ERROR);
return TCL_OK;
} else if (HaveOpt(1, "-translation")) {
@@ -9493,12 +9426,17 @@ TclCopyChannel(
* of the bytes themselves.
*/
+ /*
+ * TODO - should really only allow lossless profiles. Below reflects
+ * Tcl 8.7 alphas prior to encoding profiles
+ */
+
moveBytes = inStatePtr->inEofChar == '\0' /* No eofChar to stop input */
&& inStatePtr->inputTranslation == TCL_TRANSLATE_LF
&& outStatePtr->outputTranslation == TCL_TRANSLATE_LF
&& inStatePtr->encoding == outStatePtr->encoding
- && (inStatePtr->flags & TCL_ENCODING_STRICT) != TCL_ENCODING_STRICT
- && outStatePtr->flags & TCL_ENCODING_NOCOMPLAIN;
+ && TCL_ENCODING_PROFILE_GET(inStatePtr->flags) != TCL_ENCODING_PROFILE_STRICT
+ && TCL_ENCODING_PROFILE_GET(outStatePtr->flags) == TCL_ENCODING_PROFILE_TCL8;
/*
* Allocate a new CopyState to maintain info about the current copy in
@@ -9826,8 +9764,8 @@ CopyData(
inBinary = (inStatePtr->encoding == NULL);
outBinary = (outStatePtr->encoding == NULL);
sameEncoding = inStatePtr->encoding == outStatePtr->encoding
- && (inStatePtr->flags & TCL_ENCODING_STRICT) != TCL_ENCODING_STRICT
- && outStatePtr->flags & TCL_ENCODING_NOCOMPLAIN;
+ && TCL_ENCODING_PROFILE_GET(inStatePtr->flags) != TCL_ENCODING_PROFILE_STRICT
+ && TCL_ENCODING_PROFILE_GET(outStatePtr->flags) == TCL_ENCODING_PROFILE_TCL8;
if (!(inBinary || sameEncoding)) {
TclNewObj(bufObj);