From f1fafe7c16c654a9f7f65644db877071980b8a5d Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Wed, 22 Mar 2023 11:44:33 +0000 Subject: Move (TCL_ENCODING_PROFILE_MASK|GET|SET) from tcl.h to tclIO.h, since those are not public. Some formatting. --- generic/tcl.h | 7 ------- generic/tclCmdAH.c | 5 ++--- generic/tclEncoding.c | 12 ++++++------ generic/tclExecute.c | 6 ++---- generic/tclIO.c | 24 ++++++++++++------------ generic/tclIO.h | 7 +++++++ generic/tclTest.c | 3 +-- generic/tclTestObj.c | 3 +-- generic/tclZlib.c | 6 ++---- win/tclWinConsole.c | 3 +-- 10 files changed, 34 insertions(+), 42 deletions(-) diff --git a/generic/tcl.h b/generic/tcl.h index 4da5f43..9140ec4 100644 --- a/generic/tcl.h +++ b/generic/tcl.h @@ -2142,13 +2142,6 @@ typedef struct Tcl_EncodingType { #define TCL_ENCODING_PROFILE_TCL8 0x01000000 #define TCL_ENCODING_PROFILE_STRICT 0x02000000 #define TCL_ENCODING_PROFILE_REPLACE 0x03000000 -#define TCL_ENCODING_PROFILE_MASK 0xFF000000 -#define TCL_ENCODING_PROFILE_GET(flags_) ((flags_) & TCL_ENCODING_PROFILE_MASK) -#define TCL_ENCODING_PROFILE_SET(flags_, profile_) \ - do { \ - (flags_) &= ~TCL_ENCODING_PROFILE_MASK; \ - (flags_) |= profile_; \ - } while (0) #define TCL_ENCODING_PROFILE_DEFAULT TCL_ENCODING_PROFILE_TCL8 /* diff --git a/generic/tclCmdAH.c b/generic/tclCmdAH.c index 1a1b060..5c27bbc 100644 --- a/generic/tclCmdAH.c +++ b/generic/tclCmdAH.c @@ -675,11 +675,10 @@ EncodingConvertfromObjCmd( * Convert the string into a byte array in 'ds'. */ #if !defined(TCL_NO_DEPRECATED) && (TCL_MAJOR_VERSION < 9) - if (TCL_ENCODING_PROFILE_GET(flags) == TCL_ENCODING_PROFILE_TCL8) { + if (CHANNEL_PROFILE_GET(flags) == TCL_ENCODING_PROFILE_TCL8) { /* Permits high bits to be non-0 in byte array (Tcl 8 style) */ bytesPtr = (char *) Tcl_GetByteArrayFromObj(data, &length); - } - else + } else #endif bytesPtr = (char *) TclGetBytesFromObj(interp, data, &length); diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c index fc9d241..b472db3 100644 --- a/generic/tclEncoding.c +++ b/generic/tclEncoding.c @@ -200,10 +200,10 @@ static struct TclEncodingProfiles { {"tcl8", TCL_ENCODING_PROFILE_TCL8}, }; #define PROFILE_STRICT(flags_) \ - (TCL_ENCODING_PROFILE_GET(flags_) == TCL_ENCODING_PROFILE_STRICT) + (CHANNEL_PROFILE_GET(flags_) == TCL_ENCODING_PROFILE_STRICT) #define PROFILE_REPLACE(flags_) \ - (TCL_ENCODING_PROFILE_GET(flags_) == TCL_ENCODING_PROFILE_REPLACE) + (CHANNEL_PROFILE_GET(flags_) == TCL_ENCODING_PROFILE_REPLACE) #define UNICODE_REPLACE_CHAR ((Tcl_UniChar)0xFFFD) #define SURROGATE(c_) (((c_) & ~0x7FF) == 0xD800) @@ -2527,7 +2527,7 @@ UtfToUtfProc( flags |= PTR2INT(clientData); dstEnd = dst + dstLen - ((flags & ENCODING_UTF) ? TCL_UTF_MAX : 6); - profile = TCL_ENCODING_PROFILE_GET(flags); + profile = CHANNEL_PROFILE_GET(flags); for (numChars = 0; src < srcEnd && numChars <= charLimit; numChars++) { if ((src > srcClose) && (!Tcl_UtfCharComplete(src, srcEnd - src))) { @@ -4545,9 +4545,9 @@ TclEncodingProfileIdToName( int TclEncodingSetProfileFlags(int flags) { if (flags & TCL_ENCODING_STOPONERROR) { - TCL_ENCODING_PROFILE_SET(flags, TCL_ENCODING_PROFILE_STRICT); + CHANNEL_PROFILE_SET(flags, TCL_ENCODING_PROFILE_STRICT); } else { - int profile = TCL_ENCODING_PROFILE_GET(flags); + int profile = CHANNEL_PROFILE_GET(flags); switch (profile) { case TCL_ENCODING_PROFILE_TCL8: case TCL_ENCODING_PROFILE_STRICT: @@ -4555,7 +4555,7 @@ int TclEncodingSetProfileFlags(int flags) break; case 0: /* Unspecified by caller */ default: - TCL_ENCODING_PROFILE_SET(flags, TCL_ENCODING_PROFILE_TCL8); + CHANNEL_PROFILE_SET(flags, TCL_ENCODING_PROFILE_TCL8); break; } } diff --git a/generic/tclExecute.c b/generic/tclExecute.c index 41ce6f0..d4e9796 100644 --- a/generic/tclExecute.c +++ b/generic/tclExecute.c @@ -5279,8 +5279,7 @@ TEBCresume( } if (fromIdx == TCL_INDEX_NONE) { fromIdx = 0; - } - else if (fromIdx > length) { + } else if (fromIdx > length) { fromIdx = length; } numToDelete = 0; @@ -5317,8 +5316,7 @@ TEBCresume( } TRACE_APPEND(("\"%.30s\"\n", O2S(objResultPtr))); NEXT_INST_V(6, opnd, 1); - } - else { + } else { if (Tcl_ListObjReplace(interp, valuePtr, fromIdx, diff --git a/generic/tclIO.c b/generic/tclIO.c index b574e0d..6207f6e 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -1702,11 +1702,11 @@ Tcl_CreateChannel( } statePtr->inputEncodingState = NULL; statePtr->inputEncodingFlags = TCL_ENCODING_START; - TCL_ENCODING_PROFILE_SET(statePtr->inputEncodingFlags, + CHANNEL_PROFILE_SET(statePtr->inputEncodingFlags, TCL_ENCODING_PROFILE_TCL8); statePtr->outputEncodingState = NULL; statePtr->outputEncodingFlags = TCL_ENCODING_START; - TCL_ENCODING_PROFILE_SET(statePtr->outputEncodingFlags, + CHANNEL_PROFILE_SET(statePtr->outputEncodingFlags, TCL_ENCODING_PROFILE_TCL8); /* @@ -8060,7 +8060,7 @@ Tcl_GetChannelOption( Tcl_DStringAppendElement(dsPtr, "-profile"); } /* Note currently input and output profiles are same */ - profile = TCL_ENCODING_PROFILE_GET(statePtr->inputEncodingFlags); + profile = CHANNEL_PROFILE_GET(statePtr->inputEncodingFlags); profileName = TclEncodingProfileIdToName(interp, profile); if (profileName == NULL) { return TCL_ERROR; @@ -8266,12 +8266,12 @@ Tcl_SetChannelOption( Tcl_FreeEncoding(statePtr->encoding); statePtr->encoding = encoding; statePtr->inputEncodingState = NULL; - profile = TCL_ENCODING_PROFILE_GET(statePtr->inputEncodingFlags); + profile = CHANNEL_PROFILE_GET(statePtr->inputEncodingFlags); statePtr->inputEncodingFlags = TCL_ENCODING_START; - TCL_ENCODING_PROFILE_SET(statePtr->inputEncodingFlags, profile); + CHANNEL_PROFILE_SET(statePtr->inputEncodingFlags, profile); statePtr->outputEncodingState = NULL; statePtr->outputEncodingFlags = TCL_ENCODING_START; - TCL_ENCODING_PROFILE_SET(statePtr->outputEncodingFlags, profile); /* Same as input */ + CHANNEL_PROFILE_SET(statePtr->outputEncodingFlags, profile); /* Same as input */ ResetFlag(statePtr, CHANNEL_NEED_MORE_DATA|CHANNEL_ENCODING_ERROR); UpdateInterest(chanPtr); return TCL_OK; @@ -8335,8 +8335,8 @@ Tcl_SetChannelOption( if (TclEncodingProfileNameToId(interp, newValue, &profile) != TCL_OK) { return TCL_ERROR; } - TCL_ENCODING_PROFILE_SET(statePtr->inputEncodingFlags, profile); - TCL_ENCODING_PROFILE_SET(statePtr->outputEncodingFlags, profile); + CHANNEL_PROFILE_SET(statePtr->inputEncodingFlags, profile); + CHANNEL_PROFILE_SET(statePtr->outputEncodingFlags, profile); ResetFlag(statePtr, CHANNEL_NEED_MORE_DATA|CHANNEL_ENCODING_ERROR); return TCL_OK; } else if (HaveOpt(1, "-translation")) { @@ -9468,8 +9468,8 @@ TclCopyChannel( && inStatePtr->inputTranslation == TCL_TRANSLATE_LF && outStatePtr->outputTranslation == TCL_TRANSLATE_LF && inStatePtr->encoding == outStatePtr->encoding - && TCL_ENCODING_PROFILE_GET(inStatePtr->flags) != TCL_ENCODING_PROFILE_STRICT - && TCL_ENCODING_PROFILE_GET(outStatePtr->flags) == TCL_ENCODING_PROFILE_TCL8; + && CHANNEL_PROFILE_GET(inStatePtr->flags) != TCL_ENCODING_PROFILE_STRICT + && CHANNEL_PROFILE_GET(outStatePtr->flags) == TCL_ENCODING_PROFILE_TCL8; /* * Allocate a new CopyState to maintain info about the current copy in @@ -9797,8 +9797,8 @@ CopyData( inBinary = (inStatePtr->encoding == NULL); outBinary = (outStatePtr->encoding == NULL); sameEncoding = inStatePtr->encoding == outStatePtr->encoding - && TCL_ENCODING_PROFILE_GET(inStatePtr->flags) != TCL_ENCODING_PROFILE_STRICT - && TCL_ENCODING_PROFILE_GET(outStatePtr->flags) == TCL_ENCODING_PROFILE_TCL8; + && CHANNEL_PROFILE_GET(inStatePtr->flags) != TCL_ENCODING_PROFILE_STRICT + && CHANNEL_PROFILE_GET(outStatePtr->flags) == TCL_ENCODING_PROFILE_TCL8; if (!(inBinary || sameEncoding)) { TclNewObj(bufObj); diff --git a/generic/tclIO.h b/generic/tclIO.h index cdd96ff..5d02569 100644 --- a/generic/tclIO.h +++ b/generic/tclIO.h @@ -286,6 +286,13 @@ typedef struct ChannelState { #define CHANNEL_CLOSEDWRITE (1<<21) /* Channel write side has been closed. * No further Tcl-level write IO on * the channel is allowed. */ +#define CHANNEL_PROFILE_MASK 0xFF000000 +#define CHANNEL_PROFILE_GET(flags_) ((flags_) & CHANNEL_PROFILE_MASK) +#define CHANNEL_PROFILE_SET(flags_, profile_) \ + do { \ + (flags_) &= ~CHANNEL_PROFILE_MASK; \ + (flags_) |= profile_; \ + } while (0) /* * The length of time to wait between synthetic timer events. Must be zero or diff --git a/generic/tclTest.c b/generic/tclTest.c index f68029a..442260b 100644 --- a/generic/tclTest.c +++ b/generic/tclTest.c @@ -2103,8 +2103,7 @@ static int UtfExtWrapper( int flag; if (Tcl_GetIntFromObj(NULL, flagObjs[i], &flag) == TCL_OK) { flags |= flag; - } - else { + } else { int idx; if (Tcl_GetIndexFromObjStruct(interp, flagObjs[i], diff --git a/generic/tclTestObj.c b/generic/tclTestObj.c index 66657d9..b4c6ac3 100644 --- a/generic/tclTestObj.c +++ b/generic/tclTestObj.c @@ -1113,8 +1113,7 @@ TestobjCmd( if (objv[2]->typePtr == NULL) { Tcl_SetObjResult(interp, Tcl_NewStringObj("none", -1)); - } - else { + } else { typeName = objv[2]->typePtr->name; if (!strcmp(typeName, "utf32string")) typeName = "string"; diff --git a/generic/tclZlib.c b/generic/tclZlib.c index 3182c27..5afe1ed 100644 --- a/generic/tclZlib.c +++ b/generic/tclZlib.c @@ -453,8 +453,7 @@ GenerateHeader( if (result == TCL_CONVERT_UNKNOWN) { Tcl_AppendResult( interp, "Comment contains characters > 0xFF", NULL); - } - else { + } else { Tcl_AppendResult(interp, "Comment too large for zip", NULL); } } @@ -489,8 +488,7 @@ GenerateHeader( if (result == TCL_CONVERT_UNKNOWN) { Tcl_AppendResult( interp, "Filename contains characters > 0xFF", NULL); - } - else { + } else { Tcl_AppendResult( interp, "Filename too large for zip", NULL); } diff --git a/win/tclWinConsole.c b/win/tclWinConsole.c index 6688ab1..c93c3e4 100644 --- a/win/tclWinConsole.c +++ b/win/tclWinConsole.c @@ -882,8 +882,7 @@ ConsoleCheckProc( */ handleInfoPtr->flags |= CONSOLE_DATA_AWAITED; WakeConditionVariable(&handleInfoPtr->consoleThreadCV); - } - else if (chanInfoPtr->watchMask & TCL_WRITABLE) { + } else if (chanInfoPtr->watchMask & TCL_WRITABLE) { if (RingBufferHasFreeSpace(&handleInfoPtr->buffer)) { needEvent = 1; /* Output space available */ } -- cgit v0.12