home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_progs / prog_oth / ninfo662.lha / do_sym.c < prev    next >
C/C++ Source or Header  |  1992-05-20  |  3KB  |  120 lines

  1. /* Symbol Processing and I/O routines */
  2. #include "hunk.h"
  3. extern Flgs[26];
  4. unsigned char OneChar(file)  /* read one character from file */
  5.   BPTR file;
  6.   {
  7.   unsigned char c;
  8.   if( Read(file,&c,1) == 1)
  9.     {
  10.     return (c);
  11.     };
  12.   return (0); /* errors and eof */
  13.   }
  14.  
  15. int GrabThree(file) /* get a three byte value */
  16.   BPTR file;
  17.   {
  18.   unsigned char out[4];
  19.   int  i,j;
  20.   char *cp;
  21.   i = 0;
  22.   if( Read(file,&out[1],3) == 3 )
  23.     {
  24.     out[0] = 0;
  25.     cp = (char *)&i;
  26.     for(j=0; j<4; j++)*cp++=out[j];
  27.     return ( i );
  28.     } ;
  29.   return (0);
  30.   }
  31.  
  32. int GrabLong(file)
  33.   BPTR file;
  34.   {
  35.   int data;
  36.   if( Read(file,(UBYTE *)&data,4L) == 4)
  37.     {
  38.     return ( data );
  39.     }  ;
  40.   return(0);
  41.   }
  42.  
  43. void DoSymbolData(file)
  44.   BPTR file;
  45.   {
  46.   register   int type,i,length,t0;
  47.   char *Data;
  48.   while (1)
  49.     {
  50.     type   = OneChar(file);
  51.     length = GrabThree(file);
  52.     if( length > 32 )
  53.       {
  54.       printf(" Error in symbol length=%d\n",length);
  55.       length = 32;
  56.       };
  57.     if ( type == 0 && length == 0 ) break;
  58.     if( ! Flgs[18] )
  59.       {
  60.     switch (type)
  61.       {
  62.       case Ext_symbol: printf("Ext_symbol"); break;
  63.       case Ext_def   : printf("Ext_def   "); break;
  64.       case Ext_abs   : printf("Ext_abs   "); break;
  65.       case Ext_res   : printf("Ext_res   "); break;
  66.       case Ext_ref32 : printf("Ext_ref32 "); break;
  67.       case Ext_common: printf("Ext_common"); break;
  68.       case Ext_ref16 : printf("Ext_ref16 "); break;
  69.       case Ext_ref8  : printf("Ext_ref8  "); break;
  70.       case Ext_dref32: printf("Ext_dref32"); break;
  71.       case Ext_dref16: printf("Ext_dref16"); break;
  72.       case Ext_dref8 : printf("Ext_dref8 "); break;
  73.       default:
  74.       printf(" Unknown Symbol Reference %x (%d)",type,type);
  75.       type = Ext_ref32; /* try to recover! */
  76.       };
  77.     printf("(%x, %x):",type,length);
  78.     };
  79.     Data = malloc(length*4);
  80.     (void)Read(file,Data,length*4);
  81.     length = GrabLong(file);  /* get either the count or value */
  82.     switch (type)
  83.       {
  84.       case Ext_symbol:
  85.       case Ext_def   :
  86.       case Ext_abs   :
  87.       case Ext_res   :
  88.       if( ! Flgs[18] )
  89.         {
  90.         printf(" Value = %08.08X(%d)",length,length);
  91.         printf(" %s\n",Data);
  92.         }
  93.       break;
  94.       case Ext_common:
  95.       if( ! Flgs[18] )printf(" Size of Common = %d 32 bit words",length);
  96.       length = GrabLong(file);  /* get number of references */
  97.       case Ext_ref16 :
  98.       case Ext_ref32 :
  99.       case Ext_ref8  :
  100.       case Ext_dref32:
  101.       case Ext_dref16:
  102.       case Ext_dref8 :
  103.       if( ! Flgs[18] )
  104.         {
  105.         printf(" %s",Data);
  106.         printf("(%d references)\n",length);
  107.         (void)Dump_Raw(file,Hunk_Data,length);
  108.         }
  109.       else
  110.         {
  111.         t0 = Flgs[3];
  112.         Flgs[3] = TRUE;
  113.         (void)Dump_Raw(file,Hunk_Data,length);
  114.         Flgs[3] = t0;
  115.         };
  116.       free(Data);
  117.       };
  118.     };
  119.   }
  120.