Do not reset loc_directive_seen in dwarf2_emit_insn.
[deliverable/binutils-gdb.git] / gas / gasp.c
index ad33a4640b855f208c256af1a93985abc14ae920..0ec7054661608b06d75521d8b359d8b002255851 100644 (file)
@@ -1,5 +1,5 @@
 /* gasp.c - Gnu assembler preprocessor main program.
-   Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000
+   Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
    Free Software Foundation, Inc.
 
    Written by Steve and Judy Chamberlain of Cygnus Support,
@@ -48,10 +48,10 @@ suitable for gas to consume.
 #include "config.h"
 #include "bin-bugs.h"
 
+#include <assert.h>
 #include <stdio.h>
 #include <string.h>
 #include <getopt.h>
-#include <ctype.h>
 
 #ifdef HAVE_STDLIB_H
 #include <stdlib.h>
@@ -63,9 +63,11 @@ extern char *malloc ();
 
 #include "ansidecl.h"
 #include "libiberty.h"
+#include "safe-ctype.h"
 #include "sb.h"
 #include "macro.h"
 #include "asintl.h"
+#include "xregex.h"
 
 char *program_version = "1.2";
 
@@ -227,6 +229,8 @@ static void hash_add_to_string_table PARAMS ((hash_table *, sb *, sb *, int));
 static void hash_add_to_int_table PARAMS ((hash_table *, sb *, int));
 static hash_entry *hash_lookup PARAMS ((hash_table *, sb *));
 static void checkconst PARAMS ((int, exp_t *));
+static int is_flonum PARAMS ((int, sb *));
+static int chew_flonum PARAMS ((int, sb *, sb *));
 static int sb_strtol PARAMS ((int, sb *, int, int *));
 static int level_0 PARAMS ((int, sb *, exp_t *));
 static int level_1 PARAMS ((int, sb *, exp_t *));
@@ -522,6 +526,62 @@ checkconst (op, term)
     }
 }
 
+/* Chew the flonum from the string starting at idx.  Adjust idx to
+   point to the next character after the flonum.  */
+
+static int
+chew_flonum (idx, string, out)
+     int idx;
+     sb *string;
+     sb *out;
+{
+  sb buf;
+  regex_t reg;
+  regmatch_t match;
+
+  /* Duplicate and null terminate `string'.  */
+  sb_new (&buf);
+  sb_add_sb (&buf, string);
+  sb_add_char (&buf, '\0');
+
+  if (regcomp (&reg, "([0-9]*\\.[0-9]+([eE][+-]?[0-9]+)?)", REG_EXTENDED) != 0)
+    return idx;
+  if (regexec (&reg, &buf.ptr[idx], 1, &match, 0) != 0)
+    return idx;
+
+  /* Copy the match to the output.  */
+  assert (match.rm_eo >= match.rm_so);
+  sb_add_buffer (out, &buf.ptr[idx], match.rm_eo - match.rm_so);
+
+  sb_kill (&buf);
+  regfree (&reg);
+  idx += match.rm_eo;
+  return idx;
+}
+
+static int
+is_flonum (idx, string)
+     int idx;
+     sb *string;
+{
+  sb buf;
+  regex_t reg;
+  int rc;
+
+  /* Duplicate and null terminate `string'.  */
+  sb_new (&buf);
+  sb_add_sb (&buf, string);
+  sb_add_char (&buf, '\0');
+
+  if (regcomp (&reg, "^[0-9]*\\.[0-9]+([eE][+-]?[0-9]+)?", REG_EXTENDED) != 0)
+    return 0;
+
+  rc = regexec (&reg, &buf.ptr[idx], 0, NULL, 0);
+  sb_kill (&buf);
+  regfree (&reg);
+  return (rc == 0);
+}
+
 /* Turn the number in string at idx into a number of base, fill in
    ptr, and return the index of the first character not in the number.  */
 
@@ -539,7 +599,7 @@ sb_strtol (idx, string, base, ptr)
     {
       int ch = string->ptr[idx];
       int dig = 0;
-      if (isdigit (ch))
+      if (ISDIGIT (ch))
        dig = ch - '0';
       else if (ch >= 'a' && ch <= 'f')
        dig = ch - 'a' + 10;
@@ -574,7 +634,7 @@ level_0 (idx, string, lhs)
 
   lhs->value = 0;
 
-  if (isdigit ((unsigned char) string->ptr[idx]))
+  if (ISDIGIT (string->ptr[idx]))
     {
       idx = sb_strtol (idx, string, 10, &lhs->value);
     }
@@ -1132,7 +1192,11 @@ change_base (idx, in, out)
              idx++;
            }
        }
-      else if (isdigit ((unsigned char) in->ptr[idx]))
+      else if (is_flonum (idx, in))
+       {
+         idx = chew_flonum (idx, in, out);
+       }
+      else if (ISDIGIT (in->ptr[idx]))
        {
          int value;
          /* All numbers must start with a digit, let's chew it and
@@ -1549,6 +1613,7 @@ get_any_string (idx, in, out, expand, pretend_quoted)
          int val;
          char buf[20];
          /* Turns the next expression into a string.  */
+         /* xgettext: no-c-format */
          idx = exp_get_abs (_("% operator needs absolute expression"),
                             idx + 1,
                             in,
@@ -1676,7 +1741,7 @@ doinstr (idx, in, out)
   idx = sb_skip_comma (idx, in);
   idx = get_and_process (idx, in, &search);
   idx = sb_skip_comma (idx, in);
-  if (isdigit ((unsigned char) in->ptr[idx]))
+  if (ISDIGIT (in->ptr[idx]))
     {
       idx = exp_get_abs (_(".instr needs absolute expresson.\n"), idx, in, &start);
     }
@@ -1776,26 +1841,26 @@ process_assigns (idx, in, buf)
        }
       else if (idx + 3 < in->len
               && in->ptr[idx] == '.'
-              && toupper ((unsigned char) in->ptr[idx + 1]) == 'L'
-              && toupper ((unsigned char) in->ptr[idx + 2]) == 'E'
-              && toupper ((unsigned char) in->ptr[idx + 3]) == 'N')
+              && TOUPPER (in->ptr[idx + 1]) == 'L'
+              && TOUPPER (in->ptr[idx + 2]) == 'E'
+              && TOUPPER (in->ptr[idx + 3]) == 'N')
        idx = dolen (idx + 4, in, buf);
       else if (idx + 6 < in->len
               && in->ptr[idx] == '.'
-              && toupper ((unsigned char) in->ptr[idx + 1]) == 'I'
-              && toupper ((unsigned char) in->ptr[idx + 2]) == 'N'
-              && toupper ((unsigned char) in->ptr[idx + 3]) == 'S'
-              && toupper ((unsigned char) in->ptr[idx + 4]) == 'T'
-              && toupper ((unsigned char) in->ptr[idx + 5]) == 'R')
+              && TOUPPER (in->ptr[idx + 1]) == 'I'
+              && TOUPPER (in->ptr[idx + 2]) == 'N'
+              && TOUPPER (in->ptr[idx + 3]) == 'S'
+              && TOUPPER (in->ptr[idx + 4]) == 'T'
+              && TOUPPER (in->ptr[idx + 5]) == 'R')
        idx = doinstr (idx + 6, in, buf);
       else if (idx + 7 < in->len
               && in->ptr[idx] == '.'
-              && toupper ((unsigned char) in->ptr[idx + 1]) == 'S'
-              && toupper ((unsigned char) in->ptr[idx + 2]) == 'U'
-              && toupper ((unsigned char) in->ptr[idx + 3]) == 'B'
-              && toupper ((unsigned char) in->ptr[idx + 4]) == 'S'
-              && toupper ((unsigned char) in->ptr[idx + 5]) == 'T'
-              && toupper ((unsigned char) in->ptr[idx + 6]) == 'R')
+              && TOUPPER (in->ptr[idx + 1]) == 'S'
+              && TOUPPER (in->ptr[idx + 2]) == 'U'
+              && TOUPPER (in->ptr[idx + 3]) == 'B'
+              && TOUPPER (in->ptr[idx + 4]) == 'S'
+              && TOUPPER (in->ptr[idx + 5]) == 'T'
+              && TOUPPER (in->ptr[idx + 6]) == 'R')
        idx = dosubstr (idx + 7, in, buf);
       else if (ISFIRSTCHAR (in->ptr[idx]))
        {
@@ -2130,8 +2195,8 @@ whatcond (idx, in, val)
       char a, b;
 
       p = in->ptr + idx;
-      a = toupper ((unsigned char) p[0]);
-      b = toupper ((unsigned char) p[1]);
+      a = TOUPPER (p[0]);
+      b = TOUPPER (p[1]);
       if (a == 'E' && b == 'Q')
        cond = EQ;
       else if (a == 'N' && b == 'E')
@@ -2980,13 +3045,13 @@ chartype_init ()
   int x;
   for (x = 0; x < 256; x++)
     {
-      if (isalpha (x) || x == '_' || x == '$')
+      if (ISALPHA (x) || x == '_' || x == '$')
        chartype[x] |= FIRSTBIT;
 
       if (mri && x == '.')
        chartype[x] |= FIRSTBIT;
 
-      if (isdigit (x) || isalpha (x) || x == '_' || x == '$')
+      if (ISDIGIT (x) || ISALPHA (x) || x == '_' || x == '$')
        chartype[x] |= NEXTBIT;
 
       if (x == ' ' || x == '\t' || x == ',' || x == '"' || x == ';'
@@ -3537,6 +3602,8 @@ show_help ()
   show_usage (stdout, 0);
 }
 
+int main PARAMS ((int, char **));
+
 int
 main (argc, argv)
      int argc;
@@ -3551,6 +3618,9 @@ main (argc, argv)
 
 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
   setlocale (LC_MESSAGES, "");
+#endif
+#if defined (HAVE_SETLOCALE)
+  setlocale (LC_CTYPE, "");
 #endif
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
This page took 0.026292 seconds and 4 git commands to generate.