summaryrefslogtreecommitdiffstats
path: root/generic/tclEncoding.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tclEncoding.c')
-rw-r--r--generic/tclEncoding.c864
1 files changed, 438 insertions, 426 deletions
diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c
index 633d589..54a49aa 100644
--- a/generic/tclEncoding.c
+++ b/generic/tclEncoding.c
@@ -37,7 +37,7 @@ typedef struct Encoding {
* end-of-string in this encoding. This number
* is used to determine the source string
* length when the srcLen argument is
- * TCL_STRLEN. This number can be 1 or 2. */
+ * negative. This number can be 1 or 2. */
ClientData clientData; /* Arbitrary value associated with encoding
* type. Passed to conversion functions. */
LengthProc *lengthProc; /* Function to compute length of
@@ -92,7 +92,7 @@ typedef struct TableEncodingData {
*/
typedef struct EscapeSubTable {
- unsigned sequenceLen; /* Length of following string. */
+ unsigned int sequenceLen; /* Length of following string. */
char sequence[16]; /* Escape code that marks this encoding. */
char name[32]; /* Name for encoding. */
Encoding *encodingPtr; /* Encoding loaded using above name, or NULL
@@ -104,10 +104,10 @@ typedef struct EscapeEncodingData {
int fallback; /* Character (in this encoding) to substitute
* when this encoding cannot represent a UTF-8
* character. */
- unsigned initLen; /* Length of following string. */
+ unsigned int initLen; /* Length of following string. */
char init[16]; /* String to emit or expect before first char
* in conversion. */
- unsigned finalLen; /* Length of following string. */
+ unsigned int finalLen; /* Length of following string. */
char final[16]; /* String to emit or expect after last char in
* conversion. */
char prefixBytes[256]; /* If a byte in the input stream is the first
@@ -123,7 +123,7 @@ typedef struct EscapeEncodingData {
} EscapeEncodingData;
/*
- * Constants used when loading an encoding file to identify the type of the
+ * constants used when loading an encoding file to identify the type of the
* file.
*/
@@ -182,6 +182,7 @@ TCL_DECLARE_MUTEX(encodingMutex)
static Tcl_Encoding defaultEncoding;
static Tcl_Encoding systemEncoding;
+Tcl_Encoding tclIdentityEncoding;
/*
* The following variable is used in the sparse matrix code for a
@@ -194,11 +195,23 @@ static unsigned short emptyPage[256];
* Functions used only in this module.
*/
-static Tcl_EncodingConvertProc BinaryProc;
+static int BinaryProc(ClientData clientData,
+ const char *src, int srcLen, int flags,
+ Tcl_EncodingState *statePtr, char *dst, int dstLen,
+ int *srcReadPtr, int *dstWrotePtr,
+ int *dstCharsPtr);
static void DupEncodingIntRep(Tcl_Obj *srcPtr, Tcl_Obj *dupPtr);
-static Tcl_EncodingFreeProc EscapeFreeProc;
-static Tcl_EncodingConvertProc EscapeFromUtfProc;
-static Tcl_EncodingConvertProc EscapeToUtfProc;
+static void EscapeFreeProc(ClientData clientData);
+static int EscapeFromUtfProc(ClientData clientData,
+ const char *src, int srcLen, int flags,
+ Tcl_EncodingState *statePtr, char *dst, int dstLen,
+ int *srcReadPtr, int *dstWrotePtr,
+ int *dstCharsPtr);
+static int EscapeToUtfProc(ClientData clientData,
+ const char *src, int srcLen, int flags,
+ Tcl_EncodingState *statePtr, char *dst, int dstLen,
+ int *srcReadPtr, int *dstWrotePtr,
+ int *dstCharsPtr);
static void FillEncodingFileMap(void);
static void FreeEncoding(Tcl_Encoding encoding);
static void FreeEncodingIntRep(Tcl_Obj *objPtr);
@@ -210,30 +223,60 @@ static Tcl_Encoding LoadTableEncoding(const char *name, int type,
static Tcl_Encoding LoadEscapeEncoding(const char *name, Tcl_Channel chan);
static Tcl_Channel OpenEncodingFileChannel(Tcl_Interp *interp,
const char *name);
-static Tcl_EncodingFreeProc TableFreeProc;
-static Tcl_EncodingConvertProc TableFromUtfProc;
-static Tcl_EncodingConvertProc TableToUtfProc;
+static void TableFreeProc(ClientData clientData);
+static int TableFromUtfProc(ClientData clientData,
+ const char *src, int srcLen, int flags,
+ Tcl_EncodingState *statePtr, char *dst, int dstLen,
+ int *srcReadPtr, int *dstWrotePtr,
+ int *dstCharsPtr);
+static int TableToUtfProc(ClientData clientData, const char *src,
+ int srcLen, int flags, Tcl_EncodingState *statePtr,
+ char *dst, int dstLen, int *srcReadPtr,
+ int *dstWrotePtr, int *dstCharsPtr);
static size_t unilen(const char *src);
-static Tcl_EncodingConvertProc UnicodeToUtfProc;
-static Tcl_EncodingConvertProc UtfToUnicodeProc;
-static int UtfToUtfProc(ClientData clientData, const char *src,
- size_t srcLen, int flags,
+static int UnicodeToUtfProc(ClientData clientData,
+ const char *src, int srcLen, int flags,
+ Tcl_EncodingState *statePtr, char *dst, int dstLen,
+ int *srcReadPtr, int *dstWrotePtr,
+ int *dstCharsPtr);
+static int UtfToUnicodeProc(ClientData clientData,
+ const char *src, int srcLen, int flags,
+ Tcl_EncodingState *statePtr, char *dst, int dstLen,
+ int *srcReadPtr, int *dstWrotePtr,
+ int *dstCharsPtr);
+static int UtfToUtfProc(ClientData clientData,
+ const char *src, int srcLen, int flags,
+ Tcl_EncodingState *statePtr, char *dst, int dstLen,
+ int *srcReadPtr, int *dstWrotePtr,
+ int *dstCharsPtr, int pureNullMode);
+static int UtfIntToUtfExtProc(ClientData clientData,
+ const char *src, int srcLen, int flags,
+ Tcl_EncodingState *statePtr, char *dst, int dstLen,
+ int *srcReadPtr, int *dstWrotePtr,
+ int *dstCharsPtr);
+static int UtfExtToUtfIntProc(ClientData clientData,
+ const char *src, int srcLen, int flags,
+ Tcl_EncodingState *statePtr, char *dst, int dstLen,
+ int *srcReadPtr, int *dstWrotePtr,
+ int *dstCharsPtr);
+static int Iso88591FromUtfProc(ClientData clientData,
+ const char *src, int srcLen, int flags,
+ Tcl_EncodingState *statePtr, char *dst, int dstLen,
+ int *srcReadPtr, int *dstWrotePtr,
+ int *dstCharsPtr);
+static int Iso88591ToUtfProc(ClientData clientData,
+ const char *src, int srcLen, int flags,
Tcl_EncodingState *statePtr, char *dst,
- size_t dstLen, size_t *srcReadPtr,
- size_t *dstWrotePtr, size_t *dstCharsPtr,
- int pureNullMode);
-static Tcl_EncodingConvertProc UtfIntToUtfExtProc;
-static Tcl_EncodingConvertProc UtfExtToUtfIntProc;
-static Tcl_EncodingConvertProc Iso88591FromUtfProc;
-static Tcl_EncodingConvertProc Iso88591ToUtfProc;
+ int dstLen, int *srcReadPtr, int *dstWrotePtr,
+ int *dstCharsPtr);
/*
- * A Tcl_ObjType for holding a cached Tcl_Encoding in the otherValuePtr field
+ * A Tcl_ObjType for holding a cached Tcl_Encoding in the twoPtrValue.ptr1 field
* of the intrep. This should help the lifetime of encodings be more useful.
* See concerns raised in [Bug 1077262].
*/
-static const Tcl_ObjType encodingType = {
+static Tcl_ObjType encodingType = {
"encoding", FreeEncodingIntRep, DupEncodingIntRep, NULL, NULL
};
@@ -251,7 +294,7 @@ static const Tcl_ObjType encodingType = {
* Standard Tcl return code.
*
* Side effects:
- * Caches the Tcl_Encoding value as the internal rep of (*objPtr).
+ * Caches the Tcl_Encoding value as the internal rep of (*objPtr).
*
*----------------------------------------------------------------------
*/
@@ -263,7 +306,6 @@ Tcl_GetEncodingFromObj(
Tcl_Encoding *encodingPtr)
{
const char *name = Tcl_GetString(objPtr);
-
if (objPtr->typePtr != &encodingType) {
Tcl_Encoding encoding = Tcl_GetEncoding(interp, name);
@@ -271,7 +313,7 @@ Tcl_GetEncodingFromObj(
return TCL_ERROR;
}
TclFreeIntRep(objPtr);
- objPtr->internalRep.otherValuePtr = encoding;
+ objPtr->internalRep.twoPtrValue.ptr1 = (VOID *) encoding;
objPtr->typePtr = &encodingType;
}
*encodingPtr = Tcl_GetEncoding(NULL, name);
@@ -292,7 +334,7 @@ static void
FreeEncodingIntRep(
Tcl_Obj *objPtr)
{
- Tcl_FreeEncoding(objPtr->internalRep.otherValuePtr);
+ Tcl_FreeEncoding((Tcl_Encoding) objPtr->internalRep.twoPtrValue.ptr1);
objPtr->typePtr = NULL;
}
@@ -311,7 +353,8 @@ DupEncodingIntRep(
Tcl_Obj *srcPtr,
Tcl_Obj *dupPtr)
{
- dupPtr->internalRep.otherValuePtr = Tcl_GetEncoding(NULL, srcPtr->bytes);
+ dupPtr->internalRep.twoPtrValue.ptr1 = (VOID *)
+ Tcl_GetEncoding(NULL, srcPtr->bytes);
}
/*
@@ -349,7 +392,7 @@ int
Tcl_SetEncodingSearchPath(
Tcl_Obj *searchPath)
{
- size_t dummy;
+ int dummy;
if (TCL_ERROR == Tcl_ListObjLength(NULL, searchPath, &dummy)) {
return TCL_ERROR;
@@ -397,7 +440,7 @@ void
TclSetLibraryPath(
Tcl_Obj *path)
{
- size_t dummy;
+ int dummy;
if (TCL_ERROR == Tcl_ListObjLength(NULL, path, &dummy)) {
return;
@@ -410,8 +453,8 @@ TclSetLibraryPath(
*
* FillEncodingFileMap --
*
- * Called to bring the encoding file map in sync with the current value
- * of the encoding search path.
+ * Called to bring the encoding file map in sync with the current value
+ * of the encoding search path.
*
* Scan the directories on the encoding search path, find the *.enc
* files, and store the found pathnames in a map associated with the
@@ -434,7 +477,7 @@ TclSetLibraryPath(
static void
FillEncodingFileMap(void)
{
- size_t i, numDirs = 0;
+ int i, numDirs = 0;
Tcl_Obj *map, *searchPath;
searchPath = Tcl_GetEncodingSearchPath();
@@ -443,13 +486,13 @@ FillEncodingFileMap(void)
map = Tcl_NewDictObj();
Tcl_IncrRefCount(map);
- for (i = numDirs; i-->0 ;) {
+ for (i = numDirs-1; i >= 0; i--) {
/*
* Iterate backwards through the search path so as we overwrite
* entries found, we favor files earlier on the search path.
*/
- size_t j, numFiles;
+ int j, numFiles;
Tcl_Obj *directory, *matchFileList = Tcl_NewObj();
Tcl_Obj **filev;
Tcl_GlobTypeData readableFiles = {
@@ -464,12 +507,12 @@ FillEncodingFileMap(void)
Tcl_ListObjGetElements(NULL, matchFileList, &numFiles, &filev);
for (j=0; j<numFiles; j++) {
- Tcl_Obj *encodingName, *fileObj;
+ Tcl_Obj *encodingName, *file;
- fileObj = TclPathPart(NULL, filev[j], TCL_PATH_TAIL);
- encodingName = TclPathPart(NULL, fileObj, TCL_PATH_ROOT);
+ file = TclPathPart(NULL, filev[j], TCL_PATH_TAIL);
+ encodingName = TclPathPart(NULL, file, TCL_PATH_ROOT);
Tcl_DictObjPut(NULL, map, encodingName, directory);
- Tcl_DecrRefCount(fileObj);
+ Tcl_DecrRefCount(file);
Tcl_DecrRefCount(encodingName);
}
Tcl_DecrRefCount(matchFileList);
@@ -501,9 +544,6 @@ void
TclInitEncodingSubsystem(void)
{
Tcl_EncodingType type;
- TableEncodingData *dataPtr;
- unsigned size;
- unsigned short i;
if (encodingsInitialized) {
return;
@@ -525,7 +565,10 @@ TclInitEncodingSubsystem(void)
type.freeProc = NULL;
type.nullSize = 1;
type.clientData = NULL;
- Tcl_CreateEncoding(&type);
+
+ defaultEncoding = Tcl_CreateEncoding(&type);
+ tclIdentityEncoding = Tcl_GetEncoding(NULL, type.encodingName);
+ systemEncoding = Tcl_GetEncoding(NULL, type.encodingName);
type.encodingName = "utf-8";
type.toUtfProc = UtfExtToUtfIntProc;
@@ -550,37 +593,43 @@ TclInitEncodingSubsystem(void)
* code to duplicate the structure of a table encoding here.
*/
- dataPtr = ckalloc(sizeof(TableEncodingData));
- memset(dataPtr, 0, sizeof(TableEncodingData));
- dataPtr->fallback = '?';
-
- size = 256*(sizeof(unsigned short *) + sizeof(unsigned short));
- dataPtr->toUnicode = ckalloc(size);
- memset(dataPtr->toUnicode, 0, size);
- dataPtr->fromUnicode = ckalloc(size);
- memset(dataPtr->fromUnicode, 0, size);
+ {
+ TableEncodingData *dataPtr = (TableEncodingData *)
+ ckalloc(sizeof(TableEncodingData));
+ unsigned size;
+ unsigned short i;
+
+ memset(dataPtr, 0, sizeof(TableEncodingData));
+ dataPtr->fallback = '?';
+
+ size = 256*(sizeof(unsigned short *) + sizeof(unsigned short));
+ dataPtr->toUnicode = (unsigned short **) ckalloc(size);
+ memset(dataPtr->toUnicode, 0, size);
+ dataPtr->fromUnicode = (unsigned short **) ckalloc(size);
+ memset(dataPtr->fromUnicode, 0, size);
+
+ dataPtr->toUnicode[0] = (unsigned short *) (dataPtr->toUnicode + 256);
+ dataPtr->fromUnicode[0] = (unsigned short *)
+ (dataPtr->fromUnicode + 256);
+ for (i=1 ; i<256 ; i++) {
+ dataPtr->toUnicode[i] = emptyPage;
+ dataPtr->fromUnicode[i] = emptyPage;
+ }
- dataPtr->toUnicode[0] = (unsigned short *) (dataPtr->toUnicode + 256);
- dataPtr->fromUnicode[0] = (unsigned short *) (dataPtr->fromUnicode + 256);
- for (i=1 ; i<256 ; i++) {
- dataPtr->toUnicode[i] = emptyPage;
- dataPtr->fromUnicode[i] = emptyPage;
- }
+ for (i=0 ; i<256 ; i++) {
+ dataPtr->toUnicode[0][i] = i;
+ dataPtr->fromUnicode[0][i] = i;
+ }
- for (i=0 ; i<256 ; i++) {
- dataPtr->toUnicode[0][i] = i;
- dataPtr->fromUnicode[0][i] = i;
+ type.encodingName = "iso8859-1";
+ type.toUtfProc = Iso88591ToUtfProc;
+ type.fromUtfProc = Iso88591FromUtfProc;
+ type.freeProc = TableFreeProc;
+ type.nullSize = 1;
+ type.clientData = dataPtr;
+ Tcl_CreateEncoding(&type);
}
- type.encodingName = "iso8859-1";
- type.toUtfProc = Iso88591ToUtfProc;
- type.fromUtfProc = Iso88591FromUtfProc;
- type.freeProc = TableFreeProc;
- type.nullSize = 1;
- type.clientData = dataPtr;
- defaultEncoding = Tcl_CreateEncoding(&type);
- systemEncoding = Tcl_GetEncoding(NULL, type.encodingName);
-
encodingsInitialized = 1;
}
@@ -609,6 +658,7 @@ TclFinalizeEncodingSubsystem(void)
Tcl_MutexLock(&encodingMutex);
encodingsInitialized = 0;
FreeEncoding(systemEncoding);
+ FreeEncoding(tclIdentityEncoding);
hPtr = Tcl_FirstHashEntry(&encodingTable, &search);
while (hPtr != NULL) {
@@ -619,7 +669,7 @@ TclFinalizeEncodingSubsystem(void)
* cleaned up.
*/
- FreeEncoding(Tcl_GetHashValue(hPtr));
+ FreeEncoding((Tcl_Encoding) Tcl_GetHashValue(hPtr));
hPtr = Tcl_FirstHashEntry(&encodingTable, &search);
}
@@ -632,15 +682,15 @@ TclFinalizeEncodingSubsystem(void)
*
* Tcl_GetDefaultEncodingDir --
*
- * Legacy public interface to retrieve first directory in the encoding
- * searchPath.
+ * Legacy public interface to retrieve first directory in the encoding
+ * searchPath.
*
* Results:
* The directory pathname, as a string, or NULL for an empty encoding
* search path.
*
* Side effects:
- * None.
+ * None.
*
*-------------------------------------------------------------------------
*/
@@ -648,7 +698,7 @@ TclFinalizeEncodingSubsystem(void)
const char *
Tcl_GetDefaultEncodingDir(void)
{
- size_t numDirs;
+ int numDirs;
Tcl_Obj *first, *searchPath = Tcl_GetEncodingSearchPath();
Tcl_ListObjLength(NULL, searchPath, &numDirs);
@@ -665,14 +715,14 @@ Tcl_GetDefaultEncodingDir(void)
*
* Tcl_SetDefaultEncodingDir --
*
- * Legacy public interface to set the first directory in the encoding
- * search path.
+ * Legacy public interface to set the first directory in the encoding
+ * search path.
*
* Results:
- * None.
+ * None.
*
* Side effects:
- * Modifies the encoding search path.
+ * Modifies the encoding search path.
*
*-------------------------------------------------------------------------
*/
@@ -682,7 +732,7 @@ Tcl_SetDefaultEncodingDir(
const char *path)
{
Tcl_Obj *searchPath = Tcl_GetEncodingSearchPath();
- Tcl_Obj *directory = Tcl_NewStringObj(path, TCL_STRLEN);
+ Tcl_Obj *directory = Tcl_NewStringObj(path, -1);
searchPath = Tcl_DuplicateObj(searchPath);
Tcl_ListObjReplace(NULL, searchPath, 0, 0, 1, &directory);
@@ -732,7 +782,7 @@ Tcl_GetEncoding(
hPtr = Tcl_FindHashEntry(&encodingTable, name);
if (hPtr != NULL) {
- encodingPtr = Tcl_GetHashValue(hPtr);
+ encodingPtr = (Encoding *) Tcl_GetHashValue(hPtr);
encodingPtr->refCount++;
Tcl_MutexUnlock(&encodingMutex);
return (Tcl_Encoding) encodingPtr;
@@ -791,8 +841,9 @@ static void
FreeEncoding(
Tcl_Encoding encoding)
{
- Encoding *encodingPtr = (Encoding *) encoding;
+ Encoding *encodingPtr;
+ encodingPtr = (Encoding *) encoding;
if (encodingPtr == NULL) {
return;
}
@@ -802,13 +853,13 @@ FreeEncoding(
encodingPtr->refCount--;
if (encodingPtr->refCount == 0) {
if (encodingPtr->freeProc != NULL) {
- encodingPtr->freeProc(encodingPtr->clientData);
+ (*encodingPtr->freeProc)(encodingPtr->clientData);
}
if (encodingPtr->hPtr != NULL) {
Tcl_DeleteHashEntry(encodingPtr->hPtr);
}
- ckfree(encodingPtr->name);
- ckfree(encodingPtr);
+ ckfree((char *) encodingPtr->name);
+ ckfree((char *) encodingPtr);
}
}
@@ -878,10 +929,9 @@ Tcl_GetEncodingNames(
Tcl_MutexLock(&encodingMutex);
for (hPtr = Tcl_FirstHashEntry(&encodingTable, &search); hPtr != NULL;
hPtr = Tcl_NextHashEntry(&search)) {
- Encoding *encodingPtr = Tcl_GetHashValue(hPtr);
-
+ Encoding *encodingPtr = (Encoding *) Tcl_GetHashValue(hPtr);
Tcl_CreateHashEntry(&table,
- Tcl_NewStringObj(encodingPtr->name, TCL_STRLEN), &dummy);
+ (char *) Tcl_NewStringObj(encodingPtr->name, -1), &dummy);
}
Tcl_MutexUnlock(&encodingMutex);
@@ -894,7 +944,7 @@ Tcl_GetEncodingNames(
Tcl_DictObjFirst(NULL, map, &mapSearch, &name, NULL, &done);
for (; !done; Tcl_DictObjNext(&mapSearch, &name, NULL, &done)) {
- Tcl_CreateHashEntry(&table, name, &dummy);
+ Tcl_CreateHashEntry(&table, (char *) name, &dummy);
}
/*
@@ -1008,13 +1058,13 @@ Tcl_CreateEncoding(
* reference goes away.
*/
- encodingPtr = Tcl_GetHashValue(hPtr);
+ encodingPtr = (Encoding *) Tcl_GetHashValue(hPtr);
encodingPtr->hPtr = NULL;
}
- name = ckalloc(strlen(typePtr->encodingName) + 1);
+ name = ckalloc((unsigned) strlen(typePtr->encodingName) + 1);
- encodingPtr = ckalloc(sizeof(Encoding));
+ encodingPtr = (Encoding *) ckalloc(sizeof(Encoding));
encodingPtr->name = strcpy(name, typePtr->encodingName);
encodingPtr->toUtfProc = typePtr->toUtfProc;
encodingPtr->fromUtfProc = typePtr->fromUtfProc;
@@ -1061,17 +1111,15 @@ Tcl_ExternalToUtfDString(
Tcl_Encoding encoding, /* The encoding for the source string, or NULL
* for the default system encoding. */
const char *src, /* Source string in specified encoding. */
- size_t srcLen, /* Source string length in bytes, or
- * TCL_STRLEN for encoding-specific string
- * length. */
+ int srcLen, /* Source string length in bytes, or < 0 for
+ * encoding-specific string length. */
Tcl_DString *dstPtr) /* Uninitialized or free DString in which the
* converted string is stored. */
{
char *dst;
Tcl_EncodingState state;
- const Encoding *encodingPtr;
- int flags, result;
- size_t dstLen, soFar, srcRead, dstWrote, dstChars;
+ Encoding *encodingPtr;
+ int flags, dstLen, result, soFar, srcRead, dstWrote, dstChars;
Tcl_DStringInit(dstPtr);
dst = Tcl_DStringValue(dstPtr);
@@ -1084,15 +1132,16 @@ Tcl_ExternalToUtfDString(
if (src == NULL) {
srcLen = 0;
- } else if (srcLen == TCL_STRLEN) {
- srcLen = encodingPtr->lengthProc(src);
+ } else if (srcLen < 0) {
+ srcLen = (*encodingPtr->lengthProc)(src);
}
flags = TCL_ENCODING_START | TCL_ENCODING_END;
while (1) {
- result = encodingPtr->toUtfProc(encodingPtr->clientData, src, srcLen,
- flags, &state, dst, dstLen, &srcRead, &dstWrote, &dstChars);
+ result = (*encodingPtr->toUtfProc)(encodingPtr->clientData, src,
+ srcLen, flags, &state, dst, dstLen, &srcRead, &dstWrote,
+ &dstChars);
soFar = dst + dstWrote - Tcl_DStringValue(dstPtr);
if (result != TCL_CONVERT_NOSPACE) {
@@ -1136,9 +1185,8 @@ Tcl_ExternalToUtf(
Tcl_Encoding encoding, /* The encoding for the source string, or NULL
* for the default system encoding. */
const char *src, /* Source string in specified encoding. */
- size_t srcLen, /* Source string length in bytes, or
- * TCL_STRLEN for encoding-specific string
- * length. */
+ int srcLen, /* Source string length in bytes, or < 0 for
+ * encoding-specific string length. */
int flags, /* Conversion control flags. */
Tcl_EncodingState *statePtr,/* Place for conversion routine to store state
* information used during a piecewise
@@ -1147,23 +1195,22 @@ Tcl_ExternalToUtf(
* routine under control of flags argument. */
char *dst, /* Output buffer in which converted string is
* stored. */
- size_t dstLen, /* The maximum length of output buffer in
+ int dstLen, /* The maximum length of output buffer in
* bytes. */
- size_t *srcReadPtr, /* Filled with the number of bytes from the
+ int *srcReadPtr, /* Filled with the number of bytes from the
* source string that were converted. This may
* be less than the original source length if
* there was a problem converting some source
* characters. */
- size_t *dstWrotePtr, /* Filled with the number of bytes that were
+ int *dstWrotePtr, /* Filled with the number of bytes that were
* stored in the output buffer as a result of
* the conversion. */
- size_t *dstCharsPtr) /* Filled with the number of characters that
+ int *dstCharsPtr) /* Filled with the number of characters that
* correspond to the bytes stored in the
* output buffer. */
{
- const Encoding *encodingPtr;
- int result;
- size_t srcRead, dstWrote, dstChars;
+ Encoding *encodingPtr;
+ int result, srcRead, dstWrote, dstChars;
Tcl_EncodingState state;
if (encoding == NULL) {
@@ -1173,8 +1220,8 @@ Tcl_ExternalToUtf(
if (src == NULL) {
srcLen = 0;
- } else if (srcLen == TCL_STRLEN) {
- srcLen = encodingPtr->lengthProc(src);
+ } else if (srcLen < 0) {
+ srcLen = (*encodingPtr->lengthProc)(src);
}
if (statePtr == NULL) {
flags |= TCL_ENCODING_START | TCL_ENCODING_END;
@@ -1197,7 +1244,7 @@ Tcl_ExternalToUtf(
*/
dstLen--;
- result = encodingPtr->toUtfProc(encodingPtr->clientData, src, srcLen,
+ result = (*encodingPtr->toUtfProc)(encodingPtr->clientData, src, srcLen,
flags, statePtr, dst, dstLen, srcReadPtr, dstWrotePtr,
dstCharsPtr);
dst[*dstWrotePtr] = '\0';
@@ -1231,16 +1278,15 @@ Tcl_UtfToExternalDString(
Tcl_Encoding encoding, /* The encoding for the converted string, or
* NULL for the default system encoding. */
const char *src, /* Source string in UTF-8. */
- size_t srcLen, /* Source string length in bytes, or
- * TCL_STRLEN for strlen(). */
+ int srcLen, /* Source string length in bytes, or < 0 for
+ * strlen(). */
Tcl_DString *dstPtr) /* Uninitialized or free DString in which the
* converted string is stored. */
{
char *dst;
Tcl_EncodingState state;
- const Encoding *encodingPtr;
- int flags, result;
- size_t dstLen, soFar, srcRead, dstWrote, dstChars;
+ Encoding *encodingPtr;
+ int flags, dstLen, result, soFar, srcRead, dstWrote, dstChars;
Tcl_DStringInit(dstPtr);
dst = Tcl_DStringValue(dstPtr);
@@ -1253,12 +1299,12 @@ Tcl_UtfToExternalDString(
if (src == NULL) {
srcLen = 0;
- } else if (srcLen == TCL_STRLEN) {
+ } else if (srcLen < 0) {
srcLen = strlen(src);
}
flags = TCL_ENCODING_START | TCL_ENCODING_END;
while (1) {
- result = encodingPtr->fromUtfProc(encodingPtr->clientData, src,
+ result = (*encodingPtr->fromUtfProc)(encodingPtr->clientData, src,
srcLen, flags, &state, dst, dstLen, &srcRead, &dstWrote,
&dstChars);
soFar = dst + dstWrote - Tcl_DStringValue(dstPtr);
@@ -1307,8 +1353,8 @@ Tcl_UtfToExternal(
Tcl_Encoding encoding, /* The encoding for the converted string, or
* NULL for the default system encoding. */
const char *src, /* Source string in UTF-8. */
- size_t srcLen, /* Source string length in bytes, or
- * TCL_STRLEN for strlen(). */
+ int srcLen, /* Source string length in bytes, or < 0 for
+ * strlen(). */
int flags, /* Conversion control flags. */
Tcl_EncodingState *statePtr,/* Place for conversion routine to store state
* information used during a piecewise
@@ -1317,23 +1363,22 @@ Tcl_UtfToExternal(
* routine under control of flags argument. */
char *dst, /* Output buffer in which converted string
* is stored. */
- size_t dstLen, /* The maximum length of output buffer in
+ int dstLen, /* The maximum length of output buffer in
* bytes. */
- size_t *srcReadPtr, /* Filled with the number of bytes from the
+ int *srcReadPtr, /* Filled with the number of bytes from the
* source string that were converted. This may
* be less than the original source length if
* there was a problem converting some source
* characters. */
- size_t *dstWrotePtr, /* Filled with the number of bytes that were
+ int *dstWrotePtr, /* Filled with the number of bytes that were
* stored in the output buffer as a result of
* the conversion. */
- size_t *dstCharsPtr) /* Filled with the number of characters that
+ int *dstCharsPtr) /* Filled with the number of characters that
* correspond to the bytes stored in the
* output buffer. */
{
- const Encoding *encodingPtr;
- int result;
- size_t srcRead, dstWrote, dstChars;
+ Encoding *encodingPtr;
+ int result, srcRead, dstWrote, dstChars;
Tcl_EncodingState state;
if (encoding == NULL) {
@@ -1343,7 +1388,7 @@ Tcl_UtfToExternal(
if (src == NULL) {
srcLen = 0;
- } else if (srcLen == TCL_STRLEN) {
+ } else if (srcLen < 0) {
srcLen = strlen(src);
}
if (statePtr == NULL) {
@@ -1361,7 +1406,7 @@ Tcl_UtfToExternal(
}
dstLen -= encodingPtr->nullSize;
- result = encodingPtr->fromUtfProc(encodingPtr->clientData, src, srcLen,
+ result = (*encodingPtr->fromUtfProc)(encodingPtr->clientData, src, srcLen,
flags, statePtr, dst, dstLen, srcReadPtr, dstWrotePtr,
dstCharsPtr);
if (encodingPtr->nullSize == 2) {
@@ -1389,7 +1434,7 @@ Tcl_UtfToExternal(
*
*---------------------------------------------------------------------------
*/
-#undef Tcl_FindExecutable
+
void
Tcl_FindExecutable(
const char *argv0) /* The value of the application's argv[0]
@@ -1408,9 +1453,9 @@ Tcl_FindExecutable(
* Open the file believed to hold data for the encoding, "name".
*
* Results:
- * Returns the readable Tcl_Channel from opening the file, or NULL if the
- * file could not be successfully opened. If NULL was returned, an error
- * message is left in interp's result object, unless interp was NULL.
+ * Returns the readable Tcl_Channel from opening the file, or NULL if the
+ * file could not be successfully opened. If NULL was returned, an error
+ * message is left in interp's result object, unless interp was NULL.
*
* Side effects:
* Channel may be opened. Information about the filesystem may be cached
@@ -1425,17 +1470,17 @@ OpenEncodingFileChannel(
const char *name) /* The name of the encoding file on disk and
* also the name for new encoding. */
{
- Tcl_Obj *nameObj = Tcl_NewStringObj(name, TCL_STRLEN);
+ Tcl_Obj *nameObj = Tcl_NewStringObj(name, -1);
Tcl_Obj *fileNameObj = Tcl_DuplicateObj(nameObj);
Tcl_Obj *searchPath = Tcl_DuplicateObj(Tcl_GetEncodingSearchPath());
Tcl_Obj *map = TclGetProcessGlobalValue(&encodingFileMap);
Tcl_Obj **dir, *path, *directory = NULL;
Tcl_Channel chan = NULL;
- size_t i, numDirs;
+ int i, numDirs;
Tcl_ListObjGetElements(NULL, searchPath, &numDirs, &dir);
Tcl_IncrRefCount(nameObj);
- Tcl_AppendToObj(fileNameObj, ".enc", TCL_STRLEN);
+ Tcl_AppendToObj(fileNameObj, ".enc", -1);
Tcl_IncrRefCount(fileNameObj);
Tcl_DictObjGet(NULL, map, nameObj, &directory);
@@ -1453,7 +1498,6 @@ OpenEncodingFileChannel(
}
if (!verified) {
const char *dirString = Tcl_GetString(directory);
-
for (i=0; i<numDirs && !verified; i++) {
if (strcmp(dirString, Tcl_GetString(dir[i])) == 0) {
verified = 1;
@@ -1506,8 +1550,7 @@ OpenEncodingFileChannel(
}
if ((NULL == chan) && (interp != NULL)) {
- Tcl_SetObjResult(interp, Tcl_ObjPrintf(
- "unknown encoding \"%s\"", name));
+ Tcl_AppendResult(interp, "unknown encoding \"", name, "\"", NULL);
Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "ENCODING", name, NULL);
}
Tcl_DecrRefCount(fileNameObj);
@@ -1581,9 +1624,7 @@ LoadEncodingFile(
break;
}
if ((encoding == NULL) && (interp != NULL)) {
- Tcl_SetObjResult(interp, Tcl_ObjPrintf(
- "invalid encoding file \"%s\"", name));
- Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "ENCODING", name, NULL);
+ Tcl_AppendResult(interp, "invalid encoding file \"", name, "\"", NULL);
}
Tcl_Close(NULL, chan);
@@ -1622,11 +1663,11 @@ LoadTableEncoding(
Tcl_DString lineString;
Tcl_Obj *objPtr;
char *line;
- int i, hi, lo, numPages, symbol, fallback, len;
+ int i, hi, lo, numPages, symbol, fallback;
unsigned char used[256];
- unsigned size;
+ unsigned int size;
TableEncodingData *dataPtr;
- unsigned short *pageMemPtr, *page;
+ unsigned short *pageMemPtr;
Tcl_EncodingType encType;
/*
@@ -1673,7 +1714,7 @@ LoadTableEncoding(
#undef PAGESIZE
#define PAGESIZE (256 * sizeof(unsigned short))
- dataPtr = ckalloc(sizeof(TableEncodingData));
+ dataPtr = (TableEncodingData *) ckalloc(sizeof(TableEncodingData));
memset(dataPtr, 0, sizeof(TableEncodingData));
dataPtr->fallback = fallback;
@@ -1685,7 +1726,7 @@ LoadTableEncoding(
*/
size = 256 * sizeof(unsigned short *) + numPages * PAGESIZE;
- dataPtr->toUnicode = ckalloc(size);
+ dataPtr->toUnicode = (unsigned short **) ckalloc(size);
memset(dataPtr->toUnicode, 0, size);
pageMemPtr = (unsigned short *) (dataPtr->toUnicode + 256);
@@ -1693,7 +1734,7 @@ LoadTableEncoding(
Tcl_IncrRefCount(objPtr);
for (i = 0; i < numPages; i++) {
int ch;
- const char *p;
+ char *p;
Tcl_ReadChars(chan, objPtr, 3 + 16 * (16 * 4 + 1), 0);
p = Tcl_GetString(objPtr);
@@ -1743,26 +1784,29 @@ LoadTableEncoding(
}
}
size = 256 * sizeof(unsigned short *) + numPages * PAGESIZE;
- dataPtr->fromUnicode = ckalloc(size);
+ dataPtr->fromUnicode = (unsigned short **) ckalloc(size);
memset(dataPtr->fromUnicode, 0, size);
pageMemPtr = (unsigned short *) (dataPtr->fromUnicode + 256);
for (hi = 0; hi < 256; hi++) {
if (dataPtr->toUnicode[hi] == NULL) {
dataPtr->toUnicode[hi] = emptyPage;
- continue;
- }
- for (lo = 0; lo < 256; lo++) {
- int ch = dataPtr->toUnicode[hi][lo];
-
- if (ch != 0) {
- page = dataPtr->fromUnicode[ch >> 8];
- if (page == NULL) {
- page = pageMemPtr;
- pageMemPtr += 256;
- dataPtr->fromUnicode[ch >> 8] = page;
+ } else {
+ for (lo = 0; lo < 256; lo++) {
+ int ch;
+
+ ch = dataPtr->toUnicode[hi][lo];
+ if (ch != 0) {
+ unsigned short *page;
+
+ page = dataPtr->fromUnicode[ch >> 8];
+ if (page == NULL) {
+ page = pageMemPtr;
+ pageMemPtr += 256;
+ dataPtr->fromUnicode[ch >> 8] = page;
+ }
+ page[ch & 0xff] = (unsigned short) ((hi << 8) + lo);
}
- page[ch & 0xff] = (unsigned short) ((hi << 8) + lo);
}
}
}
@@ -1781,6 +1825,8 @@ LoadTableEncoding(
}
}
if (symbol) {
+ unsigned short *page;
+
/*
* Make a special symbol encoding that not only maps the symbol
* characters from their Unicode code points down into page 0, but
@@ -1788,7 +1834,7 @@ LoadTableEncoding(
* is so that a symbol font can be used to display a simple string
* like "abcd" and have alpha, beta, chi, delta show up, rather than
* have "unknown" chars show up because strictly speaking the symbol
- * font doesn't have glyphs for those low ASCII chars.
+ * font doesn't have glyphs for those low ascii chars.
*/
page = dataPtr->fromUnicode[0];
@@ -1813,77 +1859,57 @@ LoadTableEncoding(
*/
Tcl_DStringInit(&lineString);
-
- /*
- * Skip leading empty lines.
- */
-
- while ((len = Tcl_Gets(chan, &lineString)) == 0) {
- /* empty body */
- }
- if (len < 0) {
- goto doneParse;
- }
-
- /*
- * Require that it starts with an 'R'.
- */
-
- line = Tcl_DStringValue(&lineString);
- if (line[0] != 'R') {
- goto doneParse;
- }
-
- /*
- * Read lines from the encoding until EOF.
- */
-
- for (TclDStringClear(&lineString);
- (len = Tcl_Gets(chan, &lineString)) >= 0;
- TclDStringClear(&lineString)) {
- const unsigned char *p;
- int to, from;
+ do {
+ int len;
/*
- * Skip short lines.
+ * Skip leading empty lines.
*/
- if (len < 5) {
- continue;
+ while ((len = Tcl_Gets(chan, &lineString)) == 0) {
+ /* empty body */
}
- /*
- * Parse the line as a sequence of hex digits.
- */
-
- p = (const unsigned char *) Tcl_DStringValue(&lineString);
- to = (staticHex[p[0]] << 12) + (staticHex[p[1]] << 8)
- + (staticHex[p[2]] << 4) + staticHex[p[3]];
- if (to == 0) {
- continue;
+ if (len < 0) {
+ break;
}
- for (p += 5, len -= 5; len >= 0 && *p; p += 5, len -= 5) {
- from = (staticHex[p[0]] << 12) + (staticHex[p[1]] << 8)
- + (staticHex[p[2]] << 4) + staticHex[p[3]];
- if (from == 0) {
+ line = Tcl_DStringValue(&lineString);
+ if (line[0] != 'R') {
+ break;
+ }
+ for (Tcl_DStringSetLength(&lineString, 0);
+ (len = Tcl_Gets(chan, &lineString)) >= 0;
+ Tcl_DStringSetLength(&lineString, 0)) {
+ unsigned char* p;
+ int to, from;
+
+ if (len < 5) {
continue;
}
- dataPtr->fromUnicode[from >> 8][from & 0xff] = to;
+ p = (unsigned char*) Tcl_DStringValue(&lineString);
+ to = (staticHex[p[0]] << 12) + (staticHex[p[1]] << 8)
+ + (staticHex[p[2]] << 4) + staticHex[p[3]];
+ if (to == 0) {
+ continue;
+ }
+ for (p += 5, len -= 5; len >= 0 && *p; p += 5, len -= 5) {
+ from = (staticHex[p[0]] << 12) + (staticHex[p[1]] << 8)
+ + (staticHex[p[2]] << 4) + staticHex[p[3]];
+ if (from == 0) {
+ continue;
+ }
+ dataPtr->fromUnicode[from >> 8][from & 0xff] = to;
+ }
}
- }
- doneParse:
+ } while (0);
Tcl_DStringFree(&lineString);
- /*
- * Package everything into an encoding structure.
- */
-
encType.encodingName = name;
encType.toUtfProc = TableToUtfProc;
encType.fromUtfProc = TableFromUtfProc;
encType.freeProc = TableFreeProc;
encType.nullSize = (type == ENCODING_DOUBLEBYTE) ? 2 : 1;
- encType.clientData = dataPtr;
+ encType.clientData = (ClientData) dataPtr;
return Tcl_CreateEncoding(&encType);
}
@@ -1916,7 +1942,7 @@ LoadEscapeEncoding(
Tcl_Channel chan) /* File containing new encoding. */
{
int i;
- unsigned size;
+ unsigned int size;
Tcl_DString escapeData;
char init[16], final[16];
EscapeEncodingData *dataPtr;
@@ -1927,7 +1953,7 @@ LoadEscapeEncoding(
Tcl_DStringInit(&escapeData);
while (1) {
- size_t argc;
+ int argc;
const char **argv;
char *line;
Tcl_DString lineString;
@@ -1938,7 +1964,6 @@ LoadEscapeEncoding(
}
line = Tcl_DStringValue(&lineString);
if (Tcl_SplitList(NULL, line, &argc, &argv) != TCL_OK) {
- Tcl_DStringFree(&lineString);
continue;
}
if (argc >= 2) {
@@ -1966,8 +1991,8 @@ LoadEscapeEncoding(
*/
e = (Encoding *) Tcl_GetEncoding(NULL, est.name);
- if ((e != NULL) && (e->toUtfProc != TableToUtfProc)
- && (e->toUtfProc != Iso88591ToUtfProc)) {
+ if (e && e->toUtfProc != TableToUtfProc &&
+ e->toUtfProc != Iso88591ToUtfProc) {
Tcl_FreeEncoding((Tcl_Encoding) e);
e = NULL;
}
@@ -1975,17 +2000,17 @@ LoadEscapeEncoding(
Tcl_DStringAppend(&escapeData, (char *) &est, sizeof(est));
}
}
- ckfree(argv);
+ ckfree((char *) argv);
Tcl_DStringFree(&lineString);
}
size = sizeof(EscapeEncodingData) - sizeof(EscapeSubTable)
+ Tcl_DStringLength(&escapeData);
- dataPtr = ckalloc(size);
+ dataPtr = (EscapeEncodingData *) ckalloc(size);
dataPtr->initLen = strlen(init);
- memcpy(dataPtr->init, init, (unsigned) dataPtr->initLen + 1);
+ strcpy(dataPtr->init, init);
dataPtr->finalLen = strlen(final);
- memcpy(dataPtr->final, final, (unsigned) dataPtr->finalLen + 1);
+ strcpy(dataPtr->final, final);
dataPtr->numSubTables =
Tcl_DStringLength(&escapeData) / sizeof(EscapeSubTable);
memcpy(dataPtr->subTables, Tcl_DStringValue(&escapeData),
@@ -2003,16 +2028,12 @@ LoadEscapeEncoding(
dataPtr->prefixBytes[UCHAR(dataPtr->final[0])] = 1;
}
- /*
- * Package everything into an encoding structure.
- */
-
type.encodingName = name;
type.toUtfProc = EscapeToUtfProc;
type.fromUtfProc = EscapeFromUtfProc;
type.freeProc = EscapeFreeProc;
type.nullSize = 1;
- type.clientData = dataPtr;
+ type.clientData = (ClientData) dataPtr;
return Tcl_CreateEncoding(&type);
}
@@ -2039,7 +2060,7 @@ static int
BinaryProc(
ClientData clientData, /* Not used. */
const char *src, /* Source string (unknown encoding). */
- size_t srcLen, /* Source string length in bytes. */
+ int srcLen, /* Source string length in bytes. */
int flags, /* Conversion control flags. */
Tcl_EncodingState *statePtr,/* Place for conversion routine to store state
* information used during a piecewise
@@ -2048,14 +2069,14 @@ BinaryProc(
* routine under control of flags argument. */
char *dst, /* Output buffer in which converted string is
* stored. */
- size_t dstLen, /* The maximum length of output buffer in
+ int dstLen, /* The maximum length of output buffer in
* bytes. */
- size_t *srcReadPtr, /* Filled with the number of bytes from the
+ int *srcReadPtr, /* Filled with the number of bytes from the
* source string that were converted. */
- size_t *dstWrotePtr, /* Filled with the number of bytes that were
+ int *dstWrotePtr, /* Filled with the number of bytes that were
* stored in the output buffer as a result of
* the conversion. */
- size_t *dstCharsPtr) /* Filled with the number of characters that
+ int *dstCharsPtr) /* Filled with the number of characters that
* correspond to the bytes stored in the
* output buffer. */
{
@@ -2074,7 +2095,7 @@ BinaryProc(
*srcReadPtr = srcLen;
*dstWrotePtr = srcLen;
*dstCharsPtr = srcLen;
- memcpy(dst, src, srcLen);
+ memcpy(dst, src, (size_t) srcLen);
return result;
}
@@ -2100,7 +2121,7 @@ static int
UtfIntToUtfExtProc(
ClientData clientData, /* Not used. */
const char *src, /* Source string in UTF-8. */
- size_t srcLen, /* Source string length in bytes. */
+ int srcLen, /* Source string length in bytes. */
int flags, /* Conversion control flags. */
Tcl_EncodingState *statePtr,/* Place for conversion routine to store state
* information used during a piecewise
@@ -2109,17 +2130,17 @@ UtfIntToUtfExtProc(
* routine under control of flags argument. */
char *dst, /* Output buffer in which converted string
* is stored. */
- size_t dstLen, /* The maximum length of output buffer in
+ int dstLen, /* The maximum length of output buffer in
* bytes. */
- size_t *srcReadPtr, /* Filled with the number of bytes from the
+ int *srcReadPtr, /* Filled with the number of bytes from the
* source string that were converted. This may
* be less than the original source length if
* there was a problem converting some source
* characters. */
- size_t *dstWrotePtr, /* Filled with the number of bytes that were
+ int *dstWrotePtr, /* Filled with the number of bytes that were
* stored in the output buffer as a result of
* the conversion. */
- size_t *dstCharsPtr) /* Filled with the number of characters that
+ int *dstCharsPtr) /* Filled with the number of characters that
* correspond to the bytes stored in the
* output buffer. */
{
@@ -2144,12 +2165,11 @@ UtfIntToUtfExtProc(
*
*-------------------------------------------------------------------------
*/
-
static int
UtfExtToUtfIntProc(
ClientData clientData, /* Not used. */
const char *src, /* Source string in UTF-8. */
- size_t srcLen, /* Source string length in bytes. */
+ int srcLen, /* Source string length in bytes. */
int flags, /* Conversion control flags. */
Tcl_EncodingState *statePtr,/* Place for conversion routine to store state
* information used during a piecewise
@@ -2158,17 +2178,17 @@ UtfExtToUtfIntProc(
* routine under control of flags argument. */
char *dst, /* Output buffer in which converted string is
* stored. */
- size_t dstLen, /* The maximum length of output buffer in
+ int dstLen, /* The maximum length of output buffer in
* bytes. */
- size_t *srcReadPtr, /* Filled with the number of bytes from the
+ int *srcReadPtr, /* Filled with the number of bytes from the
* source string that were converted. This may
* be less than the original source length if
* there was a problem converting some source
* characters. */
- size_t *dstWrotePtr, /* Filled with the number of bytes that were
+ int *dstWrotePtr, /* Filled with the number of bytes that were
* stored in the output buffer as a result of
* the conversion. */
- size_t *dstCharsPtr) /* Filled with the number of characters that
+ int *dstCharsPtr) /* Filled with the number of characters that
* correspond to the bytes stored in the
* output buffer. */
{
@@ -2198,7 +2218,7 @@ static int
UtfToUtfProc(
ClientData clientData, /* Not used. */
const char *src, /* Source string in UTF-8. */
- size_t srcLen, /* Source string length in bytes. */
+ int srcLen, /* Source string length in bytes. */
int flags, /* Conversion control flags. */
Tcl_EncodingState *statePtr,/* Place for conversion routine to store state
* information used during a piecewise
@@ -2207,17 +2227,17 @@ UtfToUtfProc(
* routine under control of flags argument. */
char *dst, /* Output buffer in which converted string is
* stored. */
- size_t dstLen, /* The maximum length of output buffer in
+ int dstLen, /* The maximum length of output buffer in
* bytes. */
- size_t *srcReadPtr, /* Filled with the number of bytes from the
+ int *srcReadPtr, /* Filled with the number of bytes from the
* source string that were converted. This may
* be less than the original source length if
* there was a problem converting some source
* characters. */
- size_t *dstWrotePtr, /* Filled with the number of bytes that were
+ int *dstWrotePtr, /* Filled with the number of bytes that were
* stored in the output buffer as a result of
* the conversion. */
- size_t *dstCharsPtr, /* Filled with the number of characters that
+ int *dstCharsPtr, /* Filled with the number of characters that
* correspond to the bytes stored in the
* output buffer. */
int pureNullMode) /* Convert embedded nulls from internal
@@ -2225,9 +2245,8 @@ UtfToUtfProc(
* versa. */
{
const char *srcStart, *srcEnd, *srcClose;
- const char *dstStart, *dstEnd;
- int result;
- size_t numChars;
+ char *dstStart, *dstEnd;
+ int result, numChars;
Tcl_UniChar ch;
result = TCL_OK;
@@ -2264,7 +2283,7 @@ UtfToUtfProc(
*dst++ = *src++;
} else if (pureNullMode == 1 && UCHAR(*src) == 0xc0 &&
- UCHAR(*(src+1)) == 0x80) {
+ (src + 1 < srcEnd) && UCHAR(*(src+1)) == 0x80) {
/*
* Convert 0xc080 to real nulls when we are in output mode.
*/
@@ -2313,7 +2332,7 @@ static int
UnicodeToUtfProc(
ClientData clientData, /* Not used. */
const char *src, /* Source string in Unicode. */
- size_t srcLen, /* Source string length in bytes. */
+ int srcLen, /* Source string length in bytes. */
int flags, /* Conversion control flags. */
Tcl_EncodingState *statePtr,/* Place for conversion routine to store state
* information used during a piecewise
@@ -2322,24 +2341,23 @@ UnicodeToUtfProc(
* routine under control of flags argument. */
char *dst, /* Output buffer in which converted string is
* stored. */
- size_t dstLen, /* The maximum length of output buffer in
+ int dstLen, /* The maximum length of output buffer in
* bytes. */
- size_t *srcReadPtr, /* Filled with the number of bytes from the
+ int *srcReadPtr, /* Filled with the number of bytes from the
* source string that were converted. This may
* be less than the original source length if
* there was a problem converting some source
* characters. */
- size_t *dstWrotePtr, /* Filled with the number of bytes that were
+ int *dstWrotePtr, /* Filled with the number of bytes that were
* stored in the output buffer as a result of
* the conversion. */
- size_t *dstCharsPtr) /* Filled with the number of characters that
+ int *dstCharsPtr) /* Filled with the number of characters that
* correspond to the bytes stored in the
* output buffer. */
{
const char *srcStart, *srcEnd;
- const char *dstEnd, *dstStart;
- int result;
- size_t numChars;
+ char *dstEnd, *dstStart;
+ int result, numChars;
Tcl_UniChar ch;
result = TCL_OK;
@@ -2360,12 +2378,10 @@ UnicodeToUtfProc(
result = TCL_CONVERT_NOSPACE;
break;
}
-
/*
- * Special case for 1-byte utf chars for speed. Make sure we work with
- * Tcl_UniChar-size data.
+ * Special case for 1-byte utf chars for speed. Make sure we
+ * work with Tcl_UniChar-size data.
*/
-
ch = *(Tcl_UniChar *)src;
if (ch && ch < 0x80) {
*dst++ = (ch & 0xFF);
@@ -2402,7 +2418,7 @@ UtfToUnicodeProc(
ClientData clientData, /* TableEncodingData that specifies
* encoding. */
const char *src, /* Source string in UTF-8. */
- size_t srcLen, /* Source string length in bytes. */
+ int srcLen, /* Source string length in bytes. */
int flags, /* Conversion control flags. */
Tcl_EncodingState *statePtr,/* Place for conversion routine to store state
* information used during a piecewise
@@ -2411,23 +2427,22 @@ UtfToUnicodeProc(
* routine under control of flags argument. */
char *dst, /* Output buffer in which converted string is
* stored. */
- size_t dstLen, /* The maximum length of output buffer in
+ int dstLen, /* The maximum length of output buffer in
* bytes. */
- size_t *srcReadPtr, /* Filled with the number of bytes from the
+ int *srcReadPtr, /* Filled with the number of bytes from the
* source string that were converted. This may
* be less than the original source length if
* there was a problem converting some source
* characters. */
- size_t *dstWrotePtr, /* Filled with the number of bytes that were
+ int *dstWrotePtr, /* Filled with the number of bytes that were
* stored in the output buffer as a result of
* the conversion. */
- size_t *dstCharsPtr) /* Filled with the number of characters that
+ int *dstCharsPtr) /* Filled with the number of characters that
* correspond to the bytes stored in the
* output buffer. */
{
const char *srcStart, *srcEnd, *srcClose, *dstStart, *dstEnd;
- int result;
- size_t numChars;
+ int result, numChars;
Tcl_UniChar ch;
srcStart = src;
@@ -2456,13 +2471,11 @@ UtfToUnicodeProc(
break;
}
src += TclUtfToUniChar(src, &ch);
-
/*
- * Need to handle this in a way that won't cause misalignment by
- * casting dst to a Tcl_UniChar. [Bug 1122671]
+ * Need to handle this in a way that won't cause misalignment
+ * by casting dst to a Tcl_UniChar. [Bug 1122671]
* XXX: This hard-codes the assumed size of Tcl_UniChar as 2.
*/
-
#ifdef WORDS_BIGENDIAN
*dst++ = (ch >> 8);
*dst++ = (ch & 0xFF);
@@ -2499,7 +2512,7 @@ TableToUtfProc(
ClientData clientData, /* TableEncodingData that specifies
* encoding. */
const char *src, /* Source string in specified encoding. */
- size_t srcLen, /* Source string length in bytes. */
+ int srcLen, /* Source string length in bytes. */
int flags, /* Conversion control flags. */
Tcl_EncodingState *statePtr,/* Place for conversion routine to store state
* information used during a piecewise
@@ -2508,28 +2521,27 @@ TableToUtfProc(
* routine under control of flags argument. */
char *dst, /* Output buffer in which converted string is
* stored. */
- size_t dstLen, /* The maximum length of output buffer in
+ int dstLen, /* The maximum length of output buffer in
* bytes. */
- size_t *srcReadPtr, /* Filled with the number of bytes from the
+ int *srcReadPtr, /* Filled with the number of bytes from the
* source string that were converted. This may
* be less than the original source length if
* there was a problem converting some source
* characters. */
- size_t *dstWrotePtr, /* Filled with the number of bytes that were
+ int *dstWrotePtr, /* Filled with the number of bytes that were
* stored in the output buffer as a result of
* the conversion. */
- size_t *dstCharsPtr) /* Filled with the number of characters that
+ int *dstCharsPtr) /* Filled with the number of characters that
* correspond to the bytes stored in the
* output buffer. */
{
const char *srcStart, *srcEnd;
- const char *dstEnd, *dstStart, *prefixBytes;
- int result, byte;
- size_t numChars;
+ char *dstEnd, *dstStart, *prefixBytes;
+ int result, byte, numChars;
Tcl_UniChar ch;
- const unsigned short *const *toUnicode;
- const unsigned short *pageZero;
- TableEncodingData *dataPtr = clientData;
+ unsigned short **toUnicode;
+ unsigned short *pageZero;
+ TableEncodingData *dataPtr;
srcStart = src;
srcEnd = src + srcLen;
@@ -2537,7 +2549,8 @@ TableToUtfProc(
dstStart = dst;
dstEnd = dst + dstLen - TCL_UTF_MAX;
- toUnicode = (const unsigned short *const *) dataPtr->toUnicode;
+ dataPtr = (TableEncodingData *) clientData;
+ toUnicode = dataPtr->toUnicode;
prefixBytes = dataPtr->prefixBytes;
pageZero = toUnicode[0];
@@ -2569,11 +2582,9 @@ TableToUtfProc(
}
ch = (Tcl_UniChar) byte;
}
-
/*
* Special case for 1-byte utf chars for speed.
*/
-
if (ch && ch < 0x80) {
*dst++ = (char) ch;
} else {
@@ -2610,7 +2621,7 @@ TableFromUtfProc(
ClientData clientData, /* TableEncodingData that specifies
* encoding. */
const char *src, /* Source string in UTF-8. */
- size_t srcLen, /* Source string length in bytes. */
+ int srcLen, /* Source string length in bytes. */
int flags, /* Conversion control flags. */
Tcl_EncodingState *statePtr,/* Place for conversion routine to store state
* information used during a piecewise
@@ -2619,32 +2630,32 @@ TableFromUtfProc(
* routine under control of flags argument. */
char *dst, /* Output buffer in which converted string is
* stored. */
- size_t dstLen, /* The maximum length of output buffer in
+ int dstLen, /* The maximum length of output buffer in
* bytes. */
- size_t *srcReadPtr, /* Filled with the number of bytes from the
+ int *srcReadPtr, /* Filled with the number of bytes from the
* source string that were converted. This may
* be less than the original source length if
* there was a problem converting some source
* characters. */
- size_t *dstWrotePtr, /* Filled with the number of bytes that were
+ int *dstWrotePtr, /* Filled with the number of bytes that were
* stored in the output buffer as a result of
* the conversion. */
- size_t *dstCharsPtr) /* Filled with the number of characters that
+ int *dstCharsPtr) /* Filled with the number of characters that
* correspond to the bytes stored in the
* output buffer. */
{
const char *srcStart, *srcEnd, *srcClose;
- const char *dstStart, *dstEnd, *prefixBytes;
+ char *dstStart, *dstEnd, *prefixBytes;
Tcl_UniChar ch;
- int result, word;
- size_t len, numChars;
- TableEncodingData *dataPtr = clientData;
- const unsigned short *const *fromUnicode;
+ int result, len, word, numChars;
+ TableEncodingData *dataPtr;
+ unsigned short **fromUnicode;
result = TCL_OK;
+ dataPtr = (TableEncodingData *) clientData;
prefixBytes = dataPtr->prefixBytes;
- fromUnicode = (const unsigned short *const *) dataPtr->fromUnicode;
+ fromUnicode = dataPtr->fromUnicode;
srcStart = src;
srcEnd = src + srcLen;
@@ -2732,7 +2743,7 @@ static int
Iso88591ToUtfProc(
ClientData clientData, /* Ignored. */
const char *src, /* Source string in specified encoding. */
- size_t srcLen, /* Source string length in bytes. */
+ int srcLen, /* Source string length in bytes. */
int flags, /* Conversion control flags. */
Tcl_EncodingState *statePtr,/* Place for conversion routine to store state
* information used during a piecewise
@@ -2741,24 +2752,23 @@ Iso88591ToUtfProc(
* routine under control of flags argument. */
char *dst, /* Output buffer in which converted string is
* stored. */
- size_t dstLen, /* The maximum length of output buffer in
+ int dstLen, /* The maximum length of output buffer in
* bytes. */
- size_t *srcReadPtr, /* Filled with the number of bytes from the
+ int *srcReadPtr, /* Filled with the number of bytes from the
* source string that were converted. This may
* be less than the original source length if
* there was a problem converting some source
* characters. */
- size_t *dstWrotePtr, /* Filled with the number of bytes that were
+ int *dstWrotePtr, /* Filled with the number of bytes that were
* stored in the output buffer as a result of
* the conversion. */
- size_t *dstCharsPtr) /* Filled with the number of characters that
+ int *dstCharsPtr) /* Filled with the number of characters that
* correspond to the bytes stored in the
* output buffer. */
{
const char *srcStart, *srcEnd;
- const char *dstEnd, *dstStart;
- int result;
- size_t numChars;
+ char *dstEnd, *dstStart;
+ int result, numChars;
srcStart = src;
srcEnd = src + srcLen;
@@ -2775,11 +2785,9 @@ Iso88591ToUtfProc(
break;
}
ch = (Tcl_UniChar) *((unsigned char *) src);
-
/*
* Special case for 1-byte utf chars for speed.
*/
-
if (ch && ch < 0x80) {
*dst++ = (char) ch;
} else {
@@ -2814,7 +2822,7 @@ static int
Iso88591FromUtfProc(
ClientData clientData, /* Ignored. */
const char *src, /* Source string in UTF-8. */
- size_t srcLen, /* Source string length in bytes. */
+ int srcLen, /* Source string length in bytes. */
int flags, /* Conversion control flags. */
Tcl_EncodingState *statePtr,/* Place for conversion routine to store state
* information used during a piecewise
@@ -2823,24 +2831,23 @@ Iso88591FromUtfProc(
* routine under control of flags argument. */
char *dst, /* Output buffer in which converted string is
* stored. */
- size_t dstLen, /* The maximum length of output buffer in
+ int dstLen, /* The maximum length of output buffer in
* bytes. */
- size_t *srcReadPtr, /* Filled with the number of bytes from the
+ int *srcReadPtr, /* Filled with the number of bytes from the
* source string that were converted. This may
* be less than the original source length if
* there was a problem converting some source
* characters. */
- size_t *dstWrotePtr, /* Filled with the number of bytes that were
+ int *dstWrotePtr, /* Filled with the number of bytes that were
* stored in the output buffer as a result of
* the conversion. */
- size_t *dstCharsPtr) /* Filled with the number of characters that
+ int *dstCharsPtr) /* Filled with the number of characters that
* correspond to the bytes stored in the
* output buffer. */
{
const char *srcStart, *srcEnd, *srcClose;
- const char *dstStart, *dstEnd;
- int result;
- size_t numChars;
+ char *dstStart, *dstEnd;
+ int result, numChars;
result = TCL_OK;
@@ -2856,7 +2863,7 @@ Iso88591FromUtfProc(
for (numChars = 0; src < srcEnd; numChars++) {
Tcl_UniChar ch;
- size_t len;
+ int len;
if ((src > srcClose) && (!Tcl_UtfCharComplete(src, srcEnd - src))) {
/*
@@ -2922,15 +2929,16 @@ TableFreeProc(
ClientData clientData) /* TableEncodingData that specifies
* encoding. */
{
- TableEncodingData *dataPtr = clientData;
+ TableEncodingData *dataPtr;
/*
* Make sure we aren't freeing twice on shutdown. [Bug 219314]
*/
- ckfree(dataPtr->toUnicode);
- ckfree(dataPtr->fromUnicode);
- ckfree(dataPtr);
+ dataPtr = (TableEncodingData *) clientData;
+ ckfree((char *) dataPtr->toUnicode);
+ ckfree((char *) dataPtr->fromUnicode);
+ ckfree((char *) dataPtr);
}
/*
@@ -2955,7 +2963,7 @@ EscapeToUtfProc(
ClientData clientData, /* EscapeEncodingData that specifies
* encoding. */
const char *src, /* Source string in specified encoding. */
- size_t srcLen, /* Source string length in bytes. */
+ int srcLen, /* Source string length in bytes. */
int flags, /* Conversion control flags. */
Tcl_EncodingState *statePtr,/* Place for conversion routine to store state
* information used during a piecewise
@@ -2964,31 +2972,34 @@ EscapeToUtfProc(
* routine under control of flags argument. */
char *dst, /* Output buffer in which converted string is
* stored. */
- size_t dstLen, /* The maximum length of output buffer in
+ int dstLen, /* The maximum length of output buffer in
* bytes. */
- size_t *srcReadPtr, /* Filled with the number of bytes from the
+ int *srcReadPtr, /* Filled with the number of bytes from the
* source string that were converted. This may
* be less than the original source length if
* there was a problem converting some source
* characters. */
- size_t *dstWrotePtr, /* Filled with the number of bytes that were
+ int *dstWrotePtr, /* Filled with the number of bytes that were
* stored in the output buffer as a result of
* the conversion. */
- size_t *dstCharsPtr) /* Filled with the number of characters that
+ int *dstCharsPtr) /* Filled with the number of characters that
* correspond to the bytes stored in the
* output buffer. */
{
- EscapeEncodingData *dataPtr = clientData;
- const char *prefixBytes, *tablePrefixBytes, *srcStart, *srcEnd;
- const unsigned short *const *tableToUnicode;
- const Encoding *encodingPtr;
- int state, result;
- size_t numChars;
- const char *dstStart, *dstEnd;
+ EscapeEncodingData *dataPtr;
+ char *prefixBytes, *tablePrefixBytes;
+ unsigned short **tableToUnicode;
+ Encoding *encodingPtr;
+ int state, result, numChars;
+ const char *srcStart, *srcEnd;
+ char *dstStart, *dstEnd;
result = TCL_OK;
+
tablePrefixBytes = NULL; /* lint. */
tableToUnicode = NULL; /* lint. */
+
+ dataPtr = (EscapeEncodingData *) clientData;
prefixBytes = dataPtr->prefixBytes;
encodingPtr = NULL;
@@ -3012,9 +3023,9 @@ EscapeToUtfProc(
}
byte = *((unsigned char *) src);
if (prefixBytes[byte]) {
- size_t left, len, longest;
+ unsigned int left, len, longest;
int checked, i;
- const EscapeSubTable *subTablePtr;
+ EscapeSubTable *subTablePtr;
/*
* Saw the beginning of an escape sequence.
@@ -3112,10 +3123,9 @@ EscapeToUtfProc(
TableEncodingData *tableDataPtr;
encodingPtr = GetTableEncoding(dataPtr, state);
- tableDataPtr = encodingPtr->clientData;
+ tableDataPtr = (TableEncodingData *) encodingPtr->clientData;
tablePrefixBytes = tableDataPtr->prefixBytes;
- tableToUnicode = (const unsigned short *const*)
- tableDataPtr->toUnicode;
+ tableToUnicode = tableDataPtr->toUnicode;
}
if (tablePrefixBytes[byte]) {
@@ -3167,7 +3177,7 @@ EscapeFromUtfProc(
ClientData clientData, /* EscapeEncodingData that specifies
* encoding. */
const char *src, /* Source string in UTF-8. */
- size_t srcLen, /* Source string length in bytes. */
+ int srcLen, /* Source string length in bytes. */
int flags, /* Conversion control flags. */
Tcl_EncodingState *statePtr,/* Place for conversion routine to store state
* information used during a piecewise
@@ -3176,32 +3186,33 @@ EscapeFromUtfProc(
* routine under control of flags argument. */
char *dst, /* Output buffer in which converted string is
* stored. */
- size_t dstLen, /* The maximum length of output buffer in
+ int dstLen, /* The maximum length of output buffer in
* bytes. */
- size_t *srcReadPtr, /* Filled with the number of bytes from the
+ int *srcReadPtr, /* Filled with the number of bytes from the
* source string that were converted. This may
* be less than the original source length if
* there was a problem converting some source
* characters. */
- size_t *dstWrotePtr, /* Filled with the number of bytes that were
+ int *dstWrotePtr, /* Filled with the number of bytes that were
* stored in the output buffer as a result of
* the conversion. */
- size_t *dstCharsPtr) /* Filled with the number of characters that
+ int *dstCharsPtr) /* Filled with the number of characters that
* correspond to the bytes stored in the
* output buffer. */
{
- EscapeEncodingData *dataPtr = clientData;
- const Encoding *encodingPtr;
+ EscapeEncodingData *dataPtr;
+ Encoding *encodingPtr;
const char *srcStart, *srcEnd, *srcClose;
- const char *dstStart, *dstEnd;
- int state, result;
- size_t numChars;
- const TableEncodingData *tableDataPtr;
- const char *tablePrefixBytes;
- const unsigned short *const *tableFromUnicode;
+ char *dstStart, *dstEnd;
+ int state, result, numChars;
+ TableEncodingData *tableDataPtr;
+ char *tablePrefixBytes;
+ unsigned short **tableFromUnicode;
result = TCL_OK;
+ dataPtr = (EscapeEncodingData *) clientData;
+
srcStart = src;
srcEnd = src + srcLen;
srcClose = srcEnd;
@@ -3213,7 +3224,7 @@ EscapeFromUtfProc(
dstEnd = dst + dstLen - 1;
/*
- * RFC 1468 states that the text starts in ASCII, and switches to Japanese
+ * RFC1468 states that the text starts in ASCII, and switches to Japanese
* characters, and that the text must end in ASCII. [Patch 474358]
*/
@@ -3231,13 +3242,12 @@ EscapeFromUtfProc(
}
encodingPtr = GetTableEncoding(dataPtr, state);
- tableDataPtr = encodingPtr->clientData;
+ tableDataPtr = (TableEncodingData *) encodingPtr->clientData;
tablePrefixBytes = tableDataPtr->prefixBytes;
- tableFromUnicode = (const unsigned short *const *)
- tableDataPtr->fromUnicode;
+ tableFromUnicode = tableDataPtr->fromUnicode;
for (numChars = 0; src < srcEnd; numChars++) {
- size_t len;
+ unsigned int len;
int word;
Tcl_UniChar ch;
@@ -3255,13 +3265,13 @@ EscapeFromUtfProc(
if ((word == 0) && (ch != 0)) {
int oldState;
- const EscapeSubTable *subTablePtr;
+ EscapeSubTable *subTablePtr;
oldState = state;
for (state = 0; state < dataPtr->numSubTables; state++) {
encodingPtr = GetTableEncoding(dataPtr, state);
- tableDataPtr = encodingPtr->clientData;
- word = tableDataPtr->fromUnicode[(ch >> 8)][ch & 0xff];
+ tableDataPtr = (TableEncodingData *) encodingPtr->clientData;
+ word = tableDataPtr->fromUnicode[(ch >> 8)][ch & 0xff];
if (word != 0) {
break;
}
@@ -3274,13 +3284,12 @@ EscapeFromUtfProc(
break;
}
encodingPtr = GetTableEncoding(dataPtr, state);
- tableDataPtr = encodingPtr->clientData;
+ tableDataPtr = (TableEncodingData *) encodingPtr->clientData;
word = tableDataPtr->fallback;
}
- tablePrefixBytes = (const char *) tableDataPtr->prefixBytes;
- tableFromUnicode = (const unsigned short *const *)
- tableDataPtr->fromUnicode;
+ tablePrefixBytes = tableDataPtr->prefixBytes;
+ tableFromUnicode = tableDataPtr->fromUnicode;
/*
* The state variable has the value of oldState when word is 0.
@@ -3328,22 +3337,22 @@ EscapeFromUtfProc(
}
if ((result == TCL_OK) && (flags & TCL_ENCODING_END)) {
- unsigned len = dataPtr->subTables[0].sequenceLen;
-
+ unsigned int len = dataPtr->subTables[0].sequenceLen;
/*
- * Certain encodings like iso2022-jp need to write an escape sequence
- * after all characters have been converted. This logic checks that
- * enough room is available in the buffer for the escape bytes. The
- * TCL_ENCODING_END flag is cleared after a final escape sequence has
- * been added to the buffer so that another call to this method does
- * not attempt to append escape bytes a second time.
+ * Certain encodings like iso2022-jp need to write
+ * an escape sequence after all characters have
+ * been converted. This logic checks that enough
+ * room is available in the buffer for the escape bytes.
+ * The TCL_ENCODING_END flag is cleared after a final
+ * escape sequence has been added to the buffer so
+ * that another call to this method does not attempt
+ * to append escape bytes a second time.
*/
-
if ((dst + dataPtr->finalLen + (state?len:0)) > dstEnd) {
result = TCL_CONVERT_NOSPACE;
} else {
if (state) {
- memcpy(dst, dataPtr->subTables[0].sequence, len);
+ memcpy(dst, dataPtr->subTables[0].sequence, (size_t) len);
dst += len;
}
memcpy(dst, dataPtr->final, (size_t) dataPtr->finalLen);
@@ -3381,33 +3390,33 @@ EscapeFreeProc(
ClientData clientData) /* EscapeEncodingData that specifies
* encoding. */
{
- EscapeEncodingData *dataPtr = clientData;
+ EscapeEncodingData *dataPtr;
EscapeSubTable *subTablePtr;
int i;
+ dataPtr = (EscapeEncodingData *) clientData;
if (dataPtr == NULL) {
return;
}
-
/*
- * The subTables should be freed recursively in normal operation but not
- * during TclFinalizeEncodingSubsystem because they are also present as a
- * weak reference in the toplevel encodingTable (i.e., they don't have a
- * +1 refcount for this), and unpredictable nuking order could remove them
- * from under the following loop's feet. [Bug 2891556]
- *
- * The encodingsInitialized flag, being reset on entry to TFES, can serve
- * as a "not in finalization" test.
+ * The subTables should be freed recursively in normal operation but not
+ * during TclFinalizeEncodingSubsystem because they are also present as a
+ * weak reference in the toplevel encodingTable (ie they don't have a +1
+ * refcount for this), and unpredictable nuking order could remove them
+ * from under the following loop's feet [Bug 2891556].
+ *
+ * The encodingsInitialized flag, being reset on entry to TFES, can serve
+ * as a "not in finalization" test.
*/
-
- if (encodingsInitialized) {
- subTablePtr = dataPtr->subTables;
- for (i = 0; i < dataPtr->numSubTables; i++) {
- FreeEncoding((Tcl_Encoding) subTablePtr->encodingPtr);
- subTablePtr++;
+ if (encodingsInitialized)
+ {
+ subTablePtr = dataPtr->subTables;
+ for (i = 0; i < dataPtr->numSubTables; i++) {
+ FreeEncoding((Tcl_Encoding) subTablePtr->encodingPtr);
+ subTablePtr++;
+ }
}
- }
- ckfree(dataPtr);
+ ckfree((char *) dataPtr);
}
/*
@@ -3435,8 +3444,11 @@ GetTableEncoding(
EscapeEncodingData *dataPtr,/* Contains names of encodings. */
int state) /* Index in dataPtr of desired Encoding. */
{
- EscapeSubTable *subTablePtr = &dataPtr->subTables[state];
- Encoding *encodingPtr = subTablePtr->encodingPtr;
+ EscapeSubTable *subTablePtr;
+ Encoding *encodingPtr;
+
+ subTablePtr = &dataPtr->subTables[state];
+ encodingPtr = subTablePtr->encodingPtr;
if (encodingPtr == NULL) {
encodingPtr = (Encoding *) Tcl_GetEncoding(NULL, subTablePtr->name);
@@ -3508,47 +3520,46 @@ unilen(
static void
InitializeEncodingSearchPath(
char **valuePtr,
- size_t *lengthPtr,
+ int *lengthPtr,
Tcl_Encoding *encodingPtr)
{
- const char *bytes;
- int i;
- size_t numBytes, numDirs;
- Tcl_Obj *libPathObj, *encodingObj, *searchPathObj;
+ char *bytes;
+ int i, numDirs, numBytes;
+ Tcl_Obj *libPath, *encodingObj, *searchPath;
TclNewLiteralStringObj(encodingObj, "encoding");
- TclNewObj(searchPathObj);
+ TclNewObj(searchPath);
Tcl_IncrRefCount(encodingObj);
- Tcl_IncrRefCount(searchPathObj);
- libPathObj = TclGetLibraryPath();
- Tcl_IncrRefCount(libPathObj);
- Tcl_ListObjLength(NULL, libPathObj, &numDirs);
+ Tcl_IncrRefCount(searchPath);
+ libPath = TclGetLibraryPath();
+ Tcl_IncrRefCount(libPath);
+ Tcl_ListObjLength(NULL, libPath, &numDirs);
for (i = 0; i < numDirs; i++) {
- Tcl_Obj *directoryObj, *pathObj;
+ Tcl_Obj *directory, *path;
Tcl_StatBuf stat;
- Tcl_ListObjIndex(NULL, libPathObj, i, &directoryObj);
- pathObj = Tcl_FSJoinToPath(directoryObj, 1, &encodingObj);
- Tcl_IncrRefCount(pathObj);
- if ((0 == Tcl_FSStat(pathObj, &stat)) && S_ISDIR(stat.st_mode)) {
- Tcl_ListObjAppendElement(NULL, searchPathObj, pathObj);
+ Tcl_ListObjIndex(NULL, libPath, i, &directory);
+ path = Tcl_FSJoinToPath(directory, 1, &encodingObj);
+ Tcl_IncrRefCount(path);
+ if ((0 == Tcl_FSStat(path, &stat)) && S_ISDIR(stat.st_mode)) {
+ Tcl_ListObjAppendElement(NULL, searchPath, path);
}
- Tcl_DecrRefCount(pathObj);
+ Tcl_DecrRefCount(path);
}
- Tcl_DecrRefCount(libPathObj);
+ Tcl_DecrRefCount(libPath);
Tcl_DecrRefCount(encodingObj);
*encodingPtr = libraryPath.encoding;
if (*encodingPtr) {
((Encoding *)(*encodingPtr))->refCount++;
}
- bytes = Tcl_GetStringFromObj(searchPathObj, &numBytes);
+ bytes = Tcl_GetStringFromObj(searchPath, &numBytes);
*lengthPtr = numBytes;
- *valuePtr = ckalloc(numBytes + 1);
+ *valuePtr = ckalloc((unsigned int) numBytes + 1);
memcpy(*valuePtr, bytes, (size_t) numBytes + 1);
- Tcl_DecrRefCount(searchPathObj);
+ Tcl_DecrRefCount(searchPath);
}
/*
@@ -3558,3 +3569,4 @@ InitializeEncodingSearchPath(
* fill-column: 78
* End:
*/
+