summaryrefslogtreecommitdiff
path: root/src/parser.y
diff options
context:
space:
mode:
authorMarius Kintel <marius@kintel.net>2011-12-24 22:27:44 (GMT)
committerMarius Kintel <marius@kintel.net>2011-12-24 22:27:44 (GMT)
commita5ea98c4a499bdc534d58ecf4881d6ce435d3bd5 (patch)
tree9e0db0c0c3158f32be8458c169d569169439d5e2 /src/parser.y
parentbafbc89aa07f984ac74a3dded0f67158fe225a81 (diff)
Ported parser code from QFile to boost filesystem
Diffstat (limited to 'src/parser.y')
-rw-r--r--src/parser.y31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/parser.y b/src/parser.y
index d703a81..2fb0c3f 100644
--- a/src/parser.y
+++ b/src/parser.y
@@ -28,11 +28,6 @@
%{
-#include <QDir>
-#include <QFile>
-#include <QFileInfo>
-#include <QTextStream>
-
#include <sys/types.h>
#include <sys/stat.h>
#ifndef _MSC_VER
@@ -46,6 +41,9 @@
#include "printutils.h"
#include <sstream>
#include <boost/foreach.hpp>
+#include <boost/filesystem.hpp>
+
+using namespace boost::filesystem;
int parser_error_pos = -1;
@@ -613,7 +611,7 @@ AbstractModule *parse(const char *text, const char *path, int debug)
boost::unordered_map<std::string, Module::libs_cache_ent> Module::libs_cache;
-Module *Module::compile_library(std::string filename)
+Module *Module::compile_library(const std::string &filename)
{
struct stat st;
memset(&st, 0, sizeof(struct stat));
@@ -628,12 +626,19 @@ Module *Module::compile_library(std::string filename)
return &(*libs_cache[filename].mod);
}
- QFile f(QString::fromStdString(filename));
- if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) {
- PRINTF("WARNING: Can't open library file `%s'.", filename.c_str());
- return NULL;
- }
- QString text = QTextStream(&f).readAll();
+ FILE *fp = fopen(filename.c_str(), "rt");
+ if (!fp) {
+ fprintf(stderr, "WARNING: Can't open library file '%s'\n", filename.c_str());
+ return NULL;
+ }
+ std::stringstream text;
+ char buffer[513];
+ int ret;
+ while ((ret = fread(buffer, 1, 512, fp)) > 0) {
+ buffer[ret] = 0;
+ text << buffer;
+ }
+ fclose(fp);
print_messages_push();
@@ -644,7 +649,7 @@ Module *Module::compile_library(std::string filename)
libs_cache[filename] = e;
Module *backup_mod = module;
- Module *lib_mod = dynamic_cast<Module*>(parse(text.toLocal8Bit(), QFileInfo(QString::fromStdString(filename)).absoluteDir().absolutePath().toLocal8Bit(), 0));
+ Module *lib_mod = dynamic_cast<Module*>(parse(text.str().c_str(), absolute(filename).generic_string().c_str(), 0));
module = backup_mod;
if (lib_mod) {
contact: Jan Huwald // Impressum