OSDN Git Service

Avoid compile error on libapplefile
[lha/lha.git] / src / lha_macro.h
1 /* ------------------------------------------------------------------------ */
2 /* LHa for UNIX    Archiver Driver  macro define                            */
3 /*                                                                          */
4 /*      Modified                Nobutaka Watazaki                           */
5 /*                                                                          */
6 /*  Ver. 1.14   Soruce All chagned              1995.01.14  N.Watazaki      */
7 /*  Ver. 1.14g  modified                        2000.05.06  T.OKAMOTO       */
8 /* ------------------------------------------------------------------------ */
9
10 #define FALSE           0
11 #define TRUE            1
12
13 #define FILENAME_LENGTH 1024
14
15 #if defined __MINGW32__
16 # define getuid()       0
17 # define chown(file, uid, gid)  0
18 # define kill(pid, sig)         0
19 #endif
20
21 #if defined __DJGPP__
22 # define S_ISLNK(m)     0
23 #endif
24
25 /* ------------------------------------------------------------------------ */
26 /* YOUR CUSTOMIZIES                                                         */
27 /* ------------------------------------------------------------------------ */
28
29 #ifndef ARCHIVENAME_EXTENTION
30 #define ARCHIVENAME_EXTENTION   ".lzh"
31 #endif
32 #ifndef BACKUPNAME_EXTENTION
33 #define BACKUPNAME_EXTENTION    ".bak"
34 #endif
35
36 #define SJIS_FIRST_P(c)         \
37   (((unsigned char)(c) >= 0x80 && (unsigned char)(c) < 0xa0) || \
38    ((unsigned char)(c) >= 0xe0 && (unsigned char)(c) < 0xfd))
39 #define SJIS_SECOND_P(c)            \
40   (((unsigned char)(c) >= 0x40 && (unsigned char)(c) < 0xfd) && \
41     (unsigned char)(c) != 0x7f)
42
43 #define X0201_KANA_P(c)\
44     (0xa0 < (unsigned char)(c) && (unsigned char)(c) < 0xe0)
45
46 /* for filename conversion */
47 #define NONE 0
48 #define CODE_EUC 1
49 #define CODE_SJIS 2
50 #define CODE_UTF8 3
51 #define CODE_CAP 4              /* Columbia AppleTalk Program */
52 #define TO_LOWER 1
53 #define TO_UPPER 2
54
55 /* ------------------------------------------------------------------------ */
56 /*  LHa File Definitions                                                    */
57 /* ------------------------------------------------------------------------ */
58 #ifdef S_IFLNK
59 #define GETSTAT lstat
60 #else
61 #define GETSTAT stat
62 #endif
63
64 #define LZHUFF0_METHOD          "-lh0-"
65 #define LZHUFF1_METHOD          "-lh1-"
66 #define LZHUFF2_METHOD          "-lh2-"
67 #define LZHUFF3_METHOD          "-lh3-"
68 #define LZHUFF4_METHOD          "-lh4-"
69 #define LZHUFF5_METHOD          "-lh5-"
70 #define LZHUFF6_METHOD          "-lh6-"
71 #define LZHUFF7_METHOD          "-lh7-"
72 #define LARC_METHOD             "-lzs-"
73 #define LARC5_METHOD            "-lz5-"
74 #define LARC4_METHOD            "-lz4-"
75 #define LZHDIRS_METHOD          "-lhd-"
76 #define PMARC0_METHOD           "-pm0-"
77 #define PMARC2_METHOD           "-pm2-"
78
79 #define METHOD_TYPE_STORAGE     5
80
81 /* Added N.Watazaki ..V */
82 #define LZHUFF0_METHOD_NUM      0
83 #define LZHUFF1_METHOD_NUM      1
84 #define LZHUFF2_METHOD_NUM      2
85 #define LZHUFF3_METHOD_NUM      3
86 #define LZHUFF4_METHOD_NUM      4
87 #define LZHUFF5_METHOD_NUM      5
88 #define LZHUFF6_METHOD_NUM      6
89 #define LZHUFF7_METHOD_NUM      7
90 #define LARC_METHOD_NUM         8
91 #define LARC5_METHOD_NUM        9
92 #define LARC4_METHOD_NUM        10
93 #define LZHDIRS_METHOD_NUM      11
94 #define PMARC0_METHOD_NUM       12
95 #define PMARC2_METHOD_NUM       13
96 /* Added N.Watazaki ..^ */
97
98 #define LZHUFF0_DICBIT           0      /* no compress */
99 #define LZHUFF1_DICBIT          12      /* 2^12 =  4KB sliding dictionary */
100 #define LZHUFF2_DICBIT          13      /* 2^13 =  8KB sliding dictionary */
101 #define LZHUFF3_DICBIT          13      /* 2^13 =  8KB sliding dictionary */
102 #define LZHUFF4_DICBIT          12      /* 2^12 =  4KB sliding dictionary */
103 #define LZHUFF5_DICBIT          13      /* 2^13 =  8KB sliding dictionary */
104 #define LZHUFF6_DICBIT          15      /* 2^15 = 32KB sliding dictionary */
105 #define LZHUFF7_DICBIT          16      /* 2^16 = 64KB sliding dictionary */
106 #define LARC_DICBIT             11      /* 2^11 =  2KB sliding dictionary */
107 #define LARC5_DICBIT            12      /* 2^12 =  4KB sliding dictionary */
108 #define LARC4_DICBIT             0      /* no compress */
109 #define PMARC0_DICBIT            0      /* no compress */
110 #define PMARC2_DICBIT           13      /* 2^13 =  8KB sliding dictionary */
111
112 #ifdef SUPPORT_LH7
113 #define MAX_DICBIT          LZHUFF7_DICBIT      /* lh7 use 16bits */
114 #endif
115 #ifndef SUPPORT_LH7
116 #define MAX_DICBIT          LZHUFF6_DICBIT      /* lh6 use 15bits */
117 #endif
118
119 #define MAX_DICSIZ          (1L << MAX_DICBIT)
120
121 #define EXTEND_GENERIC          0
122 #define EXTEND_UNIX             'U'
123 #define EXTEND_MSDOS            'M'
124 #define EXTEND_MACOS            'm'
125 #define EXTEND_OS9              '9'
126 #define EXTEND_OS2              '2'
127 #define EXTEND_OS68K            'K'
128 #define EXTEND_OS386            '3' /* OS-9000??? */
129 #define EXTEND_HUMAN            'H'
130 #define EXTEND_CPM              'C'
131 #define EXTEND_FLEX             'F'
132 #define EXTEND_RUNSER           'R'
133
134 /* this OS type is not official */
135
136 #define EXTEND_TOWNSOS          'T'
137 #define EXTEND_XOSK             'X' /* OS-9 for X68000 (?) */
138 #define EXTEND_JAVA             'J'
139
140 /*---------------------------------------------------------------------------*/
141
142 #define GENERIC_ATTRIBUTE               0x20
143 #define GENERIC_DIRECTORY_ATTRIBUTE     0x10
144
145 #define CURRENT_UNIX_MINOR_VERSION      0x00
146
147 #define LHA_PATHSEP             0xff    /* path separator of the
148                                            filename in lha header.
149                                            it should compare with
150                                            `unsigned char' or `int',
151                                            that is not '\xff', but 0xff. */
152
153 #define OSK_RW_RW_RW            0000033
154 #define OSK_FILE_REGULAR        0000000
155 #define OSK_DIRECTORY_PERM      0000200
156 #define OSK_SHARED_PERM         0000100
157 #define OSK_OTHER_EXEC_PERM     0000040
158 #define OSK_OTHER_WRITE_PERM    0000020
159 #define OSK_OTHER_READ_PERM     0000010
160 #define OSK_OWNER_EXEC_PERM     0000004
161 #define OSK_OWNER_WRITE_PERM    0000002
162 #define OSK_OWNER_READ_PERM     0000001
163
164 #define UNIX_FILE_TYPEMASK      0170000
165 #define UNIX_FILE_REGULAR       0100000
166 #define UNIX_FILE_DIRECTORY     0040000
167 #define UNIX_FILE_SYMLINK       0120000
168 #define UNIX_SETUID             0004000
169 #define UNIX_SETGID             0002000
170 #define UNIX_STICKYBIT          0001000
171 #define UNIX_OWNER_READ_PERM    0000400
172 #define UNIX_OWNER_WRITE_PERM   0000200
173 #define UNIX_OWNER_EXEC_PERM    0000100
174 #define UNIX_GROUP_READ_PERM    0000040
175 #define UNIX_GROUP_WRITE_PERM   0000020
176 #define UNIX_GROUP_EXEC_PERM    0000010
177 #define UNIX_OTHER_READ_PERM    0000004
178 #define UNIX_OTHER_WRITE_PERM   0000002
179 #define UNIX_OTHER_EXEC_PERM    0000001
180 #define UNIX_RW_RW_RW           0000666
181
182 #define LZHEADER_STORAGE        4096
183
184 /* ------------------------------------------------------------------------ */
185 /*  FILE Attribute                                                          */
186 /* ------------------------------------------------------------------------ */
187 #define is_directory(statp)     (((statp)->st_mode & S_IFMT) == S_IFDIR)
188 #define is_symlink(statp)       (((statp)->st_mode & S_IFMT) == S_IFLNK)
189 #define is_regularfile(statp)   (((statp)->st_mode & S_IFMT) == S_IFREG)
190
191 #if 1 /* assume that fopen() will accepts "b" as binary mode on all systems. */
192 #define WRITE_BINARY    "wb"
193 #define READ_BINARY     "rb"
194 #else
195 #define WRITE_BINARY    "w"
196 #define READ_BINARY     "r"
197 #endif
198
199 /* ------------------------------------------------------------------------ */
200 /* Individual macro define                                                  */
201 /* ------------------------------------------------------------------------ */
202
203 #ifndef MIN
204 #define MIN(a,b) ((a) <= (b) ? (a) : (b))
205 #endif
206
207 /* bitio.c */
208 #define peekbits(n)     (bitbuf >> (sizeof(bitbuf)*8 - (n)))
209
210 /* crcio.c */
211 #define CRCPOLY         0xA001      /* CRC-16 (x^16+x^15+x^2+1) */
212 #define INITIALIZE_CRC(crc) ((crc) = 0)
213 #define UPDATE_CRC(crc, c) \
214  (crctable[((crc) ^ (unsigned char)(c)) & 0xFF] ^ ((crc) >> CHAR_BIT))
215
216 /* dhuf.c */
217 #define N_CHAR      (256 + 60 - THRESHOLD + 1)
218 #define TREESIZE_C  (N_CHAR * 2)
219 #define TREESIZE_P  (128 * 2)
220 #define TREESIZE    (TREESIZE_C + TREESIZE_P)
221 #define ROOT_C      0
222 #define ROOT_P      TREESIZE_C
223
224 /* huf.c */
225 #define USHRT_BIT           16  /* (CHAR_BIT * sizeof(ushort)) */
226 #define NP          (MAX_DICBIT + 1)
227 #define NT          (USHRT_BIT + 3)
228 #define NC          (UCHAR_MAX + MAXMATCH + 2 - THRESHOLD)
229
230 #define PBIT        5       /* smallest integer such that (1 << PBIT) > * NP */
231 #define TBIT        5       /* smallest integer such that (1 << TBIT) > * NT */
232 #define CBIT        9       /* smallest integer such that (1 << CBIT) > * NC */
233
234 /*      #if NT > NP #define NPT NT #else #define NPT NP #endif  */
235 #define NPT         0x80
236
237 /* larc.c */
238 #define MAGIC0      18
239 #define MAGIC5      19
240
241 /* lharc.c */
242 #define CMD_UNKNOWN 0
243 #define CMD_EXTRACT 1
244 #define CMD_ADD     2
245 #define CMD_LIST    3
246 #define CMD_DELETE  4
247
248 #define STREQU(a,b) (((a)[0] == (b)[0]) ? (strcmp ((a),(b)) == 0) : FALSE)
249
250 /* shuf.c */
251 #define N1          286             /* alphabet size */
252 #define N2          (2 * N1 - 1)    /* # of nodes in Huffman tree */
253 #define EXTRABITS   8               /* >= log2(F-THRESHOLD+258-N1) */
254 #define BUFBITS     16              /* >= log2(MAXBUF) */
255 #define LENFIELD    4               /* bit size of length field for tree output */
256
257 /* util.c */
258 #define BUFFERSIZE  2048
259
260 /* slide.c */
261 /*
262 #define PERCOLATE  1
263 #define NIL        0
264 #define HASH(p, c) ((p) + ((c) << hash1) + hash2)
265 */
266
267 /* slide.c */
268 #define MAXMATCH            256 /* formerly F (not more than UCHAR_MAX + 1) */
269 #define THRESHOLD           3   /* choose optimal value */