summaryrefslogtreecommitdiff
path: root/tex/context/base/l-io.lua
diff options
context:
space:
mode:
authorMarius <mariausol@gmail.com>2011-04-22 19:40:44 +0300
committerMarius <mariausol@gmail.com>2011-04-22 19:40:44 +0300
commit6f891b8572f03990803f9cb1ceb5870fcbe4d240 (patch)
tree419dc45860d70876c4a7e590eae9fc38cfcde8a0 /tex/context/base/l-io.lua
parent48aee08be6614bf30710ae7c42248f64d55f8f22 (diff)
downloadcontext-6f891b8572f03990803f9cb1ceb5870fcbe4d240.tar.gz
beta 2011.04.22 18:17
Diffstat (limited to 'tex/context/base/l-io.lua')
-rw-r--r--tex/context/base/l-io.lua44
1 files changed, 30 insertions, 14 deletions
diff --git a/tex/context/base/l-io.lua b/tex/context/base/l-io.lua
index 290dcec42..a740996c6 100644
--- a/tex/context/base/l-io.lua
+++ b/tex/context/base/l-io.lua
@@ -106,8 +106,6 @@ local nextchar = {
function io.characters(f,n)
if f then
return nextchar[n or 1], f
- else
- return nil, nil
end
end
@@ -116,40 +114,42 @@ local nextbyte = {
local a, b, c, d = f:read(1,1,1,1)
if d then
return byte(a), byte(b), byte(c), byte(d)
- else
- return nil, nil, nil, nil
+ end
+ end,
+ [3] = function(f)
+ local a, b, c = f:read(1,1,1)
+ if b then
+ return byte(a), byte(b), byte(c)
end
end,
[2] = function(f)
local a, b = f:read(1,1)
if b then
return byte(a), byte(b)
- else
- return nil, nil
end
end,
[1] = function (f)
local a = f:read(1)
if a then
return byte(a)
- else
- return nil
end
end,
[-2] = function (f)
local a, b = f:read(1,1)
if b then
return byte(b), byte(a)
- else
- return nil, nil
+ end
+ end,
+ [-3] = function(f)
+ local a, b, c = f:read(1,1,1)
+ if b then
+ return byte(c), byte(b), byte(a)
end
end,
[-4] = function(f)
local a, b, c, d = f:read(1,1,1,1)
if d then
return byte(d), byte(c), byte(b), byte(a)
- else
- return nil, nil, nil, nil
end
end
}
@@ -205,10 +205,13 @@ local function readnumber(f,n,m)
return byte(f:read(1))
elseif n == 2 then
local a, b = byte(f:read(2),1,2)
- return 256*a + b
+ return 256 * a + b
+ elseif n == 3 then
+ local a, b, c = byte(f:read(3),1,3)
+ return 256*256 * a + 256 * b + c
elseif n == 4 then
local a, b, c, d = byte(f:read(4),1,4)
- return 256*256*256 * a + 256*256 * b + 256*c + d
+ return 256*256*256 * a + 256*256 * b + 256 * c + d
elseif n == 8 then
local a, b = readnumber(f,4), readnumber(f,4)
return 256 * a + b
@@ -218,9 +221,22 @@ local function readnumber(f,n,m)
elseif n == -2 then
local b, a = byte(f:read(2),1,2)
return 256*a + b
+ elseif n == -3 then
+ local c, b, a = byte(f:read(3),1,3)
+ return 256*256 * a + 256 * b + c
elseif n == -4 then
local d, c, b, a = byte(f:read(4),1,4)
return 256*256*256 * a + 256*256 * b + 256*c + d
+ elseif n == -8 then
+ local h, g, f, e, d, c, b, a = byte(f:read(8),1,8)
+ return 256*256*256*256*256*256*256 * a +
+ 256*256*256*256*256*256 * b +
+ 256*256*256*256*256 * c +
+ 256*256*256*256 * d +
+ 256*256*256 * e +
+ 256*256 * f +
+ 256 * g +
+ h
else
return 0
end