OSDN Git Service

Use C fixincludes for UnixWare 7.
[pf3gnuchains/gcc-fork.git] / gcc / scan.c
index a4980ea..4af6a43 100644 (file)
@@ -1,5 +1,5 @@
-/* scan.c - Utility functions for scan-decls and patch-header programs.
-   Copyright (C) 1993 Free Software Foundation, Inc.
+/* Utility functions for scan-decls and fix-header programs.
+   Copyright (C) 1993, 1994, 1998 Free Software Foundation, Inc.
 
 This program is free software; you can redistribute it and/or modify it
 under the terms of the GNU General Public License as published by the
@@ -13,10 +13,11 @@ 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, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
+#include "hconfig.h"
+#include "system.h"
 #include "scan.h"
-#include <ctype.h>
 
 int lineno = 1;
 int source_lineno = 1;
@@ -34,10 +35,7 @@ make_sstring_space (str, count)
   if (new_size <= cur_size)
     return;
   
-  if (str->base == NULL)
-    str->base = xmalloc (new_size);
-  else
-    str->base = xrealloc (str->base, new_size);
+  str->base = xrealloc (str->base, new_size);
   str->ptr = str->base + cur_size;
   str->limit = str->base + new_size;
 }
@@ -48,7 +46,7 @@ sstring_append (dst, src)
      sstring *src;
 {
   register char *d, *s;
-  register count = SSTRING_LENGTH(src);
+  register int count = SSTRING_LENGTH(src);
   MAKE_SSTRING_SPACE(dst, count + 1);
   d = dst->ptr;
   s = src->base;
@@ -57,35 +55,6 @@ sstring_append (dst, src)
   *d = 0;  
 }
 
-memory_full ()
-{
-  abort();
-}
-
-char *
-xmalloc (size)
-     unsigned size;
-{
-  register char *ptr = (char *) malloc (size);
-  if (ptr != 0) return (ptr);
-  memory_full ();
-  /*NOTREACHED*/
-  return 0;
-}
-
-
-char *
-xrealloc (old, size)
-     char *old;
-     unsigned size;
-{
-  register char *ptr = (char *) realloc (old, size);
-  if (ptr != 0) return (ptr);
-  memory_full ();
-  /*NOTREACHED*/
-  return 0;
-}
-
 int
 scan_ident (fp, s, c)
      register FILE *fp;
@@ -93,13 +62,13 @@ scan_ident (fp, s, c)
      int c;
 {
   s->ptr = s->base;
-  if (isalpha(c) || c == '_')
+  if (ISALPHA(c) || c == '_')
     {
       for (;;)
        {
          SSTRING_PUT(s, c);
          c = getc (fp);
-         if (c == EOF || !(isalnum(c) || c == '_'))
+         if (c == EOF || !(ISALNUM(c) || c == '_'))
            break;
        }
     }
@@ -108,9 +77,11 @@ scan_ident (fp, s, c)
   return c;
 }
 
-int scan_string (fp, s, init)
+int
+scan_string (fp, s, init)
      register FILE *fp;
      register sstring *s;
+     int init;
 {
   int c;
   for (;;)
@@ -138,9 +109,10 @@ int scan_string (fp, s, init)
   return c;
 }
 
-/* Skip horizontal white spaces (spaces, tabs, and C-style comments). */
+/* Skip horizontal white spaces (spaces, tabs, and C-style comments).  */
 
-int skip_spaces (fp, c)
+int
+skip_spaces (fp, c)
      register FILE *fp;
      int c;
 {
@@ -205,7 +177,6 @@ get_token (fp, s)
   s->ptr = s->base;
  retry:
   c = ' ';
- again:
   c = skip_spaces (fp, c);
   if (c == '\n')
     {
@@ -218,7 +189,7 @@ get_token (fp, s)
       c = get_token (fp, s);
       if (c == INT_TOKEN)
        {
-         source_lineno = atoi (s->base);
+         source_lineno = atoi (s->base) - 1; /* '\n' will add 1 */
          get_token (fp, &source_filename);
        }
       for (;;)
@@ -227,23 +198,27 @@ get_token (fp, s)
          if (c == EOF)
            return EOF;
          if (c == '\n')
+           {
+           source_lineno++;
+           lineno++;
            goto retry;
+           }
        }
     }
   if (c == EOF)
     return EOF;
-  if (isdigit (c))
+  if (ISDIGIT (c))
     {
       do
        {
          SSTRING_PUT(s, c);
          c = getc (fp);
-       } while (c != EOF && isdigit(c));
+       } while (c != EOF && ISDIGIT(c));
       ungetc (c, fp);
       c = INT_TOKEN;
       goto done;
     }
-  if (isalpha (c) || c == '_')
+  if (ISALPHA (c) || c == '_')
     {
       c = scan_ident (fp, s, c);
       ungetc (c, fp);
@@ -251,7 +226,6 @@ get_token (fp, s)
     }
   if (c == '\'' || c == '"')
     {
-      int quote = c;
       c = scan_string (fp, s, c);
       ungetc (c, fp);
       return c == '\'' ? CHAR_TOKEN : STRING_TOKEN;
@@ -263,12 +237,17 @@ get_token (fp, s)
   return c;
 }
 
-unsigned long
-hash (str)
-     char *str;
+unsigned int
+hashstr (str, len)
+     const char *str;
+     unsigned int len;
 {
-  int h = 0;
-  /* Replace this with something faster/better! FIXME! */
-  while (*str) h = (h << 3) + *str++;
-  return h & 0x7FFFFFFF;
+  unsigned int n = len;
+  unsigned int r = 0;
+  const unsigned char *s = (const unsigned char *)str;
+
+  do
+    r = r * 67 + (*s++ - 113);
+  while (--n);
+  return r + len;
 }