summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/util-sac.lua
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2018-11-18 16:12:36 +0100
committerContext Git Mirror Bot <phg@phi-gamma.net>2018-11-18 16:12:36 +0100
commit744095aa4676553437db0d71c281a74557a3222f (patch)
treebfdf5d203b5fbfa44ee7db705d3b3475361ad28f /tex/context/base/mkiv/util-sac.lua
parente2ee706a3114129601a30908d6b8cbb57068d32c (diff)
downloadcontext-744095aa4676553437db0d71c281a74557a3222f.tar.gz
2018-11-18 14:16:00
Diffstat (limited to 'tex/context/base/mkiv/util-sac.lua')
-rw-r--r--tex/context/base/mkiv/util-sac.lua34
1 files changed, 19 insertions, 15 deletions
diff --git a/tex/context/base/mkiv/util-sac.lua b/tex/context/base/mkiv/util-sac.lua
index 62ce6bc1c..dc8ba72f1 100644
--- a/tex/context/base/mkiv/util-sac.lua
+++ b/tex/context/base/mkiv/util-sac.lua
@@ -10,19 +10,23 @@ if not modules then modules = { } end modules ['util-sac'] = {
-- with bytes)
local byte, sub = string.byte, string.sub
-local extract = bit32 and bit32.extract
+local tonumber = tonumber
utilities = utilities or { }
local streams = { }
utilities.streams = streams
function streams.open(filename,zerobased)
- local f = io.loaddata(filename)
- return { f, 1, #f, zerobased or false }
+ local f = filename and io.loaddata(filename)
+ if f then
+ return { f, 1, #f, zerobased or false }
+ end
end
function streams.openstring(f,zerobased)
- return { f, 1, #f, zerobased or false }
+ if f then
+ return { f, 1, #f, zerobased or false }
+ end
end
function streams.close()
@@ -237,31 +241,31 @@ function streams.readinteger4le(f)
end
end
-function streams.readfixed4(f)
+function streams.readfixed2(f)
local i = f[2]
- local j = i + 3
+ local j = i + 1
f[2] = j + 1
- local a, b, c, d = byte(f[1],i,j)
+ local a, b = byte(f[1],i,j)
if a >= 0x80 then
- return (0x100 * a + b - 0x10000) + (0x100 * c + d)/0x10000
+ tonumber((a - 0x100) .. "." .. b)
else
- return (0x100 * a + b ) + (0x100 * c + d)/0x10000
+ tonumber((a ) .. "." .. b)
end
end
-function streams.readfixed2(f)
+function streams.readfixed4(f)
local i = f[2]
- local j = i + 1
+ local j = i + 3
f[2] = j + 1
- local a, b = byte(f[1],i,j)
+ local a, b, c, d = byte(f[1],i,j)
if a >= 0x80 then
- return (a - 0x100) + b/0x100
+ tonumber((0x100 * a + b - 0x10000) .. "." .. (0x100 * c + d))
else
- return (a ) + b/0x100
+ tonumber((0x100 * a + b ) .. "." .. (0x100 * c + d))
end
end
-if extract then
+if bit32 then
local extract = bit32.extract
local band = bit32.band