summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2007-10-28 00:40:47 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2007-10-28 00:40:47 (GMT)
commit6875fa13ed77ee3b9fbd8277365f570919300bc5 (patch)
treefff428848af9ae6d966949794ab7ffa829ae5bd9
parente09eccf1c109d772ea755d25d028353093bbfa44 (diff)
downloadtcl-6875fa13ed77ee3b9fbd8277365f570919300bc5.zip
tcl-6875fa13ed77ee3b9fbd8277365f570919300bc5.tar.gz
tcl-6875fa13ed77ee3b9fbd8277365f570919300bc5.tar.bz2
Embed the definition of the iso8859-1 encoding directly in Tcl.
-rw-r--r--ChangeLog8
-rw-r--r--generic/tclEncoding.c48
2 files changed, 54 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 0dbc7f6..ccf0c39 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2007-10-28 Donal K. Fellows <dkf@users.sf.net>
+
+ * generic/tclEncoding.c (TclInitEncodingSubsystem): Hard code the
+ iso8859-1 encoding, as it's needed for more than just text (especially
+ binary encodings...) Note that other encodings rely on the encoding
+ being a table encoding (!) so we can't use more efficient encoding
+ mapping functions.
+
2007-10-27 Donal K. Fellows <dkf@users.sf.net>
* generic/regc_lex.c (lexescape): Close off one of the problems
diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c
index d0465aa..fbaa8e1 100644
--- a/generic/tclEncoding.c
+++ b/generic/tclEncoding.c
@@ -8,7 +8,7 @@
* 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.55 2007/04/17 14:49:53 dkf Exp $
+ * RCS: @(#) $Id: tclEncoding.c,v 1.56 2007/10/28 00:40:48 dkf Exp $
*/
#include "tclInt.h"
@@ -575,6 +575,50 @@ TclInitEncodingSubsystem(void)
type.clientData = NULL;
Tcl_CreateEncoding(&type);
+ /*
+ * Need the iso8859-1 encoding in order to process binary data, so force
+ * it to always be embedded. Note that this encoding *must* be a proper
+ * table encoding or some of the escape encodings crash! Hence the ugly
+ * code to duplicate the structure of a table encoding here.
+ */
+
+ {
+ 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;
+ }
+
+ for (i=0 ; i<256 ; i++) {
+ dataPtr->toUnicode[0][i] = i;
+ dataPtr->fromUnicode[0][i] = i;
+ }
+
+ type.encodingName = "iso8859-1";
+ type.toUtfProc = TableToUtfProc;
+ type.fromUtfProc = TableFromUtfProc;
+ type.freeProc = TableFreeProc;
+ type.nullSize = 1;
+ type.clientData = dataPtr;
+ Tcl_CreateEncoding(&type);
+ }
+
encodingsInitialized = 1;
}
@@ -2030,7 +2074,7 @@ BinaryProc(
*srcReadPtr = srcLen;
*dstWrotePtr = srcLen;
*dstCharsPtr = srcLen;
- memcpy((void *) dst, (void *) src, (size_t) srcLen);
+ memcpy(dst, src, (size_t) srcLen);
return result;
}