From d834a8d9332f18642c5511cdd56085e366635a61 Mon Sep 17 00:00:00 2001 From: pixel Date: Sat, 1 May 2004 11:48:57 +0000 Subject: Fixes, changes, improvements, ... --- lib/cdutils.cpp | 6 ++- lib/luacd.cpp | 127 ++++++++++++++++++++------------------------------------ 2 files changed, 50 insertions(+), 83 deletions(-) (limited to 'lib') diff --git a/lib/cdutils.cpp b/lib/cdutils.cpp index 3ecea36..51e2e09 100644 --- a/lib/cdutils.cpp +++ b/lib/cdutils.cpp @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: cdutils.cpp,v 1.26 2004-04-28 14:24:19 pixel Exp $ */ +/* $Id: cdutils.cpp,v 1.27 2004-05-01 11:48:58 pixel Exp $ */ #include #include @@ -844,8 +844,10 @@ ssize_t cdfile::read(void *buf, size_t count) throw (GeneralException) { count = MIN(count, (size_t) (size - itell)); - if (!count) + if (!count) { + close(); return 0; + } startsec = itell / sec_sizes[mode] + sector; startbyte = itell % sec_sizes[mode]; diff --git a/lib/luacd.cpp b/lib/luacd.cpp index b1d43a0..1f3b9fe 100644 --- a/lib/luacd.cpp +++ b/lib/luacd.cpp @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: luacd.cpp,v 1.9 2004-01-03 15:04:47 pixel Exp $ */ +/* $Id: luacd.cpp,v 1.10 2004-05-01 11:48:58 pixel Exp $ */ #include "luacd.h" @@ -27,6 +27,10 @@ \**************************/ Luacdutils::Luacdutils(cdutils * _cd) : cd(_cd) { } +class Luacdfile : public LuaHandle { + public: + Luacdfile(cdfile * h) : LuaHandle(h) {} +}; enum cdutils_methods_t { CDUTILS_SETISOW = 0, @@ -43,6 +47,7 @@ enum cdutils_methods_t { CDUTILS_FINDPATH, CDUTILS_FINDPARENT, CDUTILS_FINDDIRENTRY, + CDUTILS_NEWCDFILE, }; enum cdutils_functions_t { @@ -70,6 +75,7 @@ struct lua_functypes_t cdutils_methods[] = { { 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} }, { -1, 0, 0, 0, 0 } }; @@ -100,6 +106,7 @@ class sLua_cdutils : public Base { DECLARE_METHOD(cdutils, CDUTILS_FINDPATH); DECLARE_METHOD(cdutils, CDUTILS_FINDPARENT); DECLARE_METHOD(cdutils, CDUTILS_FINDDIRENTRY); + DECLARE_METHOD(cdutils, CDUTILS_NEWCDFILE); DECLARE_FUNCTION(cdutils, CDUTILS_NEWCDUTILS); DECLARE_FUNCTION(cdutils, CDUTILS_SWAPWORD); @@ -131,6 +138,7 @@ void Luacdutils::pushmembers(Lua * L) { PUSH_METHOD(cdutils, CDUTILS_FINDPATH); PUSH_METHOD(cdutils, CDUTILS_FINDPARENT); PUSH_METHOD(cdutils, CDUTILS_FINDDIRENTRY); + PUSH_METHOD(cdutils, CDUTILS_NEWCDFILE); } void Luacdutils::pushstatics(Lua * L) throw (GeneralException) { @@ -209,6 +217,9 @@ int sLua_cdutils::cdutils_proceed(Lua * L, int n, cdutils * cd, int caller) { Byte sdatas[2352], * datas; String path; cdutils::DirEntry * dir, * bdir, * adir; + bool invalid = false; + int sector; + cdfile * cdf; switch(caller) { case CDUTILS_SETISOW: @@ -369,7 +380,41 @@ int sLua_cdutils::cdutils_proceed(Lua * L, int n, cdutils * cd, int caller) { r = 1; free(datas); break; + case CDUTILS_NEWCDFILE: + if (L->istable(2)) { + if (n <= 3) { + dir = (cdutils::DirEntry *) LuaObject::getme(L, 2); + if (n == 3) + mode = L->tonumber(3); + cdf = new cdfile(cd, dir, mode); + } else { + invalid = true; + } + } else if (L->isnumber(2)) { + if (n >= 2) { + sector = L->tonumber(2); + if (n >= 3) + size = L->tonumber(3); + if (n == 4) + mode = L->tonumber(4); + cdf = new cdfile(cd, sector, size, mode); + } else { + invalid = true; + } + } else { + invalid = true; + } + if (invalid) { + L->error("Invalid arguments to constructor of cdfile"); + } else { + Luacdfile luacdf(cdf); + luacdf.pushdestruct(L); + r = 1; + } + break; } + + return r; } @@ -437,86 +482,6 @@ int sLua_cdutils::cdutils_proceed_statics(Lua * L, int n, int caller) { } - /*************************\ -|** class cdfile exports **| - \*************************/ - -Luacdfile::Luacdfile(cdfile * h) : LuaHandle(h) { } - -enum cdfile_functions_t { - CDFILE_NEWCDFILE = 0, -}; - -struct lua_functypes_t cdfile_functions[] = { - { CDFILE_NEWCDFILE, "cdfile", 1, 4, {LUA_OBJECT, LUA_ANY, LUA_NUMBER, LUA_NUMBER} }, - { -1, 0, 0, 0, 0 } -}; - -class sLua_cdfile : public Base { - public: - DECLARE_FUNCTION(cdfile, CDFILE_NEWCDFILE); - private: - static int cdfile_proceed_statics(Lua * L, int n, int caller); -}; - -void Luacdfile::pushmembers(Lua * L) { - LuaHandle::pushmembers(L); -} - -void Luacdfile::pushstatics(Lua * L) throw (GeneralException) { - CHECK_FUNCTIONS(cdfile); - PUSH_FUNCTION(cdfile, CDFILE_NEWCDFILE); -} - -int sLua_cdfile::cdfile_proceed_statics(Lua * L, int n, int caller) { - int r = 0; - bool invalid = false; - cdutils * cd; - cdutils::DirEntry * dir; - int sector, mode = GUESS; - ssize_t size = -1; - cdfile * cdf; - - switch(caller) { - case CDFILE_NEWCDFILE: - cd = (cdutils *) LuaObject::getme(L, 1); - if (L->istable(2)) { - if (n <= 3) { - dir = (cdutils::DirEntry *) LuaObject::getme(L, 2); - if (n == 3) - mode = L->tonumber(3); - cdf = new cdfile(cd, dir, mode); - } else { - invalid = true; - } - } else if (L->isnumber(2)) { - if (n >= 2) { - sector = L->tonumber(2); - if (n >= 3) - size = L->tonumber(3); - if (n == 4) - mode = L->tonumber(4); - cdf = new cdfile(cd, sector, size, mode); - } else { - invalid = true; - } - } else { - invalid = true; - } - if (invalid) { - L->error("Invalid arguments to constructor of cdfile"); - } else { - Luacdfile luacdf(cdf); - luacdf.pushdestruct(L); - r = 1; - } - break; - } - - return r; -} - - /***************************\ |** class direntry exports **| \***************************/ -- cgit v1.2.3