diff options
author | pixel <pixel> | 2004-05-01 11:48:15 +0000 |
---|---|---|
committer | pixel <pixel> | 2004-05-01 11:48:15 +0000 |
commit | 2d6892d1a4d9cc0f189cd7aa7a1101d35d3519a2 (patch) | |
tree | 8c8e0ed97e14b7c4cb304db1ecaa8e5e9001b32d | |
parent | 10d2965791c78a23b2e1ca91f293c3d49f852d78 (diff) |
Adding some "startup" sequence to cd-tool
-rw-r--r-- | cd-tool.lua | 180 |
1 files changed, 180 insertions, 0 deletions
diff --git a/cd-tool.lua b/cd-tool.lua new file mode 100644 index 0000000..f935ab0 --- /dev/null +++ b/cd-tool.lua @@ -0,0 +1,180 @@ +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
+
+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
+ +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
+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
+end + +function writesector(array, sector, mode) + if (cdutil == nil) then error "cdutil object non existant" end + if (sector == nil) then + return cdutil:writesector(array, sector) + elseif (mode == nil) then + return cdutil:writesector(array, sector, mode) + end +end + +-- { CDUTILS_WRITESECTOR, "writesector", 1, 3, {LUA_TABLE, LUA_NUMBER, LUA_NUMBER} }, +-- { CDUTILS_WRITEDATAS, "writedatas", 2, 4, {LUA_TABLE, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} }, +-- { CDUTILS_WRITEFILE, "writefile", 1, 4, {LUA_OBJECT, LUA_NUMBER, LUA_NUMBER, LUA_NUMBER} }, +-- { CDUTILS_GETISOINFOS, "getisoinfos", 0, 0, 0 }, +-- { CDUTILS_GETPTINFOS, "getptinfos", 0, 0, 0 }, +-- { CDUTILS_FINDPATH, "findpath", 1, 1, {LUA_STRING} }, +-- { CDUTILS_FINDPARENT, "findparent", 1, 1, {LUA_STRING} }, +-- { CDUTILS_FINDDIRENTRY, "finddirentry", 2, 2, {LUA_OBJECT, LUA_STRING} }, +-- { CDUTILS_NEWCDFILE, "cdfile", 1, 3, {LUA_ANY, LUA_NUMBER, LUA_NUMBER} }, |