summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ModuleCache.cc3
-rw-r--r--src/lexer.l35
-rw-r--r--src/mainwin.cc11
-rw-r--r--src/module.cc2
-rw-r--r--src/parsersettings.cc41
-rw-r--r--src/parsersettings.h4
6 files changed, 80 insertions, 16 deletions
diff --git a/src/ModuleCache.cc b/src/ModuleCache.cc
index 4944495..8a082af 100644
--- a/src/ModuleCache.cc
+++ b/src/ModuleCache.cc
@@ -19,9 +19,11 @@
*/
ModuleCache *ModuleCache::inst = NULL;
+#include <iostream>
static bool is_modified(const std::string &filename, const time_t &mtime)
{
+ std::cout << "cache ismod " << filename << "\n";
struct stat st;
memset(&st, 0, sizeof(struct stat));
stat(filename.c_str(), &st);
@@ -30,6 +32,7 @@ static bool is_modified(const std::string &filename, const time_t &mtime)
FileModule *ModuleCache::evaluate(const std::string &filename)
{
+ std::cout << "modcache eval" << filename << "\n";
FileModule *lib_mod = NULL;
// Create cache ID
diff --git a/src/lexer.l b/src/lexer.l
index 6dfe9bc..29f3531 100644
--- a/src/lexer.l
+++ b/src/lexer.l
@@ -113,7 +113,15 @@ use[ \t\r\n>]*"<" { BEGIN(cond_use); }
[^\t\r\n>]+ { filename = yytext; }
">" {
BEGIN(INITIAL);
- fs::path usepath;
+ fs::path fullpath = find_valid_path( sourcepath(), filename );
+ if ( fullpath.empty() ) {
+ PRINTB("WARNING: Can't open 'use' file '%s'.", filename);
+ } else {
+ handle_dep(usepath.string());
+ parserlval.text = strdup(usepath.string().c_str());
+ return TOK_USE;
+ }
+/*
if (boosty::is_absolute(fs::path(filename))) {
usepath = filename;
}
@@ -123,18 +131,12 @@ use[ \t\r\n>]*"<" { BEGIN(cond_use); }
usepath = locate_file(filename);
}
}
- /* Only accept regular files which exists */
+ // Only accept regular files which exists
if (usepath.has_parent_path() && fs::exists(usepath) && !fs::is_directory(usepath)) {
- handle_dep(usepath.string());
- parserlval.text = strdup(usepath.string().c_str());
- return TOK_USE;
+
} else {
- PRINTB("WARNING: Can't open 'use' file '%s'.", filename);
- if ( filename.size() == 0 )
- PRINT("WARNING: 'use' filename is blank");
- else if ( fs::is_directory( usepath ) )
- PRINTB("WARNING: 'use' file points to a directory: %s",filename);
}
+*/
}
}
@@ -209,6 +211,10 @@ fs::path sourcepath()
*/
void includefile()
{
+ PRINTB("includefile lex %s",filename.c_str());
+ PRINTB("includefile filepath %s",filepath.c_str());
+ PRINTB("includefile sourcepath %s",sourcepath.c_str());
+
if (filename.empty()) return;
fs::path dirinfo = sourcepath();
@@ -222,10 +228,14 @@ void includefile()
}
fs::path finfo = dirinfo / filename;
+ PRINTB("dirinfo0 %s",boosty::stringy(dirinfo) );
+ PRINTB("finfo0 %s",boosty::stringy(finfo) );
if (!exists(finfo)) {
finfo = locate_file((fs::path(filepath) / filename).string());
}
-
+ PRINTB("dinfo %s",boosty::stringy(dirinfo) );
+ PRINTB("fnam %s",boosty::stringy(filename) );
+ PRINTB("finfo %s",boosty::stringy(finfo) );
if (!exists(finfo) || finfo.empty()) {
// deal with some unusual situations with is_absolute() and Wine
fs::path fnp( fs::path(filepath) / filename );
@@ -236,9 +246,12 @@ void includefile()
if (finfo.empty()) {
PRINTB("WARNING: Can't find 'include' file '%s'.", filename);
+ PRINTB("finfo %s",boosty::stringy(finfo) );
+ finfo = dirinfo / filename;
}
std::string fullname = boosty::absolute(finfo).string();
+ PRINTB("fullname1 %s",fullname.c_str() );
// Detect circular includes
BOOST_FOREACH(std::string &s, openfilenames) {
if (s == fullname) return;
diff --git a/src/mainwin.cc b/src/mainwin.cc
index 5f9d633..e1369bf 100644
--- a/src/mainwin.cc
+++ b/src/mainwin.cc
@@ -1021,16 +1021,23 @@ bool MainWindow::fileChangedOnDisk()
// FIXME: The following two methods are duplicated in ModuleCache.cc - refactor
static bool is_modified(const std::string &filename, const time_t &mtime)
{
+ bool modified = false;
struct stat st;
memset(&st, 0, sizeof(struct stat));
- stat(filename.c_str(), &st);
- return (st.st_mtime > mtime);
+ bool success = stat(filename.c_str(), &st)==0;
+ std::cout <<"success" << success << ":" << filename << "\n";
+ if (success) modified = st.st_mtime > mtime;
+ else modified = true;
+ return modified;
}
+#include <iostream>
bool MainWindow::includesChanged()
{
if (this->root_module) {
BOOST_FOREACH(const FileModule::IncludeContainer::value_type &item, this->root_module->includes) {
+ std::cout<< item.first << "second" << item.second << "\n";
+ std::cout<< (is_modified(item.first, item.second)) <<"\n";
if (is_modified(item.first, item.second)) return true;
}
}
diff --git a/src/module.cc b/src/module.cc
index e853457..001c6c8 100644
--- a/src/module.cc
+++ b/src/module.cc
@@ -194,8 +194,10 @@ std::string Module::dump(const std::string &indent, const std::string &name) con
return dump.str();
}
+#include <iostream>
void FileModule::registerInclude(const std::string &filename)
{
+ std::cout << "reginclude" << filename << "\n";
struct stat st;
memset(&st, 0, sizeof(struct stat));
stat(filename.c_str(), &st);
diff --git a/src/parsersettings.cc b/src/parsersettings.cc
index 8d82744..4273f7c 100644
--- a/src/parsersettings.cc
+++ b/src/parsersettings.cc
@@ -20,13 +20,50 @@ void add_librarydir(const std::string &libdir)
Searces for the given file in library paths and returns the full path if found.
Returns an empty path if file cannot be found or filename is a directory.
*/
-std::string locate_file(const std::string &filename)
+fs::path search_libs(const std::string &filename)
{
BOOST_FOREACH(const std::string &dir, librarypath) {
fs::path usepath = fs::path(dir) / filename;
if (fs::exists(usepath) && !fs::is_directory(usepath)) return usepath.string();
}
- return std::string();
+ return fs::path();
+}
+
+// files must be 'ordinary' - they mus exist and be non-directories
+bool check_valid( fs::path p )
+{
+ // if p empty PRINT("WARNING: 'use' filename is blank");
+ if (!p.has_parent_path()) {
+ PRINTB("WARNING: %s invalid - no parent path",p);
+ return false;
+ }
+ if (!fs::exists(p)) {
+ PRINTB("WARNING: %s invalid - file not found",p);
+ // searched ===
+ return false;
+ }
+ if (fs::is_directory(p)) {
+ PRINTB("WARNING: %s invalid - points to a directory",p);
+ return false;
+ }
+ return true;
+}
+
+// check if file is valid, search path for valid simple file
+// return empty path on failure
+fs::path find_valid_path( fs::path sourcepath, std::string filename )
+{
+ fs::path fpath = fs::path( filename );
+
+ if ( boosty::is_absolute( fpath ) )
+ if ( check_valid( fpath ) )
+ return boosty::absolute( fpath );
+
+ fpath = sourcepath / filename;
+ if ( check_valid( fpath ) ) return fpath;
+ fpath = search_libs( filename );
+ if ( check_valid( fpath ) ) return fpath;
+ return fs::path();
}
void parser_init(const std::string &applicationpath)
diff --git a/src/parsersettings.h b/src/parsersettings.h
index 007aa9c..4c74a87 100644
--- a/src/parsersettings.h
+++ b/src/parsersettings.h
@@ -2,11 +2,13 @@
#define PARSERSETTINGS_H_
#include <string>
+#include "boosty.h"
extern int parser_error_pos;
void parser_init(const std::string &applicationpath);
void add_librarydir(const std::string &libdir);
-std::string locate_file(const std::string &filename);
+fs::path search_libs(const std::string &filename);
+fs::path find_valid_path( fs::path sourcepath, std::string filename );
#endif
contact: Jan Huwald // Impressum