File: mactypes.h

package info (click to toggle)
mcvert 2.16-6
  • links: PTS
  • area: non-free
  • in suites: potato
  • size: 164 kB
  • ctags: 218
  • sloc: ansic: 1,699; makefile: 80
file content (276 lines) | stat: -rw-r--r-- 9,979 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
#include <stdio.h>
#include <sys/types.h>
#include <sys/dir.h>
#include <sys/stat.h>

#ifdef TIMEVAL
#  include <sys/param.h>
#  include <sys/time.h>
#else
#  include <sys/timeb.h>
#endif

typedef unsigned char byte;     /* one byte, obviously */
typedef unsigned short word;    /* must be 2 bytes */
#ifndef ULONG
	typedef unsigned long ulong; /* 4 bytes */
#endif

/* declarations to keep lint informed */
char *calloc();
#include <string.h>
void exit();
#ifndef __osf__
long time();
#endif
ulong unix2mac();
ulong mac2unix();
char *ctime();
FILE *mopen();

#define TRUE  1
#define FALSE 0
#define CR 0x0d
#define LF 0x0a

/* various files and debug options */
extern FILE *devnull;	/* constant /dev/null for bit bucket output */
extern FILE *convert;	/* convert messages */
extern FILE *verbose;	/* verbose output */
extern FILE *debug;	/* debug output */
extern int   Debug;	/* debug level */
#define DEBUG (debug != devnull)

/* Compatibility issues */

#ifdef NOBYTEORDER
#define mac2word
#define mac2long
#define word2mac
#define long2mac
#else
#include <netinet/in.h>
#define mac2word (word) ntohs
#define mac2long (ulong) ntohl
#define word2mac (word) htons
#define long2mac (ulong) htonl
#endif

#ifdef NOBZEROBCOPY
#define bzero(dst,len) (memset(dst,0,len))
#define bcopy(src,dst,len) (memcpy(dst,src,len))
#endif

#define MAXEXTENSION 5          /* max(".bin", ".text", ".data", ".rsrc") */
#define SYSNAMELEN 1024         /* reasonable UNIX working name length */
#define NAMELEN 63              /* maximum legal Mac file name length */

/* Format of a bin file:
A bin file is composed of 128 byte blocks.  The first block is the
info_header (see below).  Then comes the data fork, null padded to fill the
last block.  Then comes the resource fork, padded to fill the last block.  A
proposal to follow with the text of the Get Info box has not been implemented,
to the best of my knowledge.  Version, zero1 and zero2 are what the receiving
program looks at to determine if a MacBinary transfer is being initiated.
*/

/* info file header (128 bytes) */
typedef struct {
	/* Unfortunately, the longs don't align to word boundaries */

/* decimal offset */

/* 000 */
        byte version;           /* there is only a version 0 at this time */
/* 001 */
        byte nlen;              /* Length of filename. */
/* 002 */
        byte name[NAMELEN];     /* Filename (only 1st nlen are significant) */
/* 065 */
        byte type[4];           /* File type. */
/* 069 */
        byte auth[4];           /* File creator. */
/* 073 */
        byte flags;             /* file flags: LkIvBnSyBzByChIt */
                                /* Locked, Invisible,Bundle, System */
                                /* Bozo, Busy, Changed, Init */
/* 074 */
        byte zero1;
/* 075 */
        byte icon_vert[2];      /* Vertical icon position within window */
/* 077 */
        byte icon_horiz[2];     /* Horizontal icon postion in window */
/* 079 */
        byte window_id[2];      /* Window or folder ID. */
/* 081 */
        byte protect;           /* = 1 for protected file, 0 otherwise */
/* 082 */
        byte zero2;
/* 083 */
        byte dlen[4];           /* Data Fork length (bytes) -   most sig.  */
/* 087 */
        byte rlen[4];           /* Resource Fork length         byte first */
/* 091 */
        byte ctim[4];           /* File's creation date. */
/* 095 */
        byte mtim[4];           /* File's "last modified" date. */
/* 099 */
        byte ilen[2];           /* GetInfo message length */
/* 101 */
        byte flags2;            /* Finder flags, bits 0-7 */
/* 102 */
        byte unused[14];
/* 116 */
        byte packlen[4];        /* length of total files when unpacked */
/* 120 */
        byte headlen[2];        /* length of secondary header */
/* 122 */
        byte uploadvers;        /* Version of MacBinary II that the uploading
                                 * program is written for */
/* 123 */
        byte readvers;          /* Minimum MacBinary II version needed to read
                                 * this file */
/* 124 */
        byte crc[2];            /* CRC of the previous 124 bytes */
/* 126 */
        byte padding[2];        /* two trailing unused bytes */
/* 128 */
}      info_header;

/* The *.info file of a MacTerminal file transfer either has exactly this
structure or has the protect bit in bit 6 (near the sign bit) of byte zero1.
The code I have for macbin suggests the difference, but I'm not so sure */

/*
 * Format of a hqx file:
 * (but see also binhex-40-specs.txt for legal variations)
 * 
 * It begins with a line that begins "(This file" and the rest is 64
 * character lines (except possibly the last, and not including
 * newlines) where the first begins and the last ends with a colon.
 * The characters between colons should be only from the set in tr86,
 * below, each of which corresponds to 6 bits of data.  Once that is
 * translated to 8 bit bytes, you have the real data, except that the
 * byte 0x90 may indicate, if the following character is nonzero, that
 * the previous byte is to be repeated 1 to 255 times all together
 * (that is, the count following 0x90 contains the total run length,
 * not the marginal repeat count).  The byte 0x90 is represented by
 * 0x9000.  The information in the file is the hqx_buf (see below), a
 * CRC word, the data fork, a CRC word, the resource fork, and a CRC
 * word.  There is considerable confusion about the flags.  An
 * official looking document unclearly states that the init bit is
 * always clear, as is the following byte.  The experience of others
 * suggests, however, that this is not the case.
 */

/* NOTE:
 * Jskud 25Jun92

 * a hqx file has no date/time information, and a binary constructed
 * from a hqx file will use the current time; therefore, reconverting
 * a hqx file repeatedly will generate different bin files!

 * The "flags" byte can change when refetched, for example, whether or
 * not the init bit is set (that is, the Finder has "seen" the file);
 * this can affect the hqx file, including the run length encoding, so
 * the hqx files can look quite different, although the actual
 * difference is miniscule; also, the init bit difference will not be
 * present when the hqx file is converted to a bin file, since both the
 * locked and init bits are cleared on bin file creation.

 * Because we've experienced this "spurious" difference, and since
 * the init bit is only thought meaningful when running on the Mac,
 * and to establish symmetry between bin file creation and hqx file
 * creation, we unconditionally clear the init and locked bits when
 * creating the hqx file.

 */

#define HQXLINELEN 64
typedef struct {
/* decimal offset */
/* 000 */
        byte version;           /* there is only a version 0 at this time */
/* 001 */
        byte type[4];           /* File type. */
/* 005 */
        byte auth[4];           /* File creator. */
/* 009 */
        byte flags;             /* file flags: LkIvBnSyBzByChIt */
/* 010 */
        byte protect;           /* ?Pr??????, don't know what ? bits mean */
/* 011 */
        byte dlen[4];           /* Data Fork length (bytes) -   most sig.  */
/* 015 */
        byte rlen[4];           /* Resource Fork length         byte first */
/* 019 */
        byte bugblank;          /* to fix obscure sun 3/60 problem that always
                                 * makes sizeof(hqx_header) even */
/* 020 */
}      hqx_header;

/* hqx file header buffer (includes file name) */
typedef struct {
        byte nlen;              /* Length of filename. */
        byte name[NAMELEN];     /* Filename: only nlen actually appear */
        hqx_header all_the_rest;/* and all the rest follows immediately */
}      hqx_buf;

/* every valid hqx header is at least this long */
#define MIN_HQX_HDR (sizeof(hqx_header) + 2)

/*
 *	The minimum number of hqx_lines in a file to ensure that we have
 *	enough lines to emit the entire header before starting a new file.
 * + 1 is for rounding, + 2 is for "(This file " and the blank line.
 */
#define MIN_HQX_LINES (sizeof(hqx_buf) * 4 / 3 / HQXLINELEN + 1 + 2)


/* Format of a Packit file:
Repeat the following sequence for each file in the Packit file:
    4 byte identifier ("PMag" = not compressed, "Pma4" = compressed)
    320 byte compression data (if compressed file)
        = preorder transversal of Huffman tree
        255 0 bits corresponding to nonleaf nodes
        256 1 bits corresponding to leaf nodes
        256 bytes associating leaf nodes with bytes
        1   completely wasted bit
    92 byte header (see pit_header below) *
    2 bytes CRC word for header *
    data fork (length from header) *
    resource fork (length from header) *
    2 bytes CRC word for forks *

Last file is followed by the 4 byte Ascii string, "Pend", and then the EOF.
The CRC calculations differ from those in the binhex format.

* these are in compressed form if compression is on for the file

*/

typedef struct {                /* Packit file header (92 bytes) */
        byte nlen;              /* Length of filename. */
        byte name[NAMELEN];     /* Filename (only 1st nlen are significant) */
        byte type[4];           /* File type. */
        byte auth[4];           /* File creator. */
        byte flags;             /* file flags: LkIvBnSyBzByChIt */
        byte zero1;
        byte protect;           /* = 1 for protected file, 0 otherwise */
        byte zero2;
        byte dlen[4];           /* Data Fork length (bytes) -   most sig.  */
        byte rlen[4];           /* Resource Fork length         byte first */
        byte ctim[4];           /* File's creation date. */
        byte mtim[4];           /* File's "last modified" date. */
}      pit_header;

/* types for constructing the Huffman tree */
typedef struct branch_st {
        byte flag;
        struct branch_st *one, *zero;
}         branch;

typedef struct leaf_st {
        byte flag;
        byte data;
}       leaf;