home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / APPS / macutils.lzh / MACUTILS / MCVERT / mactypes.h < prev    next >
C/C++ Source or Header  |  1996-02-02  |  8KB  |  168 lines

  1. #include <stdio.h>
  2. #ifndef OSK
  3. #include <sys/types.h>
  4. #include <sys/dir.h>
  5. #include <sys/stat.h>
  6. #include <sys/timeb.h>
  7. #else
  8. #include "/dd/blarsdefs/sys/stat.h"
  9. #include <dir.h>
  10. #include "/dd/blarsdefs/sys/timeb.h"
  11. #endif
  12.  
  13. /* Useful, though not particularly Mac related, values */
  14. typedef unsigned char byte;     /* one byte, obviously */
  15. typedef unsigned short word;    /* must be 2 bytes */
  16. typedef unsigned long ulong;    /* 4 bytes */
  17. #define TRUE  1
  18. #define FALSE 0
  19. #define CR 0x0d
  20. #define LF 0x0a
  21.  
  22. /* Compatibility issues */
  23. #ifdef BSD
  24. #define mac2word (word) ntohs
  25. #define mac2long (ulong) ntohl
  26. #define word2mac (word) htons
  27. #define long2mac (ulong) htonl
  28. #else
  29. #define mac2word
  30. #define mac2long
  31. #define word2mac
  32. #define long2mac
  33. #endif
  34.  
  35. #ifdef MAXNAMLEN/* 4.2 BSD, stdio.h */
  36. #define SYSNAMELEN MAXNAMLEN
  37. #else
  38. #define SYSNAMELEN DIRSIZ
  39. #endif
  40.  
  41. #define NAMELEN 63              /* maximum legal Mac file name length */
  42. #define BINNAMELEN 68           /* NAMELEN + len(".bin\0") */
  43.  
  44. /* Format of a bin file:
  45. A bin file is composed of 128 byte blocks.  The first block is the
  46. info_header (see below).  Then comes the data fork, null padded to fill the
  47. last block.  Then comes the resource fork, padded to fill the last block.  A
  48. proposal to follow with the text of the Get Info box has not been implemented,
  49. to the best of my knowledge.  Version, zero1 and zero2 are what the receiving
  50. program looks at to determine if a MacBinary transfer is being initiated.
  51. */ 
  52. typedef struct {     /* info file header (128 bytes). Unfortunately, these
  53.                         longs don't align to word boundaries */
  54.             byte version;           /* there is only a version 0 at this time */
  55.             byte nlen;              /* Length of filename. */
  56.             byte name[NAMELEN];     /* Filename (only 1st nlen are significant)*/
  57.             byte type[4];           /* File type. */
  58.             byte auth[4];           /* File creator. */
  59.             byte flags;             /* file flags: LkIvBnSyBzByChIt */
  60.             byte zero1;             /* Locked, Invisible,Bundle, System */
  61.                                     /* Bozo, Busy, Changed, Init */
  62.             byte icon_vert[2];      /* Vertical icon position within window */
  63.             byte icon_horiz[2];     /* Horizontal icon postion in window */
  64.             byte window_id[2];      /* Window or folder ID. */
  65.             byte protect;           /* = 1 for protected file, 0 otherwise */
  66.             byte zero2;
  67.             byte dlen[4];           /* Data Fork length (bytes) -   most sig.  */
  68.             byte rlen[4];           /* Resource Fork length         byte first */
  69.             byte ctim[4];           /* File's creation date. */
  70.             byte mtim[4];           /* File's "last modified" date. */
  71.             byte ilen[2];           /* GetInfo message length */
  72.         byte flags2;            /* Finder flags, bits 0-7 */
  73.         byte unused[14];       
  74.         byte packlen[4];        /* length of total files when unpacked */
  75.         byte headlen[2];        /* length of secondary header */
  76.         byte uploadvers;        /* Version of MacBinary II that the uploading program is written for */
  77.         byte readvers;          /* Minimum MacBinary II version needed to read this file */
  78.             byte crc[2];            /* CRC of the previous 124 bytes */
  79.         byte padding[2];        /* two trailing unused bytes */
  80.             } info_header;
  81.  
  82. /* The *.info file of a MacTerminal file transfer either has exactly this
  83. structure or has the protect bit in bit 6 (near the sign bit) of byte zero1.
  84. The code I have for macbin suggests the difference, but I'm not so sure */
  85.  
  86. /* Format of a hqx file:
  87. It begins with a line that begins "(This file
  88. and the rest is 64 character lines (except possibly the last, and not
  89. including newlines) where the first begins and the last ends with a colon.
  90. The characters between colons should be only from the set in tr86, below,
  91. each of which corresponds to 6 bits of data.  Once that is translated to
  92. 8 bit bytes, you have the real data, except that the byte 0x90 may 
  93. indicate, if the following character is nonzero, that the previous
  94. byte is to be repeated 1 to 255 times.  The byte 0x90 is represented by
  95. 0x9000.  The information in the file is the hqx_buf (see below),
  96. a CRC word, the data fork, a CRC word, the resource fork, and a CRC word.
  97. There is considerable confusion about the flags.  An official looking document
  98. unclearly states that the init bit is always clear, as is the following byte.
  99. The experience of others suggests, however, that this is not the case.
  100. */
  101.  
  102. #define HQXLINELEN 64
  103. typedef struct {
  104.             byte version;           /* there is only a version 0 at this time */
  105.             byte type[4];           /* File type. */
  106.             byte auth[4];           /* File creator. */
  107.             byte flags;             /* file flags: LkIvBnSyBzByChIt */
  108.             byte protect;           /* ?Pr??????, don't know what ? bits mean */
  109.             byte dlen[4];           /* Data Fork length (bytes) -   most sig.  */
  110.             byte rlen[4];           /* Resource Fork length         byte first */
  111.             byte bugblank;             /* to fix obscure sun 3/60 problem
  112.                                           that always makes sizeof(hqx_header
  113.                                           even */
  114.             } hqx_header;
  115. typedef struct {     /* hqx file header buffer (includes file name) */
  116.             byte nlen;              /* Length of filename. */
  117.             byte name[NAMELEN];     /* Filename: only nlen actually appear */
  118.             hqx_header all_the_rest;/* and all the rest follows immediately */
  119.             } hqx_buf;
  120.  
  121. /* Format of a Packit file:
  122. Repeat the following sequence for each file in the Packit file:
  123.     4 byte identifier ("PMag" = not compressed, "Pma4" = compressed)
  124.     320 byte compression data (if compressed file)
  125.         = preorder transversal of Huffman tree
  126.         255 0 bits corresponding to nonleaf nodes
  127.         256 1 bits corresponding to leaf nodes
  128.         256 bytes associating leaf nodes with bytes
  129.         1   completely wasted bit
  130.     92 byte header (see pit_header below) *
  131.     2 bytes CRC word for header *
  132.     data fork (length from header) *
  133.     resource fork (length from header) *
  134.     2 bytes CRC word for forks *
  135.  
  136. Last file is followed by the 4 byte Ascii string, "Pend", and then the EOF.
  137. The CRC calculations differ from those in the binhex format.
  138.  
  139. * these are in compressed form if compression is on for the file
  140.  
  141. */
  142.  
  143. typedef struct {     /* Packit file header (92 bytes) */
  144.             byte nlen;              /* Length of filename. */
  145.             byte name[NAMELEN];     /* Filename (only 1st nlen are significant)*/
  146.             byte type[4];           /* File type. */
  147.             byte auth[4];           /* File creator. */
  148.             byte flags;             /* file flags: LkIvBnSyBzByChIt */
  149.             byte zero1;
  150.             byte protect;           /* = 1 for protected file, 0 otherwise */
  151.             byte zero2;
  152.             byte dlen[4];           /* Data Fork length (bytes) -   most sig.  */
  153.             byte rlen[4];           /* Resource Fork length         byte first */
  154.             byte ctim[4];           /* File's creation date. */
  155.             byte mtim[4];           /* File's "last modified" date. */
  156.             } pit_header;
  157.  
  158. /* types for constructing the Huffman tree */
  159. typedef struct branch_st {
  160.             byte flag;
  161.             struct branch_st *one, *zero;
  162.             } branch;
  163.  
  164. typedef struct leaf_st {
  165.             byte flag;
  166.             byte data;
  167.             } leaf;
  168.