summaryrefslogtreecommitdiff
path: root/cd-tool.lua
diff options
context:
space:
mode:
authorpixel <pixel>2004-05-02 12:29:02 +0000
committerpixel <pixel>2004-05-02 12:29:02 +0000
commitb0ecd395ad3f7ae5d782713dd610a056b1b33c31 (patch)
tree8e3641d1721a12540170301f84697050b9fad425 /cd-tool.lua
parent6fe28e64b960b2a58ef0cff94898f6958467927c (diff)
Added a built-in cd-tool.lua feature.
Diffstat (limited to 'cd-tool.lua')
-rw-r--r--cd-tool.lua537
1 files changed, 273 insertions, 264 deletions
diff --git a/cd-tool.lua b/cd-tool.lua
index 4e0f0d0..7b37d0f 100644
--- a/cd-tool.lua
+++ b/cd-tool.lua
@@ -1,176 +1,181 @@
- ------------------
--- misc functions --
- ------------------
-
-function display(inp)
- if (type(inp) == "string") then
- inp = Input(inp)
- elseif (type(inp) ~= "table") then
- error("Display needs a string or an Input object")
- end
-
- while(not inp:isclosed()) do
- print(inp:read())
- end
-end
-
-function pchar(n)
- if (not ((n >= 32) and (n <= 127))) then
- n = 0x2e
- end
- return hex(n, "%c")
-end
-
-function hexdump(inp, from, to, width)
- local size, nlines, remaining, data_array, line, byte, outstring
-
- if (type(inp) == "string") then
- inp = Input(inp)
- elseif (type(inp) ~= "table") then
- error("Hexdump needs a string or an Input object")
- end
-
- size = inp:getsize()
-
- if (from == nil) then
- from = 0
- end
-
- if (to == nil) then
- to = size
- end
-
- if (to > size) then
- to = size
- end
-
- size = to - from
-
- if (width == nil) then
- width = 16
- end
-
- nlines = math.floor(size / width)
- remaining = math.mod(size, width)
- inp:seek(from)
- data_array = inp:read(size)
-
- for line = 0, nlines - 1, 1 do
- outstring = hex(line * width + from, "%08x ")
- for byte = 0, width - 1, 1 do
- outstring = outstring .. hex(data_array[line * 16 + byte]) .. " "
- end
- outstring = outstring .. " "
- for byte = 0, width - 1, 1 do
- outstring = outstring .. pchar(data_array[line * 16 + byte])
- end
- print(outstring)
- end
-
- if (remaining == 0) then
- return
- end
-
- outstring = hex(nlines * width + from, "%08x ");
- for byte = 0, remaining - 1, 1 do
- outstring = outstring .. hex(data_array[nlines * 16 + byte]) .. " "
- end
- for byte = remaining + 1, width - 1, 1 do
- outstring = outstring .. " "
- end
- outstring = outstring .. " "
- for byte = 0, remaining - 1, 1 do
- outstring = outstring .. pchar(data_array[nlines * 16 + byte])
- end
-
- print(outstring)
-end
-
-
- --------------------------
--- cdutil object wrappers --
- --------------------------
-
-function cdfile(arg1, arg2, arg3, arg4)
- local cdutil_implied = false
-
- if ((type(arg1) ~= "table") or (arg1.cdfile == nil)) then
- cdutil_implied = true
- end
-
- if ((arg2 == nil) and (arg3 == nil) and (arg4 == nil)) then
- return cdutil:cdfile(arg1)
- elseif ((arg3 == nil) and (arg4 == nil)) then
- if (cdutil_implied) then
- return cdutil:cdfile(arg1, arg2)
- else
- return arg1:cdfile(arg2)
- end
- elseif (arg4 == nil) then
- if (cdutil_implied) then
- return cdutil:cdfile(arg1, arg2, arg3)
- else
- return arg1:cdfile(arg2, arg3)
- end
- else
- return arg1:cdfile(arg2, arg3, arg4)
- end
-end
-
-function setisow(iso_w)
- if (cdutil == nil) then error "cdutil object non existant" end
- return cdutil:setisow(iso_w)
-end
-
-function guessmode(sect)
- if (cdutil == nil) then error "cdutil object non existant" end
- if (sect == nil) then
- return cdutil:guessmode()
- else
- return cdutil:guessmode(sect)
- end
-end
-
-function sectorseek(sect)
- if (cdutil == nil) then error "cdutil object non existant" end
- return cdutil:sectorseek(sect)
-end
-
-function readsector(sect, mode)
- if (cdutil == nil) then error "cdutil object non existant" end
- if (sect == nil) then
- return cdutil:readsector()
- elseif (mode == nil) then
- return cdutil:readsector(sect)
- else
- return cdutil:readsector(sect, mode)
- end
-end
+ ------------------
+-- misc functions --
+ ------------------
+
+function display(inp)
+ if (type(inp) == "string") then
+ inp = Input(inp)
+ elseif (type(inp) ~= "table") then
+ error("Display needs a string or an Input object")
+ end
+
+ while(not inp:isclosed()) do
+ print(inp:read())
+ end
+end
+
+function pchar(n)
+ if (not ((n >= 32) and (n <= 127))) then
+ n = 46
+ end
+ return hex(n, "%c")
+end
+
+function hexdump(inp, from, to, width)
+ local size, nlines, remaining, data_array, line, byte, outstring
+
+ if (type(inp) == "string") then
+ inp = Input(inp)
+ elseif (type(inp) ~= "table") then
+ error("Hexdump needs a string or an Input object")
+ end
+
+ size = inp:getsize()
+
+ if (from == nil) then
+ from = 0
+ end
+
+ if (to == nil) then
+ to = size
+ end
+
+ if (to > size) then
+ to = size
+ end
+
+ size = to - from
+
+ if (width == nil) then
+ width = 16
+ end
+
+ nlines = math.floor(size / width)
+ remaining = math.mod(size, width)
+ inp:seek(from)
+ data_array = inp:read(size)
+
+ for line = 0, nlines - 1, 1 do
+ outstring = hex(line * width + from, "%08x ")
+ for byte = 0, width - 1, 1 do
+ outstring = outstring .. hex(data_array[line * 16 + byte]) .. " "
+ end
+ outstring = outstring .. " "
+ for byte = 0, width - 1, 1 do
+ outstring = outstring .. pchar(data_array[line * 16 + byte])
+ end
+ print(outstring)
+ end
+
+ if (remaining == 0) then
+ return
+ end
+
+ outstring = hex(nlines * width + from, "%08x ");
+ for byte = 0, remaining - 1, 1 do
+ outstring = outstring .. hex(data_array[nlines * 16 + byte]) .. " "
+ end
+ for byte = remaining + 1, width - 1, 1 do
+ outstring = outstring .. " "
+ end
+ outstring = outstring .. " "
+ for byte = 0, remaining - 1, 1 do
+ outstring = outstring .. pchar(data_array[nlines * 16 + byte])
+ end
+
+ print(outstring)
+end
+
+
+ --------------------------
+-- cdutil object wrappers --
+ --------------------------
+
+function check_cdutil()
+ if (cdutil == nil) then error "cdutil object non existant" end
+end
+
+function cdfile(arg1, arg2, arg3, arg4)
+ local cdutil_implied = false
+
+ if ((type(arg1) ~= "table") or (arg1.cdfile == nil)) then
+ check_cdutil()
+ cdutil_implied = true
+ end
+
+ if ((arg2 == nil) and (arg3 == nil) and (arg4 == nil)) then
+ return cdutil:cdfile(arg1)
+ elseif ((arg3 == nil) and (arg4 == nil)) then
+ if (cdutil_implied) then
+ return cdutil:cdfile(arg1, arg2)
+ else
+ return arg1:cdfile(arg2)
+ end
+ elseif (arg4 == nil) then
+ if (cdutil_implied) then
+ return cdutil:cdfile(arg1, arg2, arg3)
+ else
+ return arg1:cdfile(arg2, arg3)
+ end
+ else
+ return arg1:cdfile(arg2, arg3, arg4)
+ end
+end
+
+function setisow(iso_w)
+ check_cdutil()
+ return cdutil:setisow(iso_w)
+end
+
+function guessmode(sect)
+ check_cdutil()
+ if (sect == nil) then
+ return cdutil:guessmode()
+ else
+ return cdutil:guessmode(sect)
+ end
+end
+
+function sectorseek(sect)
+ check_cdutil()
+ return cdutil:sectorseek(sect)
+end
+
+function readsector(sect, mode)
+ check_cdutil()
+ if (sect == nil) then
+ return cdutil:readsector()
+ elseif (mode == nil) then
+ return cdutil:readsector(sect)
+ else
+ return cdutil:readsector(sect, mode)
+ end
+end
function readdatas(size, sector, mode)
- if (cdutil == nil) then error "cdutil object non existant" end
- if (sect == nil) then
- return cdutil:readdatas(size)
- elseif (mode == nil) then
- return cdutil:readdatas(size, sect)
- else
- return cdutil:readdatas(size, sect, mode)
- end
+ check_cdutil()
+ if (sect == nil) then
+ return cdutil:readdatas(size)
+ elseif (mode == nil) then
+ return cdutil:readdatas(size, sect)
+ else
+ return cdutil:readdatas(size, sect, mode)
+ end
end
function readfile(handle, size, sector, mode)
- if (cdutil == nil) then error "cdutil object non existant" end
- if (sect == nil) then
- return cdutil:readfile(handle, size)
- elseif (mode == nil) then
- return cdutil:readfile(handle, size, sect)
- else
- return cdutil:readfile(handle, size, sect, mode)
- end
+ check_cdutil()
+ if (sect == nil) then
+ return cdutil:readfile(handle, size)
+ elseif (mode == nil) then
+ return cdutil:readfile(handle, size, sect)
+ else
+ return cdutil:readfile(handle, size, sect, mode)
+ end
end
function writesector(array, sector, mode)
- if (cdutil == nil) then error "cdutil object non existant" end
+ check_cdutil()
if (sector == nil) then
return cdutil:writesector(array, sector)
elseif (mode == nil) then
@@ -179,7 +184,7 @@ function writesector(array, sector, mode)
end
function writedatas(array, size, sector, mode)
- if (cdutil == nil) then error "cdutil object non existant" end
+ check_cdutil()
if (sector == nil) then
return cdutil:writedatas(array, size)
elseif (mode == nil) then
@@ -190,7 +195,7 @@ function writedatas(array, size, sector, mode)
end
function writefile(handle, size, sector, mode)
- if (cdutil == nil) then error "cdutil object non existant" end
+ check_cdutil()
if (size == nil) then
return cdutil:writefile(handle)
elseif (sector == nil) then
@@ -203,71 +208,75 @@ function writefile(handle, size, sector, mode)
end
function findpath(path)
- if (cdutil == nil) then error "cdutil object non existant" end
+ check_cdutil()
return cdutil:findpath(path)
end
function findparent(path)
- if (cdutil == nil) then error "cdutil object non existant" end
+ check_cdutil()
return cdutil:findparent(path)
end
function finddirectory(dir, path)
- if (cdutil == nil) then error "cdutil object non existant" end
+ check_cdutil()
return cdutil:finddirectory(dir, path)
end
-
-
- -----------------------
--- iso object wrappers --
- -----------------------
-
-function foreword(lcdutil)
- if (iso == nil) then error "iso object non existant" end
- if ((lcdutil == nil) and (cdutil == nil)) then error "cdutil object non existant" end
- if (lcdutil == nil) then
- return iso:foreword(cdutil)
- else
- return iso:foreword(lcdutil)
- end
-end
-
-function foreword_handle(handle, mode)
- if (iso == nil) then error "iso object non existant" end
- if (mode == nil) then
- return iso:foreword_handle(handle)
- else
- return iso:foreword_handle(handle, mode)
- end
-end
-
-function foreword_array(array, mode)
- if (iso == nil) then error "iso object non existant" end
- if (mode == nil) then
- return iso:foreword_array(array)
- else
- return iso:foreword_array(array, mode)
- end
-end
-
-function getdispsect()
- if (iso == nil) then error "iso object non existant" end
- return iso:getdispsect()
-end
-
-function putfile(handle, mode, sector)
- if (iso == nil) then error "iso object non existant" end
- if (mode == nil) then
- iso:putfile(handle)
- elseif (sector == nil) then
- iso:putfile(handle, mode)
- else
- iso:putfile(handle, mode, sector)
- end
-end
+
+
+ -----------------------
+-- iso object wrappers --
+ -----------------------
+
+function check_iso()
+ if (iso == nil) then error "iso object non existant" end
+end
+
+function foreword(lcdutil)
+ check_iso()
+ if ((lcdutil == nil) and (cdutil == nil)) then error "cdutil object non existant" end
+ if (lcdutil == nil) then
+ return iso:foreword(cdutil)
+ else
+ return iso:foreword(lcdutil)
+ end
+end
+
+function foreword_handle(handle, mode)
+ check_iso()
+ if (mode == nil) then
+ return iso:foreword_handle(handle)
+ else
+ return iso:foreword_handle(handle, mode)
+ end
+end
+
+function foreword_array(array, mode)
+ check_iso()
+ if (mode == nil) then
+ return iso:foreword_array(array)
+ else
+ return iso:foreword_array(array, mode)
+ end
+end
+
+function getdispsect()
+ check_iso()
+ return iso:getdispsect()
+end
+
+function putfile(handle, mode, sector)
+ check_iso()
+ if (mode == nil) then
+ iso:putfile(handle)
+ elseif (sector == nil) then
+ iso:putfile(handle, mode)
+ else
+ iso:putfile(handle, mode, sector)
+ end
+end
function putdatas(array, size, mode, sector)
- if (iso == nil) then error "iso object non existant" end
+ check_iso()
if (mode == nil) then
iso:putdatas(array, size)
elseif (sector == nil) then
@@ -278,7 +287,7 @@ function putdatas(array, size, mode, sector)
end
function createsector(array, mode, sector)
- if (iso == nil) then error "iso object non existant" end
+ check_iso()
if (mode == nil) then
iso:createsector(array)
elseif (sector == nil) then
@@ -289,43 +298,43 @@ function createsector(array, mode, sector)
end
function setEOF()
- if (iso == nil) then error "iso object non existant" end
- iso:setEOF()
-end
-
-function clearEOF()
- if (iso == nil) then error "iso object non existant" end
- iso:clearEOF()
-end
+ check_iso()
+ iso:setEOF()
+end
+
+function clearEOF()
+ check_iso()
+ iso:clearEOF()
+end
function setbasics(pvd, rootsize, ptsize, nvd, rootsect)
- if (iso == nil) then error "iso object non existant" end
- if (rootsize == nil) then
- iso:setbasics(pvd)
- elseif (ptsize == nil) then
- iso:setbasics(pvd, rootsize)
- elseif (nvd == nil) then
- iso:setbasics(pvd, rootsize, ptsize)
- elseif (rootsect) then
- iso:setbasics(pvd, rootsize, ptsize, nvd)
- else
- iso:setbasics(pvd, rootsize, ptsize, nvd, rootsect)
- end
-end
+ check_iso()
+ if (rootsize == nil) then
+ iso:setbasics(pvd)
+ elseif (ptsize == nil) then
+ iso:setbasics(pvd, rootsize)
+ elseif (nvd == nil) then
+ iso:setbasics(pvd, rootsize, ptsize)
+ elseif (rootsect) then
+ iso:setbasics(pvd, rootsize, ptsize, nvd)
+ else
+ iso:setbasics(pvd, rootsize, ptsize, nvd, rootsect)
+ end
+end
function createdir(dirtree, name, size, direntry, mode)
- if (iso == nil) then error "iso object non existant" end
- if (size == nil) then
- iso:createdir(dirtree, name)
- elseif (mode == nil) then
- iso:createdir(dirtree, name, size, direntry)
- else
- iso:createdir(dirtree, name, size, direntry, mode)
- end
-end
+ check_iso()
+ if (size == nil) then
+ iso:createdir(dirtree, name)
+ elseif (mode == nil) then
+ iso:createdir(dirtree, name, size, direntry)
+ else
+ iso:createdir(dirtree, name, size, direntry, mode)
+ end
+end
function createfile(dirtree, name, size, direntry, mode)
- if (iso == nil) then error "iso object non existant" end
+ check_iso()
if (mode == nil) then
iso:createfile(dirtree, name, size, direntry)
else
@@ -334,7 +343,7 @@ function createfile(dirtree, name, size, direntry, mode)
end
function copydir(dirtree, cdutils, direntry, mode)
- if (iso == nil) then error "iso object non existant" end
+ check_iso()
if (mode == nil) then
iso:copydir(dirtree, cdutils, direntry)
else
@@ -343,14 +352,14 @@ function copydir(dirtree, cdutils, direntry, mode)
end
function close(cuefile, mode, nsectors)
- if (iso == nil) then error "iso object non existant" end
- if (cuefile == nil) then
- iso:close()
- elseif (mode == nil) then
- iso:close(cuefile)
- elseif (nsectors == nil) then
- iso:close(cuefile, mode)
- else
- iso:close(cuefile, mode, nsectors)
- end
-end
+ check_iso()
+ if (cuefile == nil) then
+ iso:close()
+ elseif (mode == nil) then
+ iso:close(cuefile)
+ elseif (nsectors == nil) then
+ iso:close(cuefile, mode)
+ else
+ iso:close(cuefile, mode, nsectors)
+ end
+end