home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / macutils.lzh / MACUTILS / HEXBIN / dl.c < prev    next >
C/C++ Source or Header  |  1996-02-01  |  3KB  |  135 lines

  1. #include "hexbin.h"
  2. #ifdef DL
  3. #include "globals.h"
  4. #include "crc.h"
  5. #include "readline.h"
  6. #include "../fileio/machdr.h"
  7. #include "../fileio/wrfile.h"
  8. #include "../util/util.h"
  9. #include "buffer.h"
  10. #include "printhdr.h"
  11.  
  12. extern void exit();
  13.  
  14. static long dl_fork();
  15. static int nchar();
  16. static int nextc();
  17.  
  18. static char *icp = &line[0];
  19.  
  20. /* oldest format -- process .dl files */
  21. void dl(macname, filename)
  22. char *macname, *filename;
  23. {
  24.     int n;
  25.  
  26.     if(listmode) {
  27.     (void)fprintf(stderr, "This file is in \"dl\" format.\n");
  28.     }
  29.     for(n = 0; n < INFOBYTES; n++) {
  30.     info[n] = 0;
  31.     }
  32.     /* set up for Mac name */
  33.     if(macname[0] == '\0') {
  34.     /* strip directories */
  35.     macname = search_last(filename, '/');
  36.     if(macname == NULL) {
  37.         macname = filename;
  38.     } else {
  39.         macname++;
  40.     }
  41.     /* strip extension */
  42.     n = strlen(macname);
  43.     if(n > 3) {
  44.         n -= 3;
  45.         if(!strncmp(macname + n, ".dl", 3)) {
  46.         macname[n] = '\0';
  47.         }
  48.     }
  49.     }
  50.     n = strlen(macname);
  51.     if(n > F_NAMELEN) {
  52.     n = F_NAMELEN;
  53.     }
  54.     (void)strncpy(mh.m_name, macname, n);
  55.     (void)strncpy(mh.m_type, "APPL", 4);
  56.     (void)strncpy(mh.m_author, "????", 4);
  57.     mh.m_name[n] = '\0';
  58.     transname(mh.m_name, trname, n);
  59.     define_name(trname);
  60.     print_header0(0);
  61.     print_header1(0, 0);
  62.     set_put(1);
  63.     mh.m_datalen = 0;
  64.     set_put(0);
  65.     mh.m_rsrclen = dl_fork();
  66.     info[I_NAMEOFF] = n;
  67.     (void)strncpy(info + I_NAMEOFF + 1, mh.m_name, n);
  68.     (void)strncpy(info + I_TYPEOFF, mh.m_type, 4);
  69.     (void)strncpy(info + I_AUTHOFF, mh.m_author, 4);
  70.     put4(info + I_DLENOFF, (unsigned long)mh.m_datalen);
  71.     put4(info + I_RLENOFF, (unsigned long)mh.m_rsrclen);
  72.     put4(info + I_CTIMOFF, (unsigned long)mh.m_createtime);
  73.     put4(info + I_MTIMOFF, (unsigned long)mh.m_modifytime);
  74.     print_header2(0);
  75.     end_put();
  76. }
  77.  
  78. static long dl_fork()
  79. {
  80.     register unsigned long i, v, c;
  81.     register unsigned long n, bytes;
  82.  
  83.     n = 0;
  84.     bytes = 0;
  85.     v = 0;
  86.     _crc = 0;
  87.     while((i = nchar()) != '|') {
  88.     if(i < '@' || i > 'O') {
  89.         continue;
  90.     }
  91.     v = (v << 4) | (i & 0xF);
  92.     if((++n & 1) == 0) {
  93.         put_byte((char)v);
  94.         _crc += v;
  95.         v = 0;
  96.         bytes++;
  97.     }
  98.     }
  99.     c = 0;
  100.     for(i = 0 ; i < 8 ; i++) {
  101.     c = (c << 4) | (nchar() & 0xF);
  102.     }
  103.     verify_crc(bytes + _crc, c);
  104.     return bytes;
  105. }
  106.  
  107. static int nchar()
  108. {
  109.     int i;
  110.  
  111.     if((i = nextc()) == EOF) {
  112.     (void)fprintf(stderr, "Premature EOF\n");
  113. #ifdef SCAN
  114.     do_error("hexbin: Premature EOF");
  115. #endif /* SCAN */
  116.     exit(1);
  117.     }
  118.     return i & 0177;
  119. }
  120.  
  121. static int nextc()
  122. {
  123.     while(*icp == 0) {
  124.     if(readline() == 0) {
  125.         return EOF;
  126.     }
  127.     icp = &line[0];
  128.     }
  129.     return *icp++;
  130. }
  131. #else /* DL */
  132. int dl; /* keep lint and some compilers happy */
  133. #endif /* DL */
  134.  
  135.