summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobrien <obrien@FreeBSD.org>1999-08-27 11:02:42 +0000
committerobrien <obrien@FreeBSD.org>1999-08-27 11:02:42 +0000
commit550b040d681c06440843faf9eb124c7b847c012a (patch)
tree3229a94be2782af7342d4e10e960498582bac791
parentc8598bea3457510068816e9e7676b0c7c68c06e4 (diff)
downloadFreeBSD-src-550b040d681c06440843faf9eb124c7b847c012a.zip
FreeBSD-src-550b040d681c06440843faf9eb124c7b847c012a.tar.gz
Fix conflicts. This brings in rev 1.2 (FreeBSD native support -- do not
search the multitude of extended include file paths that do not exist) into EGCS 1.1.2.
-rw-r--r--contrib/gcc/cccp.c4088
1 files changed, 2228 insertions, 1860 deletions
diff --git a/contrib/gcc/cccp.c b/contrib/gcc/cccp.c
index 1e6bd40..02e6a2e 100644
--- a/contrib/gcc/cccp.c
+++ b/contrib/gcc/cccp.c
@@ -1,5 +1,5 @@
/* C Compatible Compiler Preprocessor (CCCP)
- Copyright (C) 1986, 87, 89, 92, 93, 94, 1995 Free Software Foundation, Inc.
+ Copyright (C) 1986, 87, 89, 92-97, 1998 Free Software Foundation, Inc.
Written by Paul Rubin, June 1986
Adapted to ANSI C, Richard Stallman, Jan 1987
@@ -16,249 +16,77 @@ GNU General Public License for more details.
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.
+Boston, MA 02111-1307, USA. */
- In other words, you are welcome to use, share and improve this program.
- You are forbidden to forbid anyone else to use, share and improve
- what you give them. Help stamp out software-hoarding! */
-
-typedef unsigned char U_CHAR;
-
-#ifdef EMACS
-#define NO_SHORTNAMES
-#include "../src/config.h"
-#ifdef open
-#undef open
-#undef read
-#undef write
-#endif /* open */
-#endif /* EMACS */
-
-/* The macro EMACS is defined when cpp is distributed as part of Emacs,
- for the sake of machines with limited C compilers. */
-#ifndef EMACS
#include "config.h"
-#endif /* not EMACS */
-
-#ifndef STANDARD_INCLUDE_DIR
-#define STANDARD_INCLUDE_DIR "/usr/include"
-#endif
-
-#ifndef LOCAL_INCLUDE_DIR
-#define LOCAL_INCLUDE_DIR "/usr/local/include"
-#endif
-
-#if 0 /* We can't get ptrdiff_t, so I arranged not to need PTR_INT_TYPE. */
#ifdef __STDC__
-#define PTR_INT_TYPE ptrdiff_t
+# include <stdarg.h>
#else
-#define PTR_INT_TYPE long
+# include <varargs.h>
#endif
-#endif /* 0 */
-#include "pcp.h"
+#define PRINTF_PROTO(ARGS, m, n) PVPROTO (ARGS) ATTRIBUTE_PRINTF(m, n)
-/* By default, colon separates directories in a path. */
-#ifndef PATH_SEPARATOR
-#define PATH_SEPARATOR ':'
-#endif
+#define PRINTF_PROTO_1(ARGS) PRINTF_PROTO(ARGS, 1, 2)
+#define PRINTF_PROTO_2(ARGS) PRINTF_PROTO(ARGS, 2, 3)
+#define PRINTF_PROTO_3(ARGS) PRINTF_PROTO(ARGS, 3, 4)
+#define PRINTF_PROTO_4(ARGS) PRINTF_PROTO(ARGS, 4, 5)
-#include <sys/types.h>
+#include "system.h"
#include <sys/stat.h>
-#include <ctype.h>
-#include <stdio.h>
#include <signal.h>
-/* The following symbols should be autoconfigured:
- HAVE_FCNTL_H
- HAVE_STDLIB_H
- HAVE_SYS_TIME_H
- HAVE_UNISTD_H
- STDC_HEADERS
- TIME_WITH_SYS_TIME
- In the mean time, we'll get by with approximations based
- on existing GCC configuration symbols. */
-
-#ifdef POSIX
-# ifndef HAVE_STDLIB_H
-# define HAVE_STDLIB_H 1
-# endif
-# ifndef HAVE_UNISTD_H
-# define HAVE_UNISTD_H 1
-# endif
-# ifndef STDC_HEADERS
-# define STDC_HEADERS 1
-# endif
-#endif /* defined (POSIX) */
-
-#if defined (POSIX) || (defined (USG) && !defined (VMS))
-# ifndef HAVE_FCNTL_H
-# define HAVE_FCNTL_H 1
-# endif
-#endif
-
-#ifndef RLIMIT_STACK
-# include <time.h>
-#else
-# if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
-# else
-# if HAVE_SYS_TIME_H
-# include <sys/time.h>
-# else
-# include <time.h>
-# endif
-# endif
+#ifdef HAVE_SYS_RESOURCE_H
# include <sys/resource.h>
#endif
-#if HAVE_FCNTL_H
-# include <fcntl.h>
-#endif
+typedef unsigned char U_CHAR;
-/* This defines "errno" properly for VMS, and gives us EACCES. */
-#include <errno.h>
+#include "gansidecl.h"
+#include "pcp.h"
-#if HAVE_STDLIB_H
-# include <stdlib.h>
-#else
-char *getenv ();
+#ifndef GET_ENVIRONMENT
+#define GET_ENVIRONMENT(ENV_VALUE,ENV_NAME) ENV_VALUE = getenv (ENV_NAME)
#endif
-#if STDC_HEADERS
-# include <string.h>
-# ifndef bcmp
-# define bcmp(a, b, n) memcmp (a, b, n)
-# endif
-# ifndef bcopy
-# define bcopy(s, d, n) memcpy (d, s, n)
-# endif
-# ifndef bzero
-# define bzero(d, n) memset (d, 0, n)
-# endif
-#else /* !STDC_HEADERS */
-char *index ();
-char *rindex ();
-
-# if !defined (BSTRING) && (defined (USG) || defined (VMS))
-
-# ifndef bcmp
-# define bcmp my_bcmp
-static int
-my_bcmp (a, b, n)
- register char *a;
- register char *b;
- register unsigned n;
-{
- while (n-- > 0)
- if (*a++ != *b++)
- return 1;
-
- return 0;
-}
-# endif /* !defined (bcmp) */
-
-# ifndef bcopy
-# define bcopy my_bcopy
-static void
-my_bcopy (s, d, n)
- register char *s;
- register char *d;
- register unsigned n;
-{
- while (n-- > 0)
- *d++ = *s++;
-}
-# endif /* !defined (bcopy) */
-
-# ifndef bzero
-# define bzero my_bzero
-static void
-my_bzero (b, length)
- register char *b;
- register unsigned length;
-{
- while (length-- > 0)
- *b++ = 0;
-}
-# endif /* !defined (bzero) */
-
-# endif /* !defined (BSTRING) && (defined (USG) || defined (VMS)) */
-#endif /* ! STDC_HEADERS */
-
-#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 6)
-# define __attribute__(x)
+#ifndef STANDARD_INCLUDE_DIR
+# define STANDARD_INCLUDE_DIR "/usr/include"
#endif
-#ifndef PROTO
-# if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
-# define PROTO(ARGS) ARGS
-# else
-# define PROTO(ARGS) ()
-# endif
+/* By default, colon separates directories in a path. */
+#ifndef PATH_SEPARATOR
+# define PATH_SEPARATOR ':'
#endif
-#if defined (__STDC__) && defined (HAVE_VPRINTF)
-# include <stdarg.h>
-# define VA_START(va_list, var) va_start (va_list, var)
-# define PRINTF_ALIST(msg) char *msg, ...
-# define PRINTF_DCL(msg)
-# define PRINTF_PROTO(ARGS, m, n) PROTO (ARGS) __attribute__ ((format (printf, m, n)))
+/* By default, the suffix for object files is ".o". */
+#ifdef OBJECT_SUFFIX
+# define HAVE_OBJECT_SUFFIX
#else
-# include <varargs.h>
-# define VA_START(va_list, var) va_start (va_list)
-# define PRINTF_ALIST(msg) msg, va_alist
-# define PRINTF_DCL(msg) char *msg; va_dcl
-# define PRINTF_PROTO(ARGS, m, n) () __attribute__ ((format (printf, m, n)))
-# define vfprintf(file, msg, args) \
- { \
- char *a0 = va_arg(args, char *); \
- char *a1 = va_arg(args, char *); \
- char *a2 = va_arg(args, char *); \
- char *a3 = va_arg(args, char *); \
- fprintf (file, msg, a0, a1, a2, a3); \
- }
-#endif
-
-#define PRINTF_PROTO_1(ARGS) PRINTF_PROTO(ARGS, 1, 2)
-#define PRINTF_PROTO_2(ARGS) PRINTF_PROTO(ARGS, 2, 3)
-#define PRINTF_PROTO_3(ARGS) PRINTF_PROTO(ARGS, 3, 4)
-
-#if HAVE_UNISTD_H
-# include <unistd.h>
+# define OBJECT_SUFFIX ".o"
#endif
/* VMS-specific definitions */
#ifdef VMS
#include <descrip.h>
-#define O_RDONLY 0 /* Open arg for Read/Only */
-#define O_WRONLY 1 /* Open arg for Write/Only */
-#define read(fd,buf,size) VMS_read (fd,buf,size)
-#define write(fd,buf,size) VMS_write (fd,buf,size)
+#include <ssdef.h>
+#include <syidef.h>
#define open(fname,mode,prot) VMS_open (fname,mode,prot)
#define fopen(fname,mode) VMS_fopen (fname,mode)
#define freopen(fname,mode,ofile) VMS_freopen (fname,mode,ofile)
-#define strncat(dst,src,cnt) VMS_strncat (dst,src,cnt)
#define fstat(fd,stbuf) VMS_fstat (fd,stbuf)
static int VMS_fstat (), VMS_stat ();
-static char * VMS_strncat ();
-static int VMS_read ();
-static int VMS_write ();
static int VMS_open ();
-static FILE * VMS_fopen ();
-static FILE * VMS_freopen ();
-static void hack_vms_include_specification ();
-typedef struct { unsigned :16, :16, :16; } vms_ino_t;
-#define ino_t vms_ino_t
-#define INCLUDE_LEN_FUDGE 10 /* leave room for VMS syntax conversion */
-#ifdef __GNUC__
-#define BSTRING /* VMS/GCC supplies the bstring routines */
-#endif /* __GNUC__ */
+static FILE *VMS_fopen ();
+static FILE *VMS_freopen ();
+static int hack_vms_include_specification ();
+#define INO_T_EQ(a, b) (!bcmp((char *) &(a), (char *) &(b), sizeof (a)))
+#define INO_T_HASH(a) 0
+#define INCLUDE_LEN_FUDGE 12 /* leave room for VMS syntax conversion */
#endif /* VMS */
-#ifndef O_RDONLY
-#define O_RDONLY 0
+/* Windows does not natively support inodes, and neither does MSDOS. */
+#if (defined (_WIN32) && ! defined (CYGWIN32)) || defined (__MSDOS__)
+#define INO_T_EQ(a, b) 0
#endif
#undef MIN
@@ -266,18 +94,24 @@ typedef struct { unsigned :16, :16, :16; } vms_ino_t;
#define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
#define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
-/* Find the largest host integer type and set its size and type. */
-
-#ifndef HOST_BITS_PER_WIDE_INT
-
-#if HOST_BITS_PER_LONG > HOST_BITS_PER_INT
-#define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_LONG
-#define HOST_WIDE_INT long
-#else
-#define HOST_BITS_PER_WIDE_INT HOST_BITS_PER_INT
-#define HOST_WIDE_INT int
-#endif
+/* Find the largest host integer type and set its size and type.
+ Watch out: on some crazy hosts `long' is shorter than `int'. */
+#ifndef HOST_WIDE_INT
+# if HAVE_INTTYPES_H
+# include <inttypes.h>
+# define HOST_WIDE_INT intmax_t
+# else
+# if (HOST_BITS_PER_LONG <= HOST_BITS_PER_INT && HOST_BITS_PER_LONGLONG <= HOST_BITS_PER_INT)
+# define HOST_WIDE_INT int
+# else
+# if (HOST_BITS_PER_LONGLONG <= HOST_BITS_PER_LONG || ! (defined LONG_LONG_MAX || defined LLONG_MAX))
+# define HOST_WIDE_INT long
+# else
+# define HOST_WIDE_INT long long
+# endif
+# endif
+# endif
#endif
#ifndef S_ISREG
@@ -288,22 +122,12 @@ typedef struct { unsigned :16, :16, :16; } vms_ino_t;
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#endif
-/* Define a generic NULL if one hasn't already been defined. */
-
-#ifndef NULL
-#define NULL 0
-#endif
-
-#ifndef GENERIC_PTR
-#if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
-#define GENERIC_PTR void *
-#else
-#define GENERIC_PTR char *
-#endif
+#ifndef INO_T_EQ
+#define INO_T_EQ(a, b) ((a) == (b))
#endif
-#ifndef NULL_PTR
-#define NULL_PTR ((GENERIC_PTR)0)
+#ifndef INO_T_HASH
+#define INO_T_HASH(a) (a)
#endif
#ifndef INCLUDE_LEN_FUDGE
@@ -313,26 +137,9 @@ typedef struct { unsigned :16, :16, :16; } vms_ino_t;
/* External declarations. */
extern char *version_string;
-#ifndef VMS
-#ifndef HAVE_STRERROR
-extern int sys_nerr;
-#if defined(bsd4_4)
-extern const char *const sys_errlist[];
-#else
-extern char *sys_errlist[];
-#endif
-#else /* HAVE_STRERROR */
-char *strerror ();
-#endif
-#else /* VMS */
-char *strerror (int,...);
-#endif
-int parse_escape PROTO((char **));
-HOST_WIDE_INT parse_c_expression PROTO((char *));
-
-#ifndef errno
-extern int errno;
-#endif
+extern char *update_path PROTO((char *, char *));
+HOST_WIDE_INT parse_escape PROTO((char **, HOST_WIDE_INT));
+HOST_WIDE_INT parse_c_expression PROTO((char *, int));
/* Name under which this program was invoked. */
@@ -414,6 +221,10 @@ static enum {dump_none, dump_only, dump_names, dump_definitions}
where they are defined. */
static int debug_output = 0;
+/* Nonzero means pass #include lines through to the output,
+ even if they are ifdefed out. */
+static int dump_includes;
+
/* Nonzero indicates special processing used by the pcp program. The
special effects of this mode are:
@@ -429,7 +240,7 @@ static FILE *pcp_outfile;
/* Nonzero means we are inside an IF during a -pcp run. In this mode
macro expansion is done, and preconditions are output for all macro
- uses requiring them. */
+ uses requiring them. */
static int pcp_inside_if;
/* Nonzero means never to include precompiled files.
@@ -449,7 +260,8 @@ static int pedantic_errors;
static int inhibit_warnings = 0;
-/* Nonzero means warn if slash-star appears in a comment. */
+/* Nonzero means warn if slash-star appears in a slash-star comment,
+ or if newline-backslash appears in a slash-slash comment. */
static int warn_comments;
@@ -462,6 +274,10 @@ static int warn_stringify;
static int warn_trigraphs;
+/* Nonzero means warn if undefined identifiers are evaluated in an #if. */
+
+static int warn_undef;
+
/* Nonzero means warn if #import is used. */
static int warn_import = 1;
@@ -474,12 +290,19 @@ static int warnings_are_errors;
int traditional;
+/* Nonzero for the 1989 C Standard, including corrigenda and amendments. */
+
+int c89;
+
/* Nonzero causes output not to be done,
but directives such as #define that have side effects
are still obeyed. */
static int no_output;
+/* Nonzero means we should look for header.gcc files that remap file names. */
+static int remap;
+
/* Nonzero means this file was included with a -imacros or -include
command line and should not be recorded as an include file. */
@@ -505,6 +328,10 @@ static struct file_buf {
char *fname;
/* Filename specified with #line directive. */
char *nominal_fname;
+ /* The length of nominal_fname, which may contain embedded NULs. */
+ size_t nominal_fname_len;
+ /* Include file description. */
+ struct include_file *inc;
/* Record where in the search path this file was found.
For #include_next. */
struct file_name_list *dir;
@@ -521,7 +348,7 @@ static struct file_buf {
struct if_stack *if_stack;
/* Object to be freed at end of input at this level. */
U_CHAR *free_ptr;
- /* True if this is a header file included using <FILENAME>. */
+ /* True if this is a system header file; see is_system_include. */
char system_header_p;
} instack[INPUT_STACK_MAX];
@@ -546,7 +373,7 @@ typedef struct file_buf FILE_BUF;
/* The output buffer. Its LENGTH field is the amount of room allocated
for the buffer, not the number of chars actually present. To get
- that, subtract outbuf.buf from outbuf.bufp. */
+ that, subtract outbuf.buf from outbuf.bufp. */
#define OUTBUF_SIZE 10 /* initial size of output buffer */
static FILE_BUF outbuf;
@@ -561,25 +388,28 @@ static FILE_BUF outbuf;
struct file_name_list
{
struct file_name_list *next;
- char *fname;
- /* If the following is nonzero, it is a macro name.
- Don't include the file again if that macro is defined. */
- U_CHAR *control_macro;
- /* If the following is nonzero, it is a C-language system include
+ /* If the following is 1, it is a C-language system include
directory. */
int c_system_include_path;
/* Mapping of file names for this directory. */
struct file_name_map *name_map;
/* Non-zero if name_map is valid. */
int got_name_map;
+ /* The include directory status. */
+ struct stat st;
+ /* The include prefix: "" denotes the working directory,
+ otherwise fname must end in '/'.
+ The actual size is dynamically allocated. */
+ char fname[1];
};
-/* #include "file" looks in source file dir, then stack. */
-/* #include <file> just looks in the stack. */
-/* -I directories are added to the end, then the defaults are added. */
+/* #include "file" looks in source file dir, then stack. */
+/* #include <file> just looks in the stack. */
+/* -I directories are added to the end, then the defaults are added. */
/* The */
static struct default_include {
char *fname; /* The name of the directory. */
+ char *component; /* The component containing the directory */
int cplusplus; /* Only look here if we're compiling C++. */
int cxx_aware; /* Includes in this directory don't need to
be wrapped in extern "C" when compiling
@@ -590,33 +420,43 @@ static struct default_include {
#else
= {
/* Pick up GNU C++ specific include files. */
- { GPLUSPLUS_INCLUDE_DIR, 1, 1 },
+ { GPLUSPLUS_INCLUDE_DIR, "G++", 1, 1 },
+ { OLD_GPLUSPLUS_INCLUDE_DIR, 0, 1, 1 },
#ifdef CROSS_COMPILE
/* This is the dir for fixincludes. Put it just before
the files that we fix. */
- { GCC_INCLUDE_DIR, 0, 0 },
+ { GCC_INCLUDE_DIR, "GCC", 0, 0 },
/* For cross-compilation, this dir name is generated
automatically in Makefile.in. */
- { CROSS_INCLUDE_DIR, 0, 0 },
+ { CROSS_INCLUDE_DIR, "GCC", 0, 0 },
+#ifdef TOOL_INCLUDE_DIR
/* This is another place that the target system's headers might be. */
- { TOOL_INCLUDE_DIR, 0, 0 },
+ { TOOL_INCLUDE_DIR, "BINUTILS", 0, 0 },
+#endif
#else /* not CROSS_COMPILE */
+#ifdef LOCAL_INCLUDE_DIR
/* This should be /usr/local/include and should come before
the fixincludes-fixed header files. */
- { LOCAL_INCLUDE_DIR, 0, 1 },
+ { LOCAL_INCLUDE_DIR, 0, 0, 1 },
+#endif
+#ifdef TOOL_INCLUDE_DIR
/* This is here ahead of GCC_INCLUDE_DIR because assert.h goes here.
Likewise, behind LOCAL_INCLUDE_DIR, where glibc puts its assert.h. */
- { TOOL_INCLUDE_DIR, 0, 0 },
+ { TOOL_INCLUDE_DIR, "BINUTILS", 0, 0 },
+#endif
/* This is the dir for fixincludes. Put it just before
the files that we fix. */
- { GCC_INCLUDE_DIR, 0, 0 },
+ { GCC_INCLUDE_DIR, "GCC", 0, 0 },
/* Some systems have an extra dir of include files. */
#ifdef SYSTEM_INCLUDE_DIR
- { SYSTEM_INCLUDE_DIR, 0, 0 },
+ { SYSTEM_INCLUDE_DIR, 0, 0, 0 },
#endif
- { STANDARD_INCLUDE_DIR, 0, 0 },
+#ifndef STANDARD_INCLUDE_COMPONENT
+#define STANDARD_INCLUDE_COMPONENT 0
+#endif
+ { STANDARD_INCLUDE_DIR, STANDARD_INCLUDE_COMPONENT, 0, 0 },
#endif /* not CROSS_COMPILE */
- { 0, 0, 0 }
+ { 0, 0, 0, 0 }
};
#endif /* no INCLUDE_DEFAULTS */
@@ -643,18 +483,33 @@ static struct file_name_list *last_after_include = 0; /* Last in chain */
static struct file_name_list *before_system = 0;
static struct file_name_list *last_before_system = 0; /* Last in chain */
-/* List of included files that contained #pragma once. */
-static struct file_name_list *dont_repeat_files = 0;
-
-/* List of other included files.
- If ->control_macro if nonzero, the file had a #ifndef
- around the entire contents, and ->control_macro gives the macro name. */
-static struct file_name_list *all_include_files = 0;
-
/* Directory prefix that should replace `/usr' in the standard
include file directories. */
static char *include_prefix;
+/* Maintain and search list of included files. */
+
+struct include_file {
+ struct include_file *next; /* for include_hashtab */
+ struct include_file *next_ino; /* for include_ino_hashtab */
+ char *fname;
+ /* If the following is the empty string, it means #pragma once
+ was seen in this include file, or #import was applied to the file.
+ Otherwise, if it is nonzero, it is a macro name.
+ Don't include the file again if that macro is defined. */
+ U_CHAR *control_macro;
+ /* Nonzero if the dependency on this include file has been output. */
+ int deps_output;
+ struct stat st;
+};
+
+/* Hash tables of files already included with #include or #import.
+ include_hashtab is by full name; include_ino_hashtab is by inode number. */
+
+#define INCLUDE_HASHSIZE 61
+static struct include_file *include_hashtab[INCLUDE_HASHSIZE];
+static struct include_file *include_ino_hashtab[INCLUDE_HASHSIZE];
+
/* Global list of strings read in from precompiled files. This list
is kept in the order the strings are read in, with new strings being
added at the end through stringlist_tailp. We use this list to output
@@ -702,7 +557,7 @@ enum sharp_token_type {
#define f(x) x+x+x+x+x+x+x would have replacement text "++++++" and
pattern list
{ (0, 1), (1, 1), (1, 1), ..., (1, 1), NULL }
- where (x, y) means (nchars, argno). */
+ where (x, y) means (nchars, argno). */
typedef struct definition DEFINITION;
struct definition {
@@ -713,6 +568,7 @@ struct definition {
U_CHAR *expansion;
int line; /* Line number of definition */
char *file; /* File of definition */
+ size_t file_len; /* Length of file (which can contain NULs) */
char rest_args; /* Nonzero if last arg. absorbs the rest */
struct reflist {
struct reflist *next;
@@ -736,7 +592,7 @@ struct definition {
};
/* different kinds of things that can appear in the value field
- of a hash node. Actually, this may be useless now. */
+ of a hash node. Actually, this may be useless now. */
union hashval {
char *cpval;
DEFINITION *defn;
@@ -763,7 +619,7 @@ static char rest_extension[] = "...";
plus some special tokens like __LINE__ (these each have their own
type, and the appropriate code is run when that type of node is seen.
It does not contain control words like "#define", which are recognized
- by a separate piece of code. */
+ by a separate piece of code. */
/* different flavors of hash nodes --- also used in keyword table */
enum node_type {
@@ -812,7 +668,7 @@ struct hashnode {
struct hashnode *prev;
struct hashnode **bucket_hdr; /* also, a back pointer to this node's hash
chain is kept, in case the node is the head
- of the chain and gets deleted. */
+ of the chain and gets deleted. */
enum node_type type; /* type of special token */
int length; /* length of token, for quick comparison */
U_CHAR *name; /* the actual name */
@@ -826,7 +682,7 @@ typedef struct hashnode HASHNODE;
loop computes the hash value `on the fly' for most tokens,
in order to avoid the overhead of a lot of procedure calls to
the hashf () function. Hashf () only exists for the sake of
- politeness, for use when speed isn't so important. */
+ politeness, for use when speed isn't so important. */
#define HASHSIZE 1403
static HASHNODE *hashtab[HASHSIZE];
@@ -900,7 +756,7 @@ struct assertion_hashnode {
struct assertion_hashnode *prev;
/* also, a back pointer to this node's hash
chain is kept, in case the node is the head
- of the chain and gets deleted. */
+ of the chain and gets deleted. */
struct assertion_hashnode **bucket_hdr;
int length; /* length of token, for quick comparison */
U_CHAR *name; /* the actual name */
@@ -915,7 +771,7 @@ typedef struct assertion_hashnode ASSERTION_HASHNODE;
loop computes the hash value `on the fly' for most tokens,
in order to avoid the overhead of a lot of procedure calls to
the hashf function. hashf only exists for the sake of
- politeness, for use when speed isn't so important. */
+ politeness, for use when speed isn't so important. */
#define ASSERTION_HASHSIZE 37
static ASSERTION_HASHNODE *assertion_hashtab[ASSERTION_HASHSIZE];
@@ -932,12 +788,12 @@ struct directive {
int length; /* Length of name */
int (*func) DO_PROTO; /* Function to handle directive */
char *name; /* Name of directive */
- enum node_type type; /* Code which describes which directive. */
- char angle_brackets; /* Nonzero => <...> is special. */
- char traditional_comments; /* Nonzero: keep comments if -traditional. */
- char pass_thru; /* Copy preprocessed directive to output file. */
+ enum node_type type; /* Code which describes which directive. */
};
+#define IS_INCLUDE_DIRECTIVE_TYPE(t) \
+((int) T_INCLUDE <= (int) (t) && (int) (t) <= (int) T_IMPORT)
+
/* These functions are declared to return int instead of void since they
are going to be placed in the table and some old compilers have trouble with
pointers to functions returning void. */
@@ -964,7 +820,7 @@ static int do_xifdef DO_PROTO;
/* Here is the actual list of #-directives, most-often-used first. */
static struct directive directive_table[] = {
- { 6, do_define, "define", T_DEFINE, 0, 1},
+ { 6, do_define, "define", T_DEFINE},
{ 2, do_if, "if", T_IF},
{ 5, do_xifdef, "ifdef", T_IFDEF},
{ 6, do_xifdef, "ifndef", T_IFNDEF},
@@ -972,16 +828,16 @@ static struct directive directive_table[] = {
{ 4, do_else, "else", T_ELSE},
{ 4, do_elif, "elif", T_ELIF},
{ 4, do_line, "line", T_LINE},
- { 7, do_include, "include", T_INCLUDE, 1},
- { 12, do_include, "include_next", T_INCLUDE_NEXT, 1},
- { 6, do_include, "import", T_IMPORT, 1},
+ { 7, do_include, "include", T_INCLUDE},
+ { 12, do_include, "include_next", T_INCLUDE_NEXT},
+ { 6, do_include, "import", T_IMPORT},
{ 5, do_undef, "undef", T_UNDEF},
{ 5, do_error, "error", T_ERROR},
{ 7, do_warning, "warning", T_WARNING},
#ifdef SCCS_DIRECTIVE
{ 4, do_sccs, "sccs", T_SCCS},
#endif
- { 6, do_pragma, "pragma", T_PRAGMA, 0, 0, 1},
+ { 6, do_pragma, "pragma", T_PRAGMA},
{ 5, do_ident, "ident", T_IDENT},
{ 6, do_assert, "assert", T_ASSERT},
{ 8, do_unassert, "unassert", T_UNASSERT},
@@ -992,14 +848,14 @@ static struct directive directive_table[] = {
this points to the # (or the : of the %:) that started the directive. */
U_CHAR *directive_start;
-/* table to tell if char can be part of a C identifier. */
+/* table to tell if char can be part of a C identifier. */
U_CHAR is_idchar[256];
-/* table to tell if char can be first char of a c identifier. */
+/* table to tell if char can be first char of a c identifier. */
U_CHAR is_idstart[256];
/* table to tell if c is horizontal space. */
-U_CHAR is_hor_space[256];
+static U_CHAR is_hor_space[256];
/* table to tell if c is horizontal or vertical space. */
-static U_CHAR is_space[256];
+U_CHAR is_space[256];
/* names of some characters */
static char *char_name[256];
@@ -1011,18 +867,6 @@ static int errors = 0; /* Error counter for exit code */
/* Name of output file, for error messages. */
static char *out_fname;
-/* Zero means dollar signs are punctuation.
- -$ stores 0; -traditional may store 1. Default is 1 for VMS, 0 otherwise.
- This must be 0 for correct processing of this ANSI C program:
- #define foo(a) #a
- #define lose(b) foo (b)
- #define test$
- lose (test) */
-static int dollars_in_ident;
-#ifndef DOLLARS_IN_IDENTIFIERS
-#define DOLLARS_IN_IDENTIFIERS 1
-#endif
-
/* Stack of conditionals currently in progress
(including both successful and failing conditionals). */
@@ -1030,6 +874,7 @@ static int dollars_in_ident;
struct if_stack {
struct if_stack *next; /* for chaining to the next stack frame */
char *fname; /* copied from input when frame is made */
+ size_t fname_len; /* similarly */
int lineno; /* similarly */
int if_succeeded; /* true if a leg of this if-group
has been passed through rescan */
@@ -1058,6 +903,7 @@ static int ignore_srcdir;
static int safe_read PROTO((int, char *, int));
static void safe_write PROTO((int, char *, int));
+static void eprint_string PROTO((char *, size_t));
int main PROTO((int, char **));
@@ -1081,22 +927,21 @@ static int handle_directive PROTO((FILE_BUF *, FILE_BUF *));
static struct tm *timestamp PROTO((void));
static void special_symbol PROTO((HASHNODE *, FILE_BUF *));
-static int redundant_include_p PROTO((char *));
static int is_system_include PROTO((char *));
-static char *skip_redundant_dir_prefix PROTO((char *));
+static char *base_name PROTO((char *));
+static int absolute_filename PROTO((char *));
+static size_t simplify_filename PROTO((char *));
static char *read_filename_string PROTO((int, FILE *));
static struct file_name_map *read_name_map PROTO((char *));
-static int open_include_file PROTO((char *, struct file_name_list *));
-
-static void finclude PROTO((int, char *, FILE_BUF *, int, struct file_name_list *));
-static void record_control_macro PROTO((char *, U_CHAR *));
+static int open_include_file PROTO((char *, struct file_name_list *, U_CHAR *, struct include_file **));
+static char *remap_include_file PROTO((char *, struct file_name_list *));
+static int lookup_ino_include PROTO((struct include_file *));
-static int import_hash PROTO((char *));
-static int lookup_import PROTO((char *, struct file_name_list *));
-static void add_import PROTO((int, char *));
+static void finclude PROTO((int, struct include_file *, FILE_BUF *, int, struct file_name_list *));
+static void record_control_macro PROTO((struct include_file *, U_CHAR *));
-static char *check_precompiled PROTO((int, char *, char **));
+static char *check_precompiled PROTO((int, struct stat *, char *, char **));
static int check_preconditions PROTO((char *));
static void pcfinclude PROTO((U_CHAR *, U_CHAR *, U_CHAR *, FILE_BUF *));
static void pcstring_used PROTO((HASHNODE *));
@@ -1126,11 +971,11 @@ static void do_once PROTO((void));
static HOST_WIDE_INT eval_if_expression PROTO((U_CHAR *, int));
static void conditional_skip PROTO((FILE_BUF *, int, enum node_type, U_CHAR *, FILE_BUF *));
static void skip_if_group PROTO((FILE_BUF *, int, FILE_BUF *));
-static void validate_else PROTO((U_CHAR *));
+static void validate_else PROTO((U_CHAR *, U_CHAR *));
static U_CHAR *skip_to_end_of_comment PROTO((FILE_BUF *, int *, int));
static U_CHAR *skip_quoted_string PROTO((U_CHAR *, U_CHAR *, int, int *, int *, int *));
-static char *quote_string PROTO((char *, char *));
+static char *quote_string PROTO((char *, char *, size_t));
static U_CHAR *skip_paren_group PROTO((FILE_BUF *));
/* Last arg to output_line_directive. */
@@ -1142,13 +987,13 @@ static void macroexpand PROTO((HASHNODE *, FILE_BUF *));
struct argdata;
static char *macarg PROTO((struct argdata *, int));
-static U_CHAR *macarg1 PROTO((U_CHAR *, U_CHAR *, int *, int *, int *, int));
+static U_CHAR *macarg1 PROTO((U_CHAR *, U_CHAR *, struct hashnode *, int *, int *, int *, int));
static int discard_comments PROTO((U_CHAR *, int, int));
static int change_newlines PROTO((U_CHAR *, int));
-char *my_strerror PROTO((int));
+static char *my_strerror PROTO((int));
void error PRINTF_PROTO_1((char *, ...));
static void verror PROTO((char *, va_list));
static void error_from_errno PROTO((char *));
@@ -1160,7 +1005,7 @@ static void vwarning_with_line PROTO((int, char *, va_list));
static void warning_with_line PRINTF_PROTO_2((int, char *, ...));
void pedwarn PRINTF_PROTO_1((char *, ...));
void pedwarn_with_line PRINTF_PROTO_2((int, char *, ...));
-static void pedwarn_with_file_and_line PRINTF_PROTO_3((char *, int, char *, ...));
+static void pedwarn_with_file_and_line PRINTF_PROTO_4((char *, size_t, int, char *, ...));
static void print_containing_files PROTO((void));
@@ -1185,8 +1030,10 @@ static void make_undef PROTO((char *, FILE_BUF *));
static void make_assertion PROTO((char *, char *));
+static struct file_name_list *new_include_prefix PROTO((struct file_name_list *, char *, char *, char *));
static void append_include_chain PROTO((struct file_name_list *, struct file_name_list *));
+static int quote_string_for_make PROTO((char *, char *));
static void deps_output PROTO((char *, int));
static void fatal PRINTF_PROTO_1((char *, ...)) __attribute__ ((noreturn));
@@ -1200,11 +1047,11 @@ GENERIC_PTR xmalloc PROTO((size_t));
static GENERIC_PTR xrealloc PROTO((GENERIC_PTR, size_t));
static GENERIC_PTR xcalloc PROTO((size_t, size_t));
static char *savestring PROTO((char *));
-
-static int file_size_and_mode PROTO((int, int *, long int *));
+static void print_help PROTO((void));
/* Read LEN bytes at PTR from descriptor DESC, for file FILENAME,
- retrying if necessary. Return a negative value if an error occurs,
+ 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,
otherwise return the actual number of bytes read,
which must be LEN unless end-of-file was reached. */
@@ -1214,9 +1061,16 @@ safe_read (desc, ptr, len)
char *ptr;
int len;
{
- int left = len;
+ int left, rcount, nchars;
+
+ left = len;
while (left > 0) {
- int nchars = read (desc, ptr, left);
+ rcount = left;
+#ifdef MAX_READ_LEN
+ if (rcount > MAX_READ_LEN)
+ rcount = MAX_READ_LEN;
+#endif
+ nchars = read (desc, ptr, rcount);
if (nchars < 0)
{
#ifdef EINTR
@@ -1234,7 +1088,8 @@ safe_read (desc, ptr, len)
}
/* Write LEN bytes at PTR to descriptor DESC,
- retrying if necessary, and treating any real error as fatal. */
+ retrying if necessary, and treating any real error as fatal.
+ If MAX_WRITE_LEN is defined, write at most that many bytes at a time. */
static void
safe_write (desc, ptr, len)
@@ -1242,8 +1097,15 @@ safe_write (desc, ptr, len)
char *ptr;
int len;
{
+ int wcount, written;
+
while (len > 0) {
- int written = write (desc, ptr, len);
+ wcount = len;
+#ifdef MAX_WRITE_LEN
+ if (wcount > MAX_WRITE_LEN)
+ wcount = MAX_WRITE_LEN;
+#endif
+ written = write (desc, ptr, wcount);
if (written < 0)
{
#ifdef EINTR
@@ -1256,14 +1118,108 @@ safe_write (desc, ptr, len)
len -= written;
}
}
+
+/* Print a string to stderr, with extra handling in case it contains
+ embedded NUL characters. Any present are written as is.
+
+ Using fwrite for this purpose produces undesireable results on VMS
+ when stderr happens to be a record oriented file, such as a batch log
+ file, rather than a stream oriented one. */
+
+static void
+eprint_string (string, length)
+ char *string;
+ size_t length;
+{
+ size_t segment_length;
+
+ do {
+ fprintf(stderr, "%s", string);
+ length -= (segment_length = strlen(string));
+ if (length > 0)
+ {
+ fputc('\0', stderr);
+ length -= 1;
+ /* Advance past the portion which has already been printed. */
+ string += segment_length + 1;
+ }
+ } while (length > 0);
+}
+
+
+static void
+print_help ()
+{
+ printf ("Usage: %s [switches] input output\n", progname);
+ printf ("Switches:\n");
+ printf (" -include <file> Include the contents of <file> before other files\n");
+ printf (" -imacros <file> Accept definition of marcos in <file>\n");
+ printf (" -iprefix <path> Specify <path> as a prefix for next two options\n");
+ printf (" -iwithprefix <dir> Add <dir> to the end of the system include paths\n");
+ printf (" -iwithprefixbefore <dir> Add <dir> to the end of the main include paths\n");
+ printf (" -isystem <dir> Add <dir> to the start of the system include paths\n");
+ printf (" -idirafter <dir> Add <dir> to the end of the system include paths\n");
+ printf (" -I <dir> Add <dir> to the end of the main include paths\n");
+ printf (" -nostdinc Do not search the system include directories\n");
+ printf (" -nostdinc++ Do not search the system include directories for C++\n");
+ printf (" -o <file> Put output into <file>\n");
+ printf (" -pedantic Issue all warnings demanded by strict ANSI C\n");
+ printf (" -traditional Follow K&R pre-processor behaviour\n");
+ printf (" -trigraphs Support ANSI C trigraphs\n");
+ printf (" -lang-c Assume that the input sources are in C\n");
+ printf (" -lang-c89 Assume that the input sources are in C89\n");
+ printf (" -lang-c++ Assume that the input sources are in C++\n");
+ printf (" -lang-objc Assume that the input sources are in ObjectiveC\n");
+ printf (" -lang-objc++ Assume that the input sources are in ObjectiveC++\n");
+ printf (" -lang-asm Assume that the input sources are in assembler\n");
+ printf (" -lang-chill Assume that the input sources are in Chill\n");
+ printf (" -+ Allow parsing of C++ style features\n");
+ printf (" -w Inhibit warning messages\n");
+ printf (" -Wtrigraphs Warn if trigraphs are encountered\n");
+ printf (" -Wno-trigraphs Do not warn about trigraphs\n");
+ printf (" -Wcomment{s} Warn if one comment starts inside another\n");
+ printf (" -Wno-comment{s} Do not warn about comments\n");
+ printf (" -Wtraditional Warn if a macro argument is/would be turned into\n");
+ printf (" a string if -tradtional is specified\n");
+ printf (" -Wno-traditional Do not warn about stringification\n");
+ printf (" -Wundef Warn if an undefined macro is used by #if\n");
+ printf (" -Wno-undef Do not warn about testing udefined macros\n");
+ printf (" -Wimport Warn about the use of the #import directive\n");
+ printf (" -Wno-import Do not warn about the use of #import\n");
+ printf (" -Werror Treat all warnings as errors\n");
+ printf (" -Wno-error Do not treat warnings as errors\n");
+ printf (" -Wall Enable all preprocessor warnings\n");
+ printf (" -M Generate make dependencies\n");
+ printf (" -MM As -M, but ignore system header files\n");
+ printf (" -MD As -M, but put output in a .d file\n");
+ printf (" -MMD As -MD, but ignore system header files\n");
+ printf (" -MG Treat missing header file as generated files\n");
+ printf (" -g Include #define and #undef directives in the output\n");
+ printf (" -D<macro> Define a <macro> with string '1' as its value\n");
+ printf (" -D<macro>=<val> Define a <macro> with <val> as its value\n");
+ printf (" -A<question> (<answer>) Assert the <answer> to <question>\n");
+ printf (" -U<macro> Undefine <macro> \n");
+ printf (" -u or -undef Do not predefine any macros\n");
+ printf (" -v Display the version number\n");
+ printf (" -H Print the name of header files as they are used\n");
+ printf (" -C Do not discard comments\n");
+ printf (" -dM Display a list of macro definitions active at end\n");
+ printf (" -dD Preserve macro definitions in output\n");
+ printf (" -dN As -dD except that only the names are preserved\n");
+ printf (" -dI Include #include directives in the output\n");
+ printf (" -ifoutput Describe skipped code blocks in output \n");
+ printf (" -P Do not generate #line directives\n");
+ printf (" -$ Do not include '$' in identifiers\n");
+ printf (" -remap Remap file names when including files.\n");
+ printf (" -h or --help Display this information\n");
+}
int
main (argc, argv)
int argc;
char **argv;
{
- int st_mode;
- long st_size;
+ struct stat st;
char *in_fname;
char *cp;
int f, i;
@@ -1298,42 +1254,31 @@ main (argc, argv)
/* Target-name to write with the dependency information. */
char *deps_target = 0;
-#ifdef RLIMIT_STACK
+#if defined (RLIMIT_STACK) && defined (HAVE_GETRLIMIT) && defined (HAVE_SETRLIMIT)
/* Get rid of any avoidable limit on stack size. */
{
struct rlimit rlim;
/* Set the stack limit huge so that alloca (particularly stringtab
- * in dbxread.c) does not fail. */
+ in dbxread.c) does not fail. */
getrlimit (RLIMIT_STACK, &rlim);
rlim.rlim_cur = rlim.rlim_max;
setrlimit (RLIMIT_STACK, &rlim);
}
-#endif /* RLIMIT_STACK defined */
+#endif
#ifdef SIGPIPE
signal (SIGPIPE, pipe_closed);
#endif
- cp = argv[0] + strlen (argv[0]);
- while (cp != argv[0] && cp[-1] != '/'
-#ifdef DIR_SEPARATOR
- && cp[-1] != DIR_SEPARATOR
-#endif
- )
- --cp;
- progname = cp;
+ progname = base_name (argv[0]);
#ifdef VMS
{
- /* Remove directories from PROGNAME. */
+ /* Remove extension from PROGNAME. */
char *p;
- char *s = progname;
+ char *s = progname = savestring (progname);
- if ((p = rindex (s, ':')) != 0) s = p + 1; /* skip device */
- if ((p = rindex (s, ']')) != 0) s = p + 1; /* skip directory */
- if ((p = rindex (s, '>')) != 0) s = p + 1; /* alternate (int'n'l) dir */
- s = progname = savestring (s);
if ((p = rindex (s, ';')) != 0) *p = '\0'; /* strip version number */
if ((p = rindex (s, '.')) != 0 /* strip type iff ".exe" */
&& (p[1] == 'e' || p[1] == 'E')
@@ -1347,10 +1292,8 @@ main (argc, argv)
in_fname = NULL;
out_fname = NULL;
- /* Initialize is_idchar to allow $. */
- dollars_in_ident = 1;
+ /* Initialize is_idchar. */
initialize_char_syntax ();
- dollars_in_ident = DOLLARS_IN_IDENTIFIERS > 0;
no_line_directives = 0;
no_trigraphs = 1;
@@ -1370,7 +1313,10 @@ main (argc, argv)
for (i = 1; i < argc; i++) {
if (argv[i][0] != '-') {
if (out_fname != NULL)
- fatal ("Usage: %s [switches] input output", argv[0]);
+ {
+ print_help ();
+ fatal ("Too many arguments");
+ }
else if (in_fname != NULL)
out_fname = argv[i];
else
@@ -1380,16 +1326,20 @@ main (argc, argv)
case 'i':
if (!strcmp (argv[i], "-include")) {
+ int temp = i;
+
if (i + 1 == argc)
fatal ("Filename missing after `-include' option");
else
- pend_includes[i] = argv[i+1], i++;
+ simplify_filename (pend_includes[temp] = argv[++i]);
}
if (!strcmp (argv[i], "-imacros")) {
+ int temp = i;
+
if (i + 1 == argc)
fatal ("Filename missing after `-imacros' option");
else
- pend_files[i] = argv[i+1], i++;
+ simplify_filename (pend_files[temp] = argv[++i]);
}
if (!strcmp (argv[i], "-iprefix")) {
if (i + 1 == argc)
@@ -1403,17 +1353,10 @@ main (argc, argv)
if (!strcmp (argv[i], "-isystem")) {
struct file_name_list *dirtmp;
- if (i + 1 == argc)
- fatal ("Filename missing after `-isystem' option");
-
- dirtmp = (struct file_name_list *)
- xmalloc (sizeof (struct file_name_list));
- dirtmp->next = 0;
- dirtmp->control_macro = 0;
+ if (! (dirtmp = new_include_prefix (NULL_PTR, NULL_PTR,
+ "", argv[++i])))
+ break;
dirtmp->c_system_include_path = 1;
- dirtmp->fname = xmalloc (strlen (argv[i+1]) + 1);
- strcpy (dirtmp->fname, argv[++i]);
- dirtmp->got_name_map = 0;
if (before_system == 0)
before_system = dirtmp;
@@ -1436,18 +1379,9 @@ main (argc, argv)
prefix[strlen (prefix) - 7] = 0;
}
- dirtmp = (struct file_name_list *)
- xmalloc (sizeof (struct file_name_list));
- dirtmp->next = 0; /* New one goes on the end */
- dirtmp->control_macro = 0;
- dirtmp->c_system_include_path = 0;
- if (i + 1 == argc)
- fatal ("Directory name missing after `-iwithprefix' option");
-
- dirtmp->fname = xmalloc (strlen (argv[i+1]) + strlen (prefix) + 1);
- strcpy (dirtmp->fname, prefix);
- strcat (dirtmp->fname, argv[++i]);
- dirtmp->got_name_map = 0;
+ if (! (dirtmp = new_include_prefix (NULL_PTR, NULL_PTR,
+ prefix, argv[++i])))
+ break;
if (after_include == 0)
after_include = dirtmp;
@@ -1470,35 +1404,16 @@ main (argc, argv)
prefix[strlen (prefix) - 7] = 0;
}
- dirtmp = (struct file_name_list *)
- xmalloc (sizeof (struct file_name_list));
- dirtmp->next = 0; /* New one goes on the end */
- dirtmp->control_macro = 0;
- dirtmp->c_system_include_path = 0;
- if (i + 1 == argc)
- fatal ("Directory name missing after `-iwithprefixbefore' option");
-
- dirtmp->fname = xmalloc (strlen (argv[i+1]) + strlen (prefix) + 1);
- strcpy (dirtmp->fname, prefix);
- strcat (dirtmp->fname, argv[++i]);
- dirtmp->got_name_map = 0;
-
+ dirtmp = new_include_prefix (NULL_PTR, NULL_PTR, prefix, argv[++i]);
append_include_chain (dirtmp, dirtmp);
}
/* Add directory to end of path for includes. */
if (!strcmp (argv[i], "-idirafter")) {
struct file_name_list *dirtmp;
- dirtmp = (struct file_name_list *)
- xmalloc (sizeof (struct file_name_list));
- dirtmp->next = 0; /* New one goes on the end */
- dirtmp->control_macro = 0;
- dirtmp->c_system_include_path = 0;
- if (i + 1 == argc)
- fatal ("Directory name missing after `-idirafter' option");
- else
- dirtmp->fname = argv[++i];
- dirtmp->got_name_map = 0;
+ if (! (dirtmp = new_include_prefix (NULL_PTR, NULL_PTR,
+ "", argv[++i])))
+ break;
if (after_include == 0)
after_include = dirtmp;
@@ -1529,10 +1444,10 @@ main (argc, argv)
if (i + 1 == argc)
fatal ("Filename missing after -pcp option");
pcp_fname = argv[++i];
- pcp_outfile =
- ((pcp_fname[0] != '-' || pcp_fname[1] != '\0')
- ? fopen (pcp_fname, "w")
- : stdout);
+ pcp_outfile
+ = ((pcp_fname[0] != '-' || pcp_fname[1] != '\0')
+ ? fopen (pcp_fname, "w")
+ : stdout);
if (pcp_outfile == 0)
pfatal_with_name (pcp_fname);
no_precomp = 1;
@@ -1543,8 +1458,6 @@ main (argc, argv)
if (!strcmp (argv[i], "-traditional")) {
traditional = 1;
cplusplus_comments = 0;
- if (dollars_in_ident > 0)
- dollars_in_ident = 1;
} else if (!strcmp (argv[i], "-trigraphs")) {
no_trigraphs = 0;
}
@@ -1552,15 +1465,15 @@ main (argc, argv)
case 'l':
if (! strcmp (argv[i], "-lang-c"))
- cplusplus = 0, cplusplus_comments = 1, objc = 0;
+ cplusplus = 0, cplusplus_comments = 1, c89 = 0, objc = 0;
if (! strcmp (argv[i], "-lang-c89"))
- cplusplus = 0, cplusplus_comments = 0, objc = 0;
+ cplusplus = 0, cplusplus_comments = 0, c89 = 1, objc = 0;
if (! strcmp (argv[i], "-lang-c++"))
- cplusplus = 1, cplusplus_comments = 1, objc = 0;
+ cplusplus = 1, cplusplus_comments = 1, c89 = 0, objc = 0;
if (! strcmp (argv[i], "-lang-objc"))
- objc = 1, cplusplus = 0, cplusplus_comments = 1;
+ cplusplus = 0, cplusplus_comments = 1, c89 = 0, objc = 1;
if (! strcmp (argv[i], "-lang-objc++"))
- objc = 1, cplusplus = 1, cplusplus_comments = 1;
+ cplusplus = 1, cplusplus_comments = 1, c89 = 0, objc = 1;
if (! strcmp (argv[i], "-lang-asm"))
lang_asm = 1;
if (! strcmp (argv[i], "-lint"))
@@ -1592,6 +1505,10 @@ main (argc, argv)
warn_stringify = 1;
else if (!strcmp (argv[i], "-Wno-traditional"))
warn_stringify = 0;
+ else if (!strcmp (argv[i], "-Wundef"))
+ warn_undef = 1;
+ else if (!strcmp (argv[i], "-Wno-undef"))
+ warn_undef = 0;
else if (!strcmp (argv[i], "-Wimport"))
warn_import = 1;
else if (!strcmp (argv[i], "-Wno-import"))
@@ -1666,6 +1583,9 @@ main (argc, argv)
case 'D':
dump_macros = dump_definitions;
break;
+ case 'I':
+ dump_includes = 1;
+ break;
}
}
}
@@ -1676,6 +1596,13 @@ main (argc, argv)
debug_output = 1;
break;
+ case '-':
+ if (strcmp (argv[i], "--help") != 0)
+ return i;
+ print_help ();
+ exit (0);
+ break;
+
case 'v':
fprintf (stderr, "GNU CPP version %s", version_string);
#ifdef TARGET_VERSION
@@ -1746,7 +1673,7 @@ main (argc, argv)
break;
case '$': /* Don't include $ in identifiers. */
- dollars_in_ident = 0;
+ is_idchar['$'] = is_idstart['$'] = 0;
break;
case 'I': /* Add directory to path for includes. */
@@ -1759,18 +1686,8 @@ main (argc, argv)
first_bracket_include = 0;
}
else {
- dirtmp = (struct file_name_list *)
- xmalloc (sizeof (struct file_name_list));
- dirtmp->next = 0; /* New one goes on the end */
- dirtmp->control_macro = 0;
- dirtmp->c_system_include_path = 0;
- if (argv[i][2] != 0)
- dirtmp->fname = argv[i] + 2;
- else if (i + 1 == argc)
- fatal ("Directory name missing after -I option");
- else
- dirtmp->fname = argv[++i];
- dirtmp->got_name_map = 0;
+ dirtmp = new_include_prefix (last_include, NULL_PTR, "",
+ argv[i][2] ? argv[i] + 2 : argv[++i]);
append_include_chain (dirtmp, dirtmp);
}
}
@@ -1788,6 +1705,11 @@ main (argc, argv)
no_precomp = 1;
break;
+ case 'r':
+ if (!strcmp (argv[i], "-remap"))
+ remap = 1;
+ break;
+
case 'u':
/* Sun compiler passes undocumented switch "-undef".
Let's assume it means to inhibit the predefined symbols. */
@@ -1815,13 +1737,10 @@ main (argc, argv)
/* Some people say that CPATH should replace the standard include dirs,
but that seems pointless: it comes before them, so it overrides them
anyway. */
- cp = getenv ("CPATH");
+ GET_ENVIRONMENT (cp, "CPATH");
if (cp && ! no_standard_includes)
path_include (cp);
- /* Now that dollars_in_ident is known, initialize is_idchar. */
- initialize_char_syntax ();
-
/* Initialize output buffer */
outbuf.buf = (U_CHAR *) xmalloc (OUTBUF_SIZE);
@@ -1835,6 +1754,7 @@ main (argc, argv)
if (in_fname == NULL)
in_fname = "";
fp->nominal_fname = fp->fname = in_fname;
+ fp->nominal_fname_len = strlen (in_fname);
fp->lineno = 0;
/* In C++, wchar_t is a distinct basic type, and we can expect
@@ -1851,6 +1771,63 @@ main (argc, argv)
if (!inhibit_predefs) {
char *p = (char *) alloca (strlen (predefs) + 1);
+
+#ifdef VMS
+ struct dsc$descriptor_s lcl_name;
+ struct item_list {
+ unsigned short length; /* input length */
+ unsigned short code; /* item code */
+ unsigned long dptr; /* data ptr */
+ unsigned long lptr; /* output length ptr */
+ };
+
+ unsigned long syi_length;
+ char syi_data[16];
+
+ struct item_list items[] = {
+ { 16, SYI$_VERSION, 0, 0 },
+ { 0, 0, 0, 0 }
+ };
+
+ items[0].dptr = (unsigned long)syi_data;
+ items[0].lptr = (unsigned long)(&syi_length);
+
+ if (SYS$GETSYIW (0, 0, 0, items, NULL, NULL, NULL, NULL) == SS$_NORMAL)
+ {
+ unsigned long vms_version_value;
+ char *vers;
+
+ vers = syi_data;
+ vms_version_value = 0;
+
+ if (*vers == 'V')
+ vers++;
+ if (ISDIGIT (*vers))
+ {
+ vms_version_value = (*vers - '0') * 10000000;
+ }
+ vers++;
+ if (*vers == '.')
+ {
+ vers++;
+ if (ISDIGIT (*vers))
+ {
+ vms_version_value += (*vers - '0') * 100000;
+ }
+ }
+
+ if (vms_version_value > 0)
+ {
+ char versbuf[32];
+
+ sprintf (versbuf, "__VMS_VER=%08ld", vms_version_value);
+ if (debug_output)
+ output_line_directive (fp, &outbuf, 0, same_file);
+ make_definition (versbuf, &outbuf);
+ }
+ }
+#endif
+
strcpy (p, predefs);
while (*p) {
char *q;
@@ -1938,28 +1915,27 @@ main (argc, argv)
done_initializing = 1;
- { /* read the appropriate environment variable and if it exists
- replace include_defaults with the listed path. */
+ { /* Read the appropriate environment variable and if it exists
+ replace include_defaults with the listed path. */
char *epath = 0;
switch ((objc << 1) + cplusplus)
{
case 0:
- epath = getenv ("C_INCLUDE_PATH");
+ GET_ENVIRONMENT (epath, "C_INCLUDE_PATH");
break;
case 1:
- epath = getenv ("CPLUS_INCLUDE_PATH");
+ GET_ENVIRONMENT (epath, "CPLUS_INCLUDE_PATH");
break;
case 2:
- epath = getenv ("OBJC_INCLUDE_PATH");
+ GET_ENVIRONMENT (epath, "OBJC_INCLUDE_PATH");
break;
case 3:
- epath = getenv ("OBJCPLUS_INCLUDE_PATH");
+ GET_ENVIRONMENT (epath, "OBJCPLUS_INCLUDE_PATH");
break;
}
/* If the environment var for this language is set,
add to the default list of include directories. */
if (epath) {
- char *nstore = (char *) alloca (strlen (epath) + 2);
int num_dirs;
char *startp, *endp;
@@ -1973,30 +1949,20 @@ main (argc, argv)
startp = endp = epath;
num_dirs = 0;
while (1) {
- /* Handle cases like c:/usr/lib:d:/gcc/lib */
- if ((*endp == PATH_SEPARATOR
-#if 0 /* Obsolete, now that we use semicolons as the path separator. */
-#ifdef __MSDOS__
- && (endp-startp != 1 || !isalpha (*startp))
-#endif
-#endif
- )
- || *endp == 0) {
- strncpy (nstore, startp, endp-startp);
- if (endp == startp)
- strcpy (nstore, ".");
- else
- nstore[endp-startp] = '\0';
-
- include_defaults[num_dirs].fname = savestring (nstore);
+ char c = *endp++;
+ if (c == PATH_SEPARATOR || !c) {
+ endp[-1] = 0;
+ include_defaults[num_dirs].fname
+ = startp == endp ? "." : savestring (startp);
+ endp[-1] = c;
+ include_defaults[num_dirs].component = 0;
include_defaults[num_dirs].cplusplus = cplusplus;
include_defaults[num_dirs].cxx_aware = 1;
num_dirs++;
- if (*endp == '\0')
+ if (!c)
break;
- endp = startp = endp + 1;
- } else
- endp++;
+ startp = endp;
+ }
}
/* Put the usual defaults back in at the end. */
bcopy ((char *) include_defaults_array,
@@ -2030,18 +1996,14 @@ main (argc, argv)
if (!strncmp (p->fname, default_prefix, default_len)) {
/* Yes; change prefix and add to search list. */
struct file_name_list *new
- = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
- int this_len = strlen (specd_prefix) + strlen (p->fname) - default_len;
- char *str = xmalloc (this_len + 1);
- strcpy (str, specd_prefix);
- strcat (str, p->fname + default_len);
- new->fname = str;
- new->control_macro = 0;
- new->c_system_include_path = !p->cxx_aware;
- new->got_name_map = 0;
- append_include_chain (new, new);
- if (first_system_include == 0)
- first_system_include = new;
+ = new_include_prefix (NULL_PTR, NULL_PTR, specd_prefix,
+ p->fname + default_len);
+ if (new) {
+ new->c_system_include_path = !p->cxx_aware;
+ append_include_chain (new, new);
+ if (first_system_include == 0)
+ first_system_include = new;
+ }
}
}
}
@@ -2050,14 +2012,13 @@ main (argc, argv)
/* Some standard dirs are only for C++. */
if (!p->cplusplus || (cplusplus && !no_standard_cplusplus_includes)) {
struct file_name_list *new
- = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
- new->control_macro = 0;
- new->c_system_include_path = !p->cxx_aware;
- new->fname = p->fname;
- new->got_name_map = 0;
- append_include_chain (new, new);
- if (first_system_include == 0)
- first_system_include = new;
+ = new_include_prefix (NULL_PTR, p->component, "", p->fname);
+ if (new) {
+ new->c_system_include_path = !p->cxx_aware;
+ append_include_chain (new, new);
+ if (first_system_include == 0)
+ first_system_include = new;
+ }
}
}
}
@@ -2074,37 +2035,17 @@ main (argc, argv)
for (p = include; p; p = p->next) {
if (p == first_bracket_include)
fprintf (stderr, "#include <...> search starts here:\n");
- fprintf (stderr, " %s\n", p->fname);
+ if (!p->fname[0])
+ fprintf (stderr, " .\n");
+ else if (!strcmp (p->fname, "/") || !strcmp (p->fname, "//"))
+ fprintf (stderr, " %s\n", p->fname);
+ else
+ /* Omit trailing '/'. */
+ fprintf (stderr, " %.*s\n", (int) strlen (p->fname) - 1, p->fname);
}
fprintf (stderr, "End of search list.\n");
}
- /* Scan the -imacros files before the main input.
- Much like #including them, but with no_output set
- so that only their macro definitions matter. */
-
- no_output++; no_record_file++;
- for (i = 1; i < argc; i++)
- if (pend_files[i]) {
- int fd = open (pend_files[i], O_RDONLY, 0666);
- if (fd < 0) {
- perror_with_name (pend_files[i]);
- return FATAL_EXIT_CODE;
- }
- finclude (fd, pend_files[i], &outbuf, 0, NULL_PTR);
- }
- no_output--; no_record_file--;
-
- /* Copy the entire contents of the main input file into
- the stacked input buffer previously allocated for it. */
-
- /* JF check for stdin */
- if (in_fname == NULL || *in_fname == 0) {
- in_fname = "";
- f = 0;
- } else if ((f = open (in_fname, O_RDONLY, 0666)) < 0)
- goto perror;
-
/* -MG doesn't select the form of output and must be specified with one of
-M or -MM. -MG doesn't make sense with -MD or -MMD since they don't
inhibit compilation. */
@@ -2166,15 +2107,7 @@ main (argc, argv)
char *p, *q;
int len;
- /* Discard all directory prefixes from filename. */
- if ((q = rindex (in_fname, '/')) != NULL
-#ifdef DIR_SEPARATOR
- && (q = rindex (in_fname, DIR_SEPARATOR)) != NULL
-#endif
- )
- ++q;
- else
- q = in_fname;
+ q = base_name (in_fname);
/* Copy remainder to mungable area. */
p = (char *) alloca (strlen(q) + 8);
@@ -2206,23 +2139,48 @@ main (argc, argv)
q = p + (len - 4);
/* Supply our own suffix. */
-#ifndef VMS
- strcpy (q, ".o");
-#else
- strcpy (q, ".obj");
-#endif
+ strcpy (q, OBJECT_SUFFIX);
deps_output (p, ':');
deps_output (in_fname, ' ');
}
}
- file_size_and_mode (f, &st_mode, &st_size);
+ /* Scan the -imacros files before the main input.
+ Much like #including them, but with no_output set
+ so that only their macro definitions matter. */
+
+ no_output++; no_record_file++;
+ for (i = 1; i < argc; i++)
+ if (pend_files[i]) {
+ struct include_file *inc;
+ int fd = open_include_file (pend_files[i], NULL_PTR, NULL_PTR, &inc);
+ if (fd < 0) {
+ perror_with_name (pend_files[i]);
+ return FATAL_EXIT_CODE;
+ }
+ finclude (fd, inc, &outbuf, 0, NULL_PTR);
+ }
+ no_output--; no_record_file--;
+
+ /* Copy the entire contents of the main input file into
+ the stacked input buffer previously allocated for it. */
+
+ /* JF check for stdin */
+ if (in_fname == NULL || *in_fname == 0) {
+ in_fname = "";
+ f = 0;
+ } else if ((f = open (in_fname, O_RDONLY, 0666)) < 0)
+ goto perror;
+
+ if (fstat (f, &st) != 0)
+ pfatal_with_name (in_fname);
fp->nominal_fname = fp->fname = in_fname;
+ fp->nominal_fname_len = strlen (in_fname);
fp->lineno = 1;
fp->system_header_p = 0;
/* JF all this is mine about reading pipes and ttys */
- if (! S_ISREG (st_mode)) {
+ if (! S_ISREG (st.st_mode)) {
/* Read input from a file that is not a normal disk file.
We cannot preallocate a buffer with the correct size,
so we must read in the file a piece at the time and make it bigger. */
@@ -2230,6 +2188,9 @@ main (argc, argv)
int bsize;
int cnt;
+ if (S_ISDIR (st.st_mode))
+ fatal ("Input file `%s' is a directory", in_fname);
+
bsize = 2000;
size = 0;
fp->buf = (U_CHAR *) xmalloc (bsize + 2);
@@ -2244,9 +2205,12 @@ main (argc, argv)
fp->length = size;
} else {
/* Read a file whose size we can determine in advance.
- For the sake of VMS, st_size is just an upper bound. */
- fp->buf = (U_CHAR *) xmalloc (st_size + 2);
- fp->length = safe_read (f, (char *) fp->buf, st_size);
+ For the sake of VMS, st.st_size is just an upper bound. */
+ size_t s = (size_t) st.st_size;
+ if (s != st.st_size || s + 2 < s)
+ memory_full ();
+ fp->buf = (U_CHAR *) xmalloc (s + 2);
+ fp->length = safe_read (f, (char *) fp->buf, s);
if (fp->length < 0) goto perror;
}
fp->bufp = fp->buf;
@@ -2281,12 +2245,13 @@ main (argc, argv)
no_record_file++;
for (i = 1; i < argc; i++)
if (pend_includes[i]) {
- int fd = open (pend_includes[i], O_RDONLY, 0666);
+ struct include_file *inc;
+ int fd = open_include_file (pend_includes[i], NULL_PTR, NULL_PTR, &inc);
if (fd < 0) {
perror_with_name (pend_includes[i]);
return FATAL_EXIT_CODE;
}
- finclude (fd, pend_includes[i], &outbuf, 0, NULL_PTR);
+ finclude (fd, inc, &outbuf, 0, NULL_PTR);
}
no_record_file--;
@@ -2353,38 +2318,23 @@ path_include (path)
if (*p)
while (1) {
char *q = p;
- char *name;
+ char c;
struct file_name_list *dirtmp;
/* Find the end of this name. */
- while (*q != 0 && *q != PATH_SEPARATOR) q++;
- if (p == q) {
- /* An empty name in the path stands for the current directory. */
- name = xmalloc (2);
- name[0] = '.';
- name[1] = 0;
- } else {
- /* Otherwise use the directory that is named. */
- name = xmalloc (q - p + 1);
- bcopy (p, name, q - p);
- name[q - p] = 0;
- }
+ while ((c = *q++) != PATH_SEPARATOR && c)
+ continue;
- dirtmp = (struct file_name_list *)
- xmalloc (sizeof (struct file_name_list));
- dirtmp->next = 0; /* New one goes on the end */
- dirtmp->control_macro = 0;
- dirtmp->c_system_include_path = 0;
- dirtmp->fname = name;
- dirtmp->got_name_map = 0;
+ q[-1] = 0;
+ dirtmp = new_include_prefix (last_include, NULL_PTR,
+ "", p == q ? "." : p);
+ q[-1] = c;
append_include_chain (dirtmp, dirtmp);
/* Advance past this name. */
p = q;
- if (*p == 0)
+ if (! c)
break;
- /* Skip the colon. */
- p++;
}
}
@@ -2423,7 +2373,7 @@ index0 (s, c, n)
Using an extra pass through the buffer takes a little extra time,
but is infinitely less hairy than trying to handle trigraphs inside
strings, etc. everywhere, and also makes sure that trigraphs are
- only translated in the top level of processing. */
+ only translated in the top level of processing. */
static void
trigraph_pcp (buf)
@@ -2474,7 +2424,7 @@ trigraph_pcp (buf)
len = sptr - fptr - 2;
/* BSD doc says bcopy () works right for overlapping strings. In ANSI
- C, this will be memmove (). */
+ C, this will be memmove (). */
if (bptr != fptr && len > 0)
bcopy ((char *) fptr, (char *) bptr, len);
@@ -2488,7 +2438,8 @@ trigraph_pcp (buf)
buf->length -= fptr - bptr;
buf->buf[buf->length] = '\0';
if (warn_trigraphs && fptr != bptr)
- warning_with_line (0, "%d trigraph(s) encountered", (fptr - bptr) / 2);
+ warning_with_line (0, "%lu trigraph(s) encountered",
+ (unsigned long) (fptr - bptr) / 2);
}
/* Move all backslash-newline pairs out of embarrassing places.
@@ -2568,8 +2519,7 @@ name_newline_fix (bp)
Upon return, any arg will be pointed to with argstart and will be
arglen long. Note that we don't parse that arg since it will just
- be printed out again.
-*/
+ be printed out again. */
static char *
get_lintcmd (ibp, limit, argstart, arglen, cmdlen)
@@ -2578,7 +2528,7 @@ get_lintcmd (ibp, limit, argstart, arglen, cmdlen)
U_CHAR **argstart; /* point to command arg */
int *arglen, *cmdlen; /* how long they are */
{
- long linsize;
+ HOST_WIDE_INT linsize;
register U_CHAR *numptr; /* temp for arg parsing */
*arglen = 0;
@@ -2605,10 +2555,10 @@ get_lintcmd (ibp, limit, argstart, arglen, cmdlen)
if ((linsize >= 7) && !bcmp (ibp, "VARARGS", 7)) {
*cmdlen = 7;
ibp += 7; linsize -= 7;
- if ((linsize == 0) || ! isdigit (*ibp)) return "VARARGS";
+ if ((linsize == 0) || ! ISDIGIT (*ibp)) return "VARARGS";
/* OK, read a number */
- for (numptr = *argstart = ibp; (numptr < limit) && isdigit (*numptr);
+ for (numptr = *argstart = ibp; (numptr < limit) && ISDIGIT (*numptr);
numptr++);
*arglen = numptr - *argstart;
return "VARARGS";
@@ -2773,7 +2723,7 @@ do { ip = &instack[indepth]; \
if (ident_length)
goto specialchar;
/* Copy #foo (bar lose) without macro expansion. */
- obp[-1] = '#'; /* In case it was '%'. */
+ obp[-1] = '#'; /* In case it was '%'. */
SKIP_WHITE_SPACE (ibp);
while (is_idchar[*ibp])
*obp++ = *ibp++;
@@ -2900,8 +2850,13 @@ do { ip = &instack[indepth]; \
/* A single quoted string is treated like a double -- some
programs (e.g., troff) are perverse this way */
- if (ident_length)
- goto specialchar;
+ /* Handle any pending identifier;
+ but the L in L'...' or L"..." is not an identifier. */
+ if (ident_length) {
+ if (! (ident_length == 1 && hash == HASHSTEP (0, 'L')))
+ goto specialchar;
+ ident_length = hash = 0;
+ }
start_line = ip->lineno;
@@ -2920,9 +2875,11 @@ do { ip = &instack[indepth]; \
if (!traditional) {
error_with_line (line_for_error (start_line),
"unterminated string or character constant");
- error_with_line (multiline_string_line,
- "possible real start of unterminated constant");
- multiline_string_line = 0;
+ if (multiline_string_line) {
+ error_with_line (multiline_string_line,
+ "possible real start of unterminated constant");
+ multiline_string_line = 0;
+ }
}
break;
}
@@ -2942,29 +2899,34 @@ do { ip = &instack[indepth]; \
"unterminated character constant");
goto while2end;
}
- if (pedantic && multiline_string_line == 0) {
- pedwarn_with_line (line_for_error (start_line),
- "string constant runs past end of line");
- }
- if (multiline_string_line == 0)
+ if (multiline_string_line == 0) {
+ if (pedantic)
+ pedwarn_with_line (line_for_error (start_line),
+ "string constant runs past end of line");
multiline_string_line = ip->lineno - 1;
+ }
break;
case '\\':
- if (ibp >= limit)
- break;
if (*ibp == '\n') {
- /* Backslash newline is replaced by nothing at all,
- but keep the line counts correct. */
- --obp;
+ /* Backslash newline is replaced by nothing at all, but
+ keep the line counts correct. But if we are reading
+ from a macro, keep the backslash newline, since backslash
+ newlines have already been processed. */
+ if (ip->macro)
+ *obp++ = '\n';
+ else
+ --obp;
++ibp;
++ip->lineno;
} else {
/* ANSI stupidly requires that in \\ the second \
is *not* prevented from combining with a newline. */
- while (*ibp == '\\' && ibp[1] == '\n') {
- ibp += 2;
- ++ip->lineno;
+ if (!ip->macro) {
+ while (*ibp == '\\' && ibp[1] == '\n') {
+ ibp += 2;
+ ++ip->lineno;
+ }
}
*obp++ = *ibp++;
}
@@ -2981,22 +2943,21 @@ do { ip = &instack[indepth]; \
break;
case '/':
+ if (ip->macro != 0)
+ goto randomchar;
if (*ibp == '\\' && ibp[1] == '\n')
newline_fix (ibp);
-
if (*ibp != '*'
&& !(cplusplus_comments && *ibp == '/'))
goto randomchar;
- if (ip->macro != 0)
- goto randomchar;
if (ident_length)
goto specialchar;
if (*ibp == '/') {
- /* C++ style comment... */
+ /* C++ style comment... */
start_line = ip->lineno;
- /* Comments are equivalent to spaces. */
+ /* Comments are equivalent to spaces. */
if (! put_out_comments)
obp[-1] = ' ';
@@ -3012,6 +2973,8 @@ do { ip = &instack[indepth]; \
}
break;
}
+ if (warn_comments)
+ warning ("multiline `//' comment");
++ip->lineno;
/* Copy the newline into the output buffer, in order to
avoid the pain of a #line every time a multiline comment
@@ -3029,7 +2992,7 @@ do { ip = &instack[indepth]; \
start_line = ip->lineno;
- ++ibp; /* Skip the star. */
+ ++ibp; /* Skip the star. */
/* If this cpp is for lint, we peek inside the comments: */
if (for_lint) {
@@ -3080,18 +3043,17 @@ do { ip = &instack[indepth]; \
{
U_CHAR *before_bp = ibp;
- while (ibp < limit) {
+ for (;;) {
switch (*ibp++) {
- case '/':
- if (warn_comments && *ibp == '*')
- warning ("`/*' within comment");
- break;
case '*':
+ if (ibp[-2] == '/' && warn_comments)
+ warning ("`/*' within comment");
if (*ibp == '\\' && ibp[1] == '\n')
newline_fix (ibp);
- if (ibp >= limit || *ibp == '/')
+ if (*ibp == '/')
goto comment_end;
break;
+
case '\n':
++ip->lineno;
/* Copy the newline into the output buffer, in order to
@@ -3100,26 +3062,32 @@ do { ip = &instack[indepth]; \
if (!put_out_comments)
*obp++ = '\n';
++op->lineno;
+ break;
+
+ case 0:
+ if (limit < ibp) {
+ error_with_line (line_for_error (start_line),
+ "unterminated comment");
+ goto limit_reached;
+ }
+ break;
}
}
comment_end:
- if (ibp >= limit)
- error_with_line (line_for_error (start_line),
- "unterminated comment");
- else {
- ibp++;
- if (put_out_comments) {
- bcopy ((char *) before_bp, (char *) obp, ibp - before_bp);
- obp += ibp - before_bp;
- }
+ ibp++;
+ if (put_out_comments) {
+ bcopy ((char *) before_bp, (char *) obp, ibp - before_bp);
+ obp += ibp - before_bp;
}
}
break;
case '$':
- if (!dollars_in_ident)
+ if (! is_idchar['$'])
goto randomchar;
+ if (pedantic)
+ pedwarn ("`$' in identifier");
goto letter;
case '0': case '1': case '2': case '3': case '4':
@@ -3132,9 +3100,11 @@ do { ip = &instack[indepth]; \
if (ident_length == 0) {
for (;;) {
- while (ibp[0] == '\\' && ibp[1] == '\n') {
- ++ip->lineno;
- ibp += 2;
+ if (!ip->macro) {
+ while (ibp[0] == '\\' && ibp[1] == '\n') {
+ ++ip->lineno;
+ ibp += 2;
+ }
}
c = *ibp++;
if (!is_idchar[c] && c != '.') {
@@ -3143,16 +3113,19 @@ do { ip = &instack[indepth]; \
}
*obp++ = c;
/* A sign can be part of a preprocessing number
- if it follows an e. */
- if (c == 'e' || c == 'E') {
- while (ibp[0] == '\\' && ibp[1] == '\n') {
- ++ip->lineno;
- ibp += 2;
+ if it follows an `e' or `p'. */
+ if (c == 'e' || c == 'E' || c == 'p' || c == 'P') {
+ if (!ip->macro) {
+ while (ibp[0] == '\\' && ibp[1] == '\n') {
+ ++ip->lineno;
+ ibp += 2;
+ }
}
if (*ibp == '+' || *ibp == '-') {
*obp++ = *ibp++;
- /* But traditional C does not let the token go past the sign. */
- if (traditional)
+ /* But traditional C does not let the token go past the sign,
+ and C89 does not allow `p'. */
+ if (traditional || (c89 && (c == 'p' || c == 'P')))
break;
}
}
@@ -3251,6 +3224,7 @@ do { ip = &instack[indepth]; \
/* Our input really contains a null character. */
goto randomchar;
+ limit_reached:
/* At end of a macro-expansion level, pop it and read next level. */
if (ip->macro != 0) {
obp--;
@@ -3405,35 +3379,6 @@ randomchar:
old_iln = ip->lineno;
old_oln = op->lineno;
}
- /* A comment: copy it unchanged or discard it. */
- else if (*ibp == '/' && ibp[1] == '*') {
- if (put_out_comments) {
- *obp++ = '/';
- *obp++ = '*';
- } else if (! traditional) {
- *obp++ = ' ';
- }
- ibp += 2;
- while (ibp + 1 != limit
- && !(ibp[0] == '*' && ibp[1] == '/')) {
- /* We need not worry about newline-marks,
- since they are never found in comments. */
- if (*ibp == '\n') {
- /* Newline in a file. Count it. */
- ++ip->lineno;
- ++op->lineno;
- }
- if (put_out_comments)
- *obp++ = *ibp++;
- else
- ibp++;
- }
- ibp += 2;
- if (put_out_comments) {
- *obp++ = '*';
- *obp++ = '/';
- }
- }
else if (is_space[*ibp]) {
*obp++ = *ibp++;
if (ibp[-1] == '\n') {
@@ -3460,6 +3405,59 @@ randomchar:
}
}
}
+ else if (ip->macro)
+ break;
+ else if (*ibp == '/') {
+ /* If a comment, copy it unchanged or discard it. */
+ if (ibp[1] == '\\' && ibp[2] == '\n')
+ newline_fix (ibp + 1);
+ if (ibp[1] == '*') {
+ if (put_out_comments) {
+ *obp++ = '/';
+ *obp++ = '*';
+ } else if (! traditional) {
+ *obp++ = ' ';
+ }
+ for (ibp += 2; ibp < limit; ibp++) {
+ /* We need not worry about newline-marks,
+ since they are never found in comments. */
+ if (ibp[0] == '*') {
+ if (ibp[1] == '\\' && ibp[2] == '\n')
+ newline_fix (ibp + 1);
+ if (ibp[1] == '/') {
+ ibp += 2;
+ if (put_out_comments) {
+ *obp++ = '*';
+ *obp++ = '/';
+ }
+ break;
+ }
+ }
+ if (*ibp == '\n') {
+ /* Newline in a file. Count it. */
+ ++ip->lineno;
+ ++op->lineno;
+ }
+ if (put_out_comments)
+ *obp++ = *ibp;
+ }
+ } else if (ibp[1] == '/' && cplusplus_comments) {
+ if (put_out_comments) {
+ *obp++ = '/';
+ *obp++ = '/';
+ } else if (! traditional) {
+ *obp++ = ' ';
+ }
+ for (ibp += 2; *ibp != '\n' || ibp[-1] == '\\'; ibp++)
+ if (put_out_comments)
+ *obp++ = *ibp;
+ } else
+ break;
+ }
+ else if (ibp[0] == '\\' && ibp[1] == '\n') {
+ ibp += 2;
+ ++ip->lineno;
+ }
else break;
}
if (*ibp != '(') {
@@ -3493,9 +3491,9 @@ randomchar:
if (!traditional && obp != op->buf) {
switch (obp[-1]) {
case '!': case '%': case '&': case '*':
- case '+': case '-': case '/': case ':':
- case '<': case '=': case '>': case '^':
- case '|':
+ case '+': case '-': case '.': case '/':
+ case ':': case '<': case '=': case '>':
+ case '^': case '|':
/* If we are expanding a macro arg, make a newline marker
to separate the tokens. If we are making real output,
a plain space will do. */
@@ -3604,9 +3602,14 @@ expand_to_temp_buffer (buf, limit, output_marks, assertions)
obuf.length = length * 2 + 100; /* Usually enough. Why be stingy? */
obuf.bufp = obuf.buf = (U_CHAR *) xmalloc (obuf.length);
+ obuf.nominal_fname = 0;
+ obuf.inc = 0;
+ obuf.dir = 0;
obuf.fname = 0;
obuf.macro = 0;
+ obuf.if_stack = 0;
obuf.free_ptr = 0;
+ obuf.system_header_p = 0;
CHECK_DEPTH ({return obuf;});
@@ -3615,6 +3618,8 @@ expand_to_temp_buffer (buf, limit, output_marks, assertions)
ip = &instack[indepth];
ip->fname = 0;
ip->nominal_fname = 0;
+ ip->nominal_fname_len = 0;
+ ip->inc = 0;
ip->system_header_p = 0;
ip->macro = 0;
ip->free_ptr = 0;
@@ -3680,8 +3685,11 @@ handle_directive (ip, op)
if (*bp != ' ' && *bp != '\t' && pedantic)
pedwarn ("%s in preprocessing directive", char_name[*bp]);
bp++;
- } else if (*bp == '/' && (bp[1] == '*'
- || (cplusplus_comments && bp[1] == '/'))) {
+ } else if (*bp == '/') {
+ if (bp[1] == '\\' && bp[2] == '\n')
+ newline_fix (bp + 1);
+ if (! (bp[1] == '*' || (cplusplus_comments && bp[1] == '/')))
+ break;
ip->bufp = bp + 2;
skip_to_end_of_comment (ip, &ip->lineno, 0);
bp = ip->bufp;
@@ -3773,7 +3781,7 @@ handle_directive (ip, op)
limit = ip->buf + ip->length;
unterminated = 0;
already_output = 0;
- keep_comments = traditional && kt->traditional_comments;
+ keep_comments = traditional && kt->type == T_DEFINE;
/* #import is defined only in Objective C, or when on the NeXT. */
if (kt->type == T_IMPORT
&& !(objc || lookup ((U_CHAR *) "__NeXT__", -1, -1)))
@@ -3799,8 +3807,25 @@ handle_directive (ip, op)
}
break;
+ case '"':
+ /* "..." is special for #include. */
+ if (IS_INCLUDE_DIRECTIVE_TYPE (kt->type)) {
+ while (bp < limit && *bp != '\n') {
+ if (*bp == '"') {
+ bp++;
+ break;
+ }
+ if (*bp == '\\' && bp[1] == '\n') {
+ ip->lineno++;
+ copy_directive = 1;
+ bp++;
+ }
+ bp++;
+ }
+ break;
+ }
+ /* Fall through. */
case '\'':
- case '\"':
bp = skip_quoted_string (bp - 1, limit, ip->lineno, &ip->lineno, &copy_directive, &unterminated);
/* Don't bother calling the directive if we already got an error
message due to unterminated string. Skip everything and pretend
@@ -3818,7 +3843,7 @@ handle_directive (ip, op)
/* <...> is special for #include. */
case '<':
- if (!kt->angle_brackets)
+ if (! IS_INCLUDE_DIRECTIVE_TYPE (kt->type))
break;
while (bp < limit && *bp != '>' && *bp != '\n') {
if (*bp == '\\' && bp[1] == '\n') {
@@ -3841,9 +3866,14 @@ handle_directive (ip, op)
bp = ip->bufp;
/* No need to copy the directive because of a comment at the end;
just don't include the comment in the directive. */
- if (bp == limit || *bp == '\n') {
- bp = obp;
- goto endloop1;
+ if (!put_out_comments) {
+ U_CHAR *p;
+ for (p = bp; *p == ' ' || *p == '\t'; p++)
+ continue;
+ if (*p == '\n') {
+ bp = obp;
+ goto endloop1;
+ }
}
/* Don't remove the comments if -traditional. */
if (! keep_comments)
@@ -3872,9 +3902,12 @@ handle_directive (ip, op)
RESUME_P is the next interesting data after the directive.
A comment may come between. */
- /* If a directive should be copied through, and -E was given,
+ /* If a directive should be copied through, and -C was given,
pass it through before removing comments. */
- if (!no_output && kt->pass_thru && put_out_comments) {
+ if (!no_output && put_out_comments
+ && (kt->type == T_DEFINE ? dump_macros == dump_definitions
+ : IS_INCLUDE_DIRECTIVE_TYPE (kt->type) ? dump_includes
+ : kt->type == T_PRAGMA)) {
int len;
/* Output directive name. */
@@ -3923,7 +3956,7 @@ handle_directive (ip, op)
/* <...> is special for #include. */
case '<':
- if (!kt->angle_brackets)
+ if (! IS_INCLUDE_DIRECTIVE_TYPE (kt->type))
break;
while (xp < bp && c != '>') {
c = *xp++;
@@ -3958,13 +3991,7 @@ handle_directive (ip, op)
= skip_quoted_string (xp - 1, bp, ip->lineno,
NULL_PTR, NULL_PTR, NULL_PTR);
while (xp != bp1)
- if (*xp == '\\') {
- if (*++xp != '\n')
- *cp++ = '\\';
- else
- xp++;
- } else
- *cp++ = *xp++;
+ *cp++ = *xp++;
}
break;
@@ -3998,13 +4025,12 @@ handle_directive (ip, op)
/* Some directives should be written out for cc1 to process,
just as if they were not defined. And sometimes we're copying
- definitions through. */
+ directives through. */
if (!no_output && already_output == 0
- && (kt->pass_thru
- || (kt->type == T_DEFINE
- && (dump_macros == dump_names
- || dump_macros == dump_definitions)))) {
+ && (kt->type == T_DEFINE ? (int) dump_names <= (int) dump_macros
+ : IS_INCLUDE_DIRECTIVE_TYPE (kt->type) ? dump_includes
+ : kt->type == T_PRAGMA)) {
int len;
/* Output directive name. */
@@ -4013,13 +4039,8 @@ handle_directive (ip, op)
bcopy (kt->name, (char *) op->bufp, kt->length);
op->bufp += kt->length;
- if (kt->pass_thru || dump_macros == dump_definitions) {
- /* Output arguments. */
- len = (cp - buf);
- check_expand (op, len);
- bcopy (buf, (char *) op->bufp, len);
- op->bufp += len;
- } else if (kt->type == T_DEFINE && dump_macros == dump_names) {
+ if (kt->type == T_DEFINE && dump_macros == dump_names) {
+ /* Output `#define name' only. */
U_CHAR *xp = buf;
U_CHAR *yp;
SKIP_WHITE_SPACE (xp);
@@ -4028,16 +4049,21 @@ handle_directive (ip, op)
len = (xp - yp);
check_expand (op, len + 1);
*op->bufp++ = ' ';
- bcopy (yp, op->bufp, len);
- op->bufp += len;
+ bcopy (yp, (char *) op->bufp, len);
+ } else {
+ /* Output entire directive. */
+ len = (cp - buf);
+ check_expand (op, len);
+ bcopy (buf, (char *) op->bufp, len);
}
+ op->bufp += len;
} /* Don't we need a newline or #line? */
/* Call the appropriate directive handler. buf now points to
either the appropriate place in the input buffer, or to
the temp buffer if it was necessary to make one. cp
points to the first char after the contents of the (possibly
- copied) directive, in either case. */
+ copied) directive, in either case. */
(*kt->func) (buf, cp, op, kt);
check_expand (op, ip->length - (ip->bufp - ip->buf));
@@ -4055,7 +4081,7 @@ timestamp ()
{
static struct tm *timebuf;
if (!timebuf) {
- time_t t = time ((time_t *)0);
+ time_t t = time ((time_t *) 0);
timebuf = localtime (&t);
}
return timebuf;
@@ -4102,16 +4128,14 @@ special_symbol (hp, op)
case T_FILE:
case T_BASE_FILE:
{
- char *string;
- if (hp->type == T_FILE)
- string = ip->nominal_fname;
- else
- string = instack[0].nominal_fname;
+ FILE_BUF *p = hp->type == T_FILE ? ip : &instack[0];
+ char *string = p->nominal_fname;
if (string)
{
- buf = (char *) alloca (3 + 4 * strlen (string));
- quote_string (buf, string);
+ size_t string_len = p->nominal_fname_len;
+ buf = (char *) alloca (3 + 4 * string_len);
+ quote_string (buf, string, string_len);
}
else
buf = "\"\"";
@@ -4164,6 +4188,12 @@ special_symbol (hp, op)
case T_CONST:
buf = hp->value.cpval;
+#ifdef STDC_0_IN_SYSTEM_HEADERS
+ if (ip->system_header_p
+ && hp->length == 8 && bcmp (hp->name, "__STDC__", 8) == 0
+ && !lookup ((U_CHAR *) "__STRICT_ANSI__", -1, -1))
+ buf = "0";
+#endif
if (pcp_inside_if && pcp_outfile)
/* Output a precondition for this macro use */
fprintf (pcp_outfile, "#define %s %s\n", hp->name, buf);
@@ -4198,11 +4228,13 @@ special_symbol (hp, op)
if (!is_idstart[*ip->bufp])
goto oops;
+ if (ip->bufp[0] == 'L' && (ip->bufp[1] == '\'' || ip->bufp[1] == '"'))
+ goto oops;
if ((hp = lookup (ip->bufp, -1, -1))) {
if (pcp_outfile && pcp_inside_if
&& (hp->type == T_CONST
|| (hp->type == T_MACRO && hp->value.defn->predefined)))
- /* Output a precondition for this macro use. */
+ /* Output a precondition for this macro use. */
fprintf (pcp_outfile, "#define %s\n", hp->name);
buf = " 1 ";
}
@@ -4254,29 +4286,41 @@ do_include (buf, limit, op, keyword)
FILE_BUF *op;
struct directive *keyword;
{
- int importing = (keyword->type == T_IMPORT);
+ U_CHAR *importing = keyword->type == T_IMPORT ? (U_CHAR *) "" : (U_CHAR *) 0;
int skip_dirs = (keyword->type == T_INCLUDE_NEXT);
static int import_warning = 0;
char *fname; /* Dynamically allocated fname buffer */
char *pcftry;
char *pcfname;
- U_CHAR *fbeg, *fend; /* Beginning and end of fname */
+ char *fbeg, *fend; /* Beginning and end of fname */
+ U_CHAR *fin;
struct file_name_list *search_start = include; /* Chain of dirs to search */
- struct file_name_list dsp[1]; /* First in chain, if #include "..." */
+ struct file_name_list *dsp; /* First in chain, if #include "..." */
struct file_name_list *searchptr = 0;
size_t flen;
- int f; /* file number */
+ int f = -3; /* file number */
+ struct include_file *inc = 0;
int retried = 0; /* Have already tried macro
expanding the include line*/
int angle_brackets = 0; /* 0 for "...", 1 for <...> */
+#ifdef VMS
+ int vaxc_include = 0; /* 1 for token without punctuation */
+#endif
int pcf = -1;
char *pcfbuf;
char *pcfbuflimit;
int pcfnum;
- f= -1; /* JF we iz paranoid! */
+
+ if (pedantic && !instack[indepth].system_header_p)
+ {
+ if (importing)
+ pedwarn ("ANSI C does not allow `#import'");
+ if (skip_dirs)
+ pedwarn ("ANSI C does not allow `#include_next'");
+ }
if (importing && warn_import && !inhibit_warnings
&& !instack[indepth].system_header_p && !import_warning) {
@@ -4296,25 +4340,28 @@ do_include (buf, limit, op, keyword)
get_filename:
- fbeg = buf;
- SKIP_WHITE_SPACE (fbeg);
+ fin = buf;
+ SKIP_WHITE_SPACE (fin);
/* Discard trailing whitespace so we can easily see
if we have parsed all the significant chars we were given. */
- while (limit != fbeg && is_hor_space[limit[-1]]) limit--;
+ while (limit != fin && is_hor_space[limit[-1]]) limit--;
+ fbeg = fend = (char *) alloca (limit - fin);
- switch (*fbeg++) {
+ switch (*fin++) {
case '\"':
{
FILE_BUF *fp;
/* Copy the operand text, concatenating the strings. */
{
- U_CHAR *fin = fbeg;
- fbeg = (U_CHAR *) alloca (limit - fbeg + 1);
- fend = fbeg;
- while (fin != limit) {
- while (fin != limit && *fin != '\"')
- *fend++ = *fin++;
- fin++;
+ for (;;) {
+ for (;;) {
+ if (fin == limit)
+ goto invalid_include_file_name;
+ *fend = *fin++;
+ if (*fend == '"')
+ break;
+ fend++;
+ }
if (fin == limit)
break;
/* If not at the end, there had better be another string. */
@@ -4326,48 +4373,46 @@ get_filename:
goto fail;
}
}
- *fend = 0;
/* We have "filename". Figure out directory this source
- file is coming from and put it on the front of the list. */
+ file is coming from and put it on the front of the list. */
- /* If -I- was specified, don't search current dir, only spec'd ones. */
+ /* If -I- was specified, don't search current dir, only spec'd ones. */
if (ignore_srcdir) break;
for (fp = &instack[indepth]; fp >= instack; fp--)
{
int n;
- char *ep,*nam;
+ char *nam;
if ((nam = fp->nominal_fname) != NULL) {
/* Found a named file. Figure out dir of the file,
and put it in front of the search list. */
- dsp[0].next = search_start;
- search_start = dsp;
-#ifndef VMS
- ep = rindex (nam, '/');
-#ifdef DIR_SEPARATOR
- if (ep == NULL) ep = rindex (nam, DIR_SEPARATOR);
- else {
- char *tmp = rindex (nam, DIR_SEPARATOR);
- if (tmp != NULL && tmp > ep) ep = tmp;
- }
+ dsp = ((struct file_name_list *)
+ alloca (sizeof (struct file_name_list)
+ + fp->nominal_fname_len));
+ strcpy (dsp->fname, nam);
+ simplify_filename (dsp->fname);
+ nam = base_name (dsp->fname);
+ *nam = 0;
+#ifdef VMS
+ /* for hack_vms_include_specification(), a local
+ dir specification must start with "./" on VMS. */
+ if (nam == dsp->fname)
+ {
+ *nam++ = '.';
+ *nam++ = '/';
+ *nam = 0;
+ }
#endif
-#else /* VMS */
- ep = rindex (nam, ']');
- if (ep == NULL) ep = rindex (nam, '>');
- if (ep == NULL) ep = rindex (nam, ':');
- if (ep != NULL) ep++;
-#endif /* VMS */
- if (ep != NULL) {
- n = ep - nam;
- dsp[0].fname = (char *) alloca (n + 1);
- strncpy (dsp[0].fname, nam, n);
- dsp[0].fname[n] = '\0';
+ /* But for efficiency's sake, do not insert the dir
+ if it matches the search list's first dir. */
+ dsp->next = search_start;
+ if (!search_start || strcmp (dsp->fname, search_start->fname)) {
+ search_start = dsp;
+ n = nam - dsp->fname;
if (n + INCLUDE_LEN_FUDGE > max_include_len)
max_include_len = n + INCLUDE_LEN_FUDGE;
- } else {
- dsp[0].fname = 0; /* Current directory */
}
dsp[0].got_name_map = 0;
break;
@@ -4377,13 +4422,12 @@ get_filename:
}
case '<':
- fend = fbeg;
- while (fend != limit && *fend != '>') fend++;
- if (*fend == '>' && fend + 1 == limit) {
+ while (fin != limit && *fin != '>')
+ *fend++ = *fin++;
+ if (*fin == '>' && fin + 1 == limit) {
angle_brackets = 1;
/* If -I-, start with the first -I dir after the -I-. */
- if (first_bracket_include)
- search_start = first_bracket_include;
+ search_start = first_bracket_include;
break;
}
goto fail;
@@ -4396,31 +4440,35 @@ get_filename:
* code from case '<' is repeated here) and generates a warning.
* (Note: macro expansion of `xyz' takes precedence.)
*/
- if (retried && isalpha(*(--fbeg))) {
- fend = fbeg;
- while (fend != limit && (!isspace(*fend))) fend++;
+ /* Note: The argument of ISALPHA() can be evaluated twice, so do
+ the pre-decrement outside of the macro. */
+ if (retried && (--fin, ISALPHA(*(U_CHAR *) (fin)))) {
+ while (fin != limit && (!ISSPACE(*fin)))
+ *fend++ = *fin++;
warning ("VAX-C-style include specification found, use '#include <filename.h>' !");
- if (fend == limit) {
+ vaxc_include = 1;
+ if (fin == limit) {
angle_brackets = 1;
/* If -I-, start with the first -I dir after the -I-. */
- if (first_bracket_include)
- search_start = first_bracket_include;
+ search_start = first_bracket_include;
break;
}
}
#endif
fail:
- if (retried) {
- error ("`#%s' expects \"FILENAME\" or <FILENAME>", keyword->name);
- return 0;
- } else {
+ if (! retried) {
/* Expand buffer and then remove any newline markers.
We can't just tell expand_to_temp_buffer to omit the markers,
since it would put extra spaces in include file names. */
FILE_BUF trybuf;
U_CHAR *src;
+ int errors_before_expansion = errors;
trybuf = expand_to_temp_buffer (buf, limit, 1, 0);
+ if (errors != errors_before_expansion) {
+ free (trybuf.buf);
+ goto invalid_include_file_name;
+ }
src = trybuf.buf;
buf = (U_CHAR *) alloca (trybuf.bufp - trybuf.buf + 1);
limit = buf;
@@ -4444,9 +4492,13 @@ get_filename:
}
*limit = 0;
free (trybuf.buf);
- retried++;
+ retried = 1;
goto get_filename;
}
+
+ invalid_include_file_name:
+ error ("`#%s' expects \"FILENAME\" or <FILENAME>", keyword->name);
+ return 0;
}
/* For #include_next, skip in the search path
@@ -4463,7 +4515,8 @@ get_filename:
}
}
- flen = fend - fbeg;
+ *fend = 0;
+ flen = simplify_filename (fbeg);
if (flen == 0)
{
@@ -4473,121 +4526,132 @@ get_filename:
/* Allocate this permanently, because it gets stored in the definitions
of macros. */
- fname = xmalloc (max_include_len + flen + 4);
- /* + 2 above for slash and terminating null. */
- /* + 2 added for '.h' on VMS (to support '#include filename') */
+ fname = xmalloc (max_include_len + flen + 1);
+ /* + 1 above for terminating null. */
+
+ system_include_depth += angle_brackets;
/* If specified file name is absolute, just open it. */
- if (*fbeg == '/'
-#ifdef DIR_SEPARATOR
- || *fbeg == DIR_SEPARATOR
-#endif
- ) {
- strncpy (fname, (char *) fbeg, flen);
- fname[flen] = 0;
- if (redundant_include_p (fname))
- return 0;
- if (importing)
- f = lookup_import (fname, NULL_PTR);
- else
- f = open_include_file (fname, NULL_PTR);
- if (f == -2)
- return 0; /* Already included this file */
+ if (absolute_filename (fbeg)) {
+ strcpy (fname, fbeg);
+ f = open_include_file (fname, NULL_PTR, importing, &inc);
} else {
+
+ struct bypass_dir {
+ struct bypass_dir *next;
+ char *fname;
+ struct file_name_list *searchptr;
+ } **bypass_slot = 0;
+
/* Search directory path, trying to open the file.
Copy each filename tried into FNAME. */
for (searchptr = search_start; searchptr; searchptr = searchptr->next) {
- if (searchptr->fname) {
- /* The empty string in a search path is ignored.
- This makes it possible to turn off entirely
- a standard piece of the list. */
- if (searchptr->fname[0] == 0)
- continue;
- strcpy (fname, skip_redundant_dir_prefix (searchptr->fname));
- if (fname[0] && fname[strlen (fname) - 1] != '/')
- strcat (fname, "/");
- } else {
- fname[0] = 0;
+
+ if (searchptr == first_bracket_include) {
+ /* Go to bypass directory if we know we've seen this file before. */
+ static struct bypass_dir *bypass_hashtab[INCLUDE_HASHSIZE];
+ struct bypass_dir *p;
+ bypass_slot = &bypass_hashtab[hashf ((U_CHAR *) fbeg, flen,
+ INCLUDE_HASHSIZE)];
+ for (p = *bypass_slot; p; p = p->next)
+ if (!strcmp (fbeg, p->fname)) {
+ searchptr = p->searchptr;
+ bypass_slot = 0;
+ break;
+ }
}
- strncat (fname, (char *) fbeg, flen);
+
#ifdef VMS
/* Change this 1/2 Unix 1/2 VMS file specification into a
full VMS file specification */
- if (searchptr->fname && (searchptr->fname[0] != 0)) {
- /* Fix up the filename */
- hack_vms_include_specification (fname);
- } else {
- /* This is a normal VMS filespec, so use it unchanged. */
- strncpy (fname, fbeg, flen);
- fname[flen] = 0;
- /* if it's '#include filename', add the missing .h */
- if (index(fname,'.')==NULL) {
- strcat (fname, ".h");
+ if (searchptr->fname[0])
+ {
+ strcpy (fname, searchptr->fname);
+ if (fname[strlen (fname) - 1] == ':')
+ {
+ char *slashp;
+ slashp = strchr (fbeg, '/');
+
+ /* start at root-dir of logical device if no path given. */
+ if (slashp == 0)
+ strcat (fname, "[000000]");
+ }
+ strcat (fname, fbeg);
+
+ /* Fix up the filename */
+ hack_vms_include_specification (fname, vaxc_include);
}
- }
-#endif /* VMS */
- /* ??? There are currently 3 separate mechanisms for avoiding processing
- of redundant include files: #import, #pragma once, and
- redundant_include_p. It would be nice if they were unified. */
- if (redundant_include_p (fname))
- return 0;
- if (importing)
- f = lookup_import (fname, searchptr);
else
- f = open_include_file (fname, searchptr);
- if (f == -2)
- return 0; /* Already included this file */
-#ifdef EACCES
- else if (f == -1 && errno == EACCES)
- warning ("Header file %s exists, but is not readable", fname);
-#endif
- if (f >= 0)
+ {
+ /* This is a normal VMS filespec, so use it unchanged. */
+ strcpy (fname, fbeg);
+ /* if it's '#include filename', add the missing .h */
+ if (vaxc_include && index(fname,'.')==NULL)
+ strcat (fname, ".h");
+ }
+#else
+ strcpy (fname, searchptr->fname);
+ strcat (fname, fbeg);
+#endif /* VMS */
+ f = open_include_file (fname, searchptr, importing, &inc);
+ if (f != -1) {
+ if (bypass_slot && searchptr != first_bracket_include) {
+ /* This is the first time we found this include file,
+ and we found it after first_bracket_include.
+ Record its location so that we can bypass to here next time. */
+ struct bypass_dir *p
+ = (struct bypass_dir *) xmalloc (sizeof (struct bypass_dir));
+ p->next = *bypass_slot;
+ p->fname = fname + strlen (searchptr->fname);
+ p->searchptr = searchptr;
+ *bypass_slot = p;
+ }
+ break;
+ }
+#ifdef VMS
+ /* Our VMS hacks can produce invalid filespecs, so don't worry
+ about errors other than EACCES. */
+ if (errno == EACCES)
+ break;
+#else
+ if (errno != ENOENT && errno != ENOTDIR)
break;
+#endif
}
}
+
if (f < 0) {
- /* A file that was not found. */
- strncpy (fname, (char *) fbeg, flen);
- fname[flen] = 0;
+ if (f == -2) {
+ /* The file was already included. */
+
/* If generating dependencies and -MG was specified, we assume missing
files are leaf files, living in the same directory as the source file
or other similar place; these missing files may be generated from
other files and may not exist yet (eg: y.tab.h). */
- if (print_deps_missing_files
- && print_deps > (angle_brackets || (system_include_depth > 0)))
+ } else if (print_deps_missing_files
+ && (system_include_depth != 0) < print_deps)
{
/* If it was requested as a system header file,
then assume it belongs in the first place to look for such. */
if (angle_brackets)
{
- for (searchptr = search_start; searchptr; searchptr = searchptr->next)
- {
- if (searchptr->fname)
- {
- char *p;
-
- if (searchptr->fname[0] == 0)
- continue;
- p = (char *) alloca (strlen (searchptr->fname)
- + strlen (fname) + 2);
- strcpy (p, skip_redundant_dir_prefix (searchptr->fname));
- if (p[0] && p[strlen (p) - 1] != '/')
- strcat (p, "/");
- strcat (p, fname);
- deps_output (p, ' ');
- break;
- }
- }
+ if (search_start) {
+ char *p = (char *) alloca (strlen (search_start->fname)
+ + strlen (fbeg) + 1);
+ strcpy (p, search_start->fname);
+ strcat (p, fbeg);
+ deps_output (p, ' ');
+ }
}
else
{
/* Otherwise, omit the directory, as if the file existed
in the directory with the source. */
- deps_output (fname, ' ');
+ deps_output (fbeg, ' ');
}
}
/* If -M was specified, and this header file won't be added to the
@@ -4595,57 +4659,16 @@ get_filename:
still produce correct output. Otherwise, we can't produce correct
output, because there may be dependencies we need inside the missing
file, and we don't know what directory this missing file exists in. */
- else if (print_deps
- && (print_deps <= (angle_brackets || (system_include_depth > 0))))
- warning ("No include path in which to find %s", fname);
- else if (search_start)
- error_from_errno (fname);
+ else if (0 < print_deps && print_deps <= (system_include_depth != 0))
+ warning ("No include path in which to find %s", fbeg);
+ else if (f != -3)
+ error_from_errno (fbeg);
else
- error ("No include path in which to find %s", fname);
- } else {
- /* Check to see if this include file is a once-only include file.
- If so, give up. */
-
- struct file_name_list* ptr;
-
- for (ptr = dont_repeat_files; ptr; ptr = ptr->next) {
- if (!strcmp (ptr->fname, fname)) {
- close (f);
- return 0; /* This file was once'd. */
- }
- }
-
- for (ptr = all_include_files; ptr; ptr = ptr->next) {
- if (!strcmp (ptr->fname, fname))
- break; /* This file was included before. */
- }
-
- if (ptr == 0) {
- /* This is the first time for this file. */
- /* Add it to list of files included. */
-
- ptr = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
- ptr->control_macro = 0;
- ptr->c_system_include_path = 0;
- ptr->next = all_include_files;
- all_include_files = ptr;
- ptr->fname = savestring (fname);
- ptr->got_name_map = 0;
-
- /* For -M, add this file to the dependencies. */
- if (print_deps > (angle_brackets || (system_include_depth > 0)))
- deps_output (fname, ' ');
- }
+ error ("No include path in which to find %s", fbeg);
- /* Handle -H option. */
- if (print_include_names)
- fprintf (stderr, "%*s%s\n", indepth, "", fname);
-
- if (angle_brackets)
- system_include_depth++;
+ } else {
/* Actually process the file. */
- add_import (f, fname); /* Record file on "seen" list for #import. */
pcftry = (char *) alloca (strlen (fname) + 30);
pcfbuf = 0;
@@ -4653,10 +4676,6 @@ get_filename:
if (!no_precomp)
{
- struct stat stat_f;
-
- fstat (f, &stat_f);
-
do {
sprintf (pcftry, "%s%d", fname, pcfnum++);
@@ -4665,12 +4684,12 @@ get_filename:
{
struct stat s;
- fstat (pcf, &s);
- if (bcmp ((char *) &stat_f.st_ino, (char *) &s.st_ino,
- sizeof (s.st_ino))
- || stat_f.st_dev != s.st_dev)
+ if (fstat (pcf, &s) != 0)
+ pfatal_with_name (pcftry);
+ if (! INO_T_EQ (inc->st.st_ino, s.st_ino)
+ || inc->st.st_dev != s.st_dev)
{
- pcfbuf = check_precompiled (pcf, fname, &pcfbuflimit);
+ pcfbuf = check_precompiled (pcf, &s, fname, &pcfbuflimit);
/* Don't need it any more. */
close (pcf);
}
@@ -4692,28 +4711,11 @@ get_filename:
(U_CHAR *) fname, op);
}
else
- finclude (f, fname, op, is_system_include (fname), searchptr);
-
- if (angle_brackets)
- system_include_depth--;
+ finclude (f, inc, op, is_system_include (fname), searchptr);
}
- return 0;
-}
-/* Return nonzero if there is no need to include file NAME
- because it has already been included and it contains a conditional
- to make a repeated include do nothing. */
+ system_include_depth -= angle_brackets;
-static int
-redundant_include_p (name)
- char *name;
-{
- struct file_name_list *l = all_include_files;
- for (; l; l = l->next)
- if (! strcmp (name, l->fname)
- && l->control_macro
- && lookup (l->control_macro, -1, -1))
- return 1;
return 0;
}
@@ -4736,38 +4738,127 @@ is_system_include (filename)
for (searchptr = first_system_include; searchptr;
searchptr = searchptr->next)
- if (searchptr->fname) {
- register char *sys_dir = skip_redundant_dir_prefix (searchptr->fname);
- register unsigned length = strlen (sys_dir);
+ if (! strncmp (searchptr->fname, filename, strlen (searchptr->fname)))
+ return searchptr->c_system_include_path + 1;
+ return 0;
+}
+
+/* Yield the non-directory suffix of a file name. */
- if (! strncmp (sys_dir, filename, length)
- && (filename[length] == '/'
+static char *
+base_name (fname)
+ char *fname;
+{
+ char *s = fname;
+ char *p;
+#if defined (__MSDOS__) || defined (_WIN32)
+ if (ISALPHA (s[0]) && s[1] == ':') s += 2;
+#endif
+#ifdef VMS
+ if ((p = rindex (s, ':'))) s = p + 1; /* Skip device. */
+ if ((p = rindex (s, ']'))) s = p + 1; /* Skip directory. */
+ if ((p = rindex (s, '>'))) s = p + 1; /* Skip alternate (int'n'l) dir. */
+ if (s != fname)
+ return s;
+#endif
+ if ((p = rindex (s, '/'))) s = p + 1;
#ifdef DIR_SEPARATOR
- || filename[length] == DIR_SEPARATOR
+ if ((p = rindex (s, DIR_SEPARATOR))) s = p + 1;
+#endif
+ return s;
+}
+
+/* Yield nonzero if FILENAME is absolute (i.e. not relative). */
+
+static int
+absolute_filename (filename)
+ char *filename;
+{
+#if defined (__MSDOS__) || (defined (_WIN32) && !defined (__CYGWIN32__))
+ if (ISALPHA (filename[0]) && filename[1] == ':') filename += 2;
+#endif
+#if defined (__CYGWIN32__)
+ /* At present, any path that begins with a drive spec is absolute. */
+ if (ISALPHA (filename[0]) && filename[1] == ':') return 1;
+#endif
+#ifdef VMS
+ if (index (filename, ':') != 0) return 1;
+#endif
+ if (filename[0] == '/') return 1;
+#ifdef DIR_SEPARATOR
+ if (filename[0] == DIR_SEPARATOR) return 1;
#endif
- )) {
- if (searchptr->c_system_include_path)
- return 2;
- else
- return 1;
- }
- }
return 0;
}
-
-/* Skip leading "./" from a directory name.
- This may yield the empty string, which represents the current directory. */
-static char *
-skip_redundant_dir_prefix (dir)
- char *dir;
+/* Remove unnecessary characters from FILENAME in place,
+ to avoid unnecessary filename aliasing.
+ Return the length of the resulting string.
+
+ Do only the simplifications allowed by Posix.
+ It is OK to miss simplifications on non-Posix hosts,
+ since this merely leads to suboptimal results. */
+
+static size_t
+simplify_filename (filename)
+ char *filename;
{
- while (dir[0] == '.' && dir[1] == '/')
- for (dir += 2; *dir == '/'; dir++)
- continue;
- if (dir[0] == '.' && !dir[1])
- dir++;
- return dir;
+ register char *from = filename;
+ register char *to = filename;
+ char *to0;
+
+ /* Remove redundant initial /s. */
+ if (*from == '/') {
+ *to++ = '/';
+ if (*++from == '/') {
+ if (*++from == '/') {
+ /* 3 or more initial /s are equivalent to 1 /. */
+ while (*++from == '/')
+ continue;
+ } else {
+ /* On some hosts // differs from /; Posix allows this. */
+ static int slashslash_vs_slash;
+ if (slashslash_vs_slash == 0) {
+ struct stat s1, s2;
+ slashslash_vs_slash = ((stat ("/", &s1) == 0 && stat ("//", &s2) == 0
+ && INO_T_EQ (s1.st_ino, s2.st_ino)
+ && s1.st_dev == s2.st_dev)
+ ? 1 : -1);
+ }
+ if (slashslash_vs_slash < 0)
+ *to++ = '/';
+ }
+ }
+ }
+ to0 = to;
+
+ for (;;) {
+#ifndef VMS
+ if (from[0] == '.' && from[1] == '/')
+ from += 2;
+ else
+#endif
+ {
+ /* Copy this component and trailing /, if any. */
+ while ((*to++ = *from++) != '/') {
+ if (!to[-1]) {
+ /* Trim . component at end of nonempty name. */
+ to -= filename <= to - 3 && to[-3] == '/' && to[-2] == '.';
+
+ /* Trim unnecessary trailing /s. */
+ while (to0 < --to && to[-1] == '/')
+ continue;
+
+ *to = 0;
+ return to - filename;
+ }
+ }
+ }
+
+ /* Skip /s after a /. */
+ while (*from == '/')
+ from++;
+ }
}
/* The file_name_map structure holds a mapping of file names for a
@@ -4819,7 +4910,9 @@ read_filename_string (ch, f)
return alloc;
}
-/* Read the file name map file for DIRNAME. */
+/* Read the file name map file for DIRNAME.
+ If DIRNAME is empty, read the map file for the working directory;
+ otherwise DIRNAME must end in '/'. */
static struct file_name_map *
read_name_map (dirname)
@@ -4838,9 +4931,6 @@ read_name_map (dirname)
char *name;
FILE *f;
size_t dirlen;
- int separator_needed;
-
- dirname = skip_redundant_dir_prefix (dirname);
for (map_list_ptr = map_list; map_list_ptr;
map_list_ptr = map_list_ptr->map_list_next)
@@ -4853,11 +4943,9 @@ read_name_map (dirname)
map_list_ptr->map_list_map = NULL;
dirlen = strlen (dirname);
- separator_needed = dirlen != 0 && dirname[dirlen - 1] != '/';
- name = (char *) alloca (dirlen + strlen (FILE_NAME_MAP_FILE) + 2);
+ name = (char *) alloca (dirlen + strlen (FILE_NAME_MAP_FILE) + 1);
strcpy (name, dirname);
- name[dirlen] = '/';
- strcpy (name + dirlen + separator_needed, FILE_NAME_MAP_FILE);
+ strcat (name, FILE_NAME_MAP_FILE);
f = fopen (name, "r");
if (!f)
map_list_ptr->map_list_map = NULL;
@@ -4869,6 +4957,7 @@ read_name_map (dirname)
{
char *from, *to;
struct file_name_map *ptr;
+ size_t tolen;
if (is_space[ch])
continue;
@@ -4877,19 +4966,21 @@ read_name_map (dirname)
;
to = read_filename_string (ch, f);
+ simplify_filename (from);
+ tolen = simplify_filename (to);
+
ptr = ((struct file_name_map *)
xmalloc (sizeof (struct file_name_map)));
ptr->map_from = from;
/* Make the real filename absolute. */
- if (*to == '/')
+ if (absolute_filename (to))
ptr->map_to = to;
else
{
- ptr->map_to = xmalloc (dirlen + strlen (to) + 2);
+ ptr->map_to = xmalloc (dirlen + tolen + 1);
strcpy (ptr->map_to, dirname);
- ptr->map_to[dirlen] = '/';
- strcpy (ptr->map_to + dirlen + separator_needed, to);
+ strcat (ptr->map_to, to);
free (to);
}
@@ -4910,89 +5001,166 @@ read_name_map (dirname)
}
/* Try to open include file FILENAME. SEARCHPTR is the directory
- being tried from the include file search path. This function maps
- filenames on file systems based on information read by
+ being tried from the include file search path.
+ IMPORTING is "" if we are importing, null otherwise.
+ Return -2 if found, either a matching name or a matching inode.
+ Otherwise, open the file and return a file descriptor if successful
+ or -1 if unsuccessful.
+ Unless unsuccessful, put a descriptor of the included file into *PINC.
+ This function maps filenames on file systems based on information read by
read_name_map. */
static int
-open_include_file (filename, searchptr)
+open_include_file (filename, searchptr, importing, pinc)
+ char *filename;
+ struct file_name_list *searchptr;
+ U_CHAR *importing;
+ struct include_file **pinc;
+{
+ char *fname = remap ? remap_include_file (filename, searchptr) : filename;
+ int fd = -2;
+
+ /* Look up FNAME in include_hashtab. */
+ struct include_file **phead = &include_hashtab[hashf ((U_CHAR *) fname,
+ strlen (fname),
+ INCLUDE_HASHSIZE)];
+ struct include_file *inc, *head = *phead;
+ for (inc = head; inc; inc = inc->next)
+ if (!strcmp (fname, inc->fname))
+ break;
+
+ if (!inc
+ || ! inc->control_macro
+ || (inc->control_macro[0] && ! lookup (inc->control_macro, -1, -1))) {
+
+ fd = open (fname, O_RDONLY, 0);
+
+ if (fd < 0)
+ {
+#ifdef VMS
+ /* if #include <dir/file> fails, try again with hacked spec. */
+ if (!hack_vms_include_specification (fname, 0))
+ return fd;
+ fd = open (fname, O_RDONLY, 0);
+ if (fd < 0)
+#endif
+ return fd;
+ }
+
+ if (!inc) {
+ /* FNAME was not in include_hashtab; insert a new entry. */
+ inc = (struct include_file *) xmalloc (sizeof (struct include_file));
+ inc->next = head;
+ inc->fname = fname;
+ inc->control_macro = 0;
+ inc->deps_output = 0;
+ if (fstat (fd, &inc->st) != 0)
+ pfatal_with_name (fname);
+ *phead = inc;
+
+ /* Look for another file with the same inode and device. */
+ if (lookup_ino_include (inc)
+ && inc->control_macro
+ && (!inc->control_macro[0] || lookup (inc->control_macro, -1, -1))) {
+ close (fd);
+ fd = -2;
+ }
+ }
+
+ /* For -M, add this file to the dependencies. */
+ if (! inc->deps_output && (system_include_depth != 0) < print_deps) {
+ inc->deps_output = 1;
+ deps_output (fname, ' ');
+ }
+
+ /* Handle -H option. */
+ if (print_include_names)
+ fprintf (stderr, "%*s%s\n", indepth, "", fname);
+ }
+
+ if (importing)
+ inc->control_macro = importing;
+
+ *pinc = inc;
+ return fd;
+}
+
+/* Return the remapped name of the include file FILENAME.
+ SEARCHPTR is the directory being tried from the include file path. */
+
+static char *
+remap_include_file (filename, searchptr)
char *filename;
struct file_name_list *searchptr;
{
register struct file_name_map *map;
register char *from;
- char *p, *dir;
#ifndef FREEBSD_NATIVE
- if (searchptr && ! searchptr->got_name_map)
+ if (searchptr)
{
- searchptr->name_map = read_name_map (searchptr->fname
- ? searchptr->fname : ".");
- searchptr->got_name_map = 1;
- }
-
- /* First check the mapping for the directory we are using. */
- if (searchptr && searchptr->name_map)
- {
- from = filename;
- if (searchptr->fname)
- from += strlen (searchptr->fname) + 1;
- for (map = searchptr->name_map; map; map = map->map_next)
+ if (! searchptr->got_name_map)
{
- if (! strcmp (map->map_from, from))
- {
- /* Found a match. */
- return open (map->map_to, O_RDONLY, 0666);
- }
+ searchptr->name_map = read_name_map (searchptr->fname);
+ searchptr->got_name_map = 1;
}
+
+ /* Check the mapping for the directory we are using. */
+ from = filename + strlen (searchptr->fname);
+ for (map = searchptr->name_map; map; map = map->map_next)
+ if (! strcmp (map->map_from, from))
+ return map->map_to;
}
#endif
- /* Try to find a mapping file for the particular directory we are
- looking in. Thus #include <sys/types.h> will look up sys/types.h
- in /usr/include/header.gcc and look up types.h in
- /usr/include/sys/header.gcc. */
- p = rindex (filename, '/');
-#ifdef DIR_SEPARATOR
- if (! p) p = rindex (filename, DIR_SEPARATOR);
- else {
- char *tmp = rindex (filename, DIR_SEPARATOR);
- if (tmp != NULL && tmp > p) p = tmp;
- }
-#endif
- if (! p)
- p = filename;
- if (searchptr
- && searchptr->fname
- && strlen (searchptr->fname) == p - filename
- && ! strncmp (searchptr->fname, filename, p - filename))
- {
- /* FILENAME is in SEARCHPTR, which we've already checked. */
- return open (filename, O_RDONLY, 0666);
- }
+ from = base_name (filename);
- if (p == filename)
- {
- dir = ".";
- from = filename;
- }
- else
+ if (from != filename || !searchptr)
{
- dir = (char *) alloca (p - filename + 1);
- bcopy (filename, dir, p - filename);
- dir[p - filename] = '\0';
- from = p + 1;
- }
+ /* Try to find a mapping file for the particular directory we are
+ looking in. Thus #include <sys/types.h> will look up sys/types.h
+ in /usr/include/header.gcc and look up types.h in
+ /usr/include/sys/header.gcc. */
+
+ char *dir = (char *) alloca (from - filename + 1);
+ bcopy (filename, dir, from - filename);
+ dir[from - filename] = '\0';
+
#ifndef FREEBSD_NATIVE
- for (map = read_name_map (dir); map; map = map->map_next)
- if (! strcmp (map->map_from, from))
- return open (map->map_to, O_RDONLY, 0666);
+ for (map = read_name_map (dir); map; map = map->map_next)
+ if (! strcmp (map->map_from, from))
+ return map->map_to;
#endif
+ }
- return open (filename, O_RDONLY, 0666);
+ return filename;
+}
+
+/* Insert INC into the include file table, hashed by device and inode number.
+ If a file with different name but same dev+ino was already in the table,
+ return 1 and set INC's control macro to the already-known macro. */
+
+static int
+lookup_ino_include (inc)
+ struct include_file *inc;
+{
+ int hash = ((unsigned) (inc->st.st_dev + INO_T_HASH (inc->st.st_ino))
+ % INCLUDE_HASHSIZE);
+ struct include_file *i = include_ino_hashtab[hash];
+ inc->next_ino = i;
+ include_ino_hashtab[hash] = inc;
+
+ for (; i; i = i->next_ino)
+ if (INO_T_EQ (inc->st.st_ino, i->st.st_ino)
+ && inc->st.st_dev == i->st.st_dev) {
+ inc->control_macro = i->control_macro;
+ return 1;
+ }
+
+ return 0;
}
-/* Process the contents of include file FNAME, already open on descriptor F,
+/* Process file descriptor F, which corresponds to include file INC,
with output to OP.
SYSTEM_HEADER_P is 1 if this file resides in any one of the known
"system" include directories (as decided by the `is_system_include'
@@ -5001,58 +5169,55 @@ open_include_file (filename, searchptr)
or 0 if the file name was absolute. */
static void
-finclude (f, fname, op, system_header_p, dirptr)
+finclude (f, inc, op, system_header_p, dirptr)
int f;
- char *fname;
+ struct include_file *inc;
FILE_BUF *op;
int system_header_p;
struct file_name_list *dirptr;
{
- int st_mode;
- long st_size;
- long i;
+ char *fname = inc->fname;
+ int i;
FILE_BUF *fp; /* For input stack frame */
int missing_newline = 0;
CHECK_DEPTH (return;);
- if (file_size_and_mode (f, &st_mode, &st_size) < 0)
- {
- perror_with_name (fname);
- close (f);
- return;
- }
-
fp = &instack[indepth + 1];
bzero ((char *) fp, sizeof (FILE_BUF));
fp->nominal_fname = fp->fname = fname;
+ fp->nominal_fname_len = strlen (fname);
+ fp->inc = inc;
fp->length = 0;
fp->lineno = 1;
fp->if_stack = if_stack;
fp->system_header_p = system_header_p;
fp->dir = dirptr;
- if (S_ISREG (st_mode)) {
- fp->buf = (U_CHAR *) xmalloc (st_size + 2);
+ if (S_ISREG (inc->st.st_mode)) {
+ size_t s = (size_t) inc->st.st_size;
+ if (s != inc->st.st_size || s + 2 < s)
+ memory_full ();
+ fp->buf = (U_CHAR *) xmalloc (s + 2);
fp->bufp = fp->buf;
- /* Read the file contents, knowing that st_size is an upper bound
+ /* Read the file contents, knowing that s is an upper bound
on the number of bytes we can read. */
- fp->length = safe_read (f, (char *) fp->buf, st_size);
+ fp->length = safe_read (f, (char *) fp->buf, s);
if (fp->length < 0) goto nope;
}
- else if (S_ISDIR (st_mode)) {
+ else if (S_ISDIR (inc->st.st_mode)) {
error ("directory `%s' specified in #include", fname);
close (f);
return;
} else {
/* Cannot count its file size before reading.
First read the entire file into heap and
- copy them into buffer on stack. */
+ copy them into buffer on stack. */
int bsize = 2000;
+ int st_size = 0;
- st_size = 0;
fp->buf = (U_CHAR *) xmalloc (bsize + 2);
for (;;) {
@@ -5111,158 +5276,53 @@ finclude (f, fname, op, system_header_p, dirptr)
free (fp->buf);
}
-/* Record that inclusion of the file named FILE
+/* Record that inclusion of the include file INC
should be controlled by the macro named MACRO_NAME.
This means that trying to include the file again
will do something if that macro is defined. */
static void
-record_control_macro (file, macro_name)
- char *file;
+record_control_macro (inc, macro_name)
+ struct include_file *inc;
U_CHAR *macro_name;
{
- struct file_name_list *new;
-
- for (new = all_include_files; new; new = new->next) {
- if (!strcmp (new->fname, file)) {
- new->control_macro = macro_name;
- return;
- }
- }
-
- /* If the file is not in all_include_files, something's wrong. */
- abort ();
-}
-
-/* Maintain and search list of included files, for #import. */
-
-#define IMPORT_HASH_SIZE 31
-
-struct import_file {
- char *name;
- ino_t inode;
- dev_t dev;
- struct import_file *next;
-};
-
-/* Hash table of files already included with #include or #import. */
-
-static struct import_file *import_hash_table[IMPORT_HASH_SIZE];
-
-/* Hash a file name for import_hash_table. */
-
-static int
-import_hash (f)
- char *f;
-{
- int val = 0;
-
- while (*f) val += *f++;
- return (val%IMPORT_HASH_SIZE);
-}
-
-/* Search for file FILENAME in import_hash_table.
- Return -2 if found, either a matching name or a matching inode.
- Otherwise, open the file and return a file descriptor if successful
- or -1 if unsuccessful. */
-
-static int
-lookup_import (filename, searchptr)
- char *filename;
- struct file_name_list *searchptr;
-{
- struct import_file *i;
- int h;
- int hashval;
- struct stat sb;
- int fd;
-
- hashval = import_hash (filename);
-
- /* Attempt to find file in list of already included files */
- i = import_hash_table[hashval];
-
- while (i) {
- if (!strcmp (filename, i->name))
- return -2; /* return found */
- i = i->next;
- }
- /* Open it and try a match on inode/dev */
- fd = open_include_file (filename, searchptr);
- if (fd < 0)
- return fd;
- fstat (fd, &sb);
- for (h = 0; h < IMPORT_HASH_SIZE; h++) {
- i = import_hash_table[h];
- while (i) {
- /* Compare the inode and the device.
- Supposedly on some systems the inode is not a scalar. */
- if (!bcmp ((char *) &i->inode, (char *) &sb.st_ino, sizeof (sb.st_ino))
- && i->dev == sb.st_dev) {
- close (fd);
- return -2; /* return found */
- }
- i = i->next;
- }
- }
- return fd; /* Not found, return open file */
-}
-
-/* Add the file FNAME, open on descriptor FD, to import_hash_table. */
-
-static void
-add_import (fd, fname)
- int fd;
- char *fname;
-{
- struct import_file *i;
- int hashval;
- struct stat sb;
-
- hashval = import_hash (fname);
- fstat (fd, &sb);
- i = (struct import_file *)xmalloc (sizeof (struct import_file));
- i->name = xmalloc (strlen (fname)+1);
- strcpy (i->name, fname);
- bcopy ((char *) &sb.st_ino, (char *) &i->inode, sizeof (sb.st_ino));
- i->dev = sb.st_dev;
- i->next = import_hash_table[hashval];
- import_hash_table[hashval] = i;
+ if (!inc->control_macro || inc->control_macro[0])
+ inc->control_macro = macro_name;
}
/* Load the specified precompiled header into core, and verify its
preconditions. PCF indicates the file descriptor to read, which must
- be a regular file. FNAME indicates the file name of the original
- header. *LIMIT will be set to an address one past the end of the file.
+ be a regular file. *ST is its file status.
+ FNAME indicates the file name of the original header.
+ *LIMIT will be set to an address one past the end of the file.
If the preconditions of the file are not satisfied, the buffer is
freed and we return 0. If the preconditions are satisfied, return
the address of the buffer following the preconditions. The buffer, in
this case, should never be freed because various pieces of it will
be referred to until all precompiled strings are output at the end of
- the run.
-*/
+ the run. */
+
static char *
-check_precompiled (pcf, fname, limit)
+check_precompiled (pcf, st, fname, limit)
int pcf;
- char *fname;
+ struct stat *st;
+ char *fname ATTRIBUTE_UNUSED;
char **limit;
{
- int st_mode;
- long st_size;
int length = 0;
char *buf;
char *cp;
if (pcp_outfile)
return 0;
-
- if (file_size_and_mode (pcf, &st_mode, &st_size) < 0)
- return 0;
- if (S_ISREG (st_mode))
+ if (S_ISREG (st->st_mode))
{
- buf = xmalloc (st_size + 2);
- length = safe_read (pcf, buf, st_size);
+ size_t s = (size_t) st->st_size;
+ if (s != st->st_size || s + 2 < s)
+ memory_full ();
+ buf = xmalloc (s + 2);
+ length = safe_read (pcf, buf, s);
if (length < 0)
goto nope;
}
@@ -5275,7 +5335,7 @@ check_precompiled (pcf, fname, limit)
*limit = buf + length;
- /* File is in core. Check the preconditions. */
+ /* File is in core. Check the preconditions. */
if (!check_preconditions (buf))
goto nope;
for (cp = buf; *cp; cp++)
@@ -5297,6 +5357,7 @@ check_precompiled (pcf, fname, limit)
precompiled header. These are a series of #define and #undef
lines which must match the current contents of the hash
table. */
+
static int
check_preconditions (prec)
char *prec;
@@ -5355,7 +5416,8 @@ check_preconditions (prec)
/* Process the main body of a precompiled file. BUF points to the
string section of the file, following the preconditions. LIMIT is one
character past the end. NAME is the name of the file being read
- in. OP is the main output buffer */
+ in. OP is the main output buffer. */
+
static void
pcfinclude (buf, limit, name, op)
U_CHAR *buf, *limit, *name;
@@ -5372,7 +5434,7 @@ pcfinclude (buf, limit, name, op)
nstrings = (nstrings << 8) | *cp++;
nstrings = (nstrings << 8) | *cp++;
- /* Looping over each string... */
+ /* Looping over each string... */
while (nstrings--) {
U_CHAR *string_start;
U_CHAR *endofthiskey;
@@ -5384,14 +5446,14 @@ pcfinclude (buf, limit, name, op)
/* First skip to a longword boundary */
/* ??? Why a 4-byte boundary? On all machines? */
- /* NOTE: This works correctly even if HOST_WIDE_INT
+ /* NOTE: This works correctly even if size_t
is narrower than a pointer.
Do not try risky measures here to get another type to use!
Do not include stddef.h--it will fail! */
- if ((HOST_WIDE_INT) cp & 3)
- cp += 4 - ((HOST_WIDE_INT) cp & 3);
+ if ((size_t) cp & 3)
+ cp += 4 - ((size_t) cp & 3);
- /* Now get the string. */
+ /* Now get the string. */
str = (STRINGDEF *) (GENERIC_PTR) cp;
string_start = cp += sizeof (STRINGDEF);
@@ -5401,7 +5463,7 @@ pcfinclude (buf, limit, name, op)
/* We need to macro expand the string here to ensure that the
proper definition environment is in place. If it were only
expanded when we find out it is needed, macros necessary for
- its proper expansion might have had their definitions changed. */
+ its proper expansion might have had their definitions changed. */
tmpbuf = expand_to_temp_buffer (string_start, cp++, 0, 0);
/* Lineno is already set in the precompiled file */
str->contents = tmpbuf.buf;
@@ -5414,14 +5476,14 @@ pcfinclude (buf, limit, name, op)
*stringlist_tailp = str;
stringlist_tailp = &str->chain;
- /* Next comes a fourbyte number indicating the number of keys */
- /* for this string. */
+ /* Next comes a fourbyte number indicating the number of keys
+ for this string. */
nkeys = *cp++;
nkeys = (nkeys << 8) | *cp++;
nkeys = (nkeys << 8) | *cp++;
nkeys = (nkeys << 8) | *cp++;
- /* If this number is -1, then the string is mandatory. */
+ /* If this number is -1, then the string is mandatory. */
if (nkeys == -1)
str->writeflag = 1;
else
@@ -5434,11 +5496,11 @@ pcfinclude (buf, limit, name, op)
cp += sizeof (KEYDEF);
/* Find the end of the key. At the end of this for loop we
- advance CP to the start of the next key using this variable. */
+ advance CP to the start of the next key using this variable. */
endofthiskey = cp + strlen ((char *) cp);
kp->str = str;
- /* Expand the key, and enter it into the hash table. */
+ /* Expand the key, and enter it into the hash table. */
tmpbuf = expand_to_temp_buffer (cp, endofthiskey, 0, 0);
tmpbuf.bufp = tmpbuf.buf;
@@ -5465,12 +5527,13 @@ pcfinclude (buf, limit, name, op)
}
/* This output_line_directive serves to switch us back to the current
input file in case some of these strings get output (which will
- result in line directives for the header file being output). */
+ result in line directives for the header file being output). */
output_line_directive (&instack[indepth], op, 0, enter_file);
}
-/* Called from rescan when it hits a key for strings. Mark them all */
- /* used and clean up. */
+/* Called from rescan when it hits a key for strings. Mark them all
+ used and clean up. */
+
static void
pcstring_used (hp)
HASHNODE *hp;
@@ -5482,8 +5545,9 @@ pcstring_used (hp)
delete_macro (hp);
}
-/* Write the output, interspersing precompiled strings in their */
- /* appropriate places. */
+/* Write the output, interspersing precompiled strings in their
+ appropriate places. */
+
static void
write_output ()
{
@@ -5493,10 +5557,10 @@ write_output ()
char *line_directive = xmalloc (line_directive_len);
int len;
- /* In each run through the loop, either cur_buf_loc == */
- /* next_string_loc, in which case we print a series of strings, or */
- /* it is less than next_string_loc, in which case we write some of */
- /* the buffer. */
+ /* In each run through the loop, either cur_buf_loc ==
+ next_string_loc, in which case we print a series of strings, or
+ it is less than next_string_loc, in which case we write some of
+ the buffer. */
cur_buf_loc = outbuf.buf;
next_string = stringlist;
@@ -5510,7 +5574,8 @@ write_output ()
line_directive_len *= 2);
sprintf (line_directive, "\n# %d ", next_string->lineno);
strcpy (quote_string (line_directive + strlen (line_directive),
- (char *) next_string->filename),
+ (char *) next_string->filename,
+ strlen ((char *) next_string->filename)),
"\n");
safe_write (fileno (stdout), line_directive, strlen (line_directive));
safe_write (fileno (stdout),
@@ -5569,7 +5634,7 @@ pass_thru_directive (buf, limit, op, keyword)
appeared. So the arglist is just convenience data passed
between these two routines. It is not kept around after
the current #define has been processed and entered into the
- hash table. */
+ hash table. */
struct arglist {
struct arglist *next;
@@ -5580,7 +5645,8 @@ struct arglist {
};
/* Create a DEFINITION node from a #define directive. Arguments are
- as for do_define. */
+ as for do_define. */
+
static MACRODEF
create_definition (buf, limit, op)
U_CHAR *buf, *limit;
@@ -5591,6 +5657,7 @@ create_definition (buf, limit, op)
int sym_length; /* and how long it is */
int line = instack[indepth].lineno;
char *file = instack[indepth].nominal_fname;
+ size_t file_len = instack[indepth].nominal_fname_len;
int rest_args = 0;
DEFINITION *defn;
@@ -5609,7 +5676,7 @@ create_definition (buf, limit, op)
/* Lossage will occur if identifiers or control keywords are broken
across lines using backslash. This is not the right place to take
- care of that. */
+ care of that. */
if (*bp == '(') {
struct arglist *arg_ptrs = NULL;
@@ -5640,8 +5707,10 @@ create_definition (buf, limit, op)
while (is_idchar[*bp]) {
bp++;
/* do we have a "special" rest-args extension here? */
- if (limit - bp > REST_EXTENSION_LENGTH &&
- bcmp (rest_extension, bp, REST_EXTENSION_LENGTH) == 0) {
+ if (limit - bp > REST_EXTENSION_LENGTH
+ && bcmp (rest_extension, bp, REST_EXTENSION_LENGTH) == 0) {
+ if (pedantic && !instack[indepth].system_header_p)
+ pedwarn ("ANSI C does not allow macro with variable arguments");
rest_args = 1;
temp->rest_args = 1;
break;
@@ -5673,8 +5742,8 @@ create_definition (buf, limit, op)
struct arglist *otemp;
for (otemp = temp->next; otemp != NULL; otemp = otemp->next)
- if (temp->length == otemp->length &&
- bcmp (temp->name, otemp->name, temp->length) == 0) {
+ if (temp->length == otemp->length
+ && bcmp (temp->name, otemp->name, temp->length) == 0) {
error ("duplicate argument name `%.*s' in `#define'",
temp->length, temp->name);
goto nope;
@@ -5684,7 +5753,7 @@ create_definition (buf, limit, op)
++bp; /* skip paren */
SKIP_WHITE_SPACE (bp);
- /* now everything from bp before limit is the definition. */
+ /* now everything from bp before limit is the definition. */
defn = collect_expansion (bp, limit, argno, arg_ptrs);
defn->rest_args = rest_args;
@@ -5713,7 +5782,7 @@ create_definition (buf, limit, op)
if (is_hor_space[*bp]) {
bp++;
SKIP_WHITE_SPACE (bp);
- } else {
+ } else if (sym_length) {
switch (*bp) {
case '!': case '"': case '#': case '%': case '&': case '\'':
case ')': case '*': case '+': case ',': case '-': case '.':
@@ -5731,13 +5800,14 @@ create_definition (buf, limit, op)
}
}
}
- /* Now everything from bp before limit is the definition. */
+ /* Now everything from bp before limit is the definition. */
defn = collect_expansion (bp, limit, -1, NULL_PTR);
defn->args.argnames = (U_CHAR *) "";
}
defn->line = line;
defn->file = file;
+ defn->file_len = file_len;
/* OP is null if this is a predefinition */
defn->predefined = !op;
@@ -5798,7 +5868,9 @@ do_define (buf, limit, op, keyword)
pedwarn ("`%.*s' redefined", mdef.symlen, mdef.symnam);
if (hp->type == T_MACRO)
- pedwarn_with_file_and_line (hp->value.defn->file, hp->value.defn->line,
+ pedwarn_with_file_and_line (hp->value.defn->file,
+ hp->value.defn->file_len,
+ hp->value.defn->line,
"this is the location of the previous definition");
}
/* Replace the old definition. */
@@ -5835,7 +5907,8 @@ check_macro_name (symname, usage)
for (p = symname; is_idchar[*p]; p++)
;
sym_length = p - symname;
- if (sym_length == 0)
+ if (sym_length == 0
+ || (sym_length == 1 && *symname == 'L' && (*p == '\'' || *p == '"')))
error ("invalid %s name", usage);
else if (!is_idstart[*symname]
|| (sym_length == 7 && ! bcmp (symname, "defined", 7)))
@@ -5843,9 +5916,8 @@ check_macro_name (symname, usage)
return sym_length;
}
-/*
- * return zero if two DEFINITIONs are isomorphic
- */
+/* Return zero if two DEFINITIONs are isomorphic. */
+
static int
compare_defs (d1, d2)
DEFINITION *d1, *d2;
@@ -5857,7 +5929,8 @@ compare_defs (d1, d2)
if (d1->nargs != d2->nargs)
return 1;
- if (strcmp ((char *)d1->args.argnames, (char *)d2->args.argnames))
+ if (pedantic
+ && strcmp ((char *)d1->args.argnames, (char *)d2->args.argnames))
return 1;
for (a1 = d1->pattern, a2 = d2->pattern; a1 && a2;
a1 = a1->next, a2 = a2->next) {
@@ -5954,7 +6027,7 @@ collect_expansion (buf, end, nargs, arglist)
/* Scan thru the replacement list, ignoring comments and quoted
strings, picking up on the macro calls. It does a linear search
thru the arg list on every potential symbol. Profiling might say
- that something smarter should happen. */
+ that something smarter should happen. */
if (end < buf)
abort ();
@@ -6062,7 +6135,8 @@ collect_expansion (buf, end, nargs, arglist)
p++;
SKIP_WHITE_SPACE (p);
}
- if (! is_idstart[*p] || nargs == 0)
+ if (! is_idstart[*p] || nargs == 0
+ || (*p == 'L' && (p[1] == '\'' || p[1] == '"')))
error ("`#' operator is not followed by a macro argument name");
else
stringify = p;
@@ -6071,7 +6145,7 @@ collect_expansion (buf, end, nargs, arglist)
}
} else {
/* In -traditional mode, recognize arguments inside strings and
- and character constants, and ignore special properties of #.
+ character constants, and ignore special properties of #.
Arguments inside strings are considered "stringified", but no
extra quote marks are supplied. */
switch (c) {
@@ -6101,9 +6175,12 @@ collect_expansion (buf, end, nargs, arglist)
this must be -traditional. So replace the comment with
nothing at all. */
exp_p--;
- p += 1;
- while (p < limit && !(p[-2] == '*' && p[-1] == '/'))
- p++;
+ while (++p < limit) {
+ if (p[0] == '*' && p[1] == '/') {
+ p += 2;
+ break;
+ }
+ }
#if 0
/* Mark this as a concatenation-point, as if it had been ##. */
concat = p;
@@ -6122,7 +6199,8 @@ collect_expansion (buf, end, nargs, arglist)
while (p != limit && is_idchar[*p]) p++;
id_len = p - id_beg;
- if (is_idstart[c]) {
+ if (is_idstart[c]
+ && ! (id_len == 1 && c == 'L' && (*p == '\'' || *p == '"'))) {
register struct arglist *arg;
for (arg = arglist; arg != NULL; arg = arg->next) {
@@ -6224,8 +6302,8 @@ collect_expansion (buf, end, nargs, arglist)
static int
do_assert (buf, limit, op, keyword)
U_CHAR *buf, *limit;
- FILE_BUF *op;
- struct directive *keyword;
+ FILE_BUF *op ATTRIBUTE_UNUSED;
+ struct directive *keyword ATTRIBUTE_UNUSED;
{
U_CHAR *bp; /* temp ptr into input buffer */
U_CHAR *symname; /* remember where symbol name starts */
@@ -6248,7 +6326,7 @@ do_assert (buf, limit, op, keyword)
/* Lossage will occur if identifiers or control tokens are broken
across lines using backslash. This is not the right place to take
- care of that. */
+ care of that. */
if (*bp != '(') {
error ("missing token-sequence in `#assert'");
@@ -6301,8 +6379,8 @@ do_assert (buf, limit, op, keyword)
static int
do_unassert (buf, limit, op, keyword)
U_CHAR *buf, *limit;
- FILE_BUF *op;
- struct directive *keyword;
+ FILE_BUF *op ATTRIBUTE_UNUSED;
+ struct directive *keyword ATTRIBUTE_UNUSED;
{
U_CHAR *bp; /* temp ptr into input buffer */
U_CHAR *symname; /* remember where symbol name starts */
@@ -6327,7 +6405,7 @@ do_unassert (buf, limit, op, keyword)
/* Lossage will occur if identifiers or control tokens are broken
across lines using backslash. This is not the right place to take
- care of that. */
+ care of that. */
if (*bp == '(') {
int error_flag = 0;
@@ -6541,15 +6619,14 @@ free_token_list (tokens)
}
}
-/*
- * Install a name in the assertion hash table.
- *
- * If LEN is >= 0, it is the length of the name.
- * Otherwise, compute the length by scanning the entire name.
- *
- * If HASH is >= 0, it is the precomputed hash code.
- * Otherwise, compute the hash code.
- */
+/* Install a name in the assertion hash table.
+
+ If LEN is >= 0, it is the length of the name.
+ Otherwise, compute the length by scanning the entire name.
+
+ If HASH is >= 0, it is the precomputed hash code.
+ Otherwise, compute the hash code. */
+
static ASSERTION_HASHNODE *
assertion_install (name, len, hash)
U_CHAR *name;
@@ -6580,16 +6657,15 @@ assertion_install (name, len, hash)
return hp;
}
-/*
- * find the most recent hash node for name name (ending with first
- * non-identifier char) installed by install
- *
- * If LEN is >= 0, it is the length of the name.
- * Otherwise, compute the length by scanning the entire name.
- *
- * If HASH is >= 0, it is the precomputed hash code.
- * Otherwise, compute the hash code.
- */
+/* Find the most recent hash node for name "name" (ending with first
+ non-identifier char) installed by install
+
+ If LEN is >= 0, it is the length of the name.
+ Otherwise, compute the length by scanning the entire name.
+
+ If HASH is >= 0, it is the precomputed hash code.
+ Otherwise, compute the hash code. */
+
static ASSERTION_HASHNODE *
assertion_lookup (name, len, hash)
U_CHAR *name;
@@ -6617,8 +6693,8 @@ delete_assertion (hp)
if (hp->next != NULL)
hp->next->prev = hp->prev;
- /* make sure that the bucket chain header that
- the deleted guy was on points to the right thing afterwards. */
+ /* Make sure that the bucket chain header that the deleted guy was
+ on points to the right thing afterwards. */
if (hp == *hp->bucket_hdr)
*hp->bucket_hdr = hp->next;
@@ -6635,7 +6711,7 @@ static int
do_line (buf, limit, op, keyword)
U_CHAR *buf, *limit;
FILE_BUF *op;
- struct directive *keyword;
+ struct directive *keyword ATTRIBUTE_UNUSED;
{
register U_CHAR *bp;
FILE_BUF *ip = &instack[indepth];
@@ -6650,7 +6726,7 @@ do_line (buf, limit, op, keyword)
bp = tem.buf;
SKIP_WHITE_SPACE (bp);
- if (!isdigit (*bp)) {
+ if (!ISDIGIT (*bp)) {
error ("invalid format `#line' directive");
return 0;
}
@@ -6665,7 +6741,7 @@ do_line (buf, limit, op, keyword)
pedwarn ("line number out of range in `#line' directive");
/* skip over the line number. */
- while (isdigit (*bp))
+ while (ISDIGIT (*bp))
bp++;
#if 0 /* #line 10"foo.c" is supposed to be allowed. */
@@ -6697,7 +6773,7 @@ do_line (buf, limit, op, keyword)
case '\\':
{
char *bpc = (char *) bp;
- int c = parse_escape (&bpc);
+ HOST_WIDE_INT c = parse_escape (&bpc, (HOST_WIDE_INT) (U_CHAR) (-1));
bp = (U_CHAR *) bpc;
if (c < 0)
p--;
@@ -6707,7 +6783,7 @@ do_line (buf, limit, op, keyword)
break;
case '\"':
- p[-1] = 0;
+ *--p = 0;
goto fname_done;
}
fname_done:
@@ -6748,12 +6824,12 @@ do_line (buf, limit, op, keyword)
}
}
- hash_bucket =
- &fname_table[hashf (fname, fname_length, FNAME_HASHSIZE)];
+ hash_bucket = &fname_table[hashf (fname, fname_length, FNAME_HASHSIZE)];
for (hp = *hash_bucket; hp != NULL; hp = hp->next)
if (hp->length == fname_length &&
bcmp (hp->value.cpval, fname, fname_length) == 0) {
ip->nominal_fname = hp->value.cpval;
+ ip->nominal_fname_len = fname_length;
break;
}
if (hp == 0) {
@@ -6762,9 +6838,9 @@ do_line (buf, limit, op, keyword)
hp->next = *hash_bucket;
*hash_bucket = hp;
- hp->length = fname_length;
ip->nominal_fname = hp->value.cpval = ((char *) hp) + sizeof (HASHNODE);
- bcopy (fname, hp->value.cpval, fname_length);
+ ip->nominal_fname_len = hp->length = fname_length;
+ bcopy (fname, hp->value.cpval, fname_length + 1);
}
} else if (*bp) {
error ("invalid format `#line' directive");
@@ -6777,11 +6853,9 @@ do_line (buf, limit, op, keyword)
return 0;
}
-/*
- * remove the definition of a symbol from the symbol table.
- * according to un*x /lib/cpp, it is not an error to undef
- * something that has no definitions, so it isn't one here either.
- */
+/* Remove the definition of a symbol from the symbol table.
+ according to un*x /lib/cpp, it is not an error to undef
+ something that has no definitions, so it isn't one here either. */
static int
do_undef (buf, limit, op, keyword)
@@ -6819,20 +6893,18 @@ do_undef (buf, limit, op, keyword)
return 0;
}
-/*
- * Report an error detected by the program we are processing.
- * Use the text of the line in the error message.
- * (We use error because it prints the filename & line#.)
- */
+/* Report an error detected by the program we are processing.
+ Use the text of the line in the error message.
+ (We use error because it prints the filename & line#.) */
static int
do_error (buf, limit, op, keyword)
U_CHAR *buf, *limit;
- FILE_BUF *op;
- struct directive *keyword;
+ FILE_BUF *op ATTRIBUTE_UNUSED;
+ struct directive *keyword ATTRIBUTE_UNUSED;
{
int length = limit - buf;
- U_CHAR *copy = (U_CHAR *) xmalloc (length + 1);
+ U_CHAR *copy = (U_CHAR *) alloca (length + 1);
bcopy ((char *) buf, (char *) copy, length);
copy[length] = 0;
SKIP_WHITE_SPACE (copy);
@@ -6840,24 +6912,28 @@ do_error (buf, limit, op, keyword)
return 0;
}
-/*
- * Report a warning detected by the program we are processing.
- * Use the text of the line in the warning message, then continue.
- * (We use error because it prints the filename & line#.)
- */
+/* Report a warning detected by the program we are processing.
+ Use the text of the line in the warning message, then continue.
+ (We use error because it prints the filename & line#.) */
static int
do_warning (buf, limit, op, keyword)
U_CHAR *buf, *limit;
- FILE_BUF *op;
- struct directive *keyword;
+ FILE_BUF *op ATTRIBUTE_UNUSED;
+ struct directive *keyword ATTRIBUTE_UNUSED;
{
int length = limit - buf;
- U_CHAR *copy = (U_CHAR *) xmalloc (length + 1);
+ U_CHAR *copy = (U_CHAR *) alloca (length + 1);
bcopy ((char *) buf, (char *) copy, length);
copy[length] = 0;
SKIP_WHITE_SPACE (copy);
- warning ("#warning %s", copy);
+
+ if (pedantic && !instack[indepth].system_header_p)
+ pedwarn ("ANSI C does not allow `#warning'");
+
+ /* Use `pedwarn' not `warning', because #warning isn't in the C Standard;
+ if -pedantic-errors is given, #warning should cause an error. */
+ pedwarn ("#warning %s", copy);
return 0;
}
@@ -6868,34 +6944,21 @@ static void
do_once ()
{
int i;
- FILE_BUF *ip = NULL;
for (i = indepth; i >= 0; i--)
- if (instack[i].fname != NULL) {
- ip = &instack[i];
+ if (instack[i].inc) {
+ record_control_macro (instack[i].inc, (U_CHAR *) "");
break;
}
-
- if (ip != NULL) {
- struct file_name_list *new;
-
- new = (struct file_name_list *) xmalloc (sizeof (struct file_name_list));
- new->next = dont_repeat_files;
- dont_repeat_files = new;
- new->fname = savestring (ip->fname);
- new->control_macro = 0;
- new->got_name_map = 0;
- new->c_system_include_path = 0;
- }
}
-/* #ident has already been copied to the output file, so just ignore it. */
+/* Report program identification. */
static int
do_ident (buf, limit, op, keyword)
U_CHAR *buf, *limit;
FILE_BUF *op;
- struct directive *keyword;
+ struct directive *keyword ATTRIBUTE_UNUSED;
{
FILE_BUF trybuf;
int len;
@@ -6905,22 +6968,17 @@ do_ident (buf, limit, op, keyword)
pedwarn ("ANSI C does not allow `#ident'");
trybuf = expand_to_temp_buffer (buf, limit, 0, 0);
- buf = (U_CHAR *) alloca (trybuf.bufp - trybuf.buf + 1);
- bcopy ((char *) trybuf.buf, (char *) buf, trybuf.bufp - trybuf.buf);
- limit = buf + (trybuf.bufp - trybuf.buf);
- len = (limit - buf);
- free (trybuf.buf);
-
- /* Output directive name. */
- check_expand (op, 7);
+ buf = trybuf.buf;
+ len = trybuf.bufp - buf;
+
+ /* Output expanded directive. */
+ check_expand (op, 7 + len);
bcopy ("#ident ", (char *) op->bufp, 7);
op->bufp += 7;
-
- /* Output the expanded argument line. */
- check_expand (op, len);
bcopy ((char *) buf, (char *) op->bufp, len);
op->bufp += len;
+ free (buf);
return 0;
}
@@ -6929,9 +6987,9 @@ do_ident (buf, limit, op, keyword)
static int
do_pragma (buf, limit, op, keyword)
- U_CHAR *buf, *limit;
- FILE_BUF *op;
- struct directive *keyword;
+ U_CHAR *buf, *limit ATTRIBUTE_UNUSED;
+ FILE_BUF *op ATTRIBUTE_UNUSED;
+ struct directive *keyword ATTRIBUTE_UNUSED;
{
SKIP_WHITE_SPACE (buf);
if (!strncmp ((char *) buf, "once", 4)) {
@@ -6945,25 +7003,27 @@ do_pragma (buf, limit, op, keyword)
if (!strncmp ((char *) buf, "implementation", 14)) {
/* Be quiet about `#pragma implementation' for a file only if it hasn't
been included yet. */
- struct file_name_list *ptr;
- U_CHAR *p = buf + 14, *fname, *inc_fname;
+
+ int h;
+ U_CHAR *p = buf + 14, *fname;
SKIP_WHITE_SPACE (p);
- if (*p == '\n' || *p != '\"')
+ if (*p != '\"')
return 0;
fname = p + 1;
if ((p = (U_CHAR *) index ((char *) fname, '\"')))
*p = '\0';
- for (ptr = all_include_files; ptr; ptr = ptr->next) {
- inc_fname = (U_CHAR *) rindex (ptr->fname, '/');
- inc_fname = inc_fname ? inc_fname + 1 : (U_CHAR *) ptr->fname;
- if (inc_fname && !strcmp ((char *) inc_fname, (char *) fname))
- warning ("`#pragma implementation' for `%s' appears after file is included",
- fname);
+ for (h = 0; h < INCLUDE_HASHSIZE; h++) {
+ struct include_file *inc;
+ for (inc = include_hashtab[h]; inc; inc = inc->next) {
+ if (!strcmp (base_name (inc->fname), (char *) fname)) {
+ warning ("`#pragma implementation' for \"%s\" appears after its #include",fname);
+ return 0;
+ }
+ }
}
}
-
return 0;
}
@@ -6971,10 +7031,8 @@ do_pragma (buf, limit, op, keyword)
/* This was a fun hack, but #pragma seems to start to be useful.
By failing to recognize it, we pass it through unchanged to cc1. */
-/*
- * the behavior of the #pragma directive is implementation defined.
- * this implementation defines it as follows.
- */
+/* The behavior of the #pragma directive is implementation defined.
+ this implementation defines it as follows. */
static int
do_pragma ()
@@ -7000,9 +7058,9 @@ nope:
static int
do_sccs (buf, limit, op, keyword)
- U_CHAR *buf, *limit;
- FILE_BUF *op;
- struct directive *keyword;
+ U_CHAR *buf ATTRIBUTE_UNUSED, *limit ATTRIBUTE_UNUSED;
+ FILE_BUF *op ATTRIBUTE_UNUSED;
+ struct directive *keyword ATTRIBUTE_UNUSED;
{
if (pedantic)
pedwarn ("ANSI C does not allow `#sccs'");
@@ -7011,24 +7069,22 @@ do_sccs (buf, limit, op, keyword)
#endif /* defined (SCCS_DIRECTIVE) */
-/*
- * handle #if directive by
- * 1) inserting special `defined' keyword into the hash table
- * that gets turned into 0 or 1 by special_symbol (thus,
- * if the luser has a symbol called `defined' already, it won't
- * work inside the #if directive)
- * 2) rescan the input into a temporary output buffer
- * 3) pass the output buffer to the yacc parser and collect a value
- * 4) clean up the mess left from steps 1 and 2.
- * 5) call conditional_skip to skip til the next #endif (etc.),
- * or not, depending on the value from step 3.
- */
+/* Handle #if directive by
+ 1) inserting special `defined' keyword into the hash table
+ that gets turned into 0 or 1 by special_symbol (thus,
+ if the luser has a symbol called `defined' already, it won't
+ work inside the #if directive)
+ 2) rescan the input into a temporary output buffer
+ 3) pass the output buffer to the yacc parser and collect a value
+ 4) clean up the mess left from steps 1 and 2.
+ 5) call conditional_skip to skip til the next #endif (etc.),
+ or not, depending on the value from step 3. */
static int
do_if (buf, limit, op, keyword)
U_CHAR *buf, *limit;
FILE_BUF *op;
- struct directive *keyword;
+ struct directive *keyword ATTRIBUTE_UNUSED;
{
HOST_WIDE_INT value;
FILE_BUF *ip = &instack[indepth];
@@ -7038,16 +7094,14 @@ do_if (buf, limit, op, keyword)
return 0;
}
-/*
- * handle a #elif directive by not changing if_stack either.
- * see the comment above do_else.
- */
+/* Handle a #elif directive by not changing if_stack either.
+ see the comment above do_else. */
static int
do_elif (buf, limit, op, keyword)
U_CHAR *buf, *limit;
FILE_BUF *op;
- struct directive *keyword;
+ struct directive *keyword ATTRIBUTE_UNUSED;
{
HOST_WIDE_INT value;
FILE_BUF *ip = &instack[indepth];
@@ -7059,9 +7113,12 @@ do_elif (buf, limit, op, keyword)
if (if_stack->type != T_IF && if_stack->type != T_ELIF) {
error ("`#elif' after `#else'");
fprintf (stderr, " (matches line %d", if_stack->lineno);
- if (if_stack->fname != NULL && ip->fname != NULL &&
- strcmp (if_stack->fname, ip->nominal_fname) != 0)
- fprintf (stderr, ", file %s", if_stack->fname);
+ if (! (if_stack->fname_len == ip->nominal_fname_len
+ && !bcmp (if_stack->fname, ip->nominal_fname,
+ if_stack->fname_len))) {
+ fprintf (stderr, ", file ");
+ eprint_string (if_stack->fname, if_stack->fname_len);
+ }
fprintf (stderr, ")\n");
}
if_stack->type = T_ELIF;
@@ -7081,10 +7138,9 @@ do_elif (buf, limit, op, keyword)
return 0;
}
-/*
- * evaluate a #if expression in BUF, of length LENGTH,
- * then parse the result as a C expression and return the value as an int.
- */
+/* Evaluate a #if expression in BUF, of length LENGTH, then parse the
+ result as a C expression and return the value as an int. */
+
static HOST_WIDE_INT
eval_if_expression (buf, length)
U_CHAR *buf;
@@ -7101,18 +7157,18 @@ eval_if_expression (buf, length)
pcp_inside_if = 0;
delete_macro (save_defined); /* clean up special symbol */
- value = parse_c_expression ((char *) temp_obuf.buf);
+ temp_obuf.buf[temp_obuf.length] = '\n';
+ value = parse_c_expression ((char *) temp_obuf.buf,
+ warn_undef && !instack[indepth].system_header_p);
free (temp_obuf.buf);
return value;
}
-/*
- * routine to handle ifdef/ifndef. Try to look up the symbol,
- * then do or don't skip to the #endif/#else/#elif depending
- * on what directive is actually being processed.
- */
+/* routine to handle ifdef/ifndef. Try to look up the symbol, then do
+ or don't skip to the #endif/#else/#elif depending on what directive
+ is actually being processed. */
static int
do_xifdef (buf, limit, op, keyword)
@@ -7169,18 +7225,20 @@ do_xifdef (buf, limit, op, keyword)
} else {
HASHNODE *hp;
- if (pedantic && buf[0] >= '0' && buf[0] <= '9')
- pedwarn ("`#%s' argument starts with a digit", keyword->name);
- else if (end != limit && !traditional)
- pedwarn ("garbage at end of `#%s' argument", keyword->name);
+ if (! traditional) {
+ if (ISDIGIT (buf[0]))
+ pedwarn ("`#%s' argument starts with a digit", keyword->name);
+ else if (end != limit)
+ pedwarn ("garbage at end of `#%s' argument", keyword->name);
+ }
hp = lookup (buf, end-buf, -1);
if (pcp_outfile) {
/* Output a precondition for this macro. */
- if (hp &&
- (hp->type == T_CONST
- || (hp->type == T_MACRO && hp->value.defn->predefined)))
+ if (hp
+ && (hp->type == T_CONST
+ || (hp->type == T_MACRO && hp->value.defn->predefined)))
fprintf (pcp_outfile, "#define %s\n", hp->name);
else {
U_CHAR *cp = buf;
@@ -7220,6 +7278,7 @@ conditional_skip (ip, skip, type, control_macro, op)
temp = (IF_STACK_FRAME *) xcalloc (1, sizeof (IF_STACK_FRAME));
temp->fname = ip->nominal_fname;
+ temp->fname_len = ip->nominal_fname_len;
temp->lineno = ip->lineno;
temp->next = if_stack;
temp->control_macro = control_macro;
@@ -7236,11 +7295,10 @@ conditional_skip (ip, skip, type, control_macro, op)
}
}
-/*
- * skip to #endif, #else, or #elif. adjust line numbers, etc.
- * leaves input ptr at the sharp sign found.
- * If ANY is nonzero, return at next directive of any sort.
- */
+/* Skip to #endif, #else, or #elif. adjust line numbers, etc.
+ Leaves input ptr at the sharp sign found.
+ If ANY is nonzero, return at next directive of any sort. */
+
static void
skip_if_group (ip, any, op)
FILE_BUF *ip;
@@ -7257,6 +7315,7 @@ skip_if_group (ip, any, op)
/* Save info about where the group starts. */
U_CHAR *beg_of_group = bp;
int beg_lineno = ip->lineno;
+ int skipping_include_directive = 0;
if (output_conditionals && op != 0) {
char *ptr = "#failed\n";
@@ -7285,22 +7344,49 @@ skip_if_group (ip, any, op)
bp = skip_to_end_of_comment (ip, &ip->lineno, 0);
}
break;
+ case '<':
+ if (skipping_include_directive) {
+ while (bp < endb && *bp != '>' && *bp != '\n') {
+ if (*bp == '\\' && bp[1] == '\n') {
+ ip->lineno++;
+ bp++;
+ }
+ bp++;
+ }
+ }
+ break;
case '\"':
+ if (skipping_include_directive) {
+ while (bp < endb && *bp != '\n') {
+ if (*bp == '"') {
+ bp++;
+ break;
+ }
+ if (*bp == '\\' && bp[1] == '\n') {
+ ip->lineno++;
+ bp++;
+ }
+ bp++;
+ }
+ break;
+ }
+ /* Fall through. */
case '\'':
bp = skip_quoted_string (bp - 1, endb, ip->lineno, &ip->lineno,
NULL_PTR, NULL_PTR);
break;
case '\\':
- /* Char after backslash loses its special meaning. */
- if (bp < endb) {
- if (*bp == '\n')
- ++ip->lineno; /* But do update the line-count. */
+ /* Char after backslash loses its special meaning in some cases. */
+ if (*bp == '\n') {
+ ++ip->lineno;
+ bp++;
+ } else if (traditional && bp < endb)
bp++;
- }
break;
case '\n':
++ip->lineno;
beg_of_line = bp;
+ skipping_include_directive = 0;
break;
case '%':
if (beg_of_line == 0 || traditional)
@@ -7361,23 +7447,37 @@ skip_if_group (ip, any, op)
bp++;
else if (*bp == '\\' && bp[1] == '\n')
bp += 2;
- else if (*bp == '/' && bp[1] == '*') {
- bp += 2;
- while (!(*bp == '*' && bp[1] == '/')) {
- if (*bp == '\n')
- ip->lineno++;
- bp++;
- }
- bp += 2;
- } else if (cplusplus_comments && *bp == '/' && bp[1] == '/') {
- bp += 2;
- while (bp[-1] == '\\' || *bp != '\n') {
- if (*bp == '\n')
- ip->lineno++;
- bp++;
- }
- }
- else break;
+ else if (*bp == '/') {
+ if (bp[1] == '\\' && bp[2] == '\n')
+ newline_fix (bp + 1);
+ if (bp[1] == '*') {
+ for (bp += 2; ; bp++) {
+ if (*bp == '\n')
+ ip->lineno++;
+ else if (*bp == '*') {
+ if (bp[-1] == '/' && warn_comments)
+ warning ("`/*' within comment");
+ if (bp[1] == '\\' && bp[2] == '\n')
+ newline_fix (bp + 1);
+ if (bp[1] == '/')
+ break;
+ }
+ }
+ bp += 2;
+ } else if (bp[1] == '/' && cplusplus_comments) {
+ for (bp += 2; ; bp++) {
+ if (*bp == '\n') {
+ if (bp[-1] != '\\')
+ break;
+ if (warn_comments)
+ warning ("multiline `//' comment");
+ ip->lineno++;
+ }
+ }
+ } else
+ break;
+ } else
+ break;
}
cp = bp;
@@ -7453,12 +7553,13 @@ skip_if_group (ip, any, op)
if_stack = temp;
temp->lineno = ip->lineno;
temp->fname = ip->nominal_fname;
+ temp->fname_len = ip->nominal_fname_len;
temp->type = kt->type;
break;
case T_ELSE:
case T_ENDIF:
if (pedantic && if_stack != save_if_stack)
- validate_else (bp);
+ validate_else (bp, endb);
case T_ELIF:
if (if_stack == instack[indepth].if_stack) {
error ("`#%s' not within a conditional", kt->name);
@@ -7479,7 +7580,13 @@ skip_if_group (ip, any, op)
free (temp);
break;
- default:
+ case T_INCLUDE:
+ case T_INCLUDE_NEXT:
+ case T_IMPORT:
+ skipping_include_directive = 1;
+ break;
+
+ default:
break;
}
break;
@@ -7518,18 +7625,16 @@ skip_if_group (ip, any, op)
}
}
-/*
- * handle a #else directive. Do this by just continuing processing
- * without changing if_stack ; this is so that the error message
- * for missing #endif's etc. will point to the original #if. It
- * is possible that something different would be better.
- */
+/* Handle a #else directive. Do this by just continuing processing
+ without changing if_stack ; this is so that the error message
+ for missing #endif's etc. will point to the original #if. It
+ is possible that something different would be better. */
static int
do_else (buf, limit, op, keyword)
U_CHAR *buf, *limit;
FILE_BUF *op;
- struct directive *keyword;
+ struct directive *keyword ATTRIBUTE_UNUSED;
{
FILE_BUF *ip = &instack[indepth];
@@ -7550,8 +7655,12 @@ do_else (buf, limit, op, keyword)
if (if_stack->type != T_IF && if_stack->type != T_ELIF) {
error ("`#else' after `#else'");
fprintf (stderr, " (matches line %d", if_stack->lineno);
- if (strcmp (if_stack->fname, ip->nominal_fname) != 0)
- fprintf (stderr, ", file %s", if_stack->fname);
+ if (! (if_stack->fname_len == ip->nominal_fname_len
+ && !bcmp (if_stack->fname, ip->nominal_fname,
+ if_stack->fname_len))) {
+ fprintf (stderr, ", file ");
+ eprint_string (if_stack->fname, if_stack->fname_len);
+ }
fprintf (stderr, ")\n");
}
if_stack->type = T_ELSE;
@@ -7566,15 +7675,13 @@ do_else (buf, limit, op, keyword)
return 0;
}
-/*
- * unstack after #endif directive
- */
+/* Unstack after #endif directive. */
static int
do_endif (buf, limit, op, keyword)
U_CHAR *buf, *limit;
FILE_BUF *op;
- struct directive *keyword;
+ struct directive *keyword ATTRIBUTE_UNUSED;
{
if (pedantic) {
SKIP_WHITE_SPACE (buf);
@@ -7619,7 +7726,7 @@ do_endif (buf, limit, op, keyword)
if (indepth != 0
&& ! (indepth == 1 && no_record_file)
&& ! (no_record_file && no_output))
- record_control_macro (ip->fname, temp->control_macro);
+ record_control_macro (ip->inc, temp->control_macro);
fail: ;
}
free (temp);
@@ -7630,43 +7737,45 @@ do_endif (buf, limit, op, keyword)
/* When an #else or #endif is found while skipping failed conditional,
if -pedantic was specified, this is called to warn about text after
- the directive name. P points to the first char after the directive name. */
+ the directive name. P points to the first char after the directive
+ name. */
static void
-validate_else (p)
+validate_else (p, limit)
register U_CHAR *p;
+ register U_CHAR *limit;
{
/* Advance P over whitespace and comments. */
while (1) {
- if (*p == '\\' && p[1] == '\n')
+ while (*p == '\\' && p[1] == '\n')
p += 2;
if (is_hor_space[*p])
p++;
else if (*p == '/') {
- if (p[1] == '\\' && p[2] == '\n')
- newline_fix (p + 1);
- if (p[1] == '*') {
+ while (p[1] == '\\' && p[2] == '\n')
p += 2;
+ if (p[1] == '*') {
/* Don't bother warning about unterminated comments
since that will happen later. Just be sure to exit. */
- while (*p) {
- if (p[1] == '\\' && p[2] == '\n')
- newline_fix (p + 1);
- if (*p == '*' && p[1] == '/') {
- p += 2;
- break;
+ for (p += 2; ; p++) {
+ if (p == limit)
+ return;
+ if (*p == '*') {
+ while (p[1] == '\\' && p[2] == '\n')
+ p += 2;
+ if (p[1] == '/') {
+ p += 2;
+ break;
+ }
}
- p++;
}
}
- else if (cplusplus_comments && p[1] == '/') {
- p += 2;
- while (*p && (*p != '\n' || p[-1] == '\\'))
- p++;
- }
+ else if (cplusplus_comments && p[1] == '/')
+ return;
+ else break;
} else break;
}
- if (*p && *p != '\n')
+ if (*p != '\n')
pedwarn ("text following `#else' or `#endif' violates ANSI standard");
}
@@ -7677,9 +7786,10 @@ validate_else (p)
counter is not sufficient to deal with newlines in the string.
If NOWARN is nonzero, don't warn about slash-star inside a comment.
- This feature is useful when processing a comment that is going to be
- processed or was processed at another point in the preprocessor,
- to avoid a duplicate warning. Likewise for unterminated comment errors. */
+ This feature is useful when processing a comment that is going to
+ be processed or was processed at another point in the preprocessor,
+ to avoid a duplicate warning. Likewise for unterminated comment
+ errors. */
static U_CHAR *
skip_to_end_of_comment (ip, line_counter, nowarn)
@@ -7689,54 +7799,38 @@ skip_to_end_of_comment (ip, line_counter, nowarn)
{
register U_CHAR *limit = ip->buf + ip->length;
register U_CHAR *bp = ip->bufp;
- FILE_BUF *op = &outbuf; /* JF */
- int output = put_out_comments && !line_counter;
+ FILE_BUF *op = put_out_comments && !line_counter ? &outbuf : (FILE_BUF *) 0;
int start_line = line_counter ? *line_counter : 0;
/* JF this line_counter stuff is a crock to make sure the
comment is only put out once, no matter how many times
the comment is skipped. It almost works */
- if (output) {
+ if (op) {
*op->bufp++ = '/';
- *op->bufp++ = '*';
+ *op->bufp++ = bp[-1];
}
if (cplusplus_comments && bp[-1] == '/') {
- if (output) {
- while (bp < limit) {
- *op->bufp++ = *bp;
- if (*bp == '\n' && bp[-1] != '\\')
+ for (; bp < limit; bp++) {
+ if (*bp == '\n') {
+ if (bp[-1] != '\\')
break;
- if (*bp == '\n') {
+ if (!nowarn && warn_comments)
+ warning ("multiline `//' comment");
+ if (line_counter)
++*line_counter;
+ if (op)
++op->lineno;
- }
- bp++;
- }
- op->bufp[-1] = '*';
- *op->bufp++ = '/';
- *op->bufp++ = '\n';
- } else {
- while (bp < limit) {
- if (bp[-1] != '\\' && *bp == '\n') {
- break;
- } else {
- if (*bp == '\n' && line_counter)
- ++*line_counter;
- bp++;
- }
}
+ if (op)
+ *op->bufp++ = *bp;
}
ip->bufp = bp;
return bp;
}
while (bp < limit) {
- if (output)
+ if (op)
*op->bufp++ = *bp;
switch (*bp++) {
- case '/':
- if (warn_comments && !nowarn && bp < limit && *bp == '*')
- warning ("`/*' within comment");
- break;
case '\n':
/* If this is the end of the file, we have an unterminated comment.
Don't swallow the newline. We are guaranteed that there will be a
@@ -7749,14 +7843,16 @@ skip_to_end_of_comment (ip, line_counter, nowarn)
}
if (line_counter != NULL)
++*line_counter;
- if (output)
+ if (op)
++op->lineno;
break;
case '*':
+ if (bp[-2] == '/' && !nowarn && warn_comments)
+ warning ("`/*' within comment");
if (*bp == '\\' && bp[1] == '\n')
newline_fix (bp);
if (*bp == '/') {
- if (output)
+ if (op)
*op->bufp++ = '/';
ip->bufp = ++bp;
return bp;
@@ -7771,22 +7867,21 @@ skip_to_end_of_comment (ip, line_counter, nowarn)
return bp;
}
-/*
- * Skip over a quoted string. BP points to the opening quote.
- * Returns a pointer after the closing quote. Don't go past LIMIT.
- * START_LINE is the line number of the starting point (but it need
- * not be valid if the starting point is inside a macro expansion).
- *
- * The input stack state is not changed.
- *
- * If COUNT_NEWLINES is nonzero, it points to an int to increment
- * for each newline passed.
- *
- * If BACKSLASH_NEWLINES_P is nonzero, store 1 thru it
- * if we pass a backslash-newline.
- *
- * If EOFP is nonzero, set *EOFP to 1 if the string is unterminated.
- */
+/* Skip over a quoted string. BP points to the opening quote.
+ Returns a pointer after the closing quote. Don't go past LIMIT.
+ START_LINE is the line number of the starting point (but it need
+ not be valid if the starting point is inside a macro expansion).
+
+ The input stack state is not changed.
+
+ If COUNT_NEWLINES is nonzero, it points to an int to increment
+ for each newline passed.
+
+ If BACKSLASH_NEWLINES_P is nonzero, store 1 thru it
+ if we pass a backslash-newline.
+
+ If EOFP is nonzero, set *EOFP to 1 if the string is unterminated. */
+
static U_CHAR *
skip_quoted_string (bp, limit, start_line, count_newlines, backslash_newlines_p, eofp)
register U_CHAR *bp;
@@ -7819,21 +7914,22 @@ skip_quoted_string (bp, limit, start_line, count_newlines, backslash_newlines_p,
++*count_newlines;
bp += 2;
}
- if (*bp == '\n' && count_newlines) {
+ if (*bp == '\n') {
if (backslash_newlines_p)
*backslash_newlines_p = 1;
- ++*count_newlines;
+ if (count_newlines)
+ ++*count_newlines;
}
bp++;
} else if (c == '\n') {
if (traditional) {
/* Unterminated strings and character constants are 'valid'. */
- bp--; /* Don't consume the newline. */
+ bp--; /* Don't consume the newline. */
if (eofp)
*eofp = 1;
break;
}
- if (pedantic || match == '\'') {
+ if (match == '\'') {
error_with_line (line_for_error (start_line),
"unterminated string or character constant");
bp--;
@@ -7844,8 +7940,12 @@ skip_quoted_string (bp, limit, start_line, count_newlines, backslash_newlines_p,
/* If not traditional, then allow newlines inside strings. */
if (count_newlines)
++*count_newlines;
- if (multiline_string_line == 0)
+ if (multiline_string_line == 0) {
+ if (pedantic)
+ pedwarn_with_line (line_for_error (start_line),
+ "string constant runs past end of line");
multiline_string_line = start_line;
+ }
} else if (c == match)
break;
}
@@ -7853,19 +7953,23 @@ skip_quoted_string (bp, limit, start_line, count_newlines, backslash_newlines_p,
}
/* Place into DST a quoted string representing the string SRC.
+ SRCLEN is the length of SRC; SRC may contain null bytes.
Return the address of DST's terminating null. */
+
static char *
-quote_string (dst, src)
+quote_string (dst, src, srclen)
char *dst, *src;
+ size_t srclen;
{
U_CHAR c;
+ char *srclim = src + srclen;
*dst++ = '\"';
- for (;;)
+ while (src != srclim)
switch ((c = *src++))
{
default:
- if (isprint (c))
+ if (ISPRINT (c))
*dst++ = c;
else
{
@@ -7879,12 +7983,11 @@ quote_string (dst, src)
*dst++ = '\\';
*dst++ = c;
break;
-
- case '\0':
- *dst++ = '\"';
- *dst = '\0';
- return dst;
}
+
+ *dst++ = '\"';
+ *dst = '\0';
+ return dst;
}
/* Skip across a group of balanced parens, starting from IP->bufp.
@@ -7938,13 +8041,11 @@ skip_paren_group (ip)
return p;
}
-/*
- * write out a #line directive, for instance, after an #include file.
- * If CONDITIONAL is nonzero, we can omit the #line if it would
- * appear to be a no-op, and we can output a few newlines instead
- * if we want to increase the line number by a small amount.
- * FILE_CHANGE says whether we are entering a file, leaving, or neither.
- */
+/* Write out a #line directive, for instance, after an #include file.
+ If CONDITIONAL is nonzero, we can omit the #line if it would
+ appear to be a no-op, and we can output a few newlines instead
+ if we want to increase the line number by a small amount.
+ FILE_CHANGE says whether we are entering a file, leaving, or neither. */
static void
output_line_directive (ip, op, conditional, file_change)
@@ -7978,17 +8079,17 @@ output_line_directive (ip, op, conditional, file_change)
}
}
- /* Don't output a line number of 0 if we can help it. */
- if (ip->lineno == 0 && ip->bufp - ip->buf < ip->length
- && *ip->bufp == '\n') {
+ /* Output a positive line number if possible. */
+ while (ip->lineno <= 0 && ip->bufp - ip->buf < ip->length
+ && *ip->bufp == '\n') {
ip->lineno++;
ip->bufp++;
}
- line_directive_buf = (char *) alloca (4 * strlen (ip->nominal_fname) + 100);
+ line_directive_buf = (char *) alloca (4 * ip->nominal_fname_len + 100);
sprintf (line_directive_buf, "# %d ", ip->lineno);
line_end = quote_string (line_directive_buf + strlen (line_directive_buf),
- ip->nominal_fname);
+ ip->nominal_fname, ip->nominal_fname_len);
if (file_change != same_file) {
*line_end++ = ' ';
*line_end++ = file_change == enter_file ? '1' : '2';
@@ -8100,7 +8201,7 @@ macroexpand (hp, op)
if (rest_args)
continue;
if (i < nargs || (nargs == 0 && i == 0)) {
- /* if we are working on last arg which absorbs rest of args... */
+ /* If we are working on last arg which absorbs rest of args... */
if (i == nargs - 1 && defn->rest_args)
rest_args = 1;
parse_error = macarg (&args[i], rest_args);
@@ -8253,29 +8354,30 @@ macroexpand (hp, op)
for (; i < arglen; i++) {
c = arg->raw[i];
- /* Special markers Newline Space
- generate nothing for a stringified argument. */
- if (c == '\n' && arg->raw[i+1] != '\n') {
- i++;
- continue;
- }
+ if (! in_string) {
+ /* Special markers Newline Space
+ generate nothing for a stringified argument. */
+ if (c == '\n' && arg->raw[i+1] != '\n') {
+ i++;
+ continue;
+ }
- /* Internal sequences of whitespace are replaced by one space
- except within an string or char token. */
- if (! in_string
- && (c == '\n' ? arg->raw[i+1] == '\n' : is_space[c])) {
- while (1) {
- /* Note that Newline Space does occur within whitespace
- sequences; consider it part of the sequence. */
- if (c == '\n' && is_space[arg->raw[i+1]])
- i += 2;
- else if (c != '\n' && is_space[c])
- i++;
- else break;
- c = arg->raw[i];
+ /* Internal sequences of whitespace are replaced by one space
+ except within an string or char token. */
+ if (c == '\n' ? arg->raw[i+1] == '\n' : is_space[c]) {
+ while (1) {
+ /* Note that Newline Space does occur within whitespace
+ sequences; consider it part of the sequence. */
+ if (c == '\n' && is_space[arg->raw[i+1]])
+ i += 2;
+ else if (c != '\n' && is_space[c])
+ i++;
+ else break;
+ c = arg->raw[i];
+ }
+ i--;
+ c = ' ';
}
- i--;
- c = ' ';
}
if (escaped)
@@ -8293,12 +8395,10 @@ macroexpand (hp, op)
/* Escape these chars */
if (c == '\"' || (in_string && c == '\\'))
xbuf[totlen++] = '\\';
- if (isprint (c))
- xbuf[totlen++] = c;
- else {
- sprintf ((char *) &xbuf[totlen], "\\%03o", (unsigned int) c);
- totlen += 4;
- }
+ /* We used to output e.g. \008 for control characters here,
+ but this doesn't conform to the C Standard.
+ Just output the characters as-is. */
+ xbuf[totlen++] = c;
}
if (!traditional)
xbuf[totlen++] = '\"'; /* insert ending quote */
@@ -8378,8 +8478,8 @@ macroexpand (hp, op)
abort ();
}
- /* if there is anything left of the definition
- after handling the arg list, copy that in too. */
+ /* If there is anything left of the definition after handling
+ the arg list, copy that in too. */
for (i = offset; i < defn->length; i++) {
/* if we've reached the end of the macro */
@@ -8414,6 +8514,8 @@ macroexpand (hp, op)
ip2->fname = 0;
ip2->nominal_fname = 0;
+ ip2->nominal_fname_len = 0;
+ ip2->inc = 0;
/* This may not be exactly correct, but will give much better error
messages for nested macro calls than using a line number of zero. */
ip2->lineno = start_line;
@@ -8434,11 +8536,9 @@ macroexpand (hp, op)
}
}
-/*
- * Parse a macro argument and store the info on it into *ARGPTR.
- * REST_ARGS is passed to macarg1 to make it absorb the rest of the args.
- * Return nonzero to indicate a syntax error.
- */
+/* Parse a macro argument and store the info on it into *ARGPTR.
+ REST_ARGS is passed to macarg1 to make it absorb the rest of the args.
+ Return nonzero to indicate a syntax error. */
static char *
macarg (argptr, rest_args)
@@ -8453,7 +8553,7 @@ macarg (argptr, rest_args)
/* Try to parse as much of the argument as exists at this
input stack level. */
- U_CHAR *bp = macarg1 (ip->bufp, ip->buf + ip->length,
+ U_CHAR *bp = macarg1 (ip->bufp, ip->buf + ip->length, ip->macro,
&paren, &newlines, &comments, rest_args);
/* If we find the end of the argument at this level,
@@ -8491,7 +8591,7 @@ macarg (argptr, rest_args)
ip = &instack[--indepth];
newlines = 0;
comments = 0;
- bp = macarg1 (ip->bufp, ip->buf + ip->length, &paren,
+ bp = macarg1 (ip->bufp, ip->buf + ip->length, ip->macro, &paren,
&newlines, &comments, rest_args);
final_start = bufsize;
bufsize += bp - ip->bufp;
@@ -8554,8 +8654,6 @@ macarg (argptr, rest_args)
#endif
if (c == '\"' || c == '\\') /* escape these chars */
totlen++;
- else if (!isprint (c))
- totlen += 3;
}
argptr->stringified_length = totlen;
}
@@ -8563,6 +8661,7 @@ macarg (argptr, rest_args)
}
/* Scan text from START (inclusive) up to LIMIT (exclusive),
+ taken from the expansion of MACRO,
counting parens in *DEPTHPTR,
and return if reach LIMIT
or before a `)' that would make *DEPTHPTR negative
@@ -8576,9 +8675,10 @@ macarg (argptr, rest_args)
Set *COMMENTS to 1 if a comment is seen. */
static U_CHAR *
-macarg1 (start, limit, depthptr, newlines, comments, rest_args)
+macarg1 (start, limit, macro, depthptr, newlines, comments, rest_args)
U_CHAR *start;
register U_CHAR *limit;
+ struct hashnode *macro;
int *depthptr, *newlines, *comments;
int rest_args;
{
@@ -8595,43 +8695,44 @@ macarg1 (start, limit, depthptr, newlines, comments, rest_args)
break;
case '\\':
/* Traditionally, backslash makes following char not special. */
- if (bp + 1 < limit && traditional)
- {
- bp++;
- /* But count source lines anyway. */
- if (*bp == '\n')
- ++*newlines;
- }
+ if (traditional && bp + 1 < limit && bp[1] != '\n')
+ bp++;
break;
case '\n':
++*newlines;
break;
case '/':
+ if (macro)
+ break;
if (bp[1] == '\\' && bp[2] == '\n')
newline_fix (bp + 1);
- if (cplusplus_comments && bp[1] == '/') {
+ if (bp[1] == '*') {
*comments = 1;
- bp += 2;
- while (bp < limit && (*bp != '\n' || bp[-1] == '\\')) {
- if (*bp == '\n') ++*newlines;
- bp++;
+ for (bp += 2; bp < limit; bp++) {
+ if (*bp == '\n')
+ ++*newlines;
+ else if (*bp == '*') {
+ if (bp[-1] == '/' && warn_comments)
+ warning ("`/*' within comment");
+ if (bp[1] == '\\' && bp[2] == '\n')
+ newline_fix (bp + 1);
+ if (bp[1] == '/') {
+ bp++;
+ break;
+ }
+ }
+ }
+ } else if (bp[1] == '/' && cplusplus_comments) {
+ *comments = 1;
+ for (bp += 2; bp < limit; bp++) {
+ if (*bp == '\n') {
+ ++*newlines;
+ if (bp[-1] != '\\')
+ break;
+ if (warn_comments)
+ warning ("multiline `//' comment");
+ }
}
- /* Now count the newline that we are about to skip. */
- ++*newlines;
- break;
- }
- if (bp[1] != '*' || bp + 1 >= limit)
- break;
- *comments = 1;
- bp += 2;
- while (bp + 1 < limit) {
- if (bp[0] == '*'
- && bp[1] == '\\' && bp[2] == '\n')
- newline_fix (bp + 1);
- if (bp[0] == '*' && bp[1] == '/')
- break;
- if (*bp == '\n') ++*newlines;
- bp++;
}
break;
case '\'':
@@ -8643,8 +8744,11 @@ macarg1 (start, limit, depthptr, newlines, comments, rest_args)
bp++;
if (*bp == '\n')
++*newlines;
- while (*bp == '\\' && bp[1] == '\n') {
- bp += 2;
+ if (!macro) {
+ while (*bp == '\\' && bp[1] == '\n') {
+ bp += 2;
+ ++*newlines;
+ }
}
} else if (*bp == '\n') {
++*newlines;
@@ -8740,16 +8844,16 @@ discard_comments (start, length, newlines)
obp--;
else
obp[-1] = ' ';
- ibp++;
- while (ibp + 1 < limit) {
- if (ibp[0] == '*'
- && ibp[1] == '\\' && ibp[2] == '\n')
- newline_fix (ibp + 1);
- if (ibp[0] == '*' && ibp[1] == '/')
- break;
- ibp++;
+ while (++ibp < limit) {
+ if (ibp[0] == '*') {
+ if (ibp[1] == '\\' && ibp[2] == '\n')
+ newline_fix (ibp + 1);
+ if (ibp[1] == '/') {
+ ibp += 2;
+ break;
+ }
+ }
}
- ibp += 2;
break;
case '\'':
@@ -8765,10 +8869,16 @@ discard_comments (start, length, newlines)
break;
if (c == '\n' && quotec == '\'')
break;
- if (c == '\\' && ibp < limit) {
- while (*ibp == '\\' && ibp[1] == '\n')
- ibp += 2;
- *obp++ = *ibp++;
+ if (c == '\\') {
+ if (ibp < limit && *ibp == '\n') {
+ ibp++;
+ obp--;
+ } else {
+ while (*ibp == '\\' && ibp[1] == '\n')
+ ibp += 2;
+ if (ibp < limit)
+ *obp++ = *ibp++;
+ }
}
}
}
@@ -8819,7 +8929,7 @@ change_newlines (start, length)
int quotec = c;
while (ibp < limit) {
*obp++ = c = *ibp++;
- if (c == quotec)
+ if (c == quotec && ibp[-2] != '\\')
break;
if (c == '\n' && quotec == '\'')
break;
@@ -8832,11 +8942,10 @@ change_newlines (start, length)
return obp - start;
}
-/*
- * my_strerror - return the descriptive text associated with an `errno' code.
- */
+/* my_strerror - return the descriptive text associated with an
+ `errno' code. */
-char *
+static char *
my_strerror (errnum)
int errnum;
{
@@ -8865,17 +8974,22 @@ my_strerror (errnum)
return result;
}
-/*
- * error - print error message and increment count of errors.
- */
+/* error - print error message and increment count of errors. */
void
-error (PRINTF_ALIST (msg))
- PRINTF_DCL (msg)
+error VPROTO ((char * msg, ...))
{
+#ifndef __STDC__
+ char * msg;
+#endif
va_list args;
VA_START (args, msg);
+
+#ifndef __STDC__
+ msg = va_arg (args, char *);
+#endif
+
verror (msg, args);
va_end (args);
}
@@ -8896,8 +9010,10 @@ verror (msg, args)
break;
}
- if (ip != NULL)
- fprintf (stderr, "%s:%d: ", ip->nominal_fname, ip->lineno);
+ if (ip != NULL) {
+ eprint_string (ip->nominal_fname, ip->nominal_fname_len);
+ fprintf (stderr, ":%d: ", ip->lineno);
+ }
vfprintf (stderr, msg, args);
fprintf (stderr, "\n");
errors++;
@@ -8909,6 +9025,7 @@ static void
error_from_errno (name)
char *name;
{
+ int e = errno;
int i;
FILE_BUF *ip = NULL;
@@ -8920,10 +9037,12 @@ error_from_errno (name)
break;
}
- if (ip != NULL)
- fprintf (stderr, "%s:%d: ", ip->nominal_fname, ip->lineno);
+ if (ip != NULL) {
+ eprint_string (ip->nominal_fname, ip->nominal_fname_len);
+ fprintf (stderr, ":%d: ", ip->lineno);
+ }
- fprintf (stderr, "%s: %s\n", name, my_strerror (errno));
+ fprintf (stderr, "%s: %s\n", name, my_strerror (e));
errors++;
}
@@ -8931,12 +9050,19 @@ error_from_errno (name)
/* Print error message but don't count it. */
void
-warning (PRINTF_ALIST (msg))
- PRINTF_DCL (msg)
+warning VPROTO ((char * msg, ...))
{
+#ifndef __STDC__
+ char * msg;
+#endif
va_list args;
VA_START (args, msg);
+
+#ifndef __STDC__
+ msg = va_arg (args, char *);
+#endif
+
vwarning (msg, args);
va_end (args);
}
@@ -8963,25 +9089,31 @@ vwarning (msg, args)
break;
}
- if (ip != NULL)
- fprintf (stderr, "%s:%d: ", ip->nominal_fname, ip->lineno);
+ if (ip != NULL) {
+ eprint_string (ip->nominal_fname, ip->nominal_fname_len);
+ fprintf (stderr, ":%d: ", ip->lineno);
+ }
fprintf (stderr, "warning: ");
vfprintf (stderr, msg, args);
fprintf (stderr, "\n");
}
static void
-#if defined (__STDC__) && defined (HAVE_VPRINTF)
-error_with_line (int line, PRINTF_ALIST (msg))
-#else
-error_with_line (line, PRINTF_ALIST (msg))
- int line;
- PRINTF_DCL (msg)
-#endif
+error_with_line VPROTO ((int line, char * msg, ...))
{
+#ifndef __STDC__
+ int line;
+ char * msg;
+#endif
va_list args;
VA_START (args, msg);
+
+#ifndef __STDC__
+ line = va_arg (args, int);
+ msg = va_arg (args, char *);
+#endif
+
verror_with_line (line, msg, args);
va_end (args);
}
@@ -9003,25 +9135,31 @@ verror_with_line (line, msg, args)
break;
}
- if (ip != NULL)
- fprintf (stderr, "%s:%d: ", ip->nominal_fname, line);
+ if (ip != NULL) {
+ eprint_string (ip->nominal_fname, ip->nominal_fname_len);
+ fprintf (stderr, ":%d: ", line);
+ }
vfprintf (stderr, msg, args);
fprintf (stderr, "\n");
errors++;
}
static void
-#if defined (__STDC__) && defined (HAVE_VPRINTF)
-warning_with_line (int line, PRINTF_ALIST (msg))
-#else
-warning_with_line (line, PRINTF_ALIST (msg))
- int line;
- PRINTF_DCL (msg)
-#endif
+warning_with_line VPROTO ((int line, char * msg, ...))
{
+#ifndef __STDC__
+ int line;
+ char * msg;
+#endif
va_list args;
VA_START (args, msg);
+
+#ifndef __STDC__
+ line = va_arg (args, int);
+ msg = va_arg (args, char *);
+#endif
+
vwarning_with_line (line, msg, args);
va_end (args);
}
@@ -9049,22 +9187,31 @@ vwarning_with_line (line, msg, args)
break;
}
- if (ip != NULL)
- fprintf (stderr, line ? "%s:%d: " : "%s: ", ip->nominal_fname, line);
+ if (ip != NULL) {
+ eprint_string (ip->nominal_fname, ip->nominal_fname_len);
+ fprintf (stderr, line ? ":%d: " : ": ", line);
+ }
fprintf (stderr, "warning: ");
vfprintf (stderr, msg, args);
fprintf (stderr, "\n");
}
-/* print an error message and maybe count it. */
+/* Print an error message and maybe count it. */
void
-pedwarn (PRINTF_ALIST (msg))
- PRINTF_DCL (msg)
+pedwarn VPROTO ((char * msg, ...))
{
+#ifndef __STDC__
+ char * msg;
+#endif
va_list args;
VA_START (args, msg);
+
+#ifndef __STDC__
+ msg = va_arg (args, char *);
+#endif
+
if (pedantic_errors)
verror (msg, args);
else
@@ -9073,17 +9220,21 @@ pedwarn (PRINTF_ALIST (msg))
}
void
-#if defined (__STDC__) && defined (HAVE_VPRINTF)
-pedwarn_with_line (int line, PRINTF_ALIST (msg))
-#else
-pedwarn_with_line (line, PRINTF_ALIST (msg))
- int line;
- PRINTF_DCL (msg)
-#endif
+pedwarn_with_line VPROTO ((int line, char * msg, ...))
{
+#ifndef __STDC__
+ int line;
+ char * msg;
+#endif
va_list args;
VA_START (args, msg);
+
+#ifndef __STDC__
+ line = va_arg (args, int);
+ msg = va_arg (args, char *);
+#endif
+
if (pedantic_errors)
verror_with_line (line, msg, args);
else
@@ -9095,26 +9246,36 @@ pedwarn_with_line (line, PRINTF_ALIST (msg))
giving specified file name and line number, not current. */
static void
-#if defined (__STDC__) && defined (HAVE_VPRINTF)
-pedwarn_with_file_and_line (char *file, int line, PRINTF_ALIST (msg))
-#else
-pedwarn_with_file_and_line (file, line, PRINTF_ALIST (msg))
- char *file;
- int line;
- PRINTF_DCL (msg)
+pedwarn_with_file_and_line VPROTO ((char *file, size_t file_len, int line,
+ char * msg, ...))
+{
+#ifndef __STDC__
+ char *file;
+ size_t file_len;
+ int line;
+ char * msg;
#endif
-{
va_list args;
if (!pedantic_errors && inhibit_warnings)
return;
- if (file != NULL)
- fprintf (stderr, "%s:%d: ", file, line);
+ if (file) {
+ eprint_string (file, file_len);
+ fprintf (stderr, ":%d: ", line);
+ }
if (pedantic_errors)
errors++;
if (!pedantic_errors)
fprintf (stderr, "warning: ");
VA_START (args, msg);
+
+#ifndef __STDC__
+ file = va_arg (args, char *);
+ file_len = va_arg (args, size_t);
+ line = va_arg (args, int);
+ msg = va_arg (args, char *);
+#endif
+
vfprintf (stderr, msg, args);
va_end (args);
fprintf (stderr, "\n");
@@ -9156,7 +9317,9 @@ print_containing_files ()
fprintf (stderr, ",\n ");
}
- fprintf (stderr, " from %s:%d", ip->nominal_fname, ip->lineno);
+ fprintf (stderr, " from ");
+ eprint_string (ip->nominal_fname, ip->nominal_fname_len);
+ fprintf (stderr, ":%d", ip->lineno);
}
if (! first)
fprintf (stderr, ":\n");
@@ -9204,6 +9367,7 @@ line_for_error (line)
/* You might think void was cleaner for the return type,
but that would get type mismatch in check_expand in strict ANSI. */
+
static int
grow_outbuf (obuf, needed)
register FILE_BUF *obuf;
@@ -9245,8 +9409,9 @@ grow_outbuf (obuf, needed)
* Otherwise, compute the length by scanning the entire name.
*
* If HASH is >= 0, it is the precomputed hash code.
- * Otherwise, compute the hash code.
+ * Otherwise, compute the hash code.
*/
+
static HASHNODE *
install (name, len, type, value, hash)
U_CHAR *name;
@@ -9291,7 +9456,7 @@ install (name, len, type, value, hash)
}
/*
- * find the most recent hash node for name name (ending with first
+ * find the most recent hash node for name "name" (ending with first
* non-identifier char) installed by install
*
* If LEN is >= 0, it is the length of the name.
@@ -9300,6 +9465,7 @@ install (name, len, type, value, hash)
* If HASH is >= 0, it is the precomputed hash code.
* Otherwise, compute the hash code.
*/
+
HASHNODE *
lookup (name, len, hash)
U_CHAR *name;
@@ -9350,8 +9516,8 @@ delete_macro (hp)
if (hp->next != NULL)
hp->next->prev = hp->prev;
- /* make sure that the bucket chain header that
- the deleted guy was on points to the right thing afterwards. */
+ /* Make sure that the bucket chain header that the deleted guy was
+ on points to the right thing afterwards. */
if (hp == *hp->bucket_hdr)
*hp->bucket_hdr = hp->next;
@@ -9374,6 +9540,7 @@ delete_macro (hp)
* return hash function on name. must be compatible with the one
* computed a step at a time, elsewhere
*/
+
static int
hashf (name, len, hashsize)
register U_CHAR *name;
@@ -9390,6 +9557,7 @@ hashf (name, len, hashsize)
/* Dump the definition of a single macro HP to OF. */
+
static void
dump_single_macro (hp, of)
register HASHNODE *hp;
@@ -9571,8 +9739,8 @@ initialize_char_syntax ()
is_idchar[i] = 1;
is_idchar['_'] = 1;
is_idstart['_'] = 1;
- is_idchar['$'] = dollars_in_ident;
- is_idstart['$'] = dollars_in_ident;
+ is_idchar['$'] = 1;
+ is_idstart['$'] = 1;
/* horizontal space table */
is_hor_space[' '] = 1;
@@ -9629,6 +9797,7 @@ initialize_builtins (inp, outp)
/* This is supplied using a -D by the compiler driver
so that it is present only when truly compiling with GNU C. */
/* install ((U_CHAR *) "__GNUC__", -1, T_CONST, "2", -1); */
+ install ((U_CHAR *) "__HAVE_BUILTIN_SETJMP__", -1, T_CONST, "1", -1);
if (debug_output)
{
@@ -9751,10 +9920,7 @@ make_definition (str, op)
if (unterminated)
return;
while (p != p1)
- if (*p == '\\' && p[1] == '\n')
- p += 2;
- else
- *q++ = *p++;
+ *q++ = *p++;
} else if (*p == '\\' && p[1] == '\n')
p += 2;
/* Change newline chars into newline-markers. */
@@ -9772,6 +9938,7 @@ make_definition (str, op)
ip = &instack[++indepth];
ip->nominal_fname = ip->fname = "*Initialization*";
+ ip->nominal_fname_len = strlen (ip->nominal_fname);
ip->buf = ip->bufp = buf;
ip->length = strlen ((char *) buf);
@@ -9801,6 +9968,7 @@ make_undef (str, op)
ip = &instack[++indepth];
ip->nominal_fname = ip->fname = "*undef*";
+ ip->nominal_fname_len = strlen (ip->nominal_fname);
ip->buf = ip->bufp = (U_CHAR *) str;
ip->length = strlen (str);
@@ -9857,6 +10025,7 @@ make_assertion (option, str)
ip = &instack[++indepth];
ip->nominal_fname = ip->fname = "*Initialization*";
+ ip->nominal_fname_len = strlen (ip->nominal_fname);
ip->buf = ip->bufp = buf;
ip->length = strlen ((char *) buf);
@@ -9869,12 +10038,116 @@ make_assertion (option, str)
for (kt = directive_table; kt->type != T_ASSERT; kt++)
;
- /* pass NULL as output ptr to do_define since we KNOW it never
- does any output.... */
+ /* Pass NULL as output ptr to do_define since we KNOW it never does
+ any output.... */
do_assert (buf, buf + strlen ((char *) buf) , NULL_PTR, kt);
--indepth;
}
+#ifndef DIR_SEPARATOR
+#define DIR_SEPARATOR '/'
+#endif
+
+/* The previous include prefix, if any, is PREV_FILE_NAME.
+ Translate any pathnames with COMPONENT.
+ Allocate a new include prefix whose name is the
+ simplified concatenation of PREFIX and NAME,
+ with a trailing / added if needed.
+ But return 0 if the include prefix should be ignored,
+ e.g. because it is a duplicate of PREV_FILE_NAME. */
+
+static struct file_name_list *
+new_include_prefix (prev_file_name, component, prefix, name)
+ struct file_name_list *prev_file_name;
+ char *component;
+ char *prefix;
+ char *name;
+{
+ if (name == 0)
+ fatal ("Directory name missing after command line option");
+
+ if (*name == 0)
+ /* Ignore the empty string. */
+ return 0;
+
+ prefix = update_path (prefix, component);
+ name = update_path (name, component);
+
+ {
+ struct file_name_list *dir
+ = ((struct file_name_list *)
+ xmalloc (sizeof (struct file_name_list)
+ + strlen (prefix) + strlen (name) + 2));
+ size_t len;
+ strcpy (dir->fname, prefix);
+ strcat (dir->fname, name);
+ len = simplify_filename (dir->fname);
+
+ /* Convert directory name to a prefix. */
+ if (len && dir->fname[len - 1] != DIR_SEPARATOR) {
+ if (len == 1 && dir->fname[len - 1] == '.')
+ len = 0;
+ else
+#ifdef VMS
+ /* must be '/', hack_vms_include_specification triggers on it. */
+ dir->fname[len++] = '/';
+#else
+ dir->fname[len++] = DIR_SEPARATOR;
+#endif
+ dir->fname[len] = 0;
+ }
+
+ /* Ignore a directory whose name matches the previous one. */
+ if (prev_file_name && !strcmp (prev_file_name->fname, dir->fname)) {
+ /* But treat `-Idir -I- -Idir' as `-I- -Idir'. */
+ if (!first_bracket_include)
+ first_bracket_include = prev_file_name;
+ free (dir);
+ return 0;
+ }
+
+#ifndef VMS
+ /* VMS can't stat dir prefixes, so skip these optimizations in VMS. */
+
+ /* Add a trailing "." if there is a filename. This increases the number
+ of systems that can stat directories. We remove it below. */
+ if (len != 0)
+ {
+ dir->fname[len] = '.';
+ dir->fname[len + 1] = 0;
+ }
+
+ /* Ignore a nonexistent directory. */
+ if (stat (len ? dir->fname : ".", &dir->st) != 0) {
+ if (errno != ENOENT && errno != ENOTDIR)
+ error_from_errno (dir->fname);
+ free (dir);
+ return 0;
+ }
+
+ if (len != 0)
+ dir->fname[len] = 0;
+
+ /* Ignore a directory whose identity matches the previous one. */
+ if (prev_file_name
+ && INO_T_EQ (prev_file_name->st.st_ino, dir->st.st_ino)
+ && prev_file_name->st.st_dev == dir->st.st_dev) {
+ /* But treat `-Idir -I- -Idir' as `-I- -Idir'. */
+ if (!first_bracket_include)
+ first_bracket_include = prev_file_name;
+ free (dir);
+ return 0;
+ }
+#endif /* ! VMS */
+
+ dir->next = 0;
+ dir->c_system_include_path = 0;
+ dir->got_name_map = 0;
+
+ return dir;
+ }
+}
+
/* Append a chain of `struct file_name_list's
to the end of the main include chain.
FIRST is the beginning of the chain to append, and LAST is the end. */
@@ -9908,6 +10181,67 @@ append_include_chain (first, last)
last_include = last;
}
+/* Place into DST a representation of the file named SRC that is suitable
+ for `make'. Do not null-terminate DST. Return its length. */
+static int
+quote_string_for_make (dst, src)
+ char *dst;
+ char *src;
+{
+ char *p = src;
+ int i = 0;
+ for (;;)
+ {
+ char c = *p++;
+ switch (c)
+ {
+ case '\0':
+ case ' ':
+ case '\t':
+ {
+ /* GNU make uses a weird quoting scheme for white space.
+ A space or tab preceded by 2N+1 backslashes represents
+ N backslashes followed by space; a space or tab
+ preceded by 2N backslashes represents N backslashes at
+ the end of a file name; and backslashes in other
+ contexts should not be doubled. */
+ char *q;
+ for (q = p - 1; src < q && q[-1] == '\\'; q--)
+ {
+ if (dst)
+ dst[i] = '\\';
+ i++;
+ }
+ }
+ if (!c)
+ return i;
+ if (dst)
+ dst[i] = '\\';
+ i++;
+ goto ordinary_char;
+
+ case '$':
+ if (dst)
+ dst[i] = c;
+ i++;
+ /* Fall through. This can mishandle things like "$(" but
+ there's no easy fix. */
+ default:
+ ordinary_char:
+ /* This can mishandle characters in the string "\0\n%*?[\\~";
+ exactly which chars are mishandled depends on the `make' version.
+ We know of no portable solution for this;
+ even GNU make 3.76.1 doesn't solve the problem entirely.
+ (Also, '\0' is mishandled due to our calling conventions.) */
+ if (dst)
+ dst[i] = c;
+ i++;
+ break;
+ }
+ }
+}
+
+
/* Add output to `deps_buffer' for the -M switch.
STRING points to the text to be output.
SPACER is ':' for targets, ' ' for dependencies. */
@@ -9917,7 +10251,7 @@ deps_output (string, spacer)
char *string;
int spacer;
{
- int size = strlen (string);
+ int size = quote_string_for_make ((char *) 0, string);
if (size == 0)
return;
@@ -9934,15 +10268,15 @@ deps_output (string, spacer)
spacer = 0;
}
- if (deps_size + size + 8 > deps_allocated_size) {
- deps_allocated_size = (deps_size + size + 50) * 2;
+ if (deps_size + 2 * size + 8 > deps_allocated_size) {
+ deps_allocated_size = (deps_size + 2 * size + 50) * 2;
deps_buffer = xrealloc (deps_buffer, deps_allocated_size);
}
if (spacer == ' ') {
deps_buffer[deps_size++] = ' ';
deps_column++;
}
- bcopy (string, &deps_buffer[deps_size], size);
+ quote_string_for_make (&deps_buffer[deps_size], string);
deps_size += size;
deps_column += size;
if (spacer == ':') {
@@ -9953,13 +10287,20 @@ deps_output (string, spacer)
}
static void
-fatal (PRINTF_ALIST (msg))
- PRINTF_DCL (msg)
+fatal VPROTO ((char * msg, ...))
{
+#ifndef __STDC__
+ char * msg;
+#endif
va_list args;
fprintf (stderr, "%s: ", progname);
VA_START (args, msg);
+
+#ifndef __STDC__
+ msg = va_arg (args, char *);
+#endif
+
vfprintf (stderr, msg, args);
va_end (args);
fprintf (stderr, "\n");
@@ -9979,8 +10320,7 @@ static void
perror_with_name (name)
char *name;
{
- fprintf (stderr, "%s: ", progname);
- fprintf (stderr, "%s: %s\n", name, my_strerror (errno));
+ fprintf (stderr, "%s: %s: %s\n", progname, name, my_strerror (errno));
errors++;
}
@@ -10001,7 +10341,7 @@ pfatal_with_name (name)
static void
pipe_closed (signo)
/* If this is missing, some compilers complain. */
- int signo;
+ int signo ATTRIBUTE_UNUSED;
{
fatal ("output pipe has been closed");
}
@@ -10056,68 +10396,86 @@ savestring (input)
return output;
}
-/* Get the file-mode and data size of the file open on FD
- and store them in *MODE_POINTER and *SIZE_POINTER. */
+#ifdef VMS
-static int
-file_size_and_mode (fd, mode_pointer, size_pointer)
- int fd;
- int *mode_pointer;
- long int *size_pointer;
-{
- struct stat sbuf;
+/* Under VMS we need to fix up the "include" specification filename.
- if (fstat (fd, &sbuf) < 0) return (-1);
- if (mode_pointer) *mode_pointer = sbuf.st_mode;
- if (size_pointer) *size_pointer = sbuf.st_size;
- return 0;
-}
-
-#ifdef VMS
+ Rules for possible conversions
-/* Under VMS we need to fix up the "include" specification
- filename so that everything following the 1st slash is
- changed into its correct VMS file specification. */
+ fullname tried paths
-static void
-hack_vms_include_specification (fname)
- char *fname;
+ name name
+ ./dir/name [.dir]name
+ /dir/name dir:name
+ /name [000000]name, name
+ dir/name dir:[000000]name, dir:name, dir/name
+ dir1/dir2/name dir1:[dir2]name, dir1:[000000.dir2]name
+ path:/name path:[000000]name, path:name
+ path:/dir/name path:[000000.dir]name, path:[dir]name
+ path:dir/name path:[dir]name
+ [path]:[dir]name [path.dir]name
+ path/[dir]name [path.dir]name
+
+ The path:/name input is constructed when expanding <> includes.
+
+ return 1 if name was changed, 0 else. */
+
+static int
+hack_vms_include_specification (fullname, vaxc_include)
+ char *fullname;
+ int vaxc_include;
{
- register char *cp, *cp1, *cp2;
- int f, check_filename_before_returning, no_prefix_seen;
+ register char *basename, *unixname, *local_ptr, *first_slash;
+ int f, check_filename_before_returning, must_revert;
char Local[512];
check_filename_before_returning = 0;
- no_prefix_seen = 0;
-
- /* Ignore leading "./"s */
- while (fname[0] == '.' && fname[1] == '/') {
- strcpy (fname, fname+2);
- no_prefix_seen = 1; /* mark this for later */
- }
- /* Look for the boundary between the VMS and UNIX filespecs */
- cp = rindex (fname, ']'); /* Look for end of dirspec. */
- if (cp == 0) cp = rindex (fname, '>'); /* ... Ditto */
- if (cp == 0) cp = rindex (fname, ':'); /* Look for end of devspec. */
- if (cp) {
- cp++;
- } else {
- cp = index (fname, '/'); /* Look for the "/" */
- }
+ must_revert = 0;
+ /* See if we can find a 1st slash. If not, there's no path information. */
+ first_slash = index (fullname, '/');
+ if (first_slash == 0)
+ return 0; /* Nothing to do!!! */
+
+ /* construct device spec if none given. */
+
+ if (index (fullname, ':') == 0)
+ {
+
+ /* If fullname has a slash, take it as device spec. */
+
+ if (first_slash == fullname)
+ {
+ first_slash = index (fullname+1, '/'); /* 2nd slash ? */
+ if (first_slash)
+ *first_slash = ':'; /* make device spec */
+ for (basename = fullname; *basename != 0; basename++)
+ *basename = *(basename+1); /* remove leading slash */
+ }
+ else if ((first_slash[-1] != '.') /* keep ':/', './' */
+ && (first_slash[-1] != ':')
+ && (first_slash[-1] != ']')) /* or a vms path */
+ {
+ *first_slash = ':';
+ }
+ else if ((first_slash[1] == '[') /* skip './' in './[dir' */
+ && (first_slash[-1] == '.'))
+ fullname += 2;
+ }
+
+ /* Get part after first ':' (basename[-1] == ':')
+ or last '/' (basename[-1] == '/'). */
+
+ basename = base_name (fullname);
/*
* Check if we have a vax-c style '#include filename'
* and add the missing .h
*/
- if (cp == 0) {
- if (index(fname,'.') == 0)
- strcat(fname, ".h");
- } else {
- if (index(cp,'.') == 0)
- strcat(cp, ".h");
- }
- cp2 = Local; /* initialize */
+ if (vaxc_include && !index (basename,'.'))
+ strcat (basename, ".h");
+
+ local_ptr = Local; /* initialize */
/* We are trying to do a number of things here. First of all, we are
trying to hammer the filenames into a standard format, such that later
@@ -10128,171 +10486,201 @@ hack_vms_include_specification (fname)
needed to get things working properly.
If no device is specified, then the first directory name is taken to be
- a device name (or a rooted logical). */
+ a device name (or a rooted logical). */
+
+ /* Point to the UNIX filename part (which needs to be fixed!)
+ but skip vms path information.
+ [basename != fullname since first_slash != 0]. */
+
+ if ((basename[-1] == ':') /* vms path spec. */
+ || (basename[-1] == ']')
+ || (basename[-1] == '>'))
+ unixname = basename;
+ else
+ unixname = fullname;
+
+ if (*unixname == '/')
+ unixname++;
- /* See if we found that 1st slash */
- if (cp == 0) return; /* Nothing to do!!! */
- if (*cp != '/') return; /* Nothing to do!!! */
- /* Point to the UNIX filename part (which needs to be fixed!) */
- cp1 = cp+1;
/* If the directory spec is not rooted, we can just copy
- the UNIX filename part and we are done */
- if (((cp - fname) > 1) && ((cp[-1] == ']') || (cp[-1] == '>'))) {
- if (cp[-2] != '.') {
- /*
- * The VMS part ends in a `]', and the preceding character is not a `.'.
- * We strip the `]', and then splice the two parts of the name in the
- * usual way. Given the default locations for include files in cccp.c,
- * we will only use this code if the user specifies alternate locations
- * with the /include (-I) switch on the command line. */
- cp -= 1; /* Strip "]" */
- cp1--; /* backspace */
- } else {
- /*
- * The VMS part has a ".]" at the end, and this will not do. Later
- * processing will add a second directory spec, and this would be a syntax
- * error. Thus we strip the ".]", and thus merge the directory specs.
- * We also backspace cp1, so that it points to a '/'. This inhibits the
- * generation of the 000000 root directory spec (which does not belong here
- * in this case).
- */
- cp -= 2; /* Strip ".]" */
- cp1--; }; /* backspace */
- } else {
+ the UNIX filename part and we are done. */
- /* We drop in here if there is no VMS style directory specification yet.
- * If there is no device specification either, we make the first dir a
- * device and try that. If we do not do this, then we will be essentially
- * searching the users default directory (as if they did a #include "asdf.h").
- *
- * Then all we need to do is to push a '[' into the output string. Later
- * processing will fill this in, and close the bracket.
- */
- if (cp[-1] != ':') *cp2++ = ':'; /* dev not in spec. take first dir */
- *cp2++ = '['; /* Open the directory specification */
- }
+ if (((basename - fullname) > 1)
+ && ( (basename[-1] == ']')
+ || (basename[-1] == '>')))
+ {
+ if (basename[-2] != '.')
+ {
+
+ /* The VMS part ends in a `]', and the preceding character is not a `.'.
+ -> PATH]:/name (basename = '/name', unixname = 'name')
+ We strip the `]', and then splice the two parts of the name in the
+ usual way. Given the default locations for include files in cccp.c,
+ we will only use this code if the user specifies alternate locations
+ with the /include (-I) switch on the command line. */
+
+ basename -= 1; /* Strip "]" */
+ unixname--; /* backspace */
+ }
+ else
+ {
+
+ /* The VMS part has a ".]" at the end, and this will not do. Later
+ processing will add a second directory spec, and this would be a syntax
+ error. Thus we strip the ".]", and thus merge the directory specs.
+ We also backspace unixname, so that it points to a '/'. This inhibits the
+ generation of the 000000 root directory spec (which does not belong here
+ in this case). */
+
+ basename -= 2; /* Strip ".]" */
+ unixname--; /* backspace */
+ }
+ }
+
+ else
+
+ {
+
+ /* We drop in here if there is no VMS style directory specification yet.
+ If there is no device specification either, we make the first dir a
+ device and try that. If we do not do this, then we will be essentially
+ searching the users default directory (as if they did a #include "asdf.h").
+
+ Then all we need to do is to push a '[' into the output string. Later
+ processing will fill this in, and close the bracket. */
+
+ if ((unixname != fullname) /* vms path spec found. */
+ && (basename[-1] != ':'))
+ *local_ptr++ = ':'; /* dev not in spec. take first dir */
+
+ *local_ptr++ = '['; /* Open the directory specification */
+ }
+
+ if (unixname == fullname) /* no vms dir spec. */
+ {
+ must_revert = 1;
+ if ((first_slash != 0) /* unix dir spec. */
+ && (*unixname != '/') /* not beginning with '/' */
+ && (*unixname != '.')) /* or './' or '../' */
+ *local_ptr++ = '.'; /* dir is local ! */
+ }
/* at this point we assume that we have the device spec, and (at least
the opening "[" for a directory specification. We may have directories
- specified already */
+ specified already.
- /* If there are no other slashes then the filename will be
+ If there are no other slashes then the filename will be
in the "root" directory. Otherwise, we need to add
- directory specifications. */
- if (index (cp1, '/') == 0) {
- /* Just add "000000]" as the directory string */
- strcpy (cp2, "000000]");
- cp2 += strlen (cp2);
- check_filename_before_returning = 1; /* we might need to fool with this later */
- } else {
- /* As long as there are still subdirectories to add, do them. */
- while (index (cp1, '/') != 0) {
- /* If this token is "." we can ignore it */
- if ((cp1[0] == '.') && (cp1[1] == '/')) {
- cp1 += 2;
- continue;
- }
- /* Add a subdirectory spec. Do not duplicate "." */
- if (cp2[-1] != '.' && cp2[-1] != '[' && cp2[-1] != '<')
- *cp2++ = '.';
- /* If this is ".." then the spec becomes "-" */
- if ((cp1[0] == '.') && (cp1[1] == '.') && (cp[2] == '/')) {
- /* Add "-" and skip the ".." */
- *cp2++ = '-';
- cp1 += 3;
- continue;
- }
- /* Copy the subdirectory */
- while (*cp1 != '/') *cp2++= *cp1++;
- cp1++; /* Skip the "/" */
+ directory specifications. */
+
+ if (index (unixname, '/') == 0)
+ {
+ /* if no directories specified yet and none are following. */
+ if (local_ptr[-1] == '[')
+ {
+ /* Just add "000000]" as the directory string */
+ strcpy (local_ptr, "000000]");
+ local_ptr += strlen (local_ptr);
+ check_filename_before_returning = 1; /* we might need to fool with this later */
+ }
}
- /* Close the directory specification */
- if (cp2[-1] == '.') /* no trailing periods */
- cp2--;
- *cp2++ = ']';
- }
- /* Now add the filename */
- while (*cp1) *cp2++ = *cp1++;
- *cp2 = 0;
- /* Now append it to the original VMS spec. */
- strcpy (cp, Local);
+ else
+ {
+
+ /* As long as there are still subdirectories to add, do them. */
+ while (index (unixname, '/') != 0)
+ {
+ /* If this token is "." we can ignore it
+ if it's not at the beginning of a path. */
+ if ((unixname[0] == '.') && (unixname[1] == '/'))
+ {
+ /* remove it at beginning of path. */
+ if ( ((unixname == fullname) /* no device spec */
+ && (fullname+2 != basename)) /* starts with ./ */
+ /* or */
+ || ((basename[-1] == ':') /* device spec */
+ && (unixname-1 == basename))) /* and ./ afterwards */
+ *local_ptr++ = '.'; /* make '[.' start of path. */
+ unixname += 2;
+ continue;
+ }
+
+ /* Add a subdirectory spec. Do not duplicate "." */
+ if ( local_ptr[-1] != '.'
+ && local_ptr[-1] != '['
+ && local_ptr[-1] != '<')
+ *local_ptr++ = '.';
+
+ /* If this is ".." then the spec becomes "-" */
+ if ( (unixname[0] == '.')
+ && (unixname[1] == '.')
+ && (unixname[2] == '/'))
+ {
+ /* Add "-" and skip the ".." */
+ if ((local_ptr[-1] == '.')
+ && (local_ptr[-2] == '['))
+ local_ptr--; /* prevent [.- */
+ *local_ptr++ = '-';
+ unixname += 3;
+ continue;
+ }
+
+ /* Copy the subdirectory */
+ while (*unixname != '/')
+ *local_ptr++= *unixname++;
+
+ unixname++; /* Skip the "/" */
+ }
+
+ /* Close the directory specification */
+ if (local_ptr[-1] == '.') /* no trailing periods */
+ local_ptr--;
+
+ if (local_ptr[-1] == '[') /* no dir needed */
+ local_ptr--;
+ else
+ *local_ptr++ = ']';
+ }
+
+ /* Now add the filename. */
+
+ while (*unixname)
+ *local_ptr++ = *unixname++;
+ *local_ptr = 0;
+
+ /* Now append it to the original VMS spec. */
+
+ strcpy ((must_revert==1)?fullname:basename, Local);
/* If we put a [000000] in the filename, try to open it first. If this fails,
remove the [000000], and return that name. This provides flexibility
to the user in that they can use both rooted and non-rooted logical names
to point to the location of the file. */
- if (check_filename_before_returning && no_prefix_seen) {
- f = open (fname, O_RDONLY, 0666);
- if (f >= 0) {
- /* The file name is OK as it is, so return it as is. */
- close (f);
- return;
- }
- /* The filename did not work. Try to remove the [000000] from the name,
- and return it. */
- cp = index (fname, '[');
- cp2 = index (fname, ']') + 1;
- strcpy (cp, cp2); /* this gets rid of it */
- }
- return;
-}
-#endif /* VMS */
-
-#ifdef VMS
+ if (check_filename_before_returning)
+ {
+ f = open (fullname, O_RDONLY, 0666);
+ if (f >= 0)
+ {
+ /* The file name is OK as it is, so return it as is. */
+ close (f);
+ return 1;
+ }
-/* These are the read/write replacement routines for
- VAX-11 "C". They make read/write behave enough
- like their UNIX counterparts that CCCP will work */
+ /* The filename did not work. Try to remove the [000000] from the name,
+ and return it. */
+
+ basename = index (fullname, '[');
+ local_ptr = index (fullname, ']') + 1;
+ strcpy (basename, local_ptr); /* this gets rid of it */
-static int
-read (fd, buf, size)
- int fd;
- char *buf;
- int size;
-{
-#undef read /* Get back the REAL read routine */
- register int i;
- register int total = 0;
-
- /* Read until the buffer is exhausted */
- while (size > 0) {
- /* Limit each read to 32KB */
- i = (size > (32*1024)) ? (32*1024) : size;
- i = read (fd, buf, i);
- if (i <= 0) {
- if (i == 0) return (total);
- return (i);
}
- /* Account for this read */
- total += i;
- buf += i;
- size -= i;
- }
- return (total);
-}
-static int
-write (fd, buf, size)
- int fd;
- char *buf;
- int size;
-{
-#undef write /* Get back the REAL write routine */
- int i;
- int j;
-
- /* Limit individual writes to 32Kb */
- i = size;
- while (i > 0) {
- j = (i > (32*1024)) ? (32*1024) : i;
- if (write (fd, buf, j) < 0) return (-1);
- /* Account for the data written */
- buf += j;
- i -= j;
- }
- return (size);
+ return 1;
}
+#endif /* VMS */
+
+#ifdef VMS
/* The following wrapper functions supply additional arguments to the VMS
I/O routines to optimize performance with file handling. The arguments
@@ -10300,27 +10688,27 @@ write (fd, buf, size)
"mbc=16" - Set multi-block count to 16 (use a 8192 byte buffer).
"deq=64" - When extending the file, extend it in chunks of 32Kbytes.
"fop=tef"- Truncate unused portions of file when closing file.
- "shr=nil"- Disallow file sharing while file is open.
- */
+ "shr=nil"- Disallow file sharing while file is open. */
static FILE *
-freopen (fname, type, oldfile)
+VMS_freopen (fname, type, oldfile)
char *fname;
char *type;
FILE *oldfile;
{
-#undef freopen /* Get back the REAL fopen routine */
+#undef freopen /* Get back the real freopen routine. */
if (strcmp (type, "w") == 0)
- return freopen (fname, type, oldfile, "mbc=16", "deq=64", "fop=tef", "shr=nil");
+ return freopen (fname, type, oldfile,
+ "mbc=16", "deq=64", "fop=tef", "shr=nil");
return freopen (fname, type, oldfile, "mbc=16");
}
static FILE *
-fopen (fname, type)
+VMS_fopen (fname, type)
char *fname;
char *type;
{
-#undef fopen /* Get back the REAL fopen routine */
+#undef fopen /* Get back the real fopen routine. */
/* The gcc-vms-1.42 distribution's header files prototype fopen with two
fixed arguments, which matches ANSI's specification but not VAXCRTL's
pre-ANSI implementation. This hack circumvents the mismatch problem. */
@@ -10334,40 +10722,20 @@ fopen (fname, type)
}
static int
-open (fname, flags, prot)
+VMS_open (fname, flags, prot)
char *fname;
int flags;
int prot;
{
-#undef open /* Get back the REAL open routine */
+#undef open /* Get back the real open routine. */
return open (fname, flags, prot, "mbc=16", "deq=64", "fop=tef");
}
-
-/* Avoid run-time library bug, where copying M out of N+M characters with
- N >= 65535 results in VAXCRTL's strncat falling into an infinite loop.
- gcc-cpp exercises this particular bug. [Fixed in V5.5-2's VAXCRTL.] */
-
-static char *
-strncat (dst, src, cnt)
- char *dst;
- const char *src;
- unsigned cnt;
-{
- register char *d = dst, *s = (char *) src;
- register int n = cnt; /* convert to _signed_ type */
-
- while (*d) d++; /* advance to end */
- while (--n >= 0)
- if (!(*d++ = *s++)) break;
- if (n < 0) *d = '\0';
- return dst;
-}
/* more VMS hackery */
#include <fab.h>
#include <nam.h>
-extern unsigned long sys$parse(), sys$search();
+extern unsigned long SYS$PARSE(), SYS$SEARCH();
/* Work around another library bug. If a file is located via a searchlist,
and if the device it's on is not the same device as the one specified
@@ -10381,7 +10749,7 @@ extern unsigned long sys$parse(), sys$search();
bad enough, but then compounding the problem by reporting the reason for
failure as "normal successful completion." */
-#undef fstat /* get back to library version */
+#undef fstat /* Get back to the library version. */
static int
VMS_fstat (fd, statbuf)
@@ -10414,8 +10782,8 @@ VMS_stat (name, statbuf)
{
struct FAB fab;
struct NAM nam;
- char exp_nam[NAM$C_MAXRSS+1], /* expanded name buffer for sys$parse */
- res_nam[NAM$C_MAXRSS+1]; /* resultant name buffer for sys$search */
+ char exp_nam[NAM$C_MAXRSS+1], /* expanded name buffer for SYS$PARSE */
+ res_nam[NAM$C_MAXRSS+1]; /* resultant name buffer for SYS$SEARCH */
fab = cc$rms_fab;
fab.fab$l_fna = (char *) name;
@@ -10425,9 +10793,9 @@ VMS_stat (name, statbuf)
nam.nam$l_esa = exp_nam, nam.nam$b_ess = sizeof exp_nam - 1;
nam.nam$l_rsa = res_nam, nam.nam$b_rss = sizeof res_nam - 1;
nam.nam$b_nop = NAM$M_PWD | NAM$M_NOCONCEAL;
- if (sys$parse (&fab) & 1)
+ if (SYS$PARSE (&fab) & 1)
{
- if (sys$search (&fab) & 1)
+ if (SYS$SEARCH (&fab) & 1)
{
res_nam[nam.nam$b_rsl] = '\0';
result = stat (res_nam, statbuf);
@@ -10435,7 +10803,7 @@ VMS_stat (name, statbuf)
/* Clean up searchlist context cached by the system. */
nam.nam$b_nop = NAM$M_SYNCHK;
fab.fab$l_fna = 0, fab.fab$b_fns = 0;
- (void) sys$parse (&fab);
+ (void) SYS$PARSE (&fab);
}
}
OpenPOWER on IntegriCloud