You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
-Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#include "config.h"
#include "system.h"
static struct cpp_dir *search_path_head (cpp_reader *, const char *fname,
int angle_brackets, enum include_type);
static const char *dir_name_of_file (_cpp_file *file);
-static void open_file_failed (cpp_reader *pfile, _cpp_file *file);
+static void open_file_failed (cpp_reader *pfile, _cpp_file *file, int);
static struct file_hash_entry *search_cache (struct file_hash_entry *head,
const cpp_dir *start_dir);
static _cpp_file *make_cpp_file (cpp_reader *, cpp_dir *, const char *fname);
if (file->err_no != ENOENT)
{
- open_file_failed (pfile, file);
+ open_file_failed (pfile, file, 0);
return true;
}
to open_file().
*/
_cpp_file *
-_cpp_find_file (cpp_reader *pfile, const char *fname, cpp_dir *start_dir, bool fake)
+_cpp_find_file (cpp_reader *pfile, const char *fname, cpp_dir *start_dir, bool fake, int angle_brackets)
{
struct file_hash_entry *entry, **hash_slot;
_cpp_file *file;
/* Try each path in the include chain. */
for (; !fake ;)
{
- if (file->dir == pfile->quote_include
- || file->dir == pfile->bracket_include)
- {
- entry = search_cache (*hash_slot, file->dir);
- if (entry)
- {
- /* Found the same file again. Record it as reachable
- from this position, too. */
- free ((char *) file->name);
- free (file);
- file = entry->u.file;
- goto found;
- }
- }
-
if (find_file_in_dir (pfile, file, &invalid_pch))
break;
return file;
}
- open_file_failed (pfile, file);
+ open_file_failed (pfile, file, angle_brackets);
if (invalid_pch)
{
cpp_error (pfile, CPP_DL_ERROR,
}
break;
}
- }
- /* This is a new file; put it in the list. */
- file->next_file = pfile->all_files;
- pfile->all_files = file;
+ /* Only check the cache for the starting location (done above)
+ and the quote and bracket chain heads because there are no
+ other possible starting points for searches. */
+ if (file->dir != pfile->bracket_include
+ && file->dir != pfile->quote_include)
+ continue;
- /* If this file was found in the directory-of-the-current-file,
- check whether that directory is reachable via one of the normal
- search paths. If so, we must record this entry as being
- reachable that way, otherwise we will mistakenly reprocess this
- file if it is included later from the normal search path. */
- if (file->dir && start_dir->next == pfile->quote_include)
- {
- cpp_dir *d;
- cpp_dir *proper_start_dir = pfile->quote_include;
+ entry = search_cache (*hash_slot, file->dir);
+ if (entry)
+ break;
+ }
- for (d = proper_start_dir;; d = d->next)
- {
- if (d == pfile->bracket_include)
- proper_start_dir = d;
- if (d == 0)
- {
- proper_start_dir = 0;
- break;
- }
- /* file->dir->name will have a trailing slash. */
- if (!strncmp (d->name, file->dir->name, file->dir->len - 1))
- break;
- }
- if (proper_start_dir)
- start_dir = proper_start_dir;
+ if (entry)
+ {
+ /* Cache for START_DIR too, sharing the _cpp_file structure. */
+ free ((char *) file->name);
+ free (file);
+ file = entry->u.file;
+ }
+ else
+ {
+ /* This is a new file; put it in the list. */
+ file->next_file = pfile->all_files;
+ pfile->all_files = file;
}
- found:
/* Store this new result in the hash table. */
entry = new_file_hash_entry (pfile);
entry->next = *hash_slot;
if (file->fd == -1 && !open_file (file))
{
- open_file_failed (pfile, file);
+ open_file_failed (pfile, file, 0);
return false;
}
if (!dir)
return false;
- file = _cpp_find_file (pfile, fname, dir, false);
+ file = _cpp_find_file (pfile, fname, dir, false, angle_brackets);
/* Compensate for the increment in linemap_add. In the case of a
normal #include, we're currently at the start of the line
/* Could not open FILE. The complication is dependency output. */
static void
-open_file_failed (cpp_reader *pfile, _cpp_file *file)
+open_file_failed (cpp_reader *pfile, _cpp_file *file, int angle_brackets)
{
int sysp = pfile->line_table->highest_line > 1 && pfile->buffer ? pfile->buffer->sysp : 0;
- bool print_dep = CPP_OPTION (pfile, deps.style) > !!sysp;
+ bool print_dep = CPP_OPTION (pfile, deps.style) > (angle_brackets || !!sysp);
errno = file->err_no;
if (print_dep && CPP_OPTION (pfile, deps.missing_files) && errno == ENOENT)
static struct file_hash_entry *
search_cache (struct file_hash_entry *head, const cpp_dir *start_dir)
{
- struct file_hash_entry *p;
+ while (head && head->start_dir != start_dir)
+ head = head->next;
- /* Look for a file that was found from a search starting at the
- given location. */
- for (p = head; p; p = p->next)
- if (p->start_dir == start_dir)
- return p;
- return 0;
+ return head;
}
/* Allocate a new _cpp_file structure. */
void
_cpp_fake_include (cpp_reader *pfile, const char *fname)
{
- _cpp_find_file (pfile, fname, pfile->buffer->file->dir, true);
+ _cpp_find_file (pfile, fname, pfile->buffer->file->dir, true, 0);
}
/* Not everyone who wants to set system-header-ness on a buffer can
if (!dir)
return -1;
- file = _cpp_find_file (pfile, fname, dir, false);
+ file = _cpp_find_file (pfile, fname, dir, false, angle_brackets);
if (file->err_no)
return -1;
{
free ((void *) file->buffer);
file->buffer = NULL;
+ file->buffer_valid = false;
}
}
+/* Inteface to file statistics record in _cpp_file structure. */
+struct stat *
+_cpp_get_file_stat (_cpp_file *file)
+{
+ return &file->st;
+}
+
/* Set the include chain for "" to QUOTE, for <> to BRACKET. If
QUOTE_IGNORES_SOURCE_DIR, then "" includes do not look in the
directory of the including file.
if (!open_file (f))
{
- open_file_failed (pfile, f);
+ open_file_failed (pfile, f, 0);
return false;
}
ff = fdopen (f->fd, "rb");