29#include <tdeinstance.h>
30#include <tdeapplication.h>
31#include <tdecmdlineargs.h>
32#include <tdeaboutdata.h>
33#include <ksharedptr.h>
36#include "../main/manager.h"
37#include "../main/scriptcontainer.h"
38#include "../api/interpreter.h"
42#define ERROR_NOSUCHFILE -2
43#define ERROR_OPENFAILED -3
44#define ERROR_NOINTERPRETER -4
45#define ERROR_UNHALDEDEXCEPTION -5
46#define ERROR_EXCEPTION -6
48TDEApplication* app = 0;
50int runScriptFile(
const TQString& scriptfile)
53 TQFile f(TQFile::encodeName(scriptfile));
55 std::cerr <<
"No such scriptfile: " << scriptfile.latin1() << std::endl;
56 return ERROR_NOSUCHFILE;
58 if(! f.open(IO_ReadOnly)) {
59 std::cerr <<
"Failed to open scriptfile: " << scriptfile.latin1() << std::endl;
60 return ERROR_OPENFAILED;
62 TQString scriptcode = f.readAll();
68 if(! interpreterinfo) {
69 std::cerr <<
"No interpreter for file: " << scriptfile.latin1() << std::endl;
70 return ERROR_NOINTERPRETER;
78 scriptcontainer->setCode(scriptcode);
80 scriptcontainer->execute();
81 if(scriptcontainer->hadException()) {
83 TQString errormessage = scriptcontainer->getException()->getError();
84 TQString tracedetails = scriptcontainer->getException()->getTrace();
85 std::cerr << TQString(
"%2\n%1").arg(tracedetails).arg(errormessage).latin1() << std::endl;
86 return ERROR_EXCEPTION;
91 std::cerr << TQString(
"EXCEPTION %1").arg(e->toString()).latin1() << std::endl;
92 return ERROR_UNHALDEDEXCEPTION;
97int main(
int argc,
char **argv)
99 int result = ERROR_OK;
101 TDEAboutData about(
"krossrunner",
104 "KDE application to run Kross scripts.",
105 TDEAboutData::License_LGPL,
106 "(C) 2006 Sebastian Sauer",
107 "Run Kross scripts.",
108 "http://www.dipe.org/kross",
110 about.addAuthor(
"Sebastian Sauer",
"Author",
"mail@dipe.org");
113 TDECmdLineArgs::init(argc, argv, &about);
115 static TDECmdLineOptions options[] = {
116 {
"+file", I18N_NOOP(
"Scriptfile"), 0 },
119 TDECmdLineArgs::addCmdLineOptions(options);
120 TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
123 if(args->count() < 1) {
124 std::cout <<
"Syntax: " << TDECmdLineArgs::appName() <<
" scriptfile1 [scriptfile2] [scriptfile3] ..." << std::endl;
129 app =
new TDEApplication(
true,
true );
135 for(
int i = 0; i < args->count(); i++) {
136 result = runScriptFile(TQFile::decodeName(args->arg(i)));
137 if(result != ERROR_OK)
TDESharedPtr< Exception > Ptr
Shared pointer to implement reference-counting.
While the Interpreter is the implemented interpreter this class is used to provide some abstract info...
const TQString getInterpretername()
The Manager class is the main entry point to work with Kross.
const TQString getInterpreternameForFile(const TQString &file)
InterpreterInfo * getInterpreterInfo(const TQString &interpretername)
static Manager * scriptManager()
Return the Manager instance.
TDESharedPtr< ScriptContainer > getScriptContainer(const TQString &scriptname)
Return the existing ScriptContainer with scriptname or create a new ScriptContainer instance and asso...
TDESharedPtr< ScriptContainer > Ptr
Shared pointer to implement reference-counting.