home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / program / compiler / nasm20b / nasm_src / libfix.c < prev    next >
C/C++ Source or Header  |  1993-01-19  |  3KB  |  114 lines

  1. #include <stdio.h>
  2. #include "defines.h"
  3. #include "nasm.h"
  4. #include OSBIND
  5. #include "debug.h"
  6. #include NMALLOC_H
  7. #include "labels.h"
  8. #include "object.h"
  9. #include "code.h"
  10. #include "lib.h"
  11.  
  12. #if VERSION == 2 || VERSION == 0
  13. # define V1_SIGNIFICANT 8
  14. # define V1_SIGNDIFF    (SIGNIFICANT - V1_SIGNIFICANT)
  15. # define V1_L_DIFF      V1_SIGNDIFF
  16. # define V1_GSIZE       (sizeof( g_table) - V1_L_DIFF)
  17.  
  18. typedef struct
  19. {
  20.    char     name[ FSIGNIFICANT];  /* 32 Should be plenty for non-paths */
  21.    lword    seek;
  22.    word     bytes;
  23.    word     time,
  24.             date;
  25. } old_f_table;
  26.  
  27. #define V1_F_DIFF ( sizeof( f_table) - sizeof( old_f_table))
  28. #define V1_FSIZE  ( sizeof( old_f_table))
  29. #endif
  30.  
  31.  
  32. static char sorry[] = "Sorry, but that's a library version I can't handle";
  33.  
  34. void fix_lsizes( version, gsize, fsize)
  35. lword    *gsize, *fsize;
  36. {
  37.    switch( version)
  38.    {
  39. #if VERSION == 2 || VERSION == 0
  40.       case 1 :
  41.          *gsize = *gsize / V1_GSIZE * sizeof( g_table);
  42.          *fsize = *fsize / V1_FSIZE * sizeof( f_table);
  43.          break;
  44. #endif
  45.       default :
  46.          nferror( sorry);
  47.    }
  48. }
  49.  
  50.  
  51. void fix_lversion( version, gbytes, globals, fbytes, files)
  52. lword          *gbytes, *fbytes;
  53. g_table huge   *globals;
  54. f_table huge   *files;
  55. {
  56.    switch( version)
  57.    {
  58. #if VERSION == 2 || VERSION == 0
  59.       case 1 :
  60.       {
  61.          register char huge   *p;
  62.          g_table huge         *q;
  63.          register word        i, j;
  64.          register char huge   *dst;
  65.  
  66.          i = *gbytes /= V1_GSIZE;            /* calc # symbols */
  67.          q = &globals[ i];                   /* move to end of */
  68.          p = (char huge *) q - i * V1_L_DIFF; 
  69.  
  70.          while( p -= sizeof( word), --q, i--)
  71.          {
  72.             q->index = *(word *) p;
  73.             for( dst = &q->name[ j = SIGNIFICANT]; j-- > V1_SIGNIFICANT;)
  74.                *--dst = 0; 
  75.             do
  76.                *--dst = *--p;
  77.             while( j--);
  78.          }
  79.          *gbytes *= sizeof( g_table);
  80.       }
  81.  
  82.       {
  83.          old_f_table huge     *p;
  84.          f_table huge         *q;
  85.          register word        i, j;
  86.          register char huge   *src, *dst;
  87.  
  88.          i = *fbytes /= sizeof( old_f_table);   /* calc # symbols */
  89.          q = &files[ i];                        /* move to end of */
  90.          p = (old_f_table huge *) ((char huge *) q - i * V1_F_DIFF); 
  91.  
  92.          while( --p, --q, i--)
  93.          {
  94.             q->date  = p->date;
  95.             q->time  = p->time;
  96.             q->bytes = p->bytes;
  97.             q->seek  = p->seek;
  98.             dst = &q->name[ FSIGNIFICANT];
  99.             src = &p->name[ FSIGNIFICANT];
  100.             for( j = FSIGNIFICANT; j--; *--dst = *--src);
  101.          }
  102.          *fbytes *= sizeof( f_table);
  103.       }
  104. #endif   
  105.       default :
  106.          nferror( sorry);
  107.  
  108.    }
  109. }
  110.  
  111. /* #1# the V1_SIZE + sizeof( word) is added, so that in the loop we need 
  112.        not sub with sizeof( word)!! 
  113.  */       
  114.