diff --git a/mirc/includes/mirc.h b/mirc/includes/mirc.h index eedcef3..2449f12 100644 --- a/mirc/includes/mirc.h +++ b/mirc/includes/mirc.h @@ -4,15 +4,26 @@ #include #include #include +#include #include "script.h" +class MIRCScript; + class MIRCScriptManager : public QObject { Q_OBJECT - +private: + QObject *parent; + QVector scripts; + QMap _variables; public: - //QMap 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 diff --git a/mirc/includes/parser.h b/mirc/includes/parser.h index c276423..09b0c2d 100644 --- a/mirc/includes/parser.h +++ b/mirc/includes/parser.h @@ -17,6 +17,8 @@ #include #include #include +//#include "mirc.h" +class MIRCScriptManager; using namespace std; using namespace boost; @@ -42,6 +44,7 @@ enum mirc_engine_stage { class mirc_script_engine : public QObject { Q_OBJECT private: + MIRCScriptManager *manager; mirc_aliases::iterator current_alias; mirc_variables::iterator current_variable; QStack stack; @@ -51,7 +54,8 @@ public: mirc_aliases aliases; mirc_variables vars; - mirc_script_engine() : script() { + mirc_script_engine(MIRCScriptManager *m) : script() { + manager = m; stage = PARSE; current_alias = aliases.end(); current_variable = vars.end(); diff --git a/mirc/includes/script.h b/mirc/includes/script.h index d59d44d..d629fcc 100644 --- a/mirc/includes/script.h +++ b/mirc/includes/script.h @@ -10,12 +10,13 @@ class MIRCScript : public QObject { Q_OBJECT private: + MIRCScriptManager *manager; QString script; QMap _aliases; QMap _variables; bool loaded; public: - MIRCScript(); + MIRCScript(MIRCScriptManager *m); bool load(QString filename); bool parse(QString script); bool run(); diff --git a/mirc/src/mirc.cpp b/mirc/src/mirc.cpp index 5becc27..dfbc098 100644 --- a/mirc/src/mirc.cpp +++ b/mirc/src/mirc.cpp @@ -1,4 +1,5 @@ #include "mirc.h" -MIRCScriptManager::MIRCScriptManager(QObject *parent = 0) { +MIRCScriptManager::MIRCScriptManager(QObject *parent) { + this->parent = parent; } diff --git a/mirc/src/parser.cpp b/mirc/src/parser.cpp index 4c28b09..6b6e33f 100644 --- a/mirc/src/parser.cpp +++ b/mirc/src/parser.cpp @@ -1,76 +1,38 @@ #include #include "script.h" -int main() { +int main(int argc, char* argv[]) { QTextStream output(stdout); - QString foo; - foo.append("; Hey, here's some test code\n"); - foo.append("set name Correl\n"); - foo.append("%name = Correl $&\n\tRoush\n"); - foo.append("echo Hello, %name!\n"); - foo.append("alias dostuff {\n"); - foo.append(" ; Not very useful, but good for testing the parser!\n"); - foo.append(" var %b = 42\n"); - 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 << "Code:\n" << ms->code(); - output << "Aliases:\n"; - QMapIterator alias(ms->aliases()); - while(alias.hasNext()) { - alias.next(); - output << (alias.value().global ? "global" : "local"); - output << " " << alias.key() << "\n"; - } - if (ms->run()) { - output << "MRC RAN SUCCESSFULLY\n"; - QMapIterator i(ms->variables()); - output << "Variables:\n"; - while(i.hasNext()) { - i.next(); - output << i.key() << " = " << i.value() << "\n"; - } + MIRCScriptManager *mirc = new MIRCScriptManager; + MIRCScript *ms = new MIRCScript(mirc); + if (argc < 2) { + output << "No mIRC script file was specified!\n"; + return(1); + } + output << "Attempting to load " << argv[1] << "\n"; + if (ms->load(argv[1])) { + output << "MRC LOADED\n"; + output << "Code:\n" << ms->code(); + output << "Aliases:\n"; + QMapIterator alias(ms->aliases()); + while(alias.hasNext()) { + alias.next(); + output << (alias.value().global ? "global" : "local"); + output << " " << alias.key() << "\n"; + } + if (ms->run()) { + output << "MRC RAN SUCCESSFULLY\n"; + QMapIterator i(ms->variables()); + output << "Variables:\n"; + while(i.hasNext()) { + i.next(); + output << i.key() << " = " << i.value() << "\n"; } } - } - else - { - output << "-------------------------\n"; - output << "Parsing failed\n"; - output << "stopped at: \": " << info.stop << "\"\n"; - output << "-------------------------\n"; + } else { + output << "Failed to load " << argv[1] << "\n"; + return(1); } return 0; diff --git a/mirc/src/script.cpp b/mirc/src/script.cpp index d997021..f8457f1 100644 --- a/mirc/src/script.cpp +++ b/mirc/src/script.cpp @@ -1,7 +1,8 @@ #include "script.h" #include -MIRCScript::MIRCScript() { +MIRCScript::MIRCScript(MIRCScriptManager *m) { + manager = m; } bool MIRCScript::load(QString filename) { @@ -16,7 +17,7 @@ bool MIRCScript::load(QString filename) { } 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); parse_info<> info = boost::spirit::parse((const char*)code.toLatin1(), parser); loaded = info.full; @@ -29,7 +30,7 @@ bool MIRCScript::parse(QString code) { bool MIRCScript::run() { if (!loaded) return false; - mirc_script_engine *interpreter = new mirc_script_engine(); + mirc_script_engine *interpreter = new mirc_script_engine(manager); interpreter->stage = EXECUTE; mirc_script parser(interpreter); parse_info<> info = boost::spirit::parse((const char*)script.toLatin1(), parser);