OSDN Git Service

In include:
[pf3gnuchains/gcc-fork.git] / gcc / tradcpp.c
index ec42b63..125e2cb 100644 (file)
@@ -28,8 +28,6 @@ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 #include "version.h"
 #include "cppdefault.h"
 
-#include <signal.h>
-
 typedef unsigned char U_CHAR;
 
 /* Name under which this program was invoked.  */
@@ -387,7 +385,6 @@ U_CHAR *skip_to_end_of_comment PARAMS ((FILE_BUF *, int *));
 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.  */
@@ -457,15 +454,6 @@ int deps_column;
 /* 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)
@@ -515,8 +503,6 @@ 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 *));
@@ -570,7 +556,7 @@ main (argc, argv)
                 || !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;
 
@@ -624,7 +610,7 @@ main (argc, argv)
 
       case 'D':
        {
-         char *p, *p1;
+         char *p;
 
          if (argv[i][2] != 0)
            p = argv[i] + 2;
@@ -633,8 +619,6 @@ main (argc, argv)
          else
            p = argv[++i];
 
-         if ((p1 = (char *) strchr (p, '=')) != NULL)
-           *p1 = ' ';
          pend_defs[i] = p;
        }
        break;
@@ -667,7 +651,7 @@ main (argc, argv)
        break;
 
       case 'I':                        /* Add directory to path for includes.  */
-      include:
+      add_include:
        {
          struct file_name_list *dirtmp;
 
@@ -727,14 +711,11 @@ main (argc, argv)
      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,
@@ -755,6 +736,8 @@ main (argc, argv)
        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)
@@ -793,7 +776,7 @@ main (argc, argv)
     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",
@@ -882,7 +865,7 @@ main (argc, argv)
   }
 
   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 */
@@ -901,11 +884,11 @@ main (argc, argv)
     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 */
@@ -923,7 +906,7 @@ main (argc, argv)
       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;
@@ -979,7 +962,7 @@ main (argc, argv)
     exit (FATAL_EXIT_CODE);
   exit (SUCCESS_EXIT_CODE);
 
perror:
sys_error:
   pfatal_with_name (in_fname);
 }
 
@@ -1201,32 +1184,11 @@ do { ip = &instack[indepth];            \
       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.  */
 
@@ -2578,8 +2540,8 @@ do_define (buf, limit, op, keyword)
     }
 
     ++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);
 
@@ -2601,9 +2563,9 @@ do_define (buf, limit, op, keyword)
       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 *) "";
@@ -4286,10 +4248,7 @@ fancy_abort (line, func)
      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);
 }
@@ -4673,9 +4632,18 @@ initialize_builtins ()
   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);
 }
@@ -4696,52 +4664,26 @@ make_definition (str)
   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;