summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--MSVC/Tools/Tools.vcproj3
-rw-r--r--cd-tool.cpp112
-rw-r--r--includes/luacd.h11
-rw-r--r--includes/luapsx.h4
-rw-r--r--lib/cdutils.cpp6
-rw-r--r--lib/luacd.cpp127
6 files changed, 154 insertions, 109 deletions
diff --git a/MSVC/Tools/Tools.vcproj b/MSVC/Tools/Tools.vcproj
index 43bb39e..31a5091 100644
--- a/MSVC/Tools/Tools.vcproj
+++ b/MSVC/Tools/Tools.vcproj
@@ -44,6 +44,9 @@
RelativePath="..\..\cd-tool.cpp">
</File>
<File
+ RelativePath="..\..\cd-tool.lua">
+ </File>
+ <File
RelativePath="..\..\crypto-search.cpp">
</File>
<File
diff --git a/cd-tool.cpp b/cd-tool.cpp
index e5b2ce5..efb7bfd 100644
--- a/cd-tool.cpp
+++ b/cd-tool.cpp
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: cd-tool.cpp,v 1.25 2004-04-28 14:24:17 pixel Exp $ */
+/* $Id: cd-tool.cpp,v 1.26 2004-05-01 11:48:57 pixel Exp $ */
#include <getopt.h>
#include "Input.h"
@@ -41,13 +41,65 @@ isobuilder * build = 0;
static int myprint(lua_State * _L) {
Lua * L = Lua::find(_L);
- String t = L->tostring();
+ String t = "From LUA: " + L->tostring() + "\n";
+ char * tc = t.strdup();
- Base::printm(M_STATUS, "From LUA: " + t + "\n");
+ Base::printm(M_STATUS, "%s", tc);
+
+ free(tc);
return 0;
}
+class Luabasecdtool : public LuaObject {
+ public:
+ static void pushstatics(Lua *) throw (GeneralException);
+};
+
+typedef void basecdtool;
+
+enum basecdtool_t {
+ BASECDTOOL_LOAD = 0,
+};
+
+struct lua_functypes_t basecdtool_functions[] = {
+ { BASECDTOOL_LOAD, "load", 0, 1, { LUA_ANY } },
+ { -1, 0, 0, 0, 0 }
+};
+
+class sLua_basecdtool : public Base {
+ public:
+ DECLARE_FUNCTION(basecdtool, BASECDTOOL_LOAD);
+ private:
+ static int basecdtool_proceed_statics(Lua * L, int n, int caller);
+};
+
+void Luabasecdtool::pushstatics(Lua * L) throw (GeneralException ) {
+ CHECK_FUNCTIONS(basecdtool);
+
+ PUSH_FUNCTION(basecdtool, BASECDTOOL_LOAD);
+}
+
+int sLua_basecdtool::basecdtool_proceed_statics(Lua * L, int n, int caller) {
+ int r = 0;
+
+ switch (caller) {
+ case BASECDTOOL_LOAD:
+ if (!n) {
+ L->load(&Input("cd-tool.lua"));
+ } else {
+ if (L->isstring(1)) {
+ L->load(&Input(L->tostring(1)));
+ } else {
+ Handle * t = (Handle *) LuaObject::getme(L, 1);
+ L->load(t);
+ }
+ }
+ }
+
+ return r;
+}
+
class Luacdtool : public LuaObject {
public:
static void pushstatics(Lua *) throw (GeneralException);
@@ -57,6 +109,7 @@ typedef void cdtool;
enum cdtool_functions_t {
CDTOOL_PRINT = 0,
+ CDTOOL_PRINTN,
CDTOOL_QUIT,
CDTOOL_EXIT,
CDTOOL_INFOS,
@@ -65,7 +118,8 @@ enum cdtool_functions_t {
};
struct lua_functypes_t cdtool_functions[] = {
- { CDTOOL_PRINT, "print", 1, 1, { LUA_STRING } },
+ { CDTOOL_PRINT, "print", 0, 1, { LUA_STRING } },
+ { CDTOOL_PRINTN, "printn", 1, 1, { LUA_STRING } },
{ CDTOOL_QUIT, "quit", 0, 0, 0 },
{ CDTOOL_EXIT, "exit", 0, 0, 0 },
{ CDTOOL_INFOS, "infos", 0, 1, { LUA_OBJECT } },
@@ -77,6 +131,7 @@ struct lua_functypes_t cdtool_functions[] = {
class sLua_cdtool : public Base {
public:
DECLARE_FUNCTION(cdtool, CDTOOL_PRINT);
+ DECLARE_FUNCTION(cdtool, CDTOOL_PRINTN);
DECLARE_FUNCTION(cdtool, CDTOOL_QUIT);
DECLARE_FUNCTION(cdtool, CDTOOL_EXIT);
DECLARE_FUNCTION(cdtool, CDTOOL_INFOS);
@@ -90,6 +145,7 @@ void Luacdtool::pushstatics(Lua * L) throw (GeneralException ) {
CHECK_FUNCTIONS(cdtool);
PUSH_FUNCTION(cdtool, CDTOOL_PRINT);
+ PUSH_FUNCTION(cdtool, CDTOOL_PRINTN);
PUSH_FUNCTION(cdtool, CDTOOL_QUIT);
PUSH_FUNCTION(cdtool, CDTOOL_EXIT);
PUSH_FUNCTION(cdtool, CDTOOL_INFOS);
@@ -101,11 +157,20 @@ int sLua_cdtool::cdtool_proceed_statics(Lua * L, int n, int caller) {
int r = 0;
String p;
cdutils * cd = cdutil;
+ char * tc;
+ String eol = "";
switch (caller) {
case CDTOOL_PRINT:
- p = L->tostring(1);
- printm(M_BARE, p + "\n");
+ eol = "\n";
+ case CDTOOL_PRINTN:
+ if (n)
+ p = L->tostring(1) + eol;
+ else
+ p = eol;
+ tc = p.strdup();
+ printm(M_BARE, "%s", tc);
+ free(tc);
break;
case CDTOOL_QUIT:
case CDTOOL_EXIT:
@@ -154,6 +219,7 @@ struct option long_options[] = {
{"help", 0, NULL, 'h'},
{"verbose", 0, NULL, 'v'},
{"file", 1, NULL, 'f'},
+ {"write", 0, NULL, 'w'},
{"output", 1, NULL, 'o'},
{"archive", 1, NULL, 'a'},
{"compile", 1, NULL, 'c'},
@@ -188,6 +254,8 @@ Lua * start_basic_lua(void) {
L->push(myprint);
L->setvar();
+ Luabasecdtool::pushstatics(L);
+
return L;
}
@@ -208,12 +276,13 @@ void showhelp(bool longhelp = false) {
"Options:\n"
" -v for verbose mode.\n"
" -f <iso> to load an initial iso file (object cdutil).\n"
+" -w to open the previous iso file in write mode.\n"
" -o <iso> to start creating an output iso (object iso).\n"
" -a <paq> to load an additionnal archive file.\n"
" -c <out> to dump the compiled byte code to file.\n"
" -d to enable debug mode (ie, do not strip)\n"
" -i to start interactive mode.\n"
-" -l to turn off the no exec on end line.\n"
+" -l to turn off the exec on end line.\n"
" -e <cmd> to execute this single command in LUA.\n"
" -h for this help page.\n"
, argv[0]);
@@ -253,11 +322,12 @@ void probe(void) {
virtual int startup() throw (GeneralException) {
char c;
- bool auto_exec = false, strip = true, todo = false, runit;
+ bool auto_exec = true, strip = true, todo = false, runit, write = false;
char * file = 0, * output = 0, * compile = 0, * exec = 0, * line_read = 0;
char prompt[10];
Lua * L = 0;
- Output * build_iso = 0;
+ Handle * read_iso = 0;
+ Output * build_iso = 0, * write_iso = 0;
Buffer command;
String line, endline;
int pos;
@@ -266,7 +336,7 @@ virtual int startup() throw (GeneralException) {
/* Let's start parsing options */
- while ((c = getopt_long(argc, argv, "Hhvf:o:a:c:dile:pm:", long_options, NULL)) != EOF) {
+ while ((c = getopt_long(argc, argv, "Hhvf:wo:a:c:dile:pm:", long_options, NULL)) != EOF) {
switch (c) {
case 'h':
case 'H':
@@ -279,6 +349,9 @@ virtual int startup() throw (GeneralException) {
case 'f':
file = strdup(optarg);
break;
+ case 'w':
+ write = true;
+ break;
case 'o':
output = strdup(optarg);
break;
@@ -296,7 +369,7 @@ virtual int startup() throw (GeneralException) {
todo = true;
break;
case 'l':
- auto_exec = true;
+ auto_exec = false;
break;
case 'e':
exec = strdup(optarg);
@@ -316,10 +389,14 @@ virtual int startup() throw (GeneralException) {
else
L = start_basic_lua();
+ /* Loading cd-tool.lua (only when not compiling) */
+ if (!compile)
+ L->load(&Input("cd-tool.lua"));
+
/* Loading all the scripts */
while (optind < argc) {
todo = true;
- L->load(&Input(argv[optind++]), compile);
+ L->load(&Input(argv[optind++]), !compile);
}
/* Doh... */
@@ -336,7 +413,14 @@ virtual int startup() throw (GeneralException) {
/* The basic input (and eventually output) iso file */
if (file) {
- cdutil = new cdutils(cdabstract::open_cd(file));
+ /* The write mode can't apply on a CD of course... */
+ if (write) {
+ read_iso = new Input(file);
+ write_iso = new Output(file, 0, 0);
+ } else {
+ read_iso = cdabstract::open_cd(file);
+ }
+ cdutil = new cdutils(read_iso, write_iso);
if (!cdutil->get_iso_infos())
throw Exit(-1);
Luacdutils lcdutil(cdutil);
@@ -402,7 +486,7 @@ virtual int startup() throw (GeneralException) {
try {
L->load(&command);
}
- catch (GeneralException e) {
+ catch (LuaException e) {
/* If there was an error, ignore it, and free the stack */
while(L->gettop())
L->pop();
diff --git a/includes/luacd.h b/includes/luacd.h
index 034e6f7..c26957f 100644
--- a/includes/luacd.h
+++ b/includes/luacd.h
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: luacd.h,v 1.5 2003-12-11 16:53:42 pixel Exp $ */
+/* $Id: luacd.h,v 1.6 2004-05-01 11:48:57 pixel Exp $ */
#ifndef __LUACD_H__
#define __LUACD_H__
@@ -30,7 +30,6 @@
#define CD_PUSHSTATICS(L) { \
Luacdutils::pushstatics(L); \
- Luacdfile::pushstatics(L); \
Luacddate::pushstatics(L); \
LuaPVD::pushstatics(L); \
LuaDirTree::pushstatics(L); \
@@ -46,14 +45,6 @@ class Luacdutils : public LuaObject {
cdutils * cd;
};
-class Luacdfile : public LuaHandle {
- public:
- static void pushstatics(Lua *) throw (GeneralException);
- Luacdfile(cdfile *);
- protected:
- virtual void pushmembers(Lua *);
-};
-
class Luadirentry : public LuaObject {
public:
Luadirentry(cdutils::DirEntry *);
diff --git a/includes/luapsx.h b/includes/luapsx.h
index 53d5c4f..1d28dcc 100644
--- a/includes/luapsx.h
+++ b/includes/luapsx.h
@@ -1,4 +1,4 @@
-/*
+ /*
* PSX-Tools Bundle Pack
* Copyright (C) 2002-2003 Nicolas "Pixel" Noble
*
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: luapsx.h,v 1.2 2004-02-29 17:44:42 pixel Exp $ */
+/* $Id: luapsx.h,v 1.3 2004-05-01 11:48:58 pixel Exp $ */
#ifndef __LUAPSX_H__
#define __LUAPSX_H__
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 <stdio.h>
#include <string.h>
@@ -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 **|
\***************************/