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

  1. #include "globals.h"
  2. #include "../fileio/machdr.h"
  3. #include "../fileio/wrfile.h"
  4. #include "../util/masks.h"
  5. #include "../util/util.h"
  6.  
  7. static int mcb_read;
  8.  
  9. static void mcb_wrfile();
  10.  
  11. void mcb(hdr, rsrcLength, dataLength, toread)
  12. char *hdr;
  13. unsigned long rsrcLength, dataLength;
  14. int toread;
  15. {
  16.     register int i;
  17.     int n;
  18.     char ftype[5], fauth[5];
  19.  
  20.     mcb_read = toread;
  21.     for(i = 0; i < INFOBYTES; i++) {
  22.     info[i] = hdr[i];
  23.     }
  24.  
  25.     n = hdr[I_NAMEOFF] & BYTEMASK;
  26.     if(n > F_NAMELEN) {
  27.     n = F_NAMELEN;
  28.     }
  29.     info[I_NAMEOFF] = n;
  30.     transname(hdr + I_NAMEOFF + 1, text, n);
  31.     if(hdr[I_LOCKOFF] & 1) {
  32.     hdr[I_FLAGOFF + 1] = PROTCT_MASK;
  33.     hdr[I_LOCKOFF] &= ~1;
  34.     }
  35.  
  36.     write_it = 1;
  37.     if(list) {
  38.     transname(hdr + I_TYPEOFF, ftype, 4);
  39.     transname(hdr + I_AUTHOFF, fauth, 4);
  40.     do_indent(indent);
  41.     (void)fprintf(stderr,
  42.         "name=\"%s\", type=%4.4s, author=%4.4s, data=%ld, rsrc=%ld",
  43.         text, ftype, fauth, (long)dataLength, (long)rsrcLength);
  44.     if(info_only) {
  45.         write_it = 0;
  46.     }
  47.     if(query) {
  48.         write_it = do_query();
  49.     } else {
  50.         (void)fputc('\n', stderr);
  51.     }
  52.     }
  53.  
  54.     if(write_it) {
  55.     define_name(text);
  56.     start_info(info, rsrcLength, dataLength);
  57.     start_data();
  58.     }
  59.     mcb_wrfile(dataLength);
  60.     if(write_it) {
  61.     start_rsrc();
  62.     }
  63.     mcb_wrfile(rsrcLength);
  64.     if(write_it) {
  65.     end_file();
  66.     }
  67. }
  68.  
  69. static void mcb_wrfile(ibytes)
  70. unsigned long ibytes;
  71. {
  72.     int n;
  73.  
  74.     if(write_it) {
  75.     if(ibytes == 0) {
  76.         return;
  77.     }
  78.     n = fread(out_buffer, 1, (int)ibytes, infp);
  79.     if(n != ibytes) {
  80.         (void)fprintf(stderr, "Premature EOF\n");
  81.         exit(1);
  82.     }
  83.     mcb_read -= n;
  84.     n = ((n + 127) / 128) * 128 - n;
  85.     if(n > mcb_read) {
  86.         n = mcb_read;
  87.     }
  88.     mcb_read -= n;
  89.     while(n-- > 0) {
  90.         if(getc(infp) == EOF) {
  91.         (void)fprintf(stderr, "Premature EOF\n");
  92.         exit(1);
  93.         }
  94.     }
  95.     } else {
  96.     n = ((ibytes + 127) / 128) * 128;
  97.     if(n > mcb_read) {
  98.         n = mcb_read;
  99.     }
  100.     mcb_read -= n;
  101.     while(n-- > 0) {
  102.         if(getc(infp) == EOF) {
  103.         (void)fprintf(stderr, "Premature EOF\n");
  104.         exit(1);
  105.         }
  106.     }
  107.     }
  108. }
  109.  
  110.