mirror of
https://github.com/correl/mercenary.git
synced 2024-11-23 19:19:51 +00:00
Why not load a file specified on the commandline...
Also, some placeholder functions for the great and powerful script manager! git-svn-id: file:///srv/svn/ircclient/trunk@2 a9804ffe-773b-11dd-bd7c-89c3ef1d2733
This commit is contained in:
parent
0381859219
commit
7315012830
6 changed files with 55 additions and 75 deletions
|
@ -4,15 +4,26 @@
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
#include <QVector>
|
||||||
#include "script.h"
|
#include "script.h"
|
||||||
|
|
||||||
|
class MIRCScript;
|
||||||
|
|
||||||
class MIRCScriptManager : public QObject {
|
class MIRCScriptManager : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
private:
|
||||||
|
QObject *parent;
|
||||||
|
QVector<MIRCScript> scripts;
|
||||||
|
QMap<QString, QString> _variables;
|
||||||
public:
|
public:
|
||||||
//QMap<QString, QString> variables;
|
MIRCScriptManager(QObject *parent = 0);
|
||||||
|
/*
|
||||||
|
bool load(QString filename);
|
||||||
|
bool unload(QString filename);
|
||||||
|
|
||||||
MIRCScriptManager(QObject *parent);
|
QString call_alias(QString alias, QStringList arguments);
|
||||||
|
QString variable(QString variable);
|
||||||
|
*/
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QStack>
|
#include <QStack>
|
||||||
|
//#include "mirc.h"
|
||||||
|
class MIRCScriptManager;
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace boost;
|
using namespace boost;
|
||||||
|
@ -42,6 +44,7 @@ enum mirc_engine_stage {
|
||||||
class mirc_script_engine : public QObject {
|
class mirc_script_engine : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
|
MIRCScriptManager *manager;
|
||||||
mirc_aliases::iterator current_alias;
|
mirc_aliases::iterator current_alias;
|
||||||
mirc_variables::iterator current_variable;
|
mirc_variables::iterator current_variable;
|
||||||
QStack<QStringList> stack;
|
QStack<QStringList> stack;
|
||||||
|
@ -51,7 +54,8 @@ public:
|
||||||
mirc_aliases aliases;
|
mirc_aliases aliases;
|
||||||
mirc_variables vars;
|
mirc_variables vars;
|
||||||
|
|
||||||
mirc_script_engine() : script() {
|
mirc_script_engine(MIRCScriptManager *m) : script() {
|
||||||
|
manager = m;
|
||||||
stage = PARSE;
|
stage = PARSE;
|
||||||
current_alias = aliases.end();
|
current_alias = aliases.end();
|
||||||
current_variable = vars.end();
|
current_variable = vars.end();
|
||||||
|
|
|
@ -10,12 +10,13 @@
|
||||||
class MIRCScript : public QObject {
|
class MIRCScript : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
|
MIRCScriptManager *manager;
|
||||||
QString script;
|
QString script;
|
||||||
QMap<QString, mirc_alias> _aliases;
|
QMap<QString, mirc_alias> _aliases;
|
||||||
QMap<QString, QString> _variables;
|
QMap<QString, QString> _variables;
|
||||||
bool loaded;
|
bool loaded;
|
||||||
public:
|
public:
|
||||||
MIRCScript();
|
MIRCScript(MIRCScriptManager *m);
|
||||||
bool load(QString filename);
|
bool load(QString filename);
|
||||||
bool parse(QString script);
|
bool parse(QString script);
|
||||||
bool run();
|
bool run();
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "mirc.h"
|
#include "mirc.h"
|
||||||
|
|
||||||
MIRCScriptManager::MIRCScriptManager(QObject *parent = 0) {
|
MIRCScriptManager::MIRCScriptManager(QObject *parent) {
|
||||||
|
this->parent = parent;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,50 +1,17 @@
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include "script.h"
|
#include "script.h"
|
||||||
|
|
||||||
int main() {
|
int main(int argc, char* argv[]) {
|
||||||
QTextStream output(stdout);
|
QTextStream output(stdout);
|
||||||
|
|
||||||
QString foo;
|
MIRCScriptManager *mirc = new MIRCScriptManager;
|
||||||
foo.append("; Hey, here's some test code\n");
|
MIRCScript *ms = new MIRCScript(mirc);
|
||||||
foo.append("set name Correl\n");
|
if (argc < 2) {
|
||||||
foo.append("%name = Correl $&\n\tRoush\n");
|
output << "No mIRC script file was specified!\n";
|
||||||
foo.append("echo Hello, %name!\n");
|
return(1);
|
||||||
foo.append("alias dostuff {\n");
|
}
|
||||||
foo.append(" ; Not very useful, but good for testing the parser!\n");
|
output << "Attempting to load " << argv[1] << "\n";
|
||||||
foo.append(" var %b = 42\n");
|
if (ms->load(argv[1])) {
|
||||||
foo.append(" %b = $calc(%b * 3)\n");
|
|
||||||
foo.append(" return %b;\n");
|
|
||||||
foo.append("}\n");
|
|
||||||
foo.append("alias -l dosomethingelse {\n");
|
|
||||||
foo.append(" ; Useless local alias!\n");
|
|
||||||
foo.append(" echo -s Busy doing nothing\n");
|
|
||||||
foo.append("}\n");
|
|
||||||
foo.append("alias -l dosomethingelse {\n");
|
|
||||||
foo.append(" ; Useless local alias!\n");
|
|
||||||
foo.append(" echo -s Busy doing nothing\n");
|
|
||||||
foo.append("}\n");
|
|
||||||
|
|
||||||
output << "Code:\n"
|
|
||||||
<< "================================================================================\n"
|
|
||||||
<< foo
|
|
||||||
<< "================================================================================\n"
|
|
||||||
<< "\n";
|
|
||||||
|
|
||||||
mirc_script_engine *interpreter = new mirc_script_engine();
|
|
||||||
mirc_script parser(interpreter);
|
|
||||||
|
|
||||||
parse_info<> info = parse((const char*)foo.toLatin1(), parser);
|
|
||||||
|
|
||||||
if (info.full)
|
|
||||||
{
|
|
||||||
output << "-------------------------\n";
|
|
||||||
output << "Parsing succeeded\n";
|
|
||||||
output << "-------------------------\n";
|
|
||||||
|
|
||||||
MIRCScript *ms = new MIRCScript();
|
|
||||||
output << "Creating new MIRCScript object\n";
|
|
||||||
//if (ms->parse(foo)) {
|
|
||||||
if (ms->load("test.mrc")) {
|
|
||||||
output << "MRC LOADED\n";
|
output << "MRC LOADED\n";
|
||||||
output << "Code:\n" << ms->code();
|
output << "Code:\n" << ms->code();
|
||||||
output << "Aliases:\n";
|
output << "Aliases:\n";
|
||||||
|
@ -63,14 +30,9 @@ int main() {
|
||||||
output << i.key() << " = " << i.value() << "\n";
|
output << i.key() << " = " << i.value() << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
}
|
output << "Failed to load " << argv[1] << "\n";
|
||||||
else
|
return(1);
|
||||||
{
|
|
||||||
output << "-------------------------\n";
|
|
||||||
output << "Parsing failed\n";
|
|
||||||
output << "stopped at: \": " << info.stop << "\"\n";
|
|
||||||
output << "-------------------------\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
#include "script.h"
|
#include "script.h"
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
|
||||||
MIRCScript::MIRCScript() {
|
MIRCScript::MIRCScript(MIRCScriptManager *m) {
|
||||||
|
manager = m;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MIRCScript::load(QString filename) {
|
bool MIRCScript::load(QString filename) {
|
||||||
|
@ -16,7 +17,7 @@ bool MIRCScript::load(QString filename) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MIRCScript::parse(QString code) {
|
bool MIRCScript::parse(QString code) {
|
||||||
mirc_script_engine *interpreter = new mirc_script_engine();
|
mirc_script_engine *interpreter = new mirc_script_engine(manager);
|
||||||
mirc_script parser(interpreter);
|
mirc_script parser(interpreter);
|
||||||
parse_info<> info = boost::spirit::parse((const char*)code.toLatin1(), parser);
|
parse_info<> info = boost::spirit::parse((const char*)code.toLatin1(), parser);
|
||||||
loaded = info.full;
|
loaded = info.full;
|
||||||
|
@ -29,7 +30,7 @@ bool MIRCScript::parse(QString code) {
|
||||||
|
|
||||||
bool MIRCScript::run() {
|
bool MIRCScript::run() {
|
||||||
if (!loaded) return false;
|
if (!loaded) return false;
|
||||||
mirc_script_engine *interpreter = new mirc_script_engine();
|
mirc_script_engine *interpreter = new mirc_script_engine(manager);
|
||||||
interpreter->stage = EXECUTE;
|
interpreter->stage = EXECUTE;
|
||||||
mirc_script parser(interpreter);
|
mirc_script parser(interpreter);
|
||||||
parse_info<> info = boost::spirit::parse((const char*)script.toLatin1(), parser);
|
parse_info<> info = boost::spirit::parse((const char*)script.toLatin1(), parser);
|
||||||
|
|
Loading…
Reference in a new issue