* config/tc-sparc.c (md_pseudo_table): Add 2byte, 4byte, and 8byte
[deliverable/binutils-gdb.git] / gas / listing.c
index aa9d99bbd73f12e840913e11f08157943cf5d222..b42f146de59ff42d254425ac792903487cf7986f 100644 (file)
@@ -15,7 +15,7 @@ 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
+the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
 
 /*
  Contributed by Steve Chamberlain
@@ -128,7 +128,7 @@ typedef struct file_info_struct
   int linenum;
   FILE *file;
   struct file_info_struct *next;
-  int end_pending;
+  int at_end;
 }
 
 file_info_type;
@@ -180,12 +180,12 @@ list_info_type;
 static struct list_info_struct *head;
 struct list_info_struct *listing_tail;
 extern int listing;
-extern fragS *frag_now;
-
 
 static int paper_width = 200;
 static int paper_height = 60;
 
+/* File to output listings to.  */
+static FILE *list_file;
 
 /* this static array is used to keep the text of data to be printed
    before the start of the line.
@@ -273,7 +273,7 @@ file_info (file_name)
   p->filename = xmalloc ((unsigned long) strlen (file_name) + 1);
   strcpy (p->filename, file_name);
   p->linenum = 0;
-  p->end_pending = 0;
+  p->at_end = 0;
 
   p->file = fopen (p->filename, "r");
   if (p->file)
@@ -302,8 +302,14 @@ listing_newline (ps)
   static char *last_file = NULL;
   list_info_type *new;
 
+  if (listing == 0)
+    return;
+
+  if (now_seg == absolute_section)
+    return;
+
   as_where (&file, &line);
-  if (line != last_line || last_file && file && strcmp(file, last_file))
+  if (line != last_line || (last_file && file && strcmp(file, last_file)))
     {
       last_line = line;
       last_file = file;
@@ -379,7 +385,7 @@ buffer_line (file, line, size)
   char *p = line;
 
   /* If we couldn't open the file, return an empty line */
-  if (file->file == (FILE *) NULL)
+  if (file->file == (FILE *) NULL || file->at_end)
     {
       return "";
     }
@@ -387,20 +393,8 @@ buffer_line (file, line, size)
   if (file->linenum == 0)
     rewind (file->file);
 
-  if (file->end_pending == 10)
-    {
-      *p++ = '\n';
-#if 1
-      fseek (file->file, 0, 0);
-      file->linenum = 0;
-#else
-      file->linenum = 9999999;
-#endif
-      file->end_pending = 0;
-    }
   c = fgetc (file->file);
 
-
   size -= 1;                   /* leave room for null */
 
   while (c != EOF && c != '\n')
@@ -414,7 +408,7 @@ buffer_line (file, line, size)
     }
   if (c == EOF)
     {
-      file->end_pending++;
+      file->at_end = 1;
       *p++ = '.';
       *p++ = '.';
       *p++ = '.';
@@ -467,12 +461,12 @@ listing_page (list)
 
       if (page > 1)
        {
-         printf ("\f");
+         fprintf (list_file, "\f");
        }
 
-      printf ("%s %s \t\t\tpage %d\n", LISTING_HEADER, fn, page);
-      printf ("%s\n", title);
-      printf ("%s\n", subtitle);
+      fprintf (list_file, "%s %s \t\t\tpage %d\n", LISTING_HEADER, fn, page);
+      fprintf (list_file, "%s\n", title);
+      fprintf (list_file, "%s\n", subtitle);
       on_page = 3;
       eject = 0;
     }
@@ -524,7 +518,8 @@ calc_hex (list)
        unsigned int var_rep_idx = byte_in_frag;
 
        /* Print as many bytes from the variable part as is sensible */
-       while (byte_in_frag < frag_ptr->fr_var * frag_ptr->fr_offset
+       while ((byte_in_frag
+               < frag_ptr->fr_fix + frag_ptr->fr_var * frag_ptr->fr_offset)
               && data_buffer_size < sizeof (data_buffer) - 10)
          {
            if (address == ~0)
@@ -543,7 +538,7 @@ calc_hex (list)
            var_rep_idx++;
            byte_in_frag++;
 
-           if (var_rep_idx >= frag_ptr->fr_var)
+           if (var_rep_idx >= frag_ptr->fr_fix + frag_ptr->fr_var)
              var_rep_idx = var_rep_max;
          }
       }
@@ -577,11 +572,11 @@ print_lines (list, string, address)
   /* Print the hex for the first line */
   if (address == ~0)
     {
-      printf ("% 4d     ", list->line);
+      fprintf (list_file, "% 4d     ", list->line);
       for (idx = 0; idx < nchars; idx++)
-       printf (" ");
+       fprintf (list_file, " ");
 
-      printf ("\t%s\n", string ? string : "");
+      fprintf (list_file, "\t%s\n", string ? string : "");
       on_page++;
       listing_page (0);
 
@@ -590,11 +585,11 @@ print_lines (list, string, address)
     {
       if (had_errors ())
        {
-         printf ("% 4d ???? ", list->line);
+         fprintf (list_file, "% 4d ???? ", list->line);
        }
       else
        {
-         printf ("% 4d %04x ", list->line, address);
+         fprintf (list_file, "% 4d %04x ", list->line, address);
        }
 
       /* And the data to go along with it */
@@ -602,12 +597,12 @@ print_lines (list, string, address)
 
       while (*src && idx < nchars)
        {
-         printf ("%c%c", src[0], src[1]);
+         fprintf (list_file, "%c%c", src[0], src[1]);
          src += 2;
          byte_in_word++;
          if (byte_in_word == LISTING_WORD_SIZE)
            {
-             printf (" ");
+             fprintf (list_file, " ");
              idx++;
              byte_in_word = 0;
            }
@@ -615,14 +610,14 @@ print_lines (list, string, address)
        }
 
       for (; idx < nchars; idx++)
-       printf (" ");
+       fprintf (list_file, " ");
 
-      printf ("\t%s\n", string ? string : "");
+      fprintf (list_file, "\t%s\n", string ? string : "");
       on_page++;
       listing_page (list);
       if (list->message)
        {
-         printf ("****  %s\n", list->message);
+         fprintf (list_file, "****  %s\n", list->message);
          listing_page (list);
          on_page++;
        }
@@ -635,23 +630,23 @@ print_lines (list, string, address)
          nchars = ((LISTING_WORD_SIZE * 2) + 1) * LISTING_LHS_WIDTH_SECOND - 1;
          idx = 0;
          /* Print any more lines of data, but more compactly */
-         printf ("% 4d      ", list->line);
+         fprintf (list_file, "% 4d      ", list->line);
 
          while (*src && idx < nchars)
            {
-             printf ("%c%c", src[0], src[1]);
+             fprintf (list_file, "%c%c", src[0], src[1]);
              src += 2;
              idx += 2;
              byte_in_word++;
              if (byte_in_word == LISTING_WORD_SIZE)
                {
-                 printf (" ");
+                 fprintf (list_file, " ");
                  idx++;
                  byte_in_word = 0;
                }
            }
 
-         printf ("\n");
+         fprintf (list_file, "\n");
          on_page++;
          listing_page (list);
 
@@ -687,7 +682,8 @@ list_symbol_table ()
                sprintf (buf, "%08lx", (unsigned long) val);
              else if (sizeof (val) <= sizeof (unsigned long))
                {
-                 sprintf (fmt, "%%0%dlx", sizeof (val) * 2);
+                 sprintf (fmt, "%%0%lulx",
+                          (unsigned long) (sizeof (val) * 2));
                  sprintf (buf, fmt, (unsigned long) val);
                }
 #if defined (BFD64)
@@ -704,16 +700,16 @@ list_symbol_table ()
 
              if (!got_some)
                {
-                 printf ("DEFINED SYMBOLS\n");
+                 fprintf (list_file, "DEFINED SYMBOLS\n");
                  on_page++;
                  got_some = 1;
                }
 
-             printf ("%20s:%-5d  %s:%s %s\n",
-                     ptr->sy_frag->line->file->filename,
-                     ptr->sy_frag->line->line,
-                     segment_name (S_GET_SEGMENT (ptr)),
-                     buf, S_GET_NAME (ptr));
+             fprintf (list_file, "%20s:%-5d  %s:%s %s\n",
+                      ptr->sy_frag->line->file->filename,
+                      ptr->sy_frag->line->line,
+                      segment_name (S_GET_SEGMENT (ptr)),
+                      buf, S_GET_NAME (ptr));
 
              on_page++;
              listing_page (0);
@@ -723,10 +719,10 @@ list_symbol_table ()
     }
   if (!got_some)
     {
-      printf ("NO DEFINED SYMBOLS\n");
+      fprintf (list_file, "NO DEFINED SYMBOLS\n");
       on_page++;
     }
-  printf ("\n");
+  fprintf (list_file, "\n");
   on_page++;
   listing_page (0);
 
@@ -745,11 +741,11 @@ list_symbol_table ()
              if (!got_some)
                {
                  got_some = 1;
-                 printf ("UNDEFINED SYMBOLS\n");
+                 fprintf (list_file, "UNDEFINED SYMBOLS\n");
                  on_page++;
                  listing_page (0);
                }
-             printf ("%s\n", S_GET_NAME (ptr));
+             fprintf (list_file, "%s\n", S_GET_NAME (ptr));
              on_page++;
              listing_page (0);
            }
@@ -757,7 +753,7 @@ list_symbol_table ()
     }
   if (!got_some)
     {
-      printf ("NO UNDEFINED SYMBOLS\n");
+      fprintf (list_file, "NO UNDEFINED SYMBOLS\n");
       on_page++;
       listing_page (0);
     }
@@ -773,10 +769,11 @@ print_source (current_file, list, buffer, width)
   if (current_file->file)
     {
       while (current_file->linenum < list->hll_line
-            && current_file->end_pending == 0)
+            && !current_file->at_end)
        {
          char *p = buffer_line (current_file, buffer, width);
-         printf ("%4d:%-13s **** %s\n", current_file->linenum, current_file->filename, p);
+         fprintf (list_file, "%4d:%-13s **** %s\n", current_file->linenum,
+                  current_file->filename, p);
          on_page++;
          listing_page (list);
        }
@@ -900,7 +897,7 @@ listing_listing (name)
 
          while (list->file->file
                 && list->file->linenum < list->line
-                && !list->file->end_pending)
+                && !list->file->at_end)
            {
              p = buffer_line (list->file, buffer, width);
 
@@ -919,7 +916,7 @@ listing_listing (name)
        {
          while (list->file->file
                 && list->file->linenum < list->line
-                && !list->file->end_pending)
+                && !list->file->at_end)
            p = buffer_line (list->file, buffer, width);
        }
 
@@ -935,6 +932,18 @@ listing_print (name)
   title = "";
   subtitle = "";
 
+  if (name == NULL)
+    list_file = stdout;
+  else
+    {
+      list_file = fopen (name, "w");
+      if (list_file == NULL)
+       {
+         as_perror ("can't open list file: %s", name);
+         list_file = stdout;
+       }
+    }
+
   if (listing & LISTING_NOFORM)
     {
       paper_height = 0;
@@ -963,7 +972,8 @@ void
 listing_eject (ignore)
      int ignore;
 {
-  listing_tail->edict = EDICT_EJECT;
+  if (listing)
+    listing_tail->edict = EDICT_EJECT;
 }
 
 void
@@ -979,46 +989,73 @@ void
 listing_list (on)
      int on;
 {
-  listing_tail->edict = on ? EDICT_LIST : EDICT_NOLIST;
+  if (listing)
+    listing_tail->edict = on ? EDICT_LIST : EDICT_NOLIST;
 }
 
 
 void
-listing_psize (ignore)
-     int ignore;
+listing_psize (width_only)
+     int width_only;
 {
-  paper_height = get_absolute_expression ();
-
-  if (paper_height < 0 || paper_height > 1000)
-    {
-      paper_height = 0;
-      as_warn ("strange paper height, set to no form");
-    }
-  if (*input_line_pointer == ',')
+  if (! width_only)
     {
-      input_line_pointer++;
-      paper_width = get_absolute_expression ();
+      paper_height = get_absolute_expression ();
+
+      if (paper_height < 0 || paper_height > 1000)
+       {
+         paper_height = 0;
+         as_warn ("strange paper height, set to no form");
+       }
+
+      if (*input_line_pointer != ',')
+       {
+         demand_empty_rest_of_line ();
+         return;
+       }
+
+      ++input_line_pointer;
     }
+
+  paper_width = get_absolute_expression ();
+
+  demand_empty_rest_of_line ();
 }
 
+void
+listing_nopage (ignore)
+     int ignore;
+{
+  paper_height = 0;
+}
 
 void
 listing_title (depth)
      int depth;
 {
+  int quoted;
   char *start;
   char *ttl;
   unsigned int length;
 
   SKIP_WHITESPACE ();
-  if (*input_line_pointer == '\"')
+  if (*input_line_pointer != '\"')
+    quoted = 0;
+  else
     {
-      input_line_pointer++;
-      start = input_line_pointer;
+      quoted = 1;
+      ++input_line_pointer;
+    }
+
+  start = input_line_pointer;
 
-      while (*input_line_pointer)
+  while (*input_line_pointer)
+    {
+      if (quoted
+         ? *input_line_pointer == '\"'
+         : is_end_of_line[(unsigned char) *input_line_pointer])
        {
-         if (*input_line_pointer == '\"')
+         if (listing)
            {
              length = input_line_pointer - start;
              ttl = xmalloc (length + 1);
@@ -1026,25 +1063,22 @@ listing_title (depth)
              ttl[length] = 0;
              listing_tail->edict = depth ? EDICT_SBTTL : EDICT_TITLE;
              listing_tail->edict_arg = ttl;
-             input_line_pointer++;
-             demand_empty_rest_of_line ();
-             return;
-           }
-         else if (*input_line_pointer == '\n')
-           {
-             as_bad ("New line in title");
-             demand_empty_rest_of_line ();
-             return;
-           }
-         else
-           {
-             input_line_pointer++;
            }
+         if (quoted)
+           input_line_pointer++;
+         demand_empty_rest_of_line ();
+         return;
+       }
+      else if (*input_line_pointer == '\n')
+       {
+         as_bad ("New line in title");
+         demand_empty_rest_of_line ();
+         return;
+       }
+      else
+       {
+         input_line_pointer++;
        }
-    }
-  else
-    {
-      as_bad ("expecting title in quotes");
     }
 }
 
@@ -1054,17 +1088,19 @@ void
 listing_source_line (line)
      unsigned int line;
 {
-  new_frag ();
-  listing_tail->hll_line = line;
-  new_frag ();
-
+  if (listing)
+    {
+      new_frag ();
+      listing_tail->hll_line = line;
+      new_frag ();
+    }
 }
 
 void
 listing_source_file (file)
      const char *file;
 {
-  if (listing_tail)
+  if (listing)
     listing_tail->hll_file = file_info (file);
 }
 
@@ -1103,6 +1139,13 @@ listing_psize (ignore)
   s_ignore (0);
 }
 
+void
+listing_nopage (ignore)
+     int ignore;
+{
+  s_ignore (0);
+}
+
 void 
 listing_title (depth)
      int depth;
This page took 0.030979 seconds and 4 git commands to generate.