#include "version.h"
#include "cppdefault.h"
-#include <signal.h>
-
typedef unsigned char U_CHAR;
/* Name under which this program was invoked. */
U_CHAR *skip_quoted_string PARAMS ((U_CHAR *, U_CHAR *, int,
int *, int *, int *));
-void pipe_closed PARAMS ((int));
int main PARAMS ((int, char **));
/* Convenience. Write U"string" to get an unsigned string constant. */
/* Nonzero means -I- has been seen,
so don't look for #include "foo" the source-file directory. */
int ignore_srcdir;
-\f
-/* Handler for SIGPIPE. */
-
-void
-pipe_closed (dummy)
- int dummy ATTRIBUTE_UNUSED;
-{
- exit (FATAL_EXIT_CODE);
-}
int
main (argc, argv)
dump_macros = 0;
no_output = 0;
- signal (SIGPIPE, pipe_closed);
-
max_include_len = cpp_GCC_INCLUDE_DIR_len + 7; /* ??? */
memset (pend_files, 0, argc * sizeof (char *));
|| !strcmp (argv[i], "-iwithprefix")
|| !strcmp (argv[i], "-iwithprefixbefore")
|| !strcmp (argv[i], "-idirafter"))
- goto include; /* best we can do */
+ goto add_include; /* best we can do */
break;
case 'D':
{
- char *p, *p1;
+ char *p;
if (argv[i][2] != 0)
p = argv[i] + 2;
else
p = argv[++i];
- if ((p1 = (char *) strchr (p, '=')) != NULL)
- *p1 = ' ';
pend_defs[i] = p;
}
break;
break;
case 'I': /* Add directory to path for includes. */
- include:
+ add_include:
{
struct file_name_list *dirtmp;
and option processing. */
initialize_builtins ();
- /* Do defines specified with -D. */
+ /* Do defines specified with -D and undefines specified with -U. */
for (i = 1; i < argc; i++)
if (pend_defs[i])
make_definition ((U_CHAR *)pend_defs[i]);
-
- /* Do undefines specified with -U. */
- for (i = 1; i < argc; i++)
- if (pend_undefs[i])
+ else if (pend_undefs[i])
make_undef ((U_CHAR *)pend_undefs[i]);
/* Unless -fnostdinc,
last_include->next = dirtmp;
last_include = dirtmp; /* Tail follows the last one */
dirtmp->fname = di->fname;
+ if (strlen (dirtmp->fname) > max_include_len)
+ max_include_len = strlen (dirtmp->fname);
}
if (ignore_srcdir && first_bracket_include == 0)
in_fname = "";
f = 0;
} else if ((f = open (in_fname, O_RDONLY, 0666)) < 0)
- goto perror;
+ goto sys_error;
/* Either of two environment variables can specify output of deps.
Its value is either "OUTPUT_FILE" or "OUTPUT_FILE DEPS_TARGET",
}
if (file_size_and_mode (f, &st_mode, &st_size))
- goto perror;
+ goto sys_error;
fp->fname = in_fname;
fp->lineno = 1;
/* JF all this is mine about reading pipes and ttys */
bufp = fp->buf;
for (;;) {
cnt = read (f, bufp, bsize - size);
- if (cnt < 0) goto perror; /* error! */
- if (cnt == 0) break; /* End of file */
+ if (cnt < 0) goto sys_error; /* error! */
+ if (cnt == 0) break; /* End of file */
size += cnt;
bufp += cnt;
- if (bsize == size) { /* Buffer is full! */
+ if (bsize == size) { /* Buffer is full! */
bsize *= 2;
fp->buf = (U_CHAR *) xrealloc (fp->buf, bsize + 2);
bufp = fp->buf + size; /* May have moved */
i = read (f, fp->buf + fp->length, st_size);
if (i <= 0) {
if (i == 0) break;
- goto perror;
+ goto sys_error;
}
fp->length += i;
st_size -= i;
exit (FATAL_EXIT_CODE);
exit (SUCCESS_EXIT_CODE);
- perror:
+ sys_error:
pfatal_with_name (in_fname);
}
if (ident_length)
goto specialchar;
- /* # keyword: a # must be first nonblank char on the line */
+ /* # keyword: a # must be the first char on the line */
if (beg_of_line == 0)
goto randomchar;
- {
- U_CHAR *bp;
-
- /* Scan from start of line, skipping whitespace, comments
- and backslash-newlines, and see if we reach this #.
- If not, this # is not special. */
- bp = beg_of_line;
- while (1) {
- if (is_hor_space[*bp])
- bp++;
- else if (*bp == '\\' && bp[1] == '\n')
- bp += 2;
- else if (*bp == '/' && (newline_fix (bp + 1), bp[1]) == '*') {
- bp += 2;
- while (!(*bp == '*' && (newline_fix (bp + 1), bp[1]) == '/'))
- bp++;
- bp += 1;
- }
- else break;
- }
- if (bp + 1 != ibp)
- goto randomchar;
- }
+ if (beg_of_line + 1 != ibp)
+ goto randomchar;
/* This # can start a directive. */
}
++bp; /* skip paren */
- /* Skip exactly one space or tab if any. */
- if (bp < limit && (*bp == ' ' || *bp == '\t')) ++bp;
+ while (is_hor_space[*bp]) /* and leading whitespace */
+ ++bp;
/* now everything from bp before limit is the definition. */
defn = collect_expansion (bp, limit, argno, arg_ptrs);
defn->argnames[i] = 0;
}
} else {
- /* simple expansion or empty definition; gobble it */
- if (is_hor_space[*bp])
- ++bp; /* skip exactly one blank/tab char */
+ /* simple expansion or empty definition; skip leading whitespace */
+ while (is_hor_space[*bp])
+ ++bp;
/* now everything from bp before limit is the definition. */
defn = collect_expansion (bp, limit, -1, 0);
defn->argnames = (U_CHAR *) "";
int line;
const char *func;
{
- if (!func)
- func = "?";
-
- fatal ("Internal error in \"%s\", at tradcpp.c:%d\n\
+ fatal ("Internal error in %s, at tradcpp.c:%d\n\
Please submit a full bug report.\n\
See %s for instructions.", func, line, GCCBUGURL);
}
install_spec ("__INCLUDE_LEVEL__", T_INCLUDE_LEVEL);
install_spec ("__LINE__", T_SPECLINE);
+#ifndef NO_BUILTIN_SIZE_TYPE
install_value ("__SIZE_TYPE__", SIZE_TYPE);
+#endif
+#ifndef NO_BUILTIN_PTRDIFF_TYPE
install_value ("__PTRDIFF_TYPE__", PTRDIFF_TYPE);
+#endif
+#ifndef NO_BUILTIN_WCHAR_TYPE
install_value ("__WCHAR_TYPE__", WCHAR_TYPE);
+#endif
+#ifndef NO_BUILTIN_WINT_TYPE
+ install_value ("__WINT_TYPE__", WINT_TYPE);
+#endif
install_value ("__REGISTER_PREFIX__", REGISTER_PREFIX);
install_value ("__USER_LABEL_PREFIX__", user_label_prefix);
}
FILE_BUF *ip;
struct directive *kt;
U_CHAR *buf, *p;
-
- buf = str;
- p = str;
- while (is_idchar[*p]) p++;
- if (p == str) {
- error ("malformed option `-D %s'", str);
- return;
- }
- if (*p == 0) {
- buf = (U_CHAR *) alloca (p - buf + 4);
- strcpy ((char *)buf, (char *)str);
- strcat ((char *)buf, " 1");
- } else if (*p != ' ') {
- error ("malformed option `-D %s'", str);
- return;
+ size_t len = strlen ((char *)str);
+
+ p = (U_CHAR *) strchr ((char *)str, '=');
+ if (p == NULL) {
+ /* Change -DFOO into #define FOO 1 */
+ buf = (U_CHAR *) alloca (len + 3);
+ memcpy (buf, str, len);
+ memcpy (buf + len, " 1", 3);
+ len += 2;
} else {
- U_CHAR *q;
- /* Copy the entire option so we can modify it. */
- buf = (U_CHAR *) alloca (2 * strlen ((char *)str) + 1);
- strncpy ((char *)buf, (char *)str, p - str);
- /* Change the = to a space. */
+ buf = (U_CHAR *) alloca (len + 1);
+ memcpy (buf, str, len + 1);
buf[p - str] = ' ';
- /* Scan for any backslash-newline and remove it. */
- p++;
- q = &buf[p - str];
- while (*p) {
- if (*p == '\\' && p[1] == '\n')
- p += 2;
- /* Change newline chars into newline-markers. */
- else if (*p == '\n')
- {
- *q++ = '\n';
- *q++ = '\n';
- p++;
- }
- else
- *q++ = *p++;
- }
- *q = 0;
}
ip = &instack[++indepth];
ip->fname = "*Initialization*";
ip->buf = ip->bufp = buf;
- ip->length = strlen ((char *)buf);
+ ip->length = len;
ip->lineno = 1;
ip->macro = 0;
ip->free_ptr = 0;