home *** CD-ROM | disk | FTP | other *** search
/ World of A1200 / World_Of_A1200.iso / programs / monitors / rsys / goodies / checksym / checksym.c < prev    next >
C/C++ Source or Header  |  1995-02-27  |  3KB  |  110 lines

  1. /** DoRev Header ** Do not edit! **
  2. *
  3. * Name             :  checksym.c
  4. * Creation date    :  29-Jul-92
  5. * Contents         :  checksym.c
  6. * Compiler opts.   :  -qq -wdlp -sou -pe -hi Sys.pre
  7. *
  8. * Date       Rev  Author               Comment
  9. * ---------  ---  -------------------  ----------------------------------------
  10. * 29-Jul-92    1  Rolf Boehme          Erstellt
  11. * 29-Jul-92    0  Rolf Boehme          None.
  12. *
  13. *** DoRev End **/
  14.  
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <stdlib.h>
  18. #include <ctype.h>
  19.  
  20. /* Vebesserte Version: Benutzt MACROs */
  21. int atoh(char *hex)
  22. {   int n;
  23.    register int i;
  24.  
  25.    /* Stellenzähler auf 0 setzen */
  26.    n = 0;
  27.  
  28.    /* Solange ein Zeichen in den angegebenen Bereichen liegt, */
  29.    /* werden die entsprechenden Werte aufaddiert              */
  30.    for( i = 0; isxdigit( (int)hex[i] ); i++ ){
  31.         if((hex[i] >= '0') && (hex[i] <= '9'))
  32.            n = 16*n + hex[i] - '0';
  33.         if((hex[i] >= 'a') && (hex[i] <= 'f'))
  34.            n = 16*n + 10 + (hex[i] - 'a');
  35.         if((hex[i] >= 'A') && (hex[i] <= 'F'))
  36.            n = 16*n + 10 + (hex[i] - 'A');
  37.    }
  38.  
  39.    /* Summe zurückgeben */
  40.    return(n);
  41. }
  42.  
  43.  
  44. void
  45. main(int i,char *a[])
  46. {
  47.    FILE *fin;
  48.    char line[200],fname[200],findsym[100],lastsym[100];
  49.    long findaddr = -1,symaddr,lastaddr = 0;
  50.    int segment,hunk;
  51.  
  52.    printf("\33[3;33m%s 0.1\33[0m - von Rolf Böhme, PD!\n",a[0]);
  53.  
  54.    if(i >= 2)
  55.    {
  56.       strcpy(fname,a[1]);
  57.       if( !strstr(fname,".sym") )
  58.          strcat(fname,".sym");
  59.  
  60.       if( i == 3 )
  61.          findaddr = (long)atoh(a[2]);
  62.  
  63.       if( fin = fopen(fname,"r") )
  64.       {
  65.          fgets( line,200,fin );
  66.  
  67.          while( !feof(fin) )
  68.          {
  69.             if( strstr(line,"Segment") )
  70.             {
  71.                char *tok = strtok(line," :");
  72.  
  73.                segment = atoi( strtok(NULL," :") );
  74.                strtok(NULL," :");
  75.                hunk = atoi( strtok(NULL," :") );
  76.  
  77.                puts("\n-------------------------------");
  78.                printf("Segment %d, Hunk %d",segment,hunk);
  79.                puts("\n-------------------------------");
  80.             }
  81.             else
  82.             {
  83.                line[9] = '\0';
  84.                symaddr = atoh( &line[1] );
  85.                strcpy( findsym,&line[10] );
  86.  
  87.                if( findaddr == -1 )
  88.                   printf("Adr: 0x%08x  Symbol: %s",symaddr,findsym);
  89.                else
  90.                   if( (findaddr >= lastaddr) && (findaddr < symaddr) )
  91.                      printf("Adr: 0x%08x  Symbol: %s",lastaddr,lastsym);
  92.  
  93.                strcpy(lastsym,findsym);
  94.                lastaddr = symaddr;
  95.             }
  96.  
  97.             fgets( line,200,fin );
  98.          }
  99.  
  100.          fclose(fin);
  101.       }
  102.       else
  103.          printf("Datei %s nicht gefunden!\n",fname);
  104.    }
  105.    else
  106.       printf("Aufruf: %s <Programmname> <adr>\n",a[0]);
  107.  
  108.    exit(0);
  109. }
  110.