summaryrefslogtreecommitdiff
path: root/cd-tool.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cd-tool.cpp')
-rw-r--r--cd-tool.cpp51
1 files changed, 44 insertions, 7 deletions
diff --git a/cd-tool.cpp b/cd-tool.cpp
index 9737647..d6a9b68 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.28 2004-05-02 02:29:23 pixel Exp $ */
+/* $Id: cd-tool.cpp,v 1.29 2004-05-02 12:29:02 pixel Exp $ */
#define WIP
@@ -39,6 +39,8 @@
#include <readline/readline.h>
#include <readline/history.h>
+#include "cd-tool-hc.h"
+
bool interactive = false;
cdutils * cdutil = 0;
isobuilder * build = 0;
@@ -90,7 +92,7 @@ int sLua_basecdtool::basecdtool_proceed_statics(Lua * L, int n, int caller) {
switch (caller) {
case BASECDTOOL_LOAD:
if (!n) {
- L->load(&Input("cd-tool.lua"));
+ L->load(&Input("cd-tool.lua"));
} else {
if (L->isstring(1)) {
L->load(&Input(L->tostring(1)));
@@ -231,6 +233,7 @@ struct option long_options[] = {
{"interactive", 0, NULL, 'i'},
{"line", 0, NULL, 'l'},
{"exec", 1, NULL, 'e'},
+ {"built-in", 0, NULL, 'b'},
{"probe", 0, NULL, 'p'},
{0, 0, NULL, 0 }
};
@@ -298,6 +301,8 @@ void showhelp(bool longhelp = false) {
" -i to start interactive mode.\n"
" -l to turn off the exec on end line.\n"
" -e <cmd> to execute this single command in LUA.\n"
+" -b to force the use of the built-in cd-tool.lua\n"
+" -p to run a CD device probe.\n"
" -h for a help page.\n"
, argv[0]);
@@ -336,7 +341,7 @@ void probe(void) {
virtual int startup() throw (GeneralException) {
char c;
- bool auto_exec = true, strip = true, todo = false, runit, write = false;
+ bool auto_exec = true, strip = true, todo = false, runit, write = false, builtin = false;
char * file = 0, * output = 0, * compile = 0, * exec = 0, * line_read = 0;
char prompt[10];
Lua * L = 0;
@@ -346,13 +351,13 @@ virtual int startup() throw (GeneralException) {
String line, endline;
int pos;
- verbosity = M_STATUS;
+ verbosity = M_WARNING;
showbanner();
/* Let's start parsing options */
- while ((c = getopt_long(argc, argv, "Hhvf:wo:a:c:dile:pm:", long_options, NULL)) != EOF) {
+ while ((c = getopt_long(argc, argv, "Hhvf:wo:a:c:dile:pb", long_options, NULL)) != EOF) {
switch (c) {
case 'h':
case 'H':
@@ -394,6 +399,9 @@ virtual int startup() throw (GeneralException) {
case 'p':
probe();
throw Exit(0);
+ case 'b':
+ builtin = true;
+ break;
default:
showhelp();
throw Exit(-1);
@@ -406,8 +414,31 @@ virtual int startup() throw (GeneralException) {
L = start_basic_lua();
/* Loading cd-tool.lua (only when not compiling) */
- if (!compile)
- L->load(&Input("cd-tool.lua"));
+ if (!compile && !builtin) {
+ try {
+ L->load(&Input("cd-tool.lua"));
+ }
+ catch (GeneralException e) {
+ printm(M_WARNING, "There was an error loading cd-tool.lua, using built-in: %s\n", e.GetMsg());
+ builtin = true;
+ }
+ }
+
+ if (!compile && builtin) {
+ Buffer built;
+ int i;
+
+ for (i = 0; i < cd_tool_lua_size; i++) {
+ built.writeU8(cd_tool_lua[i]);
+ }
+ try {
+ L->load(&built);
+ }
+ catch (GeneralException e) {
+ printm(M_WARNING, "There was an error loading built-in cd-tool.lua: %s\n", e.GetMsg());
+ builtin = true;
+ }
+ }
/* Loading all the scripts */
while (optind < argc) {
@@ -512,6 +543,12 @@ virtual int startup() throw (GeneralException) {
while(L->gettop())
L->pop();
}
+ catch (GeneralException e) {
+ /* A more severe exception... */
+ while(L->gettop())
+ L->pop();
+ printm(M_ERROR, "Aborted. LUA caused the following exception: %s\n", e.GetMsg());
+ }
strcpy(prompt, "> ");
} else {
strcpy(prompt, "- ");