summaryrefslogtreecommitdiffstats
path: root/generic/tclEncoding.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tclEncoding.c')
-rw-r--r--generic/tclEncoding.c251
1 files changed, 128 insertions, 123 deletions
diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c
index 2d0d389..9749218 100644
--- a/generic/tclEncoding.c
+++ b/generic/tclEncoding.c
@@ -8,12 +8,12 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclEncoding.c,v 1.48 2006/11/02 15:07:04 dkf Exp $
+ * RCS: @(#) $Id: tclEncoding.c,v 1.49 2006/11/02 15:43:51 dgp Exp $
*/
#include "tclInt.h"
-typedef size_t (LengthProc)(const char *src);
+typedef size_t (LengthProc)(CONST char *src);
/*
* The following data structure represents an encoding, which describes how to
@@ -197,19 +197,19 @@ static unsigned short emptyPage[256];
*/
static int BinaryProc(ClientData clientData,
- const char *src, int srcLen, int flags,
+ 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 void EscapeFreeProc(ClientData clientData);
static int EscapeFromUtfProc(ClientData clientData,
- const char *src, int srcLen, int flags,
+ 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,
+ CONST char *src, int srcLen, int flags,
Tcl_EncodingState *statePtr, char *dst, int dstLen,
int *srcReadPtr, int *dstWrotePtr,
int *dstCharsPtr);
@@ -218,45 +218,45 @@ static void FreeEncoding(Tcl_Encoding encoding);
static void FreeEncodingIntRep(Tcl_Obj *objPtr);
static Encoding * GetTableEncoding(EscapeEncodingData *dataPtr,
int state);
-static Tcl_Encoding LoadEncodingFile(Tcl_Interp *interp, const char *name);
-static Tcl_Encoding LoadTableEncoding(const char *name, int type,
+static Tcl_Encoding LoadEncodingFile(Tcl_Interp *interp, CONST char *name);
+static Tcl_Encoding LoadTableEncoding(CONST char *name, int type,
Tcl_Channel chan);
-static Tcl_Encoding LoadEscapeEncoding(const char *name, Tcl_Channel chan);
+static Tcl_Encoding LoadEscapeEncoding(CONST char *name, Tcl_Channel chan);
static Tcl_Channel OpenEncodingFileChannel(Tcl_Interp *interp,
- const char *name);
+ CONST char *name);
static void TableFreeProc(ClientData clientData);
static int TableFromUtfProc(ClientData clientData,
- const char *src, int srcLen, int flags,
+ 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,
+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 size_t unilen(CONST char *src);
static int UnicodeToUtfProc(ClientData clientData,
- const char *src, int srcLen, int flags,
+ 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,
+ 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,
+ 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,
+ 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,
+ CONST char *src, int srcLen, int flags,
Tcl_EncodingState *statePtr, char *dst, int dstLen,
int *srcReadPtr, int *dstWrotePtr,
int *dstCharsPtr);
@@ -296,7 +296,7 @@ Tcl_GetEncodingFromObj(
Tcl_Obj *objPtr,
Tcl_Encoding *encodingPtr)
{
- const char *name = TclGetString(objPtr);
+ CONST char *name = Tcl_GetString(objPtr);
if (objPtr->typePtr != &EncodingType) {
Tcl_Encoding encoding = Tcl_GetEncoding(interp, name);
@@ -304,7 +304,7 @@ Tcl_GetEncodingFromObj(
return TCL_ERROR;
}
TclFreeIntRep(objPtr);
- objPtr->internalRep.otherValuePtr = encoding;
+ objPtr->internalRep.otherValuePtr = (VOID *) encoding;
objPtr->typePtr = &EncodingType;
}
*encodingPtr = Tcl_GetEncoding(NULL, name);
@@ -343,7 +343,8 @@ DupEncodingIntRep(
Tcl_Obj *srcPtr,
Tcl_Obj *dupPtr)
{
- dupPtr->internalRep.otherValuePtr = Tcl_GetEncoding(NULL, srcPtr->bytes);
+ dupPtr->internalRep.otherValuePtr = (VOID *)
+ Tcl_GetEncoding(NULL, srcPtr->bytes);
}
/*
@@ -482,35 +483,34 @@ FillEncodingFileMap(void)
*/
int j, numFiles;
- Tcl_Obj *directory, *matchFileList;
+ Tcl_Obj *directory, *matchFileList = Tcl_NewObj();
Tcl_Obj **filev;
Tcl_GlobTypeData readableFiles = {
TCL_GLOB_TYPE_FILE, TCL_GLOB_PERM_R, NULL, NULL
};
- TclNewObj(matchFileList);
Tcl_ListObjIndex(NULL, searchPath, i, &directory);
Tcl_IncrRefCount(directory);
Tcl_IncrRefCount(matchFileList);
Tcl_FSMatchInDirectory(NULL, matchFileList, directory, "*.enc",
&readableFiles);
- TclListObjGetElements(matchFileList, numFiles, filev);
+ Tcl_ListObjGetElements(NULL, matchFileList, &numFiles, &filev);
for (j=0; j<numFiles; j++) {
Tcl_Obj *encodingName, *file;
file = TclPathPart(NULL, filev[j], TCL_PATH_TAIL);
encodingName = TclPathPart(NULL, file, TCL_PATH_ROOT);
Tcl_DictObjPut(NULL, map, encodingName, directory);
- TclDecrRefCount(file);
- TclDecrRefCount(encodingName);
+ Tcl_DecrRefCount(file);
+ Tcl_DecrRefCount(encodingName);
}
- TclDecrRefCount(matchFileList);
- TclDecrRefCount(directory);
+ Tcl_DecrRefCount(matchFileList);
+ Tcl_DecrRefCount(directory);
}
- TclDecrRefCount(searchPath);
+ Tcl_DecrRefCount(searchPath);
TclSetProcessGlobalValue(&encodingFileMap, map, NULL);
- TclDecrRefCount(map);
+ Tcl_DecrRefCount(map);
}
/*
@@ -639,7 +639,7 @@ TclFinalizeEncodingSubsystem(void)
*-------------------------------------------------------------------------
*/
-const char *
+CONST char *
Tcl_GetDefaultEncodingDir(void)
{
int numDirs;
@@ -651,7 +651,7 @@ Tcl_GetDefaultEncodingDir(void)
}
Tcl_ListObjIndex(NULL, searchPath, 0, &first);
- return TclGetString(first);
+ return Tcl_GetString(first);
}
/*
@@ -673,7 +673,7 @@ Tcl_GetDefaultEncodingDir(void)
void
Tcl_SetDefaultEncodingDir(
- const char *path)
+ CONST char *path)
{
Tcl_Obj *searchPath = Tcl_GetEncodingSearchPath();
Tcl_Obj *directory = Tcl_NewStringObj(path, -1);
@@ -711,7 +711,7 @@ Tcl_SetDefaultEncodingDir(
Tcl_Encoding
Tcl_GetEncoding(
Tcl_Interp *interp, /* Interp for error reporting, if not NULL. */
- const char *name) /* The name of the desired encoding. */
+ CONST char *name) /* The name of the desired encoding. */
{
Tcl_HashEntry *hPtr;
Encoding *encodingPtr;
@@ -821,7 +821,7 @@ FreeEncoding(
*---------------------------------------------------------------------------
*/
-const char *
+CONST char *
Tcl_GetEncodingName(
Tcl_Encoding encoding) /* The encoding whose name to fetch. */
{
@@ -857,11 +857,10 @@ Tcl_GetEncodingNames(
Tcl_HashTable table;
Tcl_HashSearch search;
Tcl_HashEntry *hPtr;
- Tcl_Obj *map, *name, *result;
+ Tcl_Obj *map, *name, *result = Tcl_NewObj();
Tcl_DictSearch mapSearch;
int dummy, done = 0;
- TclNewObj(result);
Tcl_InitObjHashTable(&table);
/*
@@ -929,7 +928,7 @@ Tcl_GetEncodingNames(
int
Tcl_SetSystemEncoding(
Tcl_Interp *interp, /* Interp for error reporting, if not NULL. */
- const char *name) /* The name of the desired encoding, or NULL
+ CONST char *name) /* The name of the desired encoding, or NULL
* to reset to default encoding. */
{
Tcl_Encoding encoding;
@@ -1051,7 +1050,7 @@ char *
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. */
+ CONST char *src, /* Source string in specified encoding. */
int srcLen, /* Source string length in bytes, or < 0 for
* encoding-specific string length. */
Tcl_DString *dstPtr) /* Uninitialized or free DString in which the
@@ -1125,7 +1124,7 @@ Tcl_ExternalToUtf(
Tcl_Interp *interp, /* Interp for error return, if not NULL. */
Tcl_Encoding encoding, /* The encoding for the source string, or NULL
* for the default system encoding. */
- const char *src, /* Source string in specified encoding. */
+ CONST char *src, /* Source string in specified encoding. */
int srcLen, /* Source string length in bytes, or < 0 for
* encoding-specific string length. */
int flags, /* Conversion control flags. */
@@ -1218,7 +1217,7 @@ char *
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. */
+ CONST char *src, /* Source string in UTF-8. */
int srcLen, /* Source string length in bytes, or < 0 for
* strlen(). */
Tcl_DString *dstPtr) /* Uninitialized or free DString in which the
@@ -1293,7 +1292,7 @@ Tcl_UtfToExternal(
Tcl_Interp *interp, /* Interp for error return, if not NULL. */
Tcl_Encoding encoding, /* The encoding for the converted string, or
* NULL for the default system encoding. */
- const char *src, /* Source string in UTF-8. */
+ CONST char *src, /* Source string in UTF-8. */
int srcLen, /* Source string length in bytes, or < 0 for
* strlen(). */
int flags, /* Conversion control flags. */
@@ -1378,7 +1377,7 @@ Tcl_UtfToExternal(
void
Tcl_FindExecutable(
- const char *argv0) /* The value of the application's argv[0]
+ CONST char *argv0) /* The value of the application's argv[0]
* (native). */
{
TclInitSubsystems();
@@ -1408,7 +1407,7 @@ Tcl_FindExecutable(
static Tcl_Channel
OpenEncodingFileChannel(
Tcl_Interp *interp, /* Interp for error reporting, if not NULL. */
- const char *name) /* The name of the encoding file on disk and
+ CONST char *name) /* The name of the encoding file on disk and
* also the name for new encoding. */
{
Tcl_Obj *nameObj = Tcl_NewStringObj(name, -1);
@@ -1419,7 +1418,7 @@ OpenEncodingFileChannel(
Tcl_Channel chan = NULL;
int i, numDirs;
- TclListObjGetElements(searchPath, numDirs, dir);
+ Tcl_ListObjGetElements(NULL, searchPath, &numDirs, &dir);
Tcl_IncrRefCount(nameObj);
Tcl_AppendToObj(fileNameObj, ".enc", -1);
Tcl_IncrRefCount(fileNameObj);
@@ -1438,10 +1437,9 @@ OpenEncodingFileChannel(
}
}
if (!verified) {
- const char *dirString = TclGetString(directory);
-
+ CONST char *dirString = Tcl_GetString(directory);
for (i=0; i<numDirs && !verified; i++) {
- if (strcmp(dirString, TclGetString(dir[i])) == 0) {
+ if (strcmp(dirString, Tcl_GetString(dir[i])) == 0) {
verified = 1;
}
}
@@ -1466,9 +1464,9 @@ OpenEncodingFileChannel(
Tcl_IncrRefCount(directory);
path = Tcl_FSJoinToPath(directory, 1, &fileNameObj);
Tcl_IncrRefCount(path);
- TclDecrRefCount(directory);
+ Tcl_DecrRefCount(directory);
chan = Tcl_FSOpenFileChannel(NULL, path, "r", 0);
- TclDecrRefCount(path);
+ Tcl_DecrRefCount(path);
}
/*
@@ -1479,7 +1477,7 @@ OpenEncodingFileChannel(
path = Tcl_FSJoinToPath(dir[i], 1, &fileNameObj);
Tcl_IncrRefCount(path);
chan = Tcl_FSOpenFileChannel(NULL, path, "r", 0);
- TclDecrRefCount(path);
+ Tcl_DecrRefCount(path);
if (chan != NULL) {
/*
* Save directory in the cache.
@@ -1494,9 +1492,9 @@ OpenEncodingFileChannel(
if ((NULL == chan) && (interp != NULL)) {
Tcl_AppendResult(interp, "unknown encoding \"", name, "\"", NULL);
}
- TclDecrRefCount(fileNameObj);
- TclDecrRefCount(nameObj);
- TclDecrRefCount(searchPath);
+ Tcl_DecrRefCount(fileNameObj);
+ Tcl_DecrRefCount(nameObj);
+ Tcl_DecrRefCount(searchPath);
return chan;
}
@@ -1524,7 +1522,7 @@ OpenEncodingFileChannel(
static Tcl_Encoding
LoadEncodingFile(
Tcl_Interp *interp, /* Interp for error reporting, if not NULL. */
- const char *name) /* The name of the encoding file on disk and
+ CONST char *name) /* The name of the encoding file on disk and
* also the name for new encoding. */
{
Tcl_Channel chan = NULL;
@@ -1538,14 +1536,17 @@ LoadEncodingFile(
Tcl_SetChannelOption(NULL, chan, "-encoding", "utf-8");
- do {
+ while (1) {
Tcl_DString ds;
Tcl_DStringInit(&ds);
Tcl_Gets(chan, &ds);
ch = Tcl_DStringValue(&ds)[0];
Tcl_DStringFree(&ds);
- } while (ch == '#');
+ if (ch != '#') {
+ break;
+ }
+ }
switch (ch) {
case 'S':
@@ -1594,7 +1595,7 @@ LoadEncodingFile(
static Tcl_Encoding
LoadTableEncoding(
- const char *name, /* Name for new encoding. */
+ CONST char *name, /* Name for new encoding. */
int type, /* Type of encoding (ENCODING_?????). */
Tcl_Channel chan) /* File containing new encoding. */
{
@@ -1675,7 +1676,7 @@ LoadTableEncoding(
char *p;
Tcl_ReadChars(chan, objPtr, 3 + 16 * (16 * 4 + 1), 0);
- p = TclGetString(objPtr);
+ p = Tcl_GetString(objPtr);
hi = (staticHex[UCHAR(p[0])] << 4) + staticHex[UCHAR(p[1])];
dataPtr->toUnicode[hi] = pageMemPtr;
p += 2;
@@ -1804,9 +1805,8 @@ LoadTableEncoding(
* Skip leading empty lines.
*/
- do {
- len = Tcl_Gets(chan, &lineString);
- } while (len == 0);
+ while ((len = Tcl_Gets(chan, &lineString)) == 0)
+ ;
if (len < 0) {
break;
@@ -1818,13 +1818,13 @@ LoadTableEncoding(
for (Tcl_DStringSetLength(&lineString, 0);
(len = Tcl_Gets(chan, &lineString)) >= 0;
Tcl_DStringSetLength(&lineString, 0)) {
- unsigned char *p;
+ unsigned char* p;
int to, from;
if (len < 5) {
continue;
}
- p = (unsigned char *) Tcl_DStringValue(&lineString);
+ 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) {
@@ -1847,7 +1847,7 @@ LoadTableEncoding(
encType.fromUtfProc = TableFromUtfProc;
encType.freeProc = TableFreeProc;
encType.nullSize = (type == ENCODING_DOUBLEBYTE) ? 2 : 1;
- encType.clientData = dataPtr;
+ encType.clientData = (ClientData) dataPtr;
return Tcl_CreateEncoding(&encType);
}
@@ -1876,7 +1876,7 @@ LoadTableEncoding(
static Tcl_Encoding
LoadEscapeEncoding(
- const char *name, /* Name for new encoding. */
+ CONST char *name, /* Name for new encoding. */
Tcl_Channel chan) /* File containing new encoding. */
{
int i;
@@ -1892,7 +1892,7 @@ LoadEscapeEncoding(
while (1) {
int argc;
- const char **argv;
+ CONST char **argv;
char *line;
Tcl_DString lineString;
@@ -1946,7 +1946,7 @@ LoadEscapeEncoding(
strcpy(dataPtr->final, final);
dataPtr->numSubTables =
Tcl_DStringLength(&escapeData) / sizeof(EscapeSubTable);
- memcpy(dataPtr->subTables, Tcl_DStringValue(&escapeData),
+ memcpy((VOID *) dataPtr->subTables, (VOID *) Tcl_DStringValue(&escapeData),
(size_t) Tcl_DStringLength(&escapeData));
Tcl_DStringFree(&escapeData);
@@ -1966,7 +1966,7 @@ LoadEscapeEncoding(
type.fromUtfProc = EscapeFromUtfProc;
type.freeProc = EscapeFreeProc;
type.nullSize = 1;
- type.clientData = dataPtr;
+ type.clientData = (ClientData) dataPtr;
return Tcl_CreateEncoding(&type);
}
@@ -1992,7 +1992,7 @@ LoadEscapeEncoding(
static int
BinaryProc(
ClientData clientData, /* Not used. */
- const char *src, /* Source string (unknown encoding). */
+ CONST char *src, /* Source string (unknown encoding). */
int srcLen, /* Source string length in bytes. */
int flags, /* Conversion control flags. */
Tcl_EncodingState *statePtr,/* Place for conversion routine to store state
@@ -2028,7 +2028,7 @@ BinaryProc(
*srcReadPtr = srcLen;
*dstWrotePtr = srcLen;
*dstCharsPtr = srcLen;
- memcpy(dst, src, (size_t) srcLen);
+ memcpy((void *) dst, (void *) src, (size_t) srcLen);
return result;
}
@@ -2053,7 +2053,7 @@ BinaryProc(
static int
UtfIntToUtfExtProc(
ClientData clientData, /* Not used. */
- const char *src, /* Source string in UTF-8. */
+ CONST char *src, /* Source string in UTF-8. */
int srcLen, /* Source string length in bytes. */
int flags, /* Conversion control flags. */
Tcl_EncodingState *statePtr,/* Place for conversion routine to store state
@@ -2101,7 +2101,7 @@ UtfIntToUtfExtProc(
static int
UtfExtToUtfIntProc(
ClientData clientData, /* Not used. */
- const char *src, /* Source string in UTF-8. */
+ CONST char *src, /* Source string in UTF-8. */
int srcLen, /* Source string length in bytes. */
int flags, /* Conversion control flags. */
Tcl_EncodingState *statePtr,/* Place for conversion routine to store state
@@ -2150,7 +2150,7 @@ UtfExtToUtfIntProc(
static int
UtfToUtfProc(
ClientData clientData, /* Not used. */
- const char *src, /* Source string in UTF-8. */
+ CONST char *src, /* Source string in UTF-8. */
int srcLen, /* Source string length in bytes. */
int flags, /* Conversion control flags. */
Tcl_EncodingState *statePtr,/* Place for conversion routine to store state
@@ -2177,7 +2177,7 @@ UtfToUtfProc(
* representation to real null-bytes or vice
* versa. */
{
- const char *srcStart, *srcEnd, *srcClose;
+ CONST char *srcStart, *srcEnd, *srcClose;
char *dstStart, *dstEnd;
int result, numChars;
Tcl_UniChar ch;
@@ -2224,10 +2224,10 @@ UtfToUtfProc(
*dst++ = 0;
src += 2;
} else if (!Tcl_UtfCharComplete(src, srcEnd - src)) {
- /*
- * Always check before using Tcl_UtfToUniChar. Not doing can so
- * cause it run beyond the endof the buffer! If we happen such an
- * incomplete char its byts are made to represent themselves.
+ /* Always check before using Tcl_UtfToUniChar. Not doing
+ * can so cause it run beyond the endof the buffer! If we
+ * * happen such an incomplete char its byts are made to *
+ * represent themselves.
*/
ch = (Tcl_UniChar) *src;
@@ -2264,7 +2264,7 @@ UtfToUtfProc(
static int
UnicodeToUtfProc(
ClientData clientData, /* Not used. */
- const char *src, /* Source string in Unicode. */
+ CONST char *src, /* Source string in Unicode. */
int srcLen, /* Source string length in bytes. */
int flags, /* Conversion control flags. */
Tcl_EncodingState *statePtr,/* Place for conversion routine to store state
@@ -2288,7 +2288,7 @@ UnicodeToUtfProc(
* correspond to the bytes stored in the
* output buffer. */
{
- const char *srcStart, *srcEnd;
+ CONST char *srcStart, *srcEnd;
char *dstEnd, *dstStart;
int result, numChars;
Tcl_UniChar ch;
@@ -2311,12 +2311,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);
@@ -2350,8 +2348,9 @@ UnicodeToUtfProc(
static int
UtfToUnicodeProc(
- ClientData clientData, /* Not used. */
- const char *src, /* Source string in UTF-8. */
+ ClientData clientData, /* TableEncodingData that specifies
+ * encoding. */
+ CONST char *src, /* Source string in UTF-8. */
int srcLen, /* Source string length in bytes. */
int flags, /* Conversion control flags. */
Tcl_EncodingState *statePtr,/* Place for conversion routine to store state
@@ -2375,7 +2374,7 @@ UtfToUnicodeProc(
* correspond to the bytes stored in the
* output buffer. */
{
- const char *srcStart, *srcEnd, *srcClose, *dstStart, *dstEnd;
+ CONST char *srcStart, *srcEnd, *srcClose, *dstStart, *dstEnd;
int result, numChars;
Tcl_UniChar ch;
@@ -2405,13 +2404,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);
@@ -2447,7 +2444,7 @@ static int
TableToUtfProc(
ClientData clientData, /* TableEncodingData that specifies
* encoding. */
- const char *src, /* Source string in specified encoding. */
+ CONST char *src, /* Source string in specified encoding. */
int srcLen, /* Source string length in bytes. */
int flags, /* Conversion control flags. */
Tcl_EncodingState *statePtr,/* Place for conversion routine to store state
@@ -2471,13 +2468,13 @@ TableToUtfProc(
* correspond to the bytes stored in the
* output buffer. */
{
- TableEncodingData *dataPtr = clientData;
- const char *srcStart, *srcEnd;
+ CONST char *srcStart, *srcEnd;
char *dstEnd, *dstStart, *prefixBytes;
int result, byte, numChars;
Tcl_UniChar ch;
unsigned short **toUnicode;
unsigned short *pageZero;
+ TableEncodingData *dataPtr;
srcStart = src;
srcEnd = src + srcLen;
@@ -2485,6 +2482,7 @@ TableToUtfProc(
dstStart = dst;
dstEnd = dst + dstLen - TCL_UTF_MAX;
+ dataPtr = (TableEncodingData *) clientData;
toUnicode = dataPtr->toUnicode;
prefixBytes = dataPtr->prefixBytes;
pageZero = toUnicode[0];
@@ -2517,11 +2515,9 @@ TableToUtfProc(
}
ch = (Tcl_UniChar) byte;
}
-
/*
* Special case for 1-byte utf chars for speed.
*/
-
if (ch && ch < 0x80) {
*dst++ = (char) ch;
} else {
@@ -2557,7 +2553,7 @@ static int
TableFromUtfProc(
ClientData clientData, /* TableEncodingData that specifies
* encoding. */
- const char *src, /* Source string in UTF-8. */
+ CONST char *src, /* Source string in UTF-8. */
int srcLen, /* Source string length in bytes. */
int flags, /* Conversion control flags. */
Tcl_EncodingState *statePtr,/* Place for conversion routine to store state
@@ -2581,14 +2577,16 @@ TableFromUtfProc(
* correspond to the bytes stored in the
* output buffer. */
{
- TableEncodingData *dataPtr = clientData;
- const char *srcStart, *srcEnd, *srcClose;
+ CONST char *srcStart, *srcEnd, *srcClose;
char *dstStart, *dstEnd, *prefixBytes;
Tcl_UniChar ch;
int result, len, word, numChars;
+ TableEncodingData *dataPtr;
unsigned short **fromUnicode;
result = TCL_OK;
+
+ dataPtr = (TableEncodingData *) clientData;
prefixBytes = dataPtr->prefixBytes;
fromUnicode = dataPtr->fromUnicode;
@@ -2680,12 +2678,13 @@ TableFreeProc(
ClientData clientData) /* TableEncodingData that specifies
* encoding. */
{
- TableEncodingData *dataPtr = clientData;
+ TableEncodingData *dataPtr;
/*
* Make sure we aren't freeing twice on shutdown. [Bug 219314]
*/
+ dataPtr = (TableEncodingData *) clientData;
ckfree((char *) dataPtr->toUnicode);
ckfree((char *) dataPtr->fromUnicode);
ckfree((char *) dataPtr);
@@ -2712,7 +2711,7 @@ static int
EscapeToUtfProc(
ClientData clientData, /* EscapeEncodingData that specifies
* encoding. */
- const char *src, /* Source string in specified encoding. */
+ CONST char *src, /* Source string in specified encoding. */
int srcLen, /* Source string length in bytes. */
int flags, /* Conversion control flags. */
Tcl_EncodingState *statePtr,/* Place for conversion routine to store state
@@ -2736,12 +2735,12 @@ EscapeToUtfProc(
* correspond to the bytes stored in the
* output buffer. */
{
- EscapeEncodingData *dataPtr = clientData;
+ EscapeEncodingData *dataPtr;
char *prefixBytes, *tablePrefixBytes;
unsigned short **tableToUnicode;
Encoding *encodingPtr;
int state, result, numChars;
- const char *srcStart, *srcEnd;
+ CONST char *srcStart, *srcEnd;
char *dstStart, *dstEnd;
result = TCL_OK;
@@ -2749,6 +2748,7 @@ EscapeToUtfProc(
tablePrefixBytes = NULL; /* lint. */
tableToUnicode = NULL; /* lint. */
+ dataPtr = (EscapeEncodingData *) clientData;
prefixBytes = dataPtr->prefixBytes;
encodingPtr = NULL;
@@ -2872,7 +2872,7 @@ EscapeToUtfProc(
TableEncodingData *tableDataPtr;
encodingPtr = GetTableEncoding(dataPtr, state);
- tableDataPtr = encodingPtr->clientData;
+ tableDataPtr = (TableEncodingData *) encodingPtr->clientData;
tablePrefixBytes = tableDataPtr->prefixBytes;
tableToUnicode = tableDataPtr->toUnicode;
}
@@ -2925,7 +2925,7 @@ static int
EscapeFromUtfProc(
ClientData clientData, /* EscapeEncodingData that specifies
* encoding. */
- const char *src, /* Source string in UTF-8. */
+ CONST char *src, /* Source string in UTF-8. */
int srcLen, /* Source string length in bytes. */
int flags, /* Conversion control flags. */
Tcl_EncodingState *statePtr,/* Place for conversion routine to store state
@@ -2949,9 +2949,9 @@ EscapeFromUtfProc(
* correspond to the bytes stored in the
* output buffer. */
{
- EscapeEncodingData *dataPtr = clientData;
+ EscapeEncodingData *dataPtr;
Encoding *encodingPtr;
- const char *srcStart, *srcEnd, *srcClose;
+ CONST char *srcStart, *srcEnd, *srcClose;
char *dstStart, *dstEnd;
int state, result, numChars;
TableEncodingData *tableDataPtr;
@@ -2959,6 +2959,9 @@ EscapeFromUtfProc(
unsigned short **tableFromUnicode;
result = TCL_OK;
+
+ dataPtr = (EscapeEncodingData *) clientData;
+
srcStart = src;
srcEnd = src + srcLen;
srcClose = srcEnd;
@@ -2981,14 +2984,14 @@ EscapeFromUtfProc(
*dstWrotePtr = 0;
return TCL_CONVERT_NOSPACE;
}
- memcpy(dst, dataPtr->init, (size_t) dataPtr->initLen);
+ memcpy((VOID *)dst, (VOID *)dataPtr->init, (size_t)dataPtr->initLen);
dst += dataPtr->initLen;
} else {
state = (int) *statePtr;
}
encodingPtr = GetTableEncoding(dataPtr, state);
- tableDataPtr = encodingPtr->clientData;
+ tableDataPtr = (TableEncodingData *) encodingPtr->clientData;
tablePrefixBytes = tableDataPtr->prefixBytes;
tableFromUnicode = tableDataPtr->fromUnicode;
@@ -3016,7 +3019,7 @@ EscapeFromUtfProc(
oldState = state;
for (state = 0; state < dataPtr->numSubTables; state++) {
encodingPtr = GetTableEncoding(dataPtr, state);
- tableDataPtr = encodingPtr->clientData;
+ tableDataPtr = (TableEncodingData *) encodingPtr->clientData;
word = tableDataPtr->fromUnicode[(ch >> 8)][ch & 0xff];
if (word != 0) {
break;
@@ -3030,7 +3033,7 @@ EscapeFromUtfProc(
break;
}
encodingPtr = GetTableEncoding(dataPtr, state);
- tableDataPtr = encodingPtr->clientData;
+ tableDataPtr = (TableEncodingData *) encodingPtr->clientData;
word = tableDataPtr->fallback;
}
@@ -3057,7 +3060,7 @@ EscapeFromUtfProc(
result = TCL_CONVERT_NOSPACE;
break;
}
- memcpy(dst, subTablePtr->sequence,
+ memcpy((VOID *) dst, (VOID *) subTablePtr->sequence,
(size_t) subTablePtr->sequenceLen);
dst += subTablePtr->sequenceLen;
}
@@ -3088,10 +3091,12 @@ EscapeFromUtfProc(
result = TCL_CONVERT_NOSPACE;
} else {
if (state) {
- memcpy(dst, dataPtr->subTables[0].sequence, (size_t) len);
+ memcpy((VOID *) dst, (VOID *) dataPtr->subTables[0].sequence,
+ (size_t) len);
dst += len;
}
- memcpy(dst, dataPtr->final, (size_t) dataPtr->finalLen);
+ memcpy((VOID *) dst, (VOID *) dataPtr->final,
+ (size_t) dataPtr->finalLen);
dst += dataPtr->finalLen;
}
}
@@ -3125,10 +3130,11 @@ EscapeFreeProc(
ClientData clientData) /* EscapeEncodingData that specifies
* encoding. */
{
- EscapeEncodingData *dataPtr = clientData;
+ EscapeEncodingData *dataPtr;
EscapeSubTable *subTablePtr;
int i;
+ dataPtr = (EscapeEncodingData *) clientData;
if (dataPtr == NULL) {
return;
}
@@ -3203,7 +3209,7 @@ GetTableEncoding(
static size_t
unilen(
- const char *src)
+ CONST char *src)
{
unsigned short *p;
@@ -3246,9 +3252,8 @@ InitializeEncodingSearchPath(
char *bytes;
int i, numDirs, numBytes;
Tcl_Obj *libPath, *encodingObj = Tcl_NewStringObj("encoding", -1);
- Tcl_Obj *searchPath;
+ Tcl_Obj *searchPath = Tcl_NewObj();
- TclNewObj(searchPath);
Tcl_IncrRefCount(encodingObj);
Tcl_IncrRefCount(searchPath);
libPath = TclGetLibraryPath();
@@ -3265,11 +3270,11 @@ InitializeEncodingSearchPath(
if ((0 == Tcl_FSStat(path, &stat)) && S_ISDIR(stat.st_mode)) {
Tcl_ListObjAppendElement(NULL, searchPath, path);
}
- TclDecrRefCount(path);
+ Tcl_DecrRefCount(path);
}
- TclDecrRefCount(libPath);
- TclDecrRefCount(encodingObj);
+ Tcl_DecrRefCount(libPath);
+ Tcl_DecrRefCount(encodingObj);
*encodingPtr = libraryPath.encoding;
if (*encodingPtr) {
((Encoding *)(*encodingPtr))->refCount++;
@@ -3278,8 +3283,8 @@ InitializeEncodingSearchPath(
*lengthPtr = numBytes;
*valuePtr = ckalloc((unsigned int) numBytes + 1);
- memcpy(*valuePtr, bytes, (size_t) numBytes + 1);
- TclDecrRefCount(searchPath);
+ memcpy((VOID *) *valuePtr, (VOID *) bytes, (size_t) numBytes + 1);
+ Tcl_DecrRefCount(searchPath);
}
/*