x
[deliverable/binutils-gdb.git] / gas / listing.c
index ce0983caba3a642ef4c315a15d85487b53659cb3..ef88c0d553031053d740f3518c1920ec02bb0529 100644 (file)
@@ -96,6 +96,8 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
 #include "input-file.h"
 #include "targ-cpu.h"
 
+char *malloc();
+
 #ifndef NO_LISTING
 #ifndef LISTING_HEADER
 #define LISTING_HEADER "GAS LISTING"
@@ -126,6 +128,8 @@ typedef struct file_info_struct
   int linenum;
   FILE *file;
   struct file_info_struct *next;
+  int end_pending;
+  
 } file_info_type ;
 
   
@@ -150,7 +154,7 @@ typedef struct list_info_struct
   file_info_type *hll_file;
   
   /* High level language source line */
-  unsigned int hll_line;
+  int hll_line;
   
 
   /* Pointer to any error message associated with this line */
@@ -197,7 +201,7 @@ DEFUN(listing_message,(name, message),
       char *message)
 {
   unsigned int l = strlen(name) + strlen(message)+1;
-  char *n =  malloc(l);
+  char *n =  (char*)malloc(l);
   strcpy(n,name);
   strcat(n,message);
   if(listing_tail != (list_info_type *)NULL) 
@@ -251,7 +255,13 @@ DEFUN(file_info, (file_name),
   p->filename = xmalloc(strlen(file_name)+1);
   strcpy(p->filename, file_name);
   p->linenum = 0;
-  p->file = fopen(p->filename,"r");
+  p->end_pending = 0;
+  
+  p->file = fopen(p->filename,"rb");
+if (p->file)  fgetc(p->file);
+
+
+
   return p;
   
 }
@@ -298,12 +308,18 @@ DEFUN(listing_newline,(ps),
     new->next = (list_info_type *)NULL;
     new->message = (char *)NULL;
     new->edict = EDICT_NONE;    
+    new->hll_file = (file_info_type*)NULL;
+    new->hll_line = 0;
     new_frag();
   }  
 }
 
 
-
+/* 
+ This function returns the next source line from the file supplied,
+ truncated to size.  It appends a fake line to the end of each input
+ file to make
+*/
 
 static char *
 DEFUN(buffer_line,(file, line, size),
@@ -315,13 +331,27 @@ DEFUN(buffer_line,(file, line, size),
   int c;
   
   char *p = line;
+
+  /* If we couldn't open the file, return an empty line */
   if  (file->file == (FILE*)NULL) 
   {
     return "";
   }
-  
+
+  if (file->linenum == 0)
+   rewind(file->file);
+
+  if (file->end_pending == 10) {
+      *p ++ = '\n';
+      fseek(file->file, 0,0 );
+      file->linenum = 0;
+      file->end_pending = 0;
+    }  
   c = fgetc(file->file);
+
+  
   size -= 1;                   /* leave room for null */
+
   while (c != EOF && c != '\n') 
   {
     if (count < size) 
@@ -329,12 +359,14 @@ DEFUN(buffer_line,(file, line, size),
     count++;
     
     c= fgetc(file->file);
+
   }
   if (c == EOF) 
   {
-    rewind(file->file);
-    file->linenum = 0;
-    
+    file->end_pending ++;
+    *p++ = '.';
+    *p++ = '.';
+    *p++ = '.';
   }
   file->linenum++;  
   *p++ = 0;
@@ -431,10 +463,16 @@ DEFUN(calc_hex,(list),
        address = frag_ptr->fr_address;
       }
             
-      sprintf(data_buffer + data_buffer_size, "%02X",(frag_ptr->fr_literal[byte_in_frag]) & 0xff);
+      sprintf(data_buffer + data_buffer_size,
+             "%02X",
+             (frag_ptr->fr_literal[byte_in_frag]) & 0xff);
       data_buffer_size += 2;
       byte_in_frag++;
     }
+  {
+    unsigned int var_rep_max = byte_in_frag; 
+    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 
           && data_buffer_size < sizeof(data_buffer)-10)
@@ -443,11 +481,23 @@ DEFUN(calc_hex,(list),
       {
        address =  frag_ptr->fr_address;
       }
+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 ++;
       byte_in_frag++;
+      
+      if (var_rep_idx >= frag_ptr->fr_var)
+       var_rep_idx = var_rep_max;
     }
+  }
+    
     frag_ptr = frag_ptr->fr_next;
   }
   data_buffer[data_buffer_size++] = 0;
@@ -580,6 +630,9 @@ DEFUN_VOID(list_symbol_table)
   {
     if (ptr->sy_frag->line) 
     {
+      if (S_GET_NAME(ptr)) 
+      {
+       
       if (strlen(S_GET_NAME(ptr))) 
       {
        printf("%20s:%-5d  %2d:%08x %s \n",
@@ -588,7 +641,19 @@ DEFUN_VOID(list_symbol_table)
               S_GET_SEGMENT(ptr),
               S_GET_VALUE(ptr),
               S_GET_NAME(ptr));
+      }
+      
+      else 
+      {
+       printf("%20s:%-5d  %2d:%08x\n",
+              ptr->sy_frag->line->file->filename,
+              ptr->sy_frag->line->line,
+              S_GET_SEGMENT(ptr),
+              S_GET_VALUE(ptr));
+       
 
+      }
+      
        on_page++;
        listing_page(0);
       }      
@@ -604,7 +669,7 @@ DEFUN_VOID(list_symbol_table)
   
   for (ptr = symbol_rootP; ptr != (symbolS*)NULL; ptr = symbol_next(ptr))
   {
-    if (ptr && strlen(S_GET_NAME(ptr)) != 0) 
+    if (S_GET_NAME(ptr) && strlen(S_GET_NAME(ptr)) != 0) 
     {
       if (ptr->sy_frag->line == 0) 
       {
@@ -626,14 +691,43 @@ DEFUN(print_source,(current_file, list, buffer, width),
   if (current_file->file) {  
       while (current_file->linenum < list->hll_line)
       {
-       char*    p = buffer_line(current_file, buffer, width);
-       printf("%4d:%-13s **** %s\n", current_file->linenum,  current_file->filename, p);
+       char * p = buffer_line(current_file, buffer, width);
+       printf("%4d:%-13s **** %s\n", current_file->linenum, current_file->filename, p);
        on_page++;
        listing_page(list);     
       }
     }
 }
 
+/* Sometimes the user doesn't want to be bothered by the debugging
+   records inserted by the compiler, see if the line is suspicioous */
+
+static int
+DEFUN(debugging_pseudo,(line),
+      char *line)
+{
+  while (isspace(*line)) 
+   line++;
+
+  if(*line != '.') return 0;
+  
+  line++;
+
+  if (strncmp(line, "def",3) == 0) return 1;
+  if (strncmp(line, "val",3) == 0) return 1;
+  if (strncmp(line, "scl",3) == 0) return 1;
+  if (strncmp(line, "line",4) == 0) return 1;
+  if (strncmp(line, "endef",5) == 0) return 1;
+  if (strncmp(line, "ln",2) ==0) return 1;
+  if (strncmp(line, "type",4) ==0) return 1;
+  if (strncmp(line, "size",4) == 0) return 1;
+  if (strncmp(line, "dim",3) ==0) return 1;
+  if (strncmp(line, "tag",3) == 0) return 1;
+  
+  return 0;
+
+}
+
 void 
 DEFUN(listing_listing,(name),
       char *name)
@@ -669,28 +763,28 @@ DEFUN(listing_listing,(name),
   while ( list)
   {
     width =  LISTING_RHS_WIDTH > paper_width ?  paper_width :
-     LISTING_RHS_WIDTH;
+    LISTING_RHS_WIDTH;
     
-     switch (list->edict) {
-       case EDICT_LIST:
-        show_listing++;
-        break;
-       case EDICT_NOLIST:
-        show_listing--;
-        break;
-       case EDICT_EJECT:
-        break;
-       case EDICT_NONE:
-        break;
-       case EDICT_TITLE:
-        title = list->edict_arg;
-        break;
-       case EDICT_SBTTL:
-        subtitle = list->edict_arg;
-        break;
-       default:
-        abort();
-       }
+    switch (list->edict) {
+      case EDICT_LIST:
+       show_listing++;
+       break;
+      case EDICT_NOLIST:
+       show_listing--;
+       break;
+      case EDICT_EJECT:
+       break;
+      case EDICT_NONE:
+       break;
+      case EDICT_TITLE:
+       title = list->edict_arg;
+       break;
+      case EDICT_SBTTL:
+       subtitle = list->edict_arg;
+       break;
+      default:
+       abort();
+      }
     
     if (show_listing > 0) 
     {
@@ -710,7 +804,10 @@ DEFUN(listing_listing,(name),
    
       p = buffer_line(list->file, buffer, width);      
 
-      print_lines(list, p,      calc_hex(list));
+      if (! ((listing & LISTING_NODEBUG) && debugging_pseudo(p)))
+      {      
+       print_lines(list, p,  calc_hex(list));
+      }
 
       if (list->edict == EDICT_EJECT) 
       {
@@ -768,6 +865,8 @@ DEFUN_VOID(listing_eject)
 void
 DEFUN_VOID(listing_flags)
 {
+  while ( (*input_line_pointer++) && (*input_line_pointer != '\n') )
+   input_line_pointer++;
   
 }
 void
@@ -786,7 +885,7 @@ DEFUN_VOID(listing_psize)
   if (paper_height < 0 || paper_height > 1000) 
   {
     paper_height = 0;
-    as_warn("strantge paper height, set to no form");
+    as_warn("strange paper height, set to no form");
   }
  if (*input_line_pointer == ',') 
   {
@@ -882,7 +981,7 @@ void DEFUN_VOID(listing_eject)
 {
   s_ignore();  
 }
-void DEFUN(listing_psize)
+void DEFUN_VOID(listing_psize)
 {
   s_ignore();
 }
This page took 0.027147 seconds and 4 git commands to generate.