diff options
author | pixel <pixel> | 2003-12-10 02:59:30 +0000 |
---|---|---|
committer | pixel <pixel> | 2003-12-10 02:59:30 +0000 |
commit | 5695a4b1e91154f8b9bae6d62eb9313b973fc6bd (patch) | |
tree | 071dff4a418b445451954efb04d0c1286b315387 /cd-tool.cpp | |
parent | 0b266c95523f944e62acf9251eb27450a8d73a04 (diff) |
LUALUALUALUALUALUALUALUALUA
Diffstat (limited to 'cd-tool.cpp')
-rw-r--r-- | cd-tool.cpp | 100 |
1 files changed, 81 insertions, 19 deletions
diff --git a/cd-tool.cpp b/cd-tool.cpp index 4cf9588..5080169 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.18 2003-12-08 15:12:56 pixel Exp $ */ +/* $Id: cd-tool.cpp,v 1.19 2003-12-10 02:59:30 pixel Exp $ */ #include <getopt.h> #include <stdio.h> @@ -53,6 +53,7 @@ struct option long_options[] = { {"mode", 1, NULL, 'm'}, {"force", 0, NULL, 'f'}, {"verbose", 0, NULL, 'v'}, + {"debug", 0, NULL, 'g'}, {0, 0, NULL, 0 } }; @@ -70,13 +71,28 @@ private: cdutils * cdutil; Handle * iso_r, * iso_w, * file; +Lua * startlua(void) { + Lua * L = new Lua(); + L->open_base(); + L->open_math(); + L->open_string(); + L->open_table(); + LuaInput::pushconstruct(L); + LuaOutput::pushconstruct(L); + LuaBuffer::pushconstruct(L); + CD_PUSHSTATICS(L); + L->push("print"); + L->push(myprint); + L->settable(LUA_GLOBALSINDEX); + return L; +} + void showhelp(void) { printm(M_BARE, "Usage:\n" "%s [-m <mode>] [-p <ppf file>] [-f] <isofile> <command> [command args]\n" "Where mode can be 1 for MODE 1, 2 for MODE 2, 3 for MODE 2 FORM 1,\n" -"4 for MODE 2 FORM 2, 5 for Raw, and 6 for autodetect, which is the\n" -"default behaviour.\n" +"4 for MODE 2 FORM 2, 5 for Raw, and 6 for autodetect (default)\n" "\n" "Command can be one of:\n" " infos - dumps a bunch of infos about the iso.\n" @@ -87,8 +103,15 @@ void showhelp(void) { " insert-file <file> <path> - insert the file to <path>\n" " insert <file> <addr> - insert some sectors at <addr>\n" " copy <isofile> - copy to another iso\n" -" lua <luascript> - interpret LUA script\n" -"\n", argv[0]); +" lua <luascript> - interpret single LUA script\n" +" luapatch <luapatch> <file> - create a new iso file using the LUA script\n" +" luacomp <luascript> <file> - compile a LUA script\n" +"\n" +"Additional options:\n" +" -v for verbose mode.\n" +" -g for LUA compiling debug mode (ie, no stripping)\n" +" -h for this help page\n" +, argv[0]); } void probe(void) { @@ -110,10 +133,11 @@ void probe(void) { virtual int startup() throw (GeneralException) { int type = GUESS, c, size, force = 0, sector; char * ppf = 0, * iso_name = 0, * arg1 = 0, * arg2 = 0, * f; + bool debug = false; verbosity = M_WARNING; - while ((c = getopt_long(argc, argv, "Hhm:p:fv", long_options, NULL)) != EOF) { + while ((c = getopt_long(argc, argv, "Hhm:p:fvg", long_options, NULL)) != EOF) { switch (c) { case 'h': case 'H': @@ -132,6 +156,9 @@ virtual int startup() throw (GeneralException) { case 'v': verbosity = M_INFO; break; + case 'g': + debug = true; + break; } } @@ -271,7 +298,7 @@ virtual int startup() throw (GeneralException) { } } printm(M_STATUS, "Writing file %s at path %s (sector %i).\n", arg1, arg2, dir.Sector); - cdutil->write_file(file, type, dir.Sector); + cdutil->write_file(file, -1, type, dir.Sector); printm(M_STATUS, "Updating directory entry.\n"); dir = cdutil->find_parent(f = strdup(arg2)); free(f); @@ -305,7 +332,7 @@ virtual int startup() throw (GeneralException) { sector = atoi(argv[optind++]); file = new Input(arg1); printm(M_STATUS, "Writing file %s at sector %i.\n", arg1, sector); - cdutil->write_file(file, type, sector); + cdutil->write_file(file, -1, type, sector); } else if (!strcmp(argv[optind], "copy")) { optind++; if ((argc - 1) != optind) { @@ -319,7 +346,7 @@ virtual int startup() throw (GeneralException) { isobuilder::DirTree * root = b->setbasics(isobuilder::createpvd(cdutil)); iso_r->seek(0); b->foreword(iso_r); - b->copydir(root, ".", cdutil, cdutil->rootDir); + b->copydir(root, cdutil, cdutil->rootDir); Buffer * buf = new Buffer(true); (*buf) << "Touched!\n"; @@ -337,21 +364,56 @@ virtual int startup() throw (GeneralException) { throw Exit(-1); } arg1 = argv[optind]; - Lua * L = new Lua(); - L->open_math(); - L->open_string(); - LuaInput::pushconstruct(L); - LuaOutput::pushconstruct(L); - LuaBuffer::pushconstruct(L); - CD_PUSHSTATICS(L); - L->push("print"); - L->push(myprint); - L->settable(LUA_GLOBALSINDEX); + Lua * L = startlua(); Luacdutils lcdutil(cdutil); L->push("cdutil"); lcdutil.push(L); L->settable(LUA_GLOBALSINDEX); L->load(&Input(arg1)); + delete L; + } else if (!strcmp(argv[optind], "luapatch")) { + optind++; + if ((argc - 2) != optind) { + showhelp(); + printm(M_ERROR, "luapatch needs two arguments.\n"); + throw Exit(-1); + } + arg1 = argv[optind++]; + arg2 = argv[optind]; + Output * o = new Output(arg2); + isobuilder * b; + if (type == GUESS) + b = new isobuilder(o); + else + b = new isobuilder(o, type); + Lua * L = startlua(); + Luacdutils lcdutil(cdutil); + L->push("cdutil"); + lcdutil.push(L); + L->setvar(); + Luaisobuilder liso(b); + L->push("iso"); + liso.push(L); + L->setvar(); + L->load(&Input(arg1)); + delete L; + delete b; + delete o; + } else if (!strcmp(argv[optind], "luacomp")) { + optind++; + if ((argc - 2) != optind) { + showhelp(); + printm(M_ERROR, "luacomp needs two arguments.\n"); + throw Exit(-1); + } + arg1 = argv[optind++]; + arg2 = argv[optind]; + Output * o = new Output(arg2); + Lua * L = new Lua(); + L->load(&Input(arg1), false); + L->dump(o, !debug); + delete L; + delete o; } else { showhelp(); printm(M_ERROR, "Command %s unknow.\n", argv[optind]); |