summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c/luatexdir/tex/texfileio.w
diff options
context:
space:
mode:
authorPeter Breitenlohner <peb@mppmu.mpg.de>2012-08-07 13:23:53 +0000
committerPeter Breitenlohner <peb@mppmu.mpg.de>2012-08-07 13:23:53 +0000
commite18a0d3379d56e07aaf10334bcadd4a68889819d (patch)
tree338f3bc1c47ba4ddc5b45a008cd3fce511fda666 /Build/source/texk/web2c/luatexdir/tex/texfileio.w
parent41ddf905c124da09f188bf0b7b1f40b7f5c0e47a (diff)
luaTeX: Move swap_items() to tex/texfileio.w where it is used
git-svn-id: svn://tug.org/texlive/trunk@27330 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/web2c/luatexdir/tex/texfileio.w')
-rw-r--r--Build/source/texk/web2c/luatexdir/tex/texfileio.w93
1 files changed, 93 insertions, 0 deletions
diff --git a/Build/source/texk/web2c/luatexdir/tex/texfileio.w b/Build/source/texk/web2c/luatexdir/tex/texfileio.w
index 396cfd78607..7123bdfb557 100644
--- a/Build/source/texk/web2c/luatexdir/tex/texfileio.w
+++ b/Build/source/texk/web2c/luatexdir/tex/texfileio.w
@@ -984,6 +984,99 @@ is needed.
@c
static gzFile gz_fmtfile = NULL;
+@ As distributed, the dump files are
+architecture dependent; specifically, BigEndian and LittleEndian
+architectures produce different files. These routines always output
+BigEndian files. This still does not guarantee them to be
+architecture-independent, because it is possible to make a format
+that dumps a glue ratio, i.e., a floating-point number. Fortunately,
+none of the standard formats do that.
+
+@c
+#if !defined (WORDS_BIGENDIAN) && !defined (NO_DUMP_SHARE)
+
+/* This macro is always invoked as a statement. It assumes a variable
+ `temp'. */
+# define SWAP(x, y) do { temp = x; x = y; y = temp; } while (0)
+
+/* Make the NITEMS items pointed at by P, each of size SIZE, be the
+ opposite-endianness of whatever they are now. */
+static void
+swap_items(char *pp, int nitems, int size)
+{
+ char temp;
+ unsigned total = (unsigned) (nitems * size);
+ char *q = xmalloc(total);
+ char *p = q;
+ memcpy(p,pp,total);
+ /* Since `size' does not change, we can write a while loop for each
+ case, and avoid testing `size' for each time. */
+ switch (size) {
+ /* 16-byte items happen on the DEC Alpha machine when we are not
+ doing sharable memory dumps. */
+ case 16:
+ while (nitems--) {
+ SWAP(p[0], p[15]);
+ SWAP(p[1], p[14]);
+ SWAP(p[2], p[13]);
+ SWAP(p[3], p[12]);
+ SWAP(p[4], p[11]);
+ SWAP(p[5], p[10]);
+ SWAP(p[6], p[9]);
+ SWAP(p[7], p[8]);
+ p += size;
+ }
+ break;
+
+ case 12:
+ while (nitems--) {
+ SWAP(p[0], p[11]);
+ SWAP(p[1], p[10]);
+ SWAP(p[2], p[9]);
+ SWAP(p[3], p[8]);
+ SWAP(p[4], p[7]);
+ SWAP(p[5], p[6]);
+ p += size;
+ }
+ break;
+
+ case 8:
+ while (nitems--) {
+ SWAP(p[0], p[7]);
+ SWAP(p[1], p[6]);
+ SWAP(p[2], p[5]);
+ SWAP(p[3], p[4]);
+ p += size;
+ }
+ break;
+
+ case 4:
+ while (nitems--) {
+ SWAP(p[0], p[3]);
+ SWAP(p[1], p[2]);
+ p += size;
+ }
+ break;
+
+ case 2:
+ while (nitems--) {
+ SWAP(p[0], p[1]);
+ p += size;
+ }
+ break;
+
+ case 1:
+ /* Nothing to do. */
+ break;
+
+ default:
+ FATAL1("Can't swap a %d-byte item for (un)dumping", size);
+ }
+ memcpy(pp,q,total);
+ xfree(q);
+}
+#endif /* not WORDS_BIGENDIAN and not NO_DUMP_SHARE */
+
@ That second swap is to make sure following calls don't get
confused in the case of |dump_things|.