aboutsummaryrefslogtreecommitdiff
path: root/gcc/cppfiles.c
diff options
context:
space:
mode:
authorZack Weinberg <zack@rabi.phys.columbia.edu>1998-12-07 13:35:20 +0000
committerDave Brolley <brolley@gcc.gnu.org>1998-12-07 08:35:20 -0500
commitf1a86df6cbc181439d3c1b402275110c9debd76d (patch)
tree8639ccd7c1c382473eaf051751bf1a983dde27b5 /gcc/cppfiles.c
parent93447205e549088d1d5208e82462b5f681030632 (diff)
downloadgcc-f1a86df6cbc181439d3c1b402275110c9debd76d.zip
gcc-f1a86df6cbc181439d3c1b402275110c9debd76d.tar.gz
gcc-f1a86df6cbc181439d3c1b402275110c9debd76d.tar.bz2
cpplib.h (struct cpp_buffer): Replace dir and dlen members with a struct file_name_list pointer.
1998-11-26 01:17 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu> * cpplib.h (struct cpp_buffer): Replace dir and dlen members with a struct file_name_list pointer. (struct cpp_reader): Add pointer to chain of `actual directory' include searchpath entries. (struct file_name_list): Add *alloc pointer for the sake of the actual-directory chain. Move definition of HOST_WIDE_INT here. (cpp_parse_escape): Change prototype to match changes in cppexp.c. * cppfiles.c (actual_directory): New function. (finclude): Use it to initialize the buffer's actual_dir entry. (find_include_file): We don't need to fix up max_include_len here. * cpplib.c (do_include): Don't allocate a file_name_list on the fly for current directory "" includes, use the one that's been preallocated in pfile->buffer->actual_dir. Hoist out duplicate code from the search_start selection logic. (cpp_reader_init): Initialize pfile->actual_dirs. Remove definition of HOST_WIDE_INT. Change calls to cpp_parse_escape to match changes in cppexp.c (note hardcoded MASK, which is safe since this is the source character set). * cppexp.c: Bring over changes to cpp_parse_escape from cccp.c to handle wide character constants in #if directives. The function now returns a HOST_WIDE_INT, and takes a third argument which is a binary mask for all legal values (0x00ff for 8-bit `char', 0xffff for 16-bit `wchar_t', etc.) Define MAX_CHAR_TYPE_MASK and MAX_WCHAR_TYPE_MASK. Change callers of cpp_parse_escape to match. [Fixes c-torture/execute/widechar-1.c] From-SVN: r24153
Diffstat (limited to 'gcc/cppfiles.c')
-rw-r--r--gcc/cppfiles.c89
1 files changed, 58 insertions, 31 deletions
diff --git a/gcc/cppfiles.c b/gcc/cppfiles.c
index 8a4a0ef..8c01cdd 100644
--- a/gcc/cppfiles.c
+++ b/gcc/cppfiles.c
@@ -42,6 +42,7 @@ static char *remap_filename PROTO ((cpp_reader *, char *,
struct file_name_list *));
static long safe_read PROTO ((int, char *, int));
static void simplify_pathname PROTO ((char *));
+static struct file_name_list *actual_directory PROTO ((cpp_reader *, char *));
#if 0
static void hack_vms_include_specification PROTO ((char *));
@@ -422,11 +423,6 @@ find_include_file (pfile, fname, search_start, ihash, before)
/* Search directory path, trying to open the file. */
- /* The first entry in the search list may be a buffer-specific entry,
- and its directory name may be longer than max_include_len. Adjust
- as appropriate. */
- if (pfile->max_include_len < search_start->nlen)
- pfile->max_include_len = search_start->nlen;
len = strlen (fname);
name = xmalloc (len + pfile->max_include_len + 2 + INCLUDE_LEN_FUDGE);
@@ -690,34 +686,11 @@ finclude (pfile, fd, ihash)
fp->colno = 1;
fp->cleanup = file_cleanup;
- /* The ->dir field is only used when ignore_srcdir is not in effect;
+ /* The ->actual_dir field is only used when ignore_srcdir is not in effect;
see do_include */
if (!CPP_OPTIONS (pfile)->ignore_srcdir)
- {
- char *last_slash;
- fp->dir = savestring (fp->fname);
- last_slash = rindex (fp->dir, '/');
- if (last_slash)
- {
- if (last_slash == fp->dir)
- {
- fp->dlen = 1;
- last_slash[1] = '\0';
- }
- else
- {
- fp->dlen = last_slash - fp->dir;
- *last_slash = '\0';
- }
- }
- else
- {
- fp->dir[0] = '.';
- fp->dir[1] = '\0';
- fp->dlen = 1;
- }
- }
-
+ fp->actual_dir = actual_directory (pfile, fp->fname);
+
if (S_ISREG (st.st_mode))
{
st_size = (size_t) st.st_size;
@@ -790,6 +763,60 @@ finclude (pfile, fd, ihash)
return 0;
}
+static struct file_name_list *
+actual_directory (pfile, fname)
+ cpp_reader *pfile;
+ char *fname;
+{
+ char *last_slash, *dir;
+ size_t dlen;
+ struct file_name_list *x;
+
+ dir = savestring (fname);
+ last_slash = rindex (dir, '/');
+ if (last_slash)
+ {
+ if (last_slash == dir)
+ {
+ dlen = 1;
+ last_slash[1] = '\0';
+ }
+ else
+ {
+ dlen = last_slash - dir;
+ *last_slash = '\0';
+ }
+ }
+ else
+ {
+ dir[0] = '.';
+ dir[1] = '\0';
+ dlen = 1;
+ }
+
+ if (dlen > pfile->max_include_len)
+ pfile->max_include_len = dlen;
+
+ for (x = pfile->actual_dirs; x; x = x->alloc)
+ if (!strcmp (x->name, dir))
+ {
+ free (dir);
+ return x;
+ }
+
+ /* Not found, make a new one. */
+ x = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
+ x->name = dir;
+ x->nlen = dlen;
+ x->next = CPP_OPTIONS (pfile)->quote_include;
+ x->alloc = pfile->actual_dirs;
+ x->sysp = 0;
+ x->name_map = NULL;
+
+ pfile->actual_dirs = x;
+ return x;
+}
+
/* Read LEN bytes at PTR from descriptor DESC, for file FILENAME,
retrying if necessary. If MAX_READ_LEN is defined, read at most
that bytes at a time. Return a negative value if an error occurs,