--- /dev/null
+/*
+ * Arguments.cpp
+ *
+ * Created on: Sep 15, 2012
+ * Author: holy
+ */
+
+#include "Arguments.h"
+
+#include <stdexcept>
+#include <string>
+
+namespace app {
+
+Arguments::Arguments()
+: outfile(0) {
+
+}
+
+
+void Arguments::Read(int argc, char **argv) {
+ for (int i(1); i < argc; ++i) {
+ char *arg(argv[i]);
+ if (arg[0] == '-') {
+ switch (arg[1]) {
+ case 'o':
+ if (i + 1 >= argc) {
+ throw std::runtime_error("missing argument to -o");
+ }
+ ++i;
+ outfile = argv[i];
+ break;
+ default:
+ throw std::runtime_error(std::string("unknown option ") + arg[1]);
+ break;
+ }
+ } else {
+ infiles.push_back(arg);
+ }
+ }
+}
+
+}
--- /dev/null
+/*
+ * Arguments.h
+ *
+ * Created on: Sep 15, 2012
+ * Author: holy
+ */
+
+#ifndef APP_ARGUMENTS_H_
+#define APP_ARGUMENTS_H_
+
+#include <vector>
+
+namespace app {
+
+class Arguments {
+
+public:
+ Arguments();
+ ~Arguments() { }
+
+public:
+ void Read(int argc, char **argv);
+
+ const std::vector<char *> &Infiles() const { return infiles; }
+
+ bool OutfileSet() const { return outfile; }
+ const char *OutfilePath() const { return outfile; }
+
+private:
+ std::vector<char *> infiles;
+ const char *outfile;
+
+};
+
+}
+
+#endif /* APP_ARGUMENTS_H_ */
*/
#include "app/Application.h"
+#include "app/Arguments.h"
#include "app/Input.h"
#include "battle/BattleState.h"
#include "battle/Hero.h"
#include <ctime>
#include <exception>
#include <iostream>
+#include <string>
#include <SDL.h>
#include <SDL_image.h>
using app::Application;
+using app::Arguments;
using app::Input;
using battle::BattleState;
using battle::Hero;
using std::cout;
using std::endl;
using std::exception;
+using std::string;
+using std::vector;
int main(int argc, char **argv) {
const int width = 800;
Stats::CreateTypeDescription();
common::TargetingMode::CreateTypeDescription();
+ Arguments args;
+ args.Read(argc, argv);
+
ParsedSource source;
- Parser("test-data/test.l2s", source).Parse();
- Parser("test-data/ikaris.l2s", source).Parse();
- Parser("test-data/items.l2s", source).Parse();
- Parser("test-data/spells.l2s", source).Parse();
- Parser("test-data/constants.l2s", source).Parse();
+
+ for (vector<char *>::const_iterator i(args.Infiles().begin()), end(args.Infiles().end()); i != end; ++i) {
+ string filePath(*i);
+ switch (filePath[filePath.size() - 1]) {
+ case 'o':
+ // TODO: load object file
+ break;
+ case 's':
+ Parser(filePath, source).Parse();
+ break;
+ default:
+ throw std::runtime_error("don't know what to do with " + filePath);
+ }
+ }
+
+// Parser("test-data/test.l2s", source).Parse();
+// Parser("test-data/ikaris.l2s", source).Parse();
+// Parser("test-data/items.l2s", source).Parse();
+// Parser("test-data/spells.l2s", source).Parse();
+// Parser("test-data/constants.l2s", source).Parse();
+
Interpreter intp(source);
intp.ReadSource();
-// std::ofstream testOut("test-data/test.l2o");
-// Compiler(intp).Write(testOut);
-// return 0;
+ if (args.OutfileSet()) {
+ std::ofstream testOut(args.OutfilePath());
+ Compiler(intp).Write(testOut);
+ return 0;
+ }
int battleResId(TypeDescription::GetTypeId("BattleResources"));
int heroId(TypeDescription::GetTypeId("Hero"));