home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 1 / crawlyvol1.bin / program / compiler / sozobon / scsrc20 / ld / rel.c < prev    next >
C/C++ Source or Header  |  1991-02-22  |  2KB  |  119 lines

  1.  
  2. /*
  3.  * Copyright (c) 1991 by Sozobon, Limited.  Author: Johann Ruegg
  4.  *
  5.  * Permission is granted to anyone to use this software for any purpose
  6.  * on any computer system, and to redistribute it freely, with the
  7.  * following restrictions:
  8.  * 1) No charge may be made other than reasonable charges for reproduction.
  9.  * 2) Modified versions must be clearly marked as such.
  10.  * 3) The authors are not responsible for any harmful consequences
  11.  *    of using this software, even if they result from defects in it.
  12.  */
  13.  
  14. #ifndef UNIXHOST
  15. #define SWAPW(a,b)
  16. #define SWAPL(a,b)
  17. #else
  18. #define SWAPW(a,b)    swapw(a,b)
  19. #define SWAPL(a,b)    swapl(a,b)
  20. #endif
  21.  
  22. extern int ofd;
  23. extern int orelb;
  24.  
  25. long reloffs;
  26. int relbeg;
  27. long relsz = 0;
  28.  
  29. relstart()
  30. {
  31.     reloffs = 0;
  32.     relbeg = 1;
  33. }
  34.  
  35. relout(n, relp)
  36. register short *relp;
  37. {
  38.     short x;
  39.     register int i, cnt;
  40.     long lasti;
  41.  
  42.     lasti = -reloffs;
  43.     cnt = n / sizeof(short);
  44.     for (i=0; i<cnt; i++) {
  45.  
  46.         x = *relp++;
  47.  
  48.         switch (x) {
  49.         case 7:
  50.         case 0:
  51.             break;
  52.         case 5:
  53.             x = *relp;
  54.             switch (x) {
  55.             case 0:
  56.                 goto skip;
  57.             case 1:
  58.             case 2:
  59.             case 3:
  60.                 seerel(i-lasti);
  61.                 lasti = i;
  62.                 break;
  63.             default:
  64.                 fatal("Bad reloc");
  65.             }
  66. skip:
  67.             relp++;
  68.             i++;
  69.             break;
  70.         default:
  71.             fatal("bad reloc");
  72.         }
  73.     }
  74.     reloffs = i-lasti;
  75. }
  76.  
  77. seerel(n)
  78. long n;
  79. {
  80.     union {
  81.         long ls;
  82.         char bs[4];
  83.     } lb;
  84.     char c;
  85.     int i;
  86.  
  87.     if (relbeg) {
  88.         relbeg = 0;
  89.         lb.ls = 2*n;
  90.         SWAPL(&lb.ls, 1);
  91.         for (i=0; i<4; i++)
  92.             rputc(lb.bs[i]);
  93.         return;
  94.     }
  95.  
  96.     n *= 2;
  97.     while (n > 254) {
  98.         rputc(1);
  99.         n -= 254;
  100.     }
  101.     c = n;
  102.     rputc(c);
  103. }
  104.  
  105. relend()
  106. {
  107.     rputc(0);
  108.  
  109.     t_rewind(orelb);
  110.     bfcopy(orelb, ofd, relsz);
  111. }
  112.  
  113. rputc(c)
  114. char c;
  115. {
  116.     t_write(orelb, &c, 1);
  117.     relsz++;
  118. }
  119.