Compare commits

...
4 changed files with 29 additions and 63 deletions
+3 -3
View File
@@ -611,11 +611,11 @@ numArgsError: /* ONLY jump here if nothing needs to be freed!!! */
}
switch (optIndex) {
case PROFILE:
if (TclEncodingProfileNameToId(interp,
Tcl_GetString(objv[argIndex]),
&profile) != TCL_OK) {
if (Tcl_GetIndexFromObjStruct(interp, objv[argIndex], TclEncodingProfiles,
sizeof(TclEncodingProfiles[0]), "profile", 0, &profile) != TCL_OK) {
return TCL_ERROR;
}
profile = TclEncodingProfiles[profile].value;
break;
case FAILINDEX:
failVarObj = objv[argIndex];
+11 -55
View File
@@ -190,13 +190,11 @@ Tcl_Encoding tclIdentityEncoding = NULL;
/*
* Names of encoding profiles and corresponding integer values
*/
static struct TclEncodingProfiles {
const char *name;
int value;
} encodingProfiles[] = {
{"tcl8", TCL_ENCODING_PROFILE_TCL8},
{"strict", TCL_ENCODING_PROFILE_STRICT},
const TclEncodingProfile TclEncodingProfiles[] = {
{"replace", TCL_ENCODING_PROFILE_REPLACE},
{"strict", TCL_ENCODING_PROFILE_STRICT},
{"tcl8", TCL_ENCODING_PROFILE_TCL8},
{NULL, 0},
};
#define PROFILE_STRICT(flags_) \
((TCL_ENCODING_PROFILE_GET(flags_) == TCL_ENCODING_PROFILE_STRICT) \
@@ -4391,47 +4389,6 @@ InitializeEncodingSearchPath(
Tcl_DecrRefCount(searchPathObj);
}
/*
*------------------------------------------------------------------------
*
* TclEncodingProfileParseName --
*
* Maps an encoding profile name to its integer equivalent.
*
* Results:
* TCL_OK on success or TCL_ERROR on failure.
*
* Side effects:
* Returns the profile enum value in *profilePtr
*
*------------------------------------------------------------------------
*/
int
TclEncodingProfileNameToId(
Tcl_Interp *interp, /* For error messages. May be NULL */
const char *profileName, /* Name of profile */
int *profilePtr) /* Output */
{
size_t i;
for (i = 0; i < sizeof(encodingProfiles) / sizeof(encodingProfiles[0]); ++i) {
if (!strcmp(profileName, encodingProfiles[i].name)) {
*profilePtr = encodingProfiles[i].value;
return TCL_OK;
}
}
if (interp) {
Tcl_SetObjResult(
interp,
Tcl_ObjPrintf(
"bad profile \"%s\". Must be \"tcl8\" or \"strict\".",
profileName));
Tcl_SetErrorCode(
interp, "TCL", "ENCODING", "PROFILE", profileName, NULL);
}
return TCL_ERROR;
}
/*
*------------------------------------------------------------------------
*
@@ -4454,9 +4411,9 @@ TclEncodingProfileIdToName(
{
size_t i;
for (i = 0; i < sizeof(encodingProfiles) / sizeof(encodingProfiles[0]); ++i) {
if (profileValue == encodingProfiles[i].value) {
return encodingProfiles[i].name;
for (i = 0; TclEncodingProfiles[i].name != NULL; ++i) {
if (profileValue == TclEncodingProfiles[i].value) {
return TclEncodingProfiles[i].name;
}
}
if (interp) {
@@ -4532,13 +4489,12 @@ int TclEncodingSetProfileFlags(int flags)
void
TclGetEncodingProfiles(Tcl_Interp *interp)
{
int i, n;
int i;
Tcl_Obj *objPtr;
n = sizeof(encodingProfiles) / sizeof(encodingProfiles[0]);
objPtr = Tcl_NewListObj(n, NULL);
for (i = 0; i < n; ++i) {
objPtr = Tcl_NewListObj(0, NULL);
for (i = 0; TclEncodingProfiles[i].name; ++i) {
Tcl_ListObjAppendElement(
interp, objPtr, Tcl_NewStringObj(encodingProfiles[i].name, -1));
interp, objPtr, Tcl_NewStringObj(TclEncodingProfiles[i].name, -1));
}
Tcl_SetObjResult(interp, objPtr);
}
+9 -1
View File
@@ -8287,9 +8287,17 @@ Tcl_SetChannelOption(
return TCL_OK;
} else if (HaveOpt(1, "-encodingprofile")) {
int profile;
if (TclEncodingProfileNameToId(interp, newValue, &profile) != TCL_OK) {
len = strlen(newValue);
for (profile = 0; TclEncodingProfiles[profile].name; ++profile) {
if (len > 0 && strncmp(newValue, TclEncodingProfiles[profile].name, len) == 0) {
break;
}
}
if (TclEncodingProfiles[profile].name == NULL) {
Tcl_AppendResult(interp, "bad value for -encodingprofile: must be one of replace, strict, or tcl8", NULL);
return TCL_ERROR;
}
profile = TclEncodingProfiles[profile].value;
TCL_ENCODING_PROFILE_SET(statePtr->inputEncodingFlags, profile);
TCL_ENCODING_PROFILE_SET(statePtr->outputEncodingFlags, profile);
ResetFlag(statePtr, CHANNEL_NEED_MORE_DATA|CHANNEL_ENCODING_ERROR);
+6 -4
View File
@@ -2884,10 +2884,12 @@ MODULE_SCOPE TclPlatformType tclPlatform;
*/
MODULE_SCOPE Tcl_Encoding tclIdentityEncoding;
MODULE_SCOPE int
TclEncodingProfileNameToId(Tcl_Interp *interp,
const char *profileName,
int *profilePtr);
typedef struct {
const char *name;
int value;
} TclEncodingProfile;
MODULE_SCOPE const TclEncodingProfile TclEncodingProfiles[];
MODULE_SCOPE const char *TclEncodingProfileIdToName(Tcl_Interp *interp,
int profileId);
MODULE_SCOPE int TclEncodingSetProfileFlags(int flags);