aboutsummaryrefslogtreecommitdiff
path: root/gcc/cppfiles.c
diff options
context:
space:
mode:
authorZack Weinberg <zack@wolery.cumb.org>2000-03-02 20:14:32 +0000
committerZack Weinberg <zack@gcc.gnu.org>2000-03-02 20:14:32 +0000
commitc45da1ca925d67685ca633b48a4ca1ec44dfaca1 (patch)
tree83b50be95e2db0783f35dfe9f8625210e9368a40 /gcc/cppfiles.c
parente97f22c9757e8c7bbf123b6ec1af68791f41d6fa (diff)
downloadgcc-c45da1ca925d67685ca633b48a4ca1ec44dfaca1.zip
gcc-c45da1ca925d67685ca633b48a4ca1ec44dfaca1.tar.gz
gcc-c45da1ca925d67685ca633b48a4ca1ec44dfaca1.tar.bz2
cppfiles.c (cpp_read_file): New function.
* cppfiles.c (cpp_read_file): New function. * cpphash.c (collect_expansion): Make sure to reset last_token to NORM when we hit a string. Handle trailing whitespace properly when the expansion is empty. (create_definition): Disable line commands while parsing the directive line. (dump_definition): If pfile->lineno == 0, output a line command ahead of the dump, and add a trailing newline. * cppinit.c (append_include_chain): Add fifth argument, which indicates whether or not system headers are C++ aware. (initialize_standard_includes): New function, broken out of read_and_prescan. Pass 'cxx_aware' value from the include_defaults_array on to append_include_chain. (dump_special_to_buffer): Const-ify char array. (builtin_array): Don't dump __BASE_FILE__. (cpp_start_read): Use cpp_read_file. Reorder code for clarity. Don't output line commands here for -D/-A/-U switches. Don't call deps_output for files included with -include or -imacros. * cpplib.c (do_define): Don't pay any attention to the second argument. (cpp_expand_to_buffer): Disable line commands while scanning. (output_line_command): Work in the file buffer. * cpplib.h: Remove no_record_file flag from struct cpp_reader. Fix formatting of comments. Prototype cpp_read_file. From-SVN: r32293
Diffstat (limited to 'gcc/cppfiles.c')
-rw-r--r--gcc/cppfiles.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/gcc/cppfiles.c b/gcc/cppfiles.c
index 6b0d919..add6272 100644
--- a/gcc/cppfiles.c
+++ b/gcc/cppfiles.c
@@ -609,6 +609,62 @@ remap_filename (pfile, name, loc)
return name;
}
+/* Push an input buffer and load it up with the contents of FNAME.
+ If FNAME is "" or NULL, read standard input. */
+int
+cpp_read_file (pfile, fname)
+ cpp_reader *pfile;
+ const char *fname;
+{
+ struct include_hash *ih_fake;
+ int f;
+
+ if (fname == NULL || *fname == 0)
+ {
+ fname = "";
+ f = 0;
+ }
+
+ /* Open the file in nonblocking mode, so we don't get stuck if
+ someone clever has asked cpp to process /dev/rmt0. finclude()
+ will check that we have a real file to work with. Also take
+ care not to acquire a controlling terminal by mistake (this can't
+ happen on sane systems, but paranoia is a virtue). */
+ else if ((f = open (fname, O_RDONLY|O_NONBLOCK|O_NOCTTY, 0666)) < 0)
+ {
+ cpp_notice_from_errno (pfile, fname);
+ return 0;
+ }
+
+ /* Push the buffer. */
+ if (!cpp_push_buffer (pfile, NULL, 0))
+ goto failed_push;
+
+ /* Gin up an include_hash structure for this file and feed it
+ to finclude. */
+
+ ih_fake = (struct include_hash *) xmalloc (sizeof (struct include_hash));
+ ih_fake->next = 0;
+ ih_fake->next_this_file = 0;
+ ih_fake->foundhere = ABSOLUTE_PATH; /* well sort of ... */
+ ih_fake->name = fname;
+ ih_fake->control_macro = 0;
+ ih_fake->buf = (char *)-1;
+ ih_fake->limit = 0;
+ if (!finclude (pfile, f, ih_fake))
+ goto failed_finclude;
+
+ return 1;
+
+ failed_finclude:
+ /* If finclude fails, it pops the buffer. */
+ free (ih_fake);
+ failed_push:
+ if (f)
+ close (f);
+ return 0;
+}
+
/* Read the contents of FD into the buffer on the top of PFILE's stack.
IHASH points to the include hash entry for the file associated with
FD.