../src/loader/Interpreter.cpp \
../src/loader/ParsedSource.cpp \
../src/loader/Parser.cpp \
-../src/loader/Tokenizer.cpp
+../src/loader/Tokenizer.cpp \
+../src/loader/utility.cpp
OBJS += \
./src/loader/Interpreter.o \
./src/loader/ParsedSource.o \
./src/loader/Parser.o \
-./src/loader/Tokenizer.o
+./src/loader/Tokenizer.o \
+./src/loader/utility.o
CPP_DEPS += \
./src/loader/Interpreter.d \
./src/loader/ParsedSource.d \
./src/loader/Parser.d \
-./src/loader/Tokenizer.d
+./src/loader/Tokenizer.d \
+./src/loader/utility.d
# Each subdirectory must supply rules for building sources it contributes
../src/loader/Interpreter.cpp \
../src/loader/ParsedSource.cpp \
../src/loader/Parser.cpp \
-../src/loader/Tokenizer.cpp
+../src/loader/Tokenizer.cpp \
+../src/loader/utility.cpp
OBJS += \
./src/loader/Interpreter.o \
./src/loader/ParsedSource.o \
./src/loader/Parser.o \
-./src/loader/Tokenizer.o
+./src/loader/Tokenizer.o \
+./src/loader/utility.o
CPP_DEPS += \
./src/loader/Interpreter.d \
./src/loader/ParsedSource.d \
./src/loader/Parser.d \
-./src/loader/Tokenizer.d
+./src/loader/Tokenizer.d \
+./src/loader/utility.d
# Each subdirectory must supply rules for building sources it contributes
#include "Parser.h"
+#include "utility.h"
+
#include <auto_ptr.h>
#include <fstream>
namespace loader {
-Parser::Parser(const char *file, ParsedSource &product)
+Parser::Parser(const string &file, ParsedSource &product)
: file(file)
-, in(file)
+, dirname(Dirname(file))
+, in(this->file.c_str())
, tok(in)
, product(product) {
if (!in) {
void Parser::ParseIncludeDirective() {
Tokenizer::Token t(GetToken());
AssertTokenType(t.type, Tokenizer::Token::STRING);
- Parser sub(t.str.c_str(), product); // TODO: resolve path name
+ Parser sub(CatPath(dirname, t.str), product);
sub.Parse();
}
class Parser {
public:
- Parser(const char *file, ParsedSource &product);
+ Parser(const std::string &file, ParsedSource &product);
~Parser() { }
private:
Parser(const Parser &);
public:
class Error: public std::runtime_error {
public:
- Error(const char *file, int line, const std::string &msg)
+ Error(const std::string &file, int line, const std::string &msg)
: std::runtime_error(msg), file(file), line(line) { };
- const char *File() const { return file; }
+ ~Error() throw() { }
+ const std::string &File() const { return file; }
int Line() const { return line; }
private:
- const char *file;
+ std::string file;
int line;
};
bool BeginOfPropertyList(const Tokenizer::Token &) const;
private:
- const char *file;
+ std::string file;
+ std::string dirname;
std::ifstream in;
Tokenizer tok;
ParsedSource &product;
--- /dev/null
+/*
+ * utility.cpp
+ *
+ * Created on: Sep 1, 2012
+ * Author: holy
+ */
+
+#include "utility.h"
+
+#include <cstring>
+#include <libgen.h>
+
+using std::string;
+
+namespace loader {
+
+string Dirname(const string &path) {
+ // unix version
+ char *str(new char[path.size() + 1]);
+ std::memcpy(str, path.c_str(), path.size());
+ str[path.size()] = '\0';
+ string dn(dirname(str));
+ delete str;
+ return dn;
+}
+
+string CatPath(const string &lhs, const string &rhs) {
+ // unix version
+ string path(lhs);
+ if (!path.empty() && path[path.size() - 1] != '/') {
+ path += '/';
+ }
+ if (!rhs.empty() && rhs[0] == '/') {
+ path.append(rhs, 1, string::npos);
+ } else {
+ path += rhs;
+ }
+ return path;
+}
+
+}
--- /dev/null
+/*
+ * utility.h
+ *
+ * Created on: Sep 1, 2012
+ * Author: holy
+ */
+
+#ifndef LOADER_UTILITY_H_
+#define LOADER_UTILITY_H_
+
+#include <string>
+
+namespace loader {
+
+std::string Dirname(const std::string &path);
+
+std::string CatPath(const std::string &lhs, const std::string &rhs);
+
+}
+
+#endif /* LOADER_UTILITY_H_ */
offset: <0,64>
}
-include "test-data/spells.l2s"
+include "spells.l2s"
export String spellMenuHeadline "Please choose a spell."
-include "test-data/ikaris.l2s"
-include "test-data/items.l2s"
+include "ikaris.l2s"
+include "items.l2s"
export String itemMenuHeadline "Please choose an item."