home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Amiga / Workbench / Archivers / mcvertWOS.lha / mcvertppc / mactypes.h < prev    next >
C/C++ Source or Header  |  1998-04-12  |  10KB  |  277 lines

  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <sys/dir.h>
  4. #include <sys/stat.h>
  5.  
  6. #ifdef TIMEVAL
  7. #  include <sys/param.h>
  8. #  include <sys/time.h>
  9. #else
  10. #  include <sys/timeb.h>
  11. #endif
  12.  
  13. typedef unsigned char byte;     /* one byte, obviously */
  14. typedef unsigned short word;    /* must be 2 bytes */
  15. #ifndef ULONG
  16.         typedef unsigned long ulong; /* 4 bytes */
  17. #endif
  18.  
  19. /* declarations to keep lint informed */
  20. char *calloc();
  21. #include <string.h>
  22. void exit();
  23. #ifndef __osf__
  24. long time();
  25. #endif
  26. ulong unix2mac();
  27. ulong mac2unix();
  28. char *ctime();
  29. FILE *mopen();
  30.  
  31. #define TRUE  1
  32. #define FALSE 0
  33. #define CR 0x0d
  34. #define LF 0x0a
  35.  
  36. /* various files and debug options */
  37. extern FILE *devnull;   /* constant /dev/null for bit bucket output */
  38. extern FILE *convert;   /* convert messages */
  39. extern FILE *verbose;   /* verbose output */
  40. extern FILE *Mydebug;     /* debug output */
  41. extern int   MyDebug;     /* debug level */
  42. #define DEBUG (debug != devnull)
  43.  
  44. /* Compatibility issues */
  45.  
  46. #ifdef NOBYTEORDER
  47. #define mac2word
  48. #define mac2long
  49. #define word2mac
  50. #define long2mac
  51. #else
  52. #include <netinet/in.h>
  53. #define mac2word (word) ntohs
  54. #define mac2long (ulong) ntohl
  55. #define word2mac (word) htons
  56. #define long2mac (ulong) htonl
  57. #endif
  58.  
  59. #ifdef NOBZEROBCOPY
  60. #define bzero(dst,len) (memset(dst,0,len))
  61. #define bcopy(src,dst,len) (memcpy(dst,src,len))
  62. #endif
  63.  
  64. #define MAXEXTENSION 5          /* max(".bin", ".text", ".data", ".rsrc") */
  65. #define SYSNAMELEN 1024         /* reasonable UNIX working name length */
  66. #define NAMELEN 63              /* maximum legal Mac file name length */
  67.  
  68. /* Format of a bin file:
  69. A bin file is composed of 128 byte blocks.  The first block is the
  70. info_header (see below).  Then comes the data fork, null padded to fill the
  71. last block.  Then comes the resource fork, padded to fill the last block.  A
  72. proposal to follow with the text of the Get Info box has not been implemented,
  73. to the best of my knowledge.  Version, zero1 and zero2 are what the receiving
  74. program looks at to determine if a MacBinary transfer is being initiated.
  75. */
  76.  
  77. /* info file header (128 bytes) */
  78. typedef struct {
  79.         /* Unfortunately, the longs don't align to word boundaries */
  80.  
  81. /* decimal offset */
  82.  
  83. /* 000 */
  84.         byte version;           /* there is only a version 0 at this time */
  85. /* 001 */
  86.         byte nlen;              /* Length of filename. */
  87. /* 002 */
  88.         byte name[NAMELEN];     /* Filename (only 1st nlen are significant) */
  89. /* 065 */
  90.         byte type[4];           /* File type. */
  91. /* 069 */
  92.         byte auth[4];           /* File creator. */
  93. /* 073 */
  94.         byte flags;             /* file flags: LkIvBnSyBzByChIt */
  95.                                 /* Locked, Invisible,Bundle, System */
  96.                                 /* Bozo, Busy, Changed, Init */
  97. /* 074 */
  98.         byte zero1;
  99. /* 075 */
  100.         byte icon_vert[2];      /* Vertical icon position within window */
  101. /* 077 */
  102.         byte icon_horiz[2];     /* Horizontal icon postion in window */
  103. /* 079 */
  104.         byte window_id[2];      /* Window or folder ID. */
  105. /* 081 */
  106.         byte protect;           /* = 1 for protected file, 0 otherwise */
  107. /* 082 */
  108.         byte zero2;
  109. /* 083 */
  110.         byte dlen[4];           /* Data Fork length (bytes) -   most sig.  */
  111. /* 087 */
  112.         byte rlen[4];           /* Resource Fork length         byte first */
  113. /* 091 */
  114.         byte ctim[4];           /* File's creation date. */
  115. /* 095 */
  116.         byte mtim[4];           /* File's "last modified" date. */
  117. /* 099 */
  118.         byte ilen[2];           /* GetInfo message length */
  119. /* 101 */
  120.         byte flags2;            /* Finder flags, bits 0-7 */
  121. /* 102 */
  122.         byte unused[14];
  123. /* 116 */
  124.         byte packlen[4];        /* length of total files when unpacked */
  125. /* 120 */
  126.         byte headlen[2];        /* length of secondary header */
  127. /* 122 */
  128.         byte uploadvers;        /* Version of MacBinary II that the uploading
  129.                                  * program is written for */
  130. /* 123 */
  131.         byte readvers;          /* Minimum MacBinary II version needed to read
  132.                                  * this file */
  133. /* 124 */
  134.         byte crc[2];            /* CRC of the previous 124 bytes */
  135. /* 126 */
  136.         byte padding[2];        /* two trailing unused bytes */
  137. /* 128 */
  138. }      info_header;
  139.  
  140. /* The *.info file of a MacTerminal file transfer either has exactly this
  141. structure or has the protect bit in bit 6 (near the sign bit) of byte zero1.
  142. The code I have for macbin suggests the difference, but I'm not so sure */
  143.  
  144. /*
  145.  * Format of a hqx file:
  146.  * (but see also binhex-40-specs.txt for legal variations)
  147.  * 
  148.  * It begins with a line that begins "(This file" and the rest is 64
  149.  * character lines (except possibly the last, and not including
  150.  * newlines) where the first begins and the last ends with a colon.
  151.  * The characters between colons should be only from the set in tr86,
  152.  * below, each of which corresponds to 6 bits of data.  Once that is
  153.  * translated to 8 bit bytes, you have the real data, except that the
  154.  * byte 0x90 may indicate, if the following character is nonzero, that
  155.  * the previous byte is to be repeated 1 to 255 times all together
  156.  * (that is, the count following 0x90 contains the total run length,
  157.  * not the marginal repeat count).  The byte 0x90 is represented by
  158.  * 0x9000.  The information in the file is the hqx_buf (see below), a
  159.  * CRC word, the data fork, a CRC word, the resource fork, and a CRC
  160.  * word.  There is considerable confusion about the flags.  An
  161.  * official looking document unclearly states that the init bit is
  162.  * always clear, as is the following byte.  The experience of others
  163.  * suggests, however, that this is not the case.
  164.  */
  165.  
  166. /* NOTE:
  167.  * Jskud 25Jun92
  168.  
  169.  * a hqx file has no date/time information, and a binary constructed
  170.  * from a hqx file will use the current time; therefore, reconverting
  171.  * a hqx file repeatedly will generate different bin files!
  172.  
  173.  * The "flags" byte can change when refetched, for example, whether or
  174.  * not the init bit is set (that is, the Finder has "seen" the file);
  175.  * this can affect the hqx file, including the run length encoding, so
  176.  * the hqx files can look quite different, although the actual
  177.  * difference is miniscule; also, the init bit difference will not be
  178.  * present when the hqx file is converted to a bin file, since both the
  179.  * locked and init bits are cleared on bin file creation.
  180.  
  181.  * Because we've experienced this "spurious" difference, and since
  182.  * the init bit is only thought meaningful when running on the Mac,
  183.  * and to establish symmetry between bin file creation and hqx file
  184.  * creation, we unconditionally clear the init and locked bits when
  185.  * creating the hqx file.
  186.  
  187.  */
  188.  
  189. #define HQXLINELEN 64
  190. typedef struct {
  191. /* decimal offset */
  192. /* 000 */
  193.         byte version;           /* there is only a version 0 at this time */
  194. /* 001 */
  195.         byte type[4];           /* File type. */
  196. /* 005 */
  197.         byte auth[4];           /* File creator. */
  198. /* 009 */
  199.         byte flags;             /* file flags: LkIvBnSyBzByChIt */
  200. /* 010 */
  201.         byte protect;           /* ?Pr??????, don't know what ? bits mean */
  202. /* 011 */
  203.         byte dlen[4];           /* Data Fork length (bytes) -   most sig.  */
  204. /* 015 */
  205.         byte rlen[4];           /* Resource Fork length         byte first */
  206. /* 019 */
  207.         byte bugblank;          /* to fix obscure sun 3/60 problem that always
  208.                                  * makes sizeof(hqx_header) even */
  209. /* 020 */
  210. }      hqx_header;
  211.  
  212. /* hqx file header buffer (includes file name) */
  213. typedef struct {
  214.         byte nlen;              /* Length of filename. */
  215.         byte name[NAMELEN];     /* Filename: only nlen actually appear */
  216.         hqx_header all_the_rest;/* and all the rest follows immediately */
  217. }      hqx_buf;
  218.  
  219. /* every valid hqx header is at least this long */
  220. #define MIN_HQX_HDR (sizeof(hqx_header) + 2)
  221.  
  222. /*
  223.  *      The minimum number of hqx_lines in a file to ensure that we have
  224.  *      enough lines to emit the entire header before starting a new file.
  225.  * + 1 is for rounding, + 2 is for "(This file " and the blank line.
  226.  */
  227. #define MIN_HQX_LINES (sizeof(hqx_buf) * 4 / 3 / HQXLINELEN + 1 + 2)
  228.  
  229.  
  230. /* Format of a Packit file:
  231. Repeat the following sequence for each file in the Packit file:
  232.     4 byte identifier ("PMag" = not compressed, "Pma4" = compressed)
  233.     320 byte compression data (if compressed file)
  234.         = preorder transversal of Huffman tree
  235.         255 0 bits corresponding to nonleaf nodes
  236.         256 1 bits corresponding to leaf nodes
  237.         256 bytes associating leaf nodes with bytes
  238.         1   completely wasted bit
  239.     92 byte header (see pit_header below) *
  240.     2 bytes CRC word for header *
  241.     data fork (length from header) *
  242.     resource fork (length from header) *
  243.     2 bytes CRC word for forks *
  244.  
  245. Last file is followed by the 4 byte Ascii string, "Pend", and then the EOF.
  246. The CRC calculations differ from those in the binhex format.
  247.  
  248. * these are in compressed form if compression is on for the file
  249.  
  250. */
  251.  
  252. typedef struct {                /* Packit file header (92 bytes) */
  253.         byte nlen;              /* Length of filename. */
  254.         byte name[NAMELEN];     /* Filename (only 1st nlen are significant) */
  255.         byte type[4];           /* File type. */
  256.         byte auth[4];           /* File creator. */
  257.         byte flags;             /* file flags: LkIvBnSyBzByChIt */
  258.         byte zero1;
  259.         byte protect;           /* = 1 for protected file, 0 otherwise */
  260.         byte zero2;
  261.         byte dlen[4];           /* Data Fork length (bytes) -   most sig.  */
  262.         byte rlen[4];           /* Resource Fork length         byte first */
  263.         byte ctim[4];           /* File's creation date. */
  264.         byte mtim[4];           /* File's "last modified" date. */
  265. }      pit_header;
  266.  
  267. /* types for constructing the Huffman tree */
  268. typedef struct branch_st {
  269.         byte flag;
  270.         struct branch_st *one, *zero;
  271. }         branch;
  272.  
  273. typedef struct leaf_st {
  274.         byte flag;
  275.         byte data;
  276. }       leaf;
  277.