} format;
+bool file_exists(const std::string & file)
+{
+ struct stat buf;
+ int error = stat (file.c_str(), &buf);
+
+ return ((error == 0) &&
+ S_ISREG(buf.st_mode));
+}
+
+
// for the given file, fill a
// respective entry in the "direct_includes"
// map listing the names of those
std::abort();
}
- // next try to locate the file
- // in absolute paths. this is
- // easy if it was included via
- // "...", but for <...> we have
- // to work a little harder
+ // next try to locate the file in
+ // absolute paths. For includes of the
+ // form #include "...", we check the
+ // current path first.
if (included_file[0] != '/')
{
- if (line[pos] == '"')
- included_file = present_path+included_file;
- else
- for (std::vector<std::string>::const_iterator
+ bool is_relative_path = false;
+ if (line[pos] == '"' && file_exists(present_path+included_file))
+ {
+ included_file = present_path+included_file;
+ is_relative_path = true;
+ }
+
+ if (is_relative_path == false)
+ for (std::vector<std::string>::const_iterator
include_dir=include_directories.begin();
include_dir!=include_directories.end(); ++include_dir)
{
- struct stat buf;
- int error = stat ((*include_dir+included_file).c_str(), &buf);
-
- if ((error == 0) &&
- S_ISREG(buf.st_mode))
+ if (file_exists((*include_dir+included_file)))
{
included_file = *include_dir+included_file;
break;
// it will be generated by make
// later, so we better keep it
// on the list.
- if (line[pos] != '"' || included_file.rfind(".inst") != (included_file.size()-5)) {
- struct stat buf;
- int error = stat (included_file.c_str(), &buf);
-
- if ((error != 0) ||
- !S_ISREG(buf.st_mode))
- continue;
- }
+ bool is_inst_file =
+ included_file.size()>5 && (included_file.rfind(".inst") == (included_file.size()-5));
+
+ if (line[pos] != '"' || !is_inst_file)
+ {
+ if (!file_exists(included_file))
+ continue;
+ }
// work on the include file
// recursively. note that the
- // first line of this file
+ // first line of this function
// saves us from infinite
// recursions in case of
// include loops