Skip to content

Commit 3048053

Browse files
committed
Simplify error strings to save space.
1 parent 70a8638 commit 3048053

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

util/UNZIP.LUA

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env lua
22

33
---Halt and catch fire if E is set
4-
local function D() if E then error(E, 0) end end
4+
function D() if E then error(E, 0) end end
55

66
---New bit stream
7-
local function nbs(r)
7+
function nbs(r)
88

99
-- b = buffer
1010
-- p = position
@@ -16,17 +16,16 @@ local function nbs(r)
1616
local function F()
1717
if p > #b then
1818
b = r()
19-
if not b or #b == 0 then return false end
20-
p = 1
19+
if b or #b ~= 0 then p = 1 else return 0 end
2120
end
22-
return true
21+
return 1
2322
end
2423

2524
---Need bits
2625
local function nb(n)
2726
while bc < n do
2827
if p > #b then
29-
if not F() then error("Unexpected EOF") end
28+
if F()==0 then error("!EOF",0) end
3029
end
3130
bb = bb + (b:byte(p) << bc)
3231
p = p + 1
@@ -49,7 +48,7 @@ local function nbs(r)
4948
end
5049

5150
---Reverse bits
52-
local function rv(x, bits)
51+
function rv(x, bits)
5352
local y = 0
5453

5554
for _ = 1, bits do
@@ -61,7 +60,7 @@ local function rv(x, bits)
6160
end
6261

6362
---Make huffman
64-
local function mh(lengths)
63+
function mh(lengths)
6564

6665
-- m = maximum length
6766
-- c = counts
@@ -97,7 +96,7 @@ local function mh(lengths)
9796
end
9897

9998
---Read huffman
100-
local function rh(bs, h)
99+
function rh(bs, h)
101100

102101
-- c = code
103102
local c = 0
@@ -109,13 +108,13 @@ local function rh(bs, h)
109108
if e and e.len == l then return e.sym end
110109
end
111110

112-
error("invalid Huffman code")
111+
error("!Huffman", 0)
113112
end
114113

115114
---Inflate a deflated file inside a zip
116115
---@param r function The reader function
117116
---@param w function The writer function
118-
local function inf(r, w)
117+
function inf(r, w)
119118

120119
-- bs = bit stream
121120
-- op = output position
@@ -259,7 +258,7 @@ local function inf(r, w)
259258
dv = db + da
260259

261260
if dv <= 0 or dv > op then
262-
error("Invalid distance " .. tostring(dv) .. " (outpos=" .. tostring(op) .. ")")
261+
error("!Distance", 0)
263262
end
264263

265264
-- Read from window history
@@ -270,7 +269,7 @@ local function inf(r, w)
270269
end
271270
end
272271
else
273-
error("Unsupported block type: "..tostring(t))
272+
error("!Unsupported", 0)
274273
end
275274

276275
if f == 1 then kg = false end
@@ -279,7 +278,7 @@ local function inf(r, w)
279278
F()
280279
end
281280

282-
local function crc32(s, c)
281+
function crc32(s, c)
283282

284283
-- x = maximum
285284
-- c = crc number
@@ -294,7 +293,7 @@ local function crc32(s, c)
294293
return c ~ x
295294
end
296295

297-
local function unzip(p)
296+
function unzip(p)
298297

299298
-- C = read chunk size
300299
-- f = file
@@ -387,12 +386,12 @@ local function unzip(p)
387386
elseif cm == 8 then -- deflated file
388387
inf(RC, W)
389388
else
390-
print("Unsupported compression")
389+
print("!Unsupported")
391390
end
392391

393392
of:close()
394393

395-
if cr ~= cr then print("CRC mismatch") end
394+
if cr ~= cr then print("!CRC") end
396395
end
397396
end
398397

0 commit comments

Comments
 (0)