summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c
diff options
context:
space:
mode:
authorJonathan Kew <jfkthame@googlemail.com>2008-03-05 14:13:14 +0000
committerJonathan Kew <jfkthame@googlemail.com>2008-03-05 14:13:14 +0000
commit34fb63e0edf29dee94dba0dee6c5563022b224ca (patch)
treee8fd50c2605705a258366bc9aa7b816d1c051e8b /Build/source/texk/web2c
parenta8558f6a9e4f5c968d90f47e9274c415c7aa023e (diff)
xetex bugfix in gettexstring()
git-svn-id: svn://tug.org/texlive/trunk@6866 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/web2c')
-rw-r--r--Build/source/texk/web2c/lib/texmfmp.c61
1 files changed, 51 insertions, 10 deletions
diff --git a/Build/source/texk/web2c/lib/texmfmp.c b/Build/source/texk/web2c/lib/texmfmp.c
index 28f6c8acd79..bf6c5234346 100644
--- a/Build/source/texk/web2c/lib/texmfmp.c
+++ b/Build/source/texk/web2c/lib/texmfmp.c
@@ -395,7 +395,7 @@ topenin P1H(void)
unsigned char *ptr = (unsigned char *)&(argv[i][0]);
/* need to interpret UTF8 from the command line */
UInt32 rval;
- while (rval = *(ptr++)) {
+ while ((rval = *(ptr++)) != 0) {
UInt16 extraBytes = bytesFromUTF8[rval];
switch (extraBytes) { /* note: code falls through cases! */
case 5: rval <<= 6; if (*ptr) rval += *(ptr++);
@@ -1909,7 +1909,7 @@ maketexstring(const_string s)
len = strlen(s);
checkpoolpointer (poolptr, len); /* in the XeTeX case, this may be more than enough */
#ifdef XeTeX
- while (rval = *(cp++)) {
+ while ((rval = *(cp++)) != 0) {
UInt16 extraBytes = bytesFromUTF8[rval];
switch (extraBytes) { /* note: code falls through cases! */
case 5: rval <<= 6; if (*cp) rval += *(cp++);
@@ -1973,22 +1973,65 @@ compare_paths P2C(const_string, p1, const_string, p2)
return ret;
}
-#ifdef XeTeX
-#define strstartar strstart
-#endif
+#ifdef XeTeX /* the string pool is UTF-16 but we want a UTF-8 string */
+
+string
+gettexstring P1C(strnumber, s)
+{
+ unsigned bytesToWrite = 0;
+ poolpointer len, i, j;
+ string name;
+ len = strstart[s + 1 - 65536L] - strstart[s - 65536L];
+ name = (string)xmalloc(len * 3 + 1); /* max UTF16->UTF8 expansion (code units, not bytes) */
+ for (i = 0, j = 0; i < len; i++) {
+ unsigned c = strpool[i + strstart[s - 65536L]];
+ if (c >= 0xD800 && c <= 0xDBFF) {
+ unsigned lo = strpool[++i + strstart[s - 65536L]];
+ if (lo >= 0xDC00 && lo <= 0xDFFF)
+ c = (c - 0xD800) * 0x0400 + lo - 0xDC00;
+ else
+ c = 0xFFFD;
+ }
+ if (c < 0x80)
+ bytesToWrite = 1;
+ else if (c < 0x800)
+ bytesToWrite = 2;
+ else if (c < 0x10000)
+ bytesToWrite = 3;
+ else if (c < 0x110000)
+ bytesToWrite = 4;
+ else {
+ bytesToWrite = 3;
+ c = 0xFFFD;
+ }
+
+ j += bytesToWrite;
+ switch (bytesToWrite) { /* note: everything falls through. */
+ case 4: name[--j] = ((c | 0x80) & 0xBF); c >>= 6;
+ case 3: name[--j] = ((c | 0x80) & 0xBF); c >>= 6;
+ case 2: name[--j] = ((c | 0x80) & 0xBF); c >>= 6;
+ case 1: name[--j] = (c | firstByteMark[bytesToWrite]);
+ }
+ j += bytesToWrite;
+ }
+ name[j] = 0;
+ return name;
+}
+
+#else
string
gettexstring P1C(strnumber, s)
{
poolpointer len;
string name;
-#if !defined(Omega) && !defined(eOmega) && !defined(Aleph) && !defined(XeTeX)
+#if !defined(Omega) && !defined(eOmega) && !defined(Aleph)
len = strstart[s + 1] - strstart[s];
#else
len = strstartar[s + 1 - 65536L] - strstartar[s - 65536L];
#endif
name = (string)xmalloc (len + 1);
-#if !defined(Omega) && !defined(eOmega) && !defined(Aleph) && !defined(XeTeX)
+#if !defined(Omega) && !defined(eOmega) && !defined(Aleph)
strncpy (name, (string)&strpool[strstart[s]], len);
#else
{
@@ -2001,9 +2044,7 @@ gettexstring P1C(strnumber, s)
return name;
}
-#ifdef XeTeX
-#undef strstartar
-#endif
+#endif /* not XeTeX */
boolean
isnewsource P2C(strnumber, srcfilename, int, lineno)