home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1987 / 12 / naro / stable.c < prev   
Text File  |  1987-12-21  |  7KB  |  74 lines

  1. #include <stdio.h>                                                                           
  2. #include <stdlib.h>                                                                          
  3. #include <string.h>                                                                          
  4. #include <dos.h>                                                                             
  5.                                                                                              
  6. #include "loc.h"                                                                             
  7. #include "externs.h"                                                                         
  8.                                                                                              
  9. char  *errstr = "Unable to locate global symbol \"%s\"\n" ;                                  
  10.                                                                                              
  11.                                                                                              
  12. void  read_symbol_table(seg_list)                                                            
  13. SEG_DESCRIPTOR *seg_list ;                                                                   
  14. {                                                                                            
  15.    char  buf[128] ;                                                                          
  16.    int   count, found ;                                                                      
  17.    unsigned int   vseg, off;                                                                 
  18.    char  symbol[32], attrb[10] ;                                                             
  19.                                                                                              
  20.    SEG_DESCRIPTOR *p ;                                                                       
  21.    SYMBOL_LIST *q ;                                                                          
  22.                                                                                              
  23.    /*                                                                                        
  24.       This function reads the linker map file and extracts the                               
  25.       symbol information.                                                                    
  26.    */                                                                                        
  27.                                                                                              
  28.    /* Seek to the beginning of the file */                                                   
  29.    if (fseek(map_file, 0L, SEEK_SET) != 0)   {                                               
  30.       perror(__FILE__) ;                                                                     
  31.       exit(1) ;                                                                              
  32.    }                                                                                         
  33.                                                                                              
  34.    /* Search thru the file for the symbol tables */                                          
  35.    while (1)   {                                                                             
  36.       if (fgets(buf, sizeof(buf), map_file) == NULL)                                         
  37.          return ;                                                                            
  38.                                                                                              
  39.       if (strstr(strupr(buf), "ADDRESS") != NULL)                                            
  40.          break ;                                                                             
  41.    }                                                                                         
  42.                                                                                              
  43.    /* Read each of the symbol entries */                                                     
  44.    while (1)   {                                                                             
  45.       count = fscanf(map_file, " %4x:%4x%5c %s", &vseg, &off, attrb, symb;                   
  46.       if (count != 4)                                                                        
  47.          break ;                                                                             
  48.       else    {                                                                              
  49.          p = seg_list ;                                                                      
  50.          found = FALSE ;                                                                     
  51.          while (p != NULL)   {                                                               
  52.             if ((p->vseg != vseg) || (p->len == 0))   {                                      
  53.                p = p->next ;                                                                 
  54.                continue ;                                                                    
  55.             }                                                                                
  56.                                                                                              
  57.             q = (SYMBOL_LIST *) malloc(sizeof(*q)) ;                                         
  58.             strcpy(q->name, symbol) ;                                                        
  59.             q->value = off ;                                                                 
  60.             q->type = 1 ;                                                                    
  61.             q->next = p->symbol_list ;                                                       
  62.             p->symbol_list = q ;                                                             
  63.             p->symbols++ ;                                                                   
  64.             found = TRUE ;                                                                   
  65.             break ;                                                                          
  66.          }                                                                                   
  67.                                                                                              
  68.          if (found == FALSE)                                                                 
  69.             fprintf(stderr, errstr, symbol) ;                                                
  70.       }                                                                                      
  71.    }                                                                                         
  72.                                                                                              
  73.    return ;                                                                                  
  74. }