* README-vms: Delete.
[deliverable/binutils-gdb.git] / gas / listing.c
index c92f2db11c33682ee5f1edce45f85072e62a6ec4..61ef6f55e40f94acc29a8d38abcf6aa6cba8ade0 100644 (file)
@@ -1,27 +1,26 @@
-/* listing.c - mainting assembly listings
+/* listing.c - maintain assembly listings
    Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-   2001
+   2001, 2002, 2003, 2005
    Free Software Foundation, Inc.
 
-This file is part of GAS, the GNU Assembler.
+   This file is part of GAS, the GNU Assembler.
 
-GAS is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
+   GAS is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
 
-GAS is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+   GAS is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
-You should have received a copy of the GNU General Public License
-along with GAS; see the file COPYING.  If not, write to the Free
-Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.  */
+   You should have received a copy of the GNU General Public License
+   along with GAS; see the file COPYING.  If not, write to the Free
+   Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
+   02110-1301, USA.  */
 
-/*
- Contributed by Steve Chamberlain <sac@cygnus.com>
+/* Contributed by Steve Chamberlain <sac@cygnus.com>
 
  A listing page looks like:
 
@@ -65,7 +64,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  The function listing_newline remembers the frag associated with the
  newline, and creates a new frag - note that this is wasteful, but not
  a big deal, since listing slows things down a lot anyway.  The
- function also rememebers when the filename changes.
+ function also remembers when the filename changes.
 
  When all the input has finished, and gas has had a chance to settle
  down, the listing is output. This is done by running down the list of
@@ -86,13 +85,12 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  LISTING_LHS_WIDTH_SECOND   Number of words for the data on the lhs
                        for the second line
 
- LISTING_LHS_CONT_LINES        Max number of lines to use up for a continutation
+ LISTING_LHS_CONT_LINES        Max number of lines to use up for a continuation
  LISTING_RHS_WIDTH      Number of chars from the input file to print
-                        on a line
-*/
+                        on a line.  */
 
 #include "as.h"
-#include <obstack.h>
+#include "obstack.h"
 #include "safe-ctype.h"
 #include "input-file.h"
 #include "subsegs.h"
@@ -119,7 +117,8 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #endif
 
 /* This structure remembers which .s were used.  */
-typedef struct file_info_struct {
+typedef struct file_info_struct
+{
   struct file_info_struct * next;
   char *                    filename;
   long                      pos;
@@ -127,14 +126,16 @@ typedef struct file_info_struct {
   int                       at_end;
 } file_info_type;
 
-/* This structure rememebrs which line from which file goes into which
+/* This structure remembers which line from which file goes into which
    frag.  */
-struct list_info_struct {
+struct list_info_struct
+{
   /* Frag which this line of source is nearest to.  */
   fragS *frag;
 
   /* The actual line in the source file.  */
   unsigned int line;
+
   /* Pointer to the file info struct for the file which this line
      belongs to.  */
   file_info_type *file;
@@ -148,21 +149,23 @@ struct list_info_struct {
   /* Pointer to the file info struct for the high level language
      source line that belongs here.  */
   file_info_type *hll_file;
+
   /* High level language source line.  */
   unsigned int hll_line;
 
   /* Pointer to any error message associated with this line.  */
   char *message;
 
-  enum {
-    EDICT_NONE,
-    EDICT_SBTTL,
-    EDICT_TITLE,
-    EDICT_NOLIST,
-    EDICT_LIST,
-    EDICT_NOLIST_NEXT,
-    EDICT_EJECT
-  } edict;
+  enum
+    {
+      EDICT_NONE,
+      EDICT_SBTTL,
+      EDICT_TITLE,
+      EDICT_NOLIST,
+      EDICT_LIST,
+      EDICT_NOLIST_NEXT,
+      EDICT_EJECT
+    } edict;
   char *edict_arg;
 
   /* Nonzero if this line is to be omitted because it contains
@@ -204,27 +207,20 @@ static FILE *list_file;
 static char *data_buffer;
 
 /* Prototypes.  */
-static void listing_message PARAMS ((const char *name, const char *message));
-static file_info_type *file_info PARAMS ((const char *file_name));
-static void new_frag PARAMS ((void));
-static char *buffer_line PARAMS ((file_info_type *file,
-                                 char *line, unsigned int size));
-static void listing_page PARAMS ((list_info_type *list));
-static unsigned int calc_hex PARAMS ((list_info_type *list));
-static void print_lines PARAMS ((list_info_type *, unsigned int,
-                                char *, unsigned int));
-static void list_symbol_table PARAMS ((void));
-static void print_source PARAMS ((file_info_type *current_file,
-                                 list_info_type *list,
-                                 char *buffer,
-                                 unsigned int width));
-static int debugging_pseudo PARAMS ((list_info_type *, const char *));
-static void listing_listing PARAMS ((char *name));
+static void listing_message (const char *, const char *);
+static file_info_type *file_info (const char *);
+static void new_frag (void);
+static char *buffer_line (file_info_type *, char *, unsigned int);
+static void listing_page (list_info_type *);
+static unsigned int calc_hex (list_info_type *);
+static void print_lines (list_info_type *, unsigned int, char *, unsigned int);
+static void list_symbol_table (void);
+static void print_source (file_info_type *, list_info_type *, char *, unsigned int);
+static int debugging_pseudo (list_info_type *, const char *);
+static void listing_listing (char *);
 
 static void
-listing_message (name, message)
-     const char *name;
-     const char *message;
+listing_message (const char *name, const char *message)
 {
   if (listing_tail != (list_info_type *) NULL)
     {
@@ -237,22 +233,19 @@ listing_message (name, message)
 }
 
 void
-listing_warning (message)
-     const char *message;
+listing_warning (const char *message)
 {
   listing_message (_("Warning:"), message);
 }
 
 void
-listing_error (message)
-     const char *message;
+listing_error (const char *message)
 {
   listing_message (_("Error:"), message);
 }
 
 static file_info_type *
-file_info (file_name)
-     const char *file_name;
+file_info (const char *file_name)
 {
   /* Find an entry with this file name.  */
   file_info_type *p = file_info_head;
@@ -265,12 +258,10 @@ file_info (file_name)
     }
 
   /* Make new entry.  */
-
-  p = (file_info_type *) xmalloc (sizeof (file_info_type));
+  p = xmalloc (sizeof (file_info_type));
   p->next = file_info_head;
   file_info_head = p;
-  p->filename = xmalloc ((unsigned long) strlen (file_name) + 1);
-  strcpy (p->filename, file_name);
+  p->filename = xstrdup (file_name);
   p->pos = 0;
   p->linenum = 0;
   p->at_end = 0;
@@ -279,17 +270,14 @@ file_info (file_name)
 }
 
 static void
-new_frag ()
+new_frag (void)
 {
-
   frag_wane (frag_now);
   frag_new (0);
-
 }
 
 void
-listing_newline (ps)
-     char *ps;
+listing_newline (char *ps)
 {
   char *file;
   unsigned int line;
@@ -383,7 +371,7 @@ listing_newline (ps)
     }
   else
     {
-      new = (list_info_type *) xmalloc (sizeof (list_info_type));
+      new = xmalloc (sizeof (list_info_type));
       new->line_contents = ps;
     }
 
@@ -433,7 +421,7 @@ listing_newline (ps)
    with the new instruction.  */
 
 void
-listing_prev_line ()
+listing_prev_line (void)
 {
   list_info_type *l;
   fragS *f;
@@ -460,10 +448,7 @@ listing_prev_line ()
    file to make.  */
 
 static char *
-buffer_line (file, line, size)
-     file_info_type *file;
-     char *line;
-     unsigned int size;
+buffer_line (file_info_type *file, char *line, unsigned int size)
 {
   unsigned int count = 0;
   int c;
@@ -534,8 +519,7 @@ static char *subtitle;              /* Current subtitle */
 static unsigned int on_page;   /* Number of lines printed on current page */
 
 static void
-listing_page (list)
-     list_info_type *list;
+listing_page (list_info_type *list)
 {
   /* Grope around, see if we can see a title or subtitle edict coming up
      soon.  (we look down 10 lines of the page and see if it's there)  */
@@ -578,8 +562,7 @@ listing_page (list)
 }
 
 static unsigned int
-calc_hex (list)
-     list_info_type *list;
+calc_hex (list_info_type *list)
 {
   int data_buffer_size;
   list_info_type *first = list;
@@ -606,9 +589,7 @@ calc_hex (list)
             && data_buffer_size < MAX_BYTES - 3)
        {
          if (address == ~(unsigned int) 0)
-           {
-             address = frag_ptr->fr_address / OCTETS_PER_BYTE;
-           }
+           address = frag_ptr->fr_address / OCTETS_PER_BYTE;
 
          sprintf (data_buffer + data_buffer_size,
                   "%02X",
@@ -616,36 +597,31 @@ calc_hex (list)
          data_buffer_size += 2;
          octet_in_frag++;
        }
-    if (frag_ptr->fr_type == rs_fill)
-      {
-       unsigned int var_rep_max = octet_in_frag;
-       unsigned int var_rep_idx = octet_in_frag;
-
-       /* Print as many bytes from the variable part as is sensible.  */
-       while (((offsetT) octet_in_frag
-               < (frag_ptr->fr_fix + frag_ptr->fr_var * frag_ptr->fr_offset))
-              && data_buffer_size < MAX_BYTES - 3)
-         {
-           if (address == ~(unsigned int) 0)
-             {
+      if (frag_ptr->fr_type == rs_fill)
+       {
+         unsigned int var_rep_max = octet_in_frag;
+         unsigned int var_rep_idx = octet_in_frag;
+
+         /* Print as many bytes from the variable part as is sensible.  */
+         while (((offsetT) octet_in_frag
+                 < (frag_ptr->fr_fix + frag_ptr->fr_var * frag_ptr->fr_offset))
+                && data_buffer_size < MAX_BYTES - 3)
+           {
+             if (address == ~(unsigned int) 0)
                address = frag_ptr->fr_address / OCTETS_PER_BYTE;
-             }
-           sprintf (data_buffer + data_buffer_size,
-                    "%02X",
-                    (frag_ptr->fr_literal[var_rep_idx]) & 0xff);
-#if 0
-           data_buffer[data_buffer_size++] = '*';
-           data_buffer[data_buffer_size++] = '*';
-#endif
-           data_buffer_size += 2;
 
-           var_rep_idx++;
-           octet_in_frag++;
+             sprintf (data_buffer + data_buffer_size,
+                      "%02X",
+                      (frag_ptr->fr_literal[var_rep_idx]) & 0xff);
+             data_buffer_size += 2;
 
-           if ((offsetT) var_rep_idx >= frag_ptr->fr_fix + frag_ptr->fr_var)
-             var_rep_idx = var_rep_max;
-         }
-      }
+             var_rep_idx++;
+             octet_in_frag++;
+
+             if ((offsetT) var_rep_idx >= frag_ptr->fr_fix + frag_ptr->fr_var)
+               var_rep_idx = var_rep_max;
+           }
+       }
 
       frag_ptr = frag_ptr->fr_next;
     }
@@ -654,11 +630,8 @@ calc_hex (list)
 }
 
 static void
-print_lines (list, lineno, string, address)
-     list_info_type *list;
-     unsigned int lineno;
-     char *string;
-     unsigned int address;
+print_lines (list_info_type *list, unsigned int lineno,
+            char *string, unsigned int address)
 {
   unsigned int idx;
   unsigned int nchars;
@@ -762,7 +735,7 @@ print_lines (list, lineno, string, address)
 }
 
 static void
-list_symbol_table ()
+list_symbol_table (void)
 {
   extern symbolS *symbol_rootP;
   int got_some = 0;
@@ -776,11 +749,10 @@ list_symbol_table ()
       if (SEG_NORMAL (S_GET_SEGMENT (ptr))
          || S_GET_SEGMENT (ptr) == absolute_section)
        {
-#ifdef BFD_ASSEMBLER
          /* Don't report section symbols.  They are not interesting.  */
          if (symbol_section_p (ptr))
            continue;
-#endif
+
          if (S_GET_NAME (ptr))
            {
              char buf[30], fmt[8];
@@ -870,11 +842,8 @@ list_symbol_table ()
 }
 
 static void
-print_source (current_file, list, buffer, width)
-     file_info_type *current_file;
-     list_info_type *list;
-     char *buffer;
-     unsigned int width;
+print_source (file_info_type *current_file, list_info_type *list,
+             char *buffer, unsigned int width)
 {
   if (!current_file->at_end)
     {
@@ -882,6 +851,7 @@ print_source (current_file, list, buffer, width)
             && !current_file->at_end)
        {
          char *p = buffer_line (current_file, buffer, width);
+
          fprintf (list_file, "%4u:%-13s **** %s\n", current_file->linenum,
                   current_file->filename, p);
          on_page++;
@@ -894,9 +864,7 @@ print_source (current_file, list, buffer, width)
    records inserted by the compiler, see if the line is suspicious.  */
 
 static int
-debugging_pseudo (list, line)
-     list_info_type *list;
-     const char *line;
+debugging_pseudo (list_info_type *list, const char *line)
 {
   static int in_debug;
   int was_debug;
@@ -956,7 +924,6 @@ debugging_pseudo (list, line)
     return 1;
   if (strncmp (line, "tag", 3) == 0)
     return 1;
-
   if (strncmp (line, "stabs", 5) == 0)
     return 1;
   if (strncmp (line, "stabn", 5) == 0)
@@ -966,8 +933,7 @@ debugging_pseudo (list, line)
 }
 
 static void
-listing_listing (name)
-     char *name ATTRIBUTE_UNUSED;
+listing_listing (char *name ATTRIBUTE_UNUSED)
 {
   list_info_type *list = head;
   file_info_type *current_hll_file = (file_info_type *) NULL;
@@ -987,7 +953,6 @@ listing_listing (name)
       if (list->next)
        list->frag = list->next->frag;
       list = list->next;
-
     }
 
   list = head->next;
@@ -1049,24 +1014,19 @@ listing_listing (name)
          message = 0;
 
          if (list->hll_file)
-           {
-             current_hll_file = list->hll_file;
-           }
+           current_hll_file = list->hll_file;
 
          if (current_hll_file && list->hll_line && (listing & LISTING_HLL))
-           {
-             print_source (current_hll_file, list, buffer, width);
-           }
+           print_source (current_hll_file, list, buffer, width);
 
          if (list->line_contents)
            {
              if (!((listing & LISTING_NODEBUG)
                    && debugging_pseudo (list, list->line_contents)))
-               {
-                 print_lines (list,
-                              list->file->linenum == 0 ? list->line : list->file->linenum,
-                              list->line_contents, calc_hex (list));
-               }
+               print_lines (list,
+                            list->file->linenum == 0 ? list->line : list->file->linenum,
+                            list->line_contents, calc_hex (list));
+
              free (list->line_contents);
              list->line_contents = NULL;
            }
@@ -1091,9 +1051,7 @@ listing_listing (name)
            }
 
          if (list->edict == EDICT_EJECT)
-           {
-             eject = 1;
-           }
+           eject = 1;
        }
 
       if (list->edict == EDICT_NOLIST_NEXT && show_listing == 1)
@@ -1108,8 +1066,7 @@ listing_listing (name)
 }
 
 void
-listing_print (name)
-     char *name;
+listing_print (char *name)
 {
   int using_stdout;
 
@@ -1128,6 +1085,7 @@ listing_print (name)
        using_stdout = 0;
       else
        {
+         bfd_set_error (bfd_error_system_call);
          as_perror (_("can't open list file: %s"), name);
          list_file = stdout;
          using_stdout = 1;
@@ -1135,50 +1093,42 @@ listing_print (name)
     }
 
   if (listing & LISTING_NOFORM)
-    {
-      paper_height = 0;
-    }
+    paper_height = 0;
 
   if (listing & LISTING_LISTING)
-    {
-      listing_listing (name);
-    }
+    listing_listing (name);
 
   if (listing & LISTING_SYMBOLS)
-    {
-      list_symbol_table ();
-    }
+    list_symbol_table ();
 
   if (! using_stdout)
     {
       if (fclose (list_file) == EOF)
-       as_perror (_("error closing list file: %s"), name);
+       {
+         bfd_set_error (bfd_error_system_call);
+         as_perror (_("error closing list file: %s"), name);
+       }
     }
 
   if (last_open_file)
-    {
-      fclose (last_open_file);
-    }
+    fclose (last_open_file);
 }
 
 void
-listing_file (name)
-     const char *name;
+listing_file (const char *name)
 {
   fn = name;
 }
 
 void
-listing_eject (ignore)
-     int ignore ATTRIBUTE_UNUSED;
+listing_eject (int ignore ATTRIBUTE_UNUSED)
 {
   if (listing)
     listing_tail->edict = EDICT_EJECT;
 }
 
 void
-listing_flags (ignore)
-     int ignore ATTRIBUTE_UNUSED;
+listing_flags (int ignore ATTRIBUTE_UNUSED)
 {
   while ((*input_line_pointer++) && (*input_line_pointer != '\n'))
     input_line_pointer++;
@@ -1191,8 +1141,7 @@ listing_flags (ignore)
    the current line should be listed, but the next line should not.  */
 
 void
-listing_list (on)
-     int on;
+listing_list (int on)
 {
   if (listing)
     {
@@ -1221,8 +1170,7 @@ listing_list (on)
 }
 
 void
-listing_psize (width_only)
-     int width_only;
+listing_psize (int width_only)
 {
   if (! width_only)
     {
@@ -1249,15 +1197,13 @@ listing_psize (width_only)
 }
 
 void
-listing_nopage (ignore)
-     int ignore ATTRIBUTE_UNUSED;
+listing_nopage (int ignore ATTRIBUTE_UNUSED)
 {
   paper_height = 0;
 }
 
 void
-listing_title (depth)
-     int depth;
+listing_title (int depth)
 {
   int quoted;
   char *start;
@@ -1309,8 +1255,7 @@ listing_title (depth)
 }
 
 void
-listing_source_line (line)
-     unsigned int line;
+listing_source_line (unsigned int line)
 {
   if (listing)
     {
@@ -1321,8 +1266,7 @@ listing_source_line (line)
 }
 
 void
-listing_source_file (file)
-     const char *file;
+listing_source_file (const char *file)
 {
   if (listing)
     listing_tail->hll_file = file_info (file);
@@ -1333,73 +1277,59 @@ listing_source_file (file)
 /* Dummy functions for when compiled without listing enabled.  */
 
 void
-listing_flags (ignore)
-     int ignore;
+listing_flags (int ignore)
 {
   s_ignore (0);
 }
 
 void
-listing_list (on)
-     int on;
+listing_list (int on)
 {
   s_ignore (0);
 }
 
 void
-listing_eject (ignore)
-     int ignore;
+listing_eject (int ignore)
 {
   s_ignore (0);
 }
 
 void
-listing_psize (ignore)
-     int ignore;
+listing_psize (int ignore)
 {
   s_ignore (0);
 }
 
 void
-listing_nopage (ignore)
-     int ignore;
+listing_nopage (int ignore)
 {
   s_ignore (0);
 }
 
 void
-listing_title (depth)
-     int depth;
+listing_title (int depth)
 {
   s_ignore (0);
 }
 
 void
-listing_file (name)
-     const char *name;
+listing_file (const char *name)
 {
-
 }
 
 void
-listing_newline (name)
-     char *name;
+listing_newline (char *name)
 {
-
 }
 
 void
-listing_source_line (n)
-     unsigned int n;
+listing_source_line (unsigned int n)
 {
-
 }
 
 void
-listing_source_file (n)
-     const char *n;
+listing_source_file (const char *n)
 {
-
 }
 
 #endif
This page took 0.035177 seconds and 4 git commands to generate.