OSDN Git Service

* src/lhadd.c (append_it): macro STRING_COMPARE() discarded.
[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 /* macro VERSION and PLATFORM are defined in config.h by configure script */
11 #define LHA_VERSION "LHa for UNIX version " VERSION " (" PLATFORM ")"
12
13 #define FALSE                   0
14 #define TRUE                    1
15
16 #define FILENAME_LENGTH 1024
17
18 #if defined __MINGW32__
19 # define getuid()       0
20 # define chown(file, uid, gid)  0
21 # define kill(pid, sig)         0
22 #endif
23
24 /* ------------------------------------------------------------------------ */
25 /* YOUR CUSTOMIZIES                                                                                                                     */
26 /* ------------------------------------------------------------------------ */
27
28 #ifndef ARCHIVENAME_EXTENTION
29 #define ARCHIVENAME_EXTENTION   ".lzh"
30 #endif
31 #ifndef BACKUPNAME_EXTENTION
32 #define BACKUPNAME_EXTENTION    ".bak"
33 #endif
34
35 #define SJC_FIRST_P(c)                  \
36   (((unsigned char)(c) >= 0x80) &&      \
37    (((unsigned char)(c) < 0xa0) ||      \
38     ((unsigned char)(c) >= 0xe0) &&     \
39     ((unsigned char)(c) < 0xfd)))
40 #define SJC_SECOND_P(c)                 \
41   (((unsigned char)(c) >= 0x40) &&      \
42    ((unsigned char)(c) < 0xfd) &&       \
43    ((unsigned char)(c) != 0x7f))
44
45 #define X0201_KANA_P(c)\
46         (0xa0 < (unsigned char)(c) && (unsigned char)(c) < 0xe0)
47
48 /* for filename conversion */
49 #define NONE 0
50 #define CODE_EUC 1
51 #define CODE_SJIS 2
52 #define CODE_UTF8 3
53 #define TO_LOWER 1
54 #define TO_UPPER 2
55
56 #ifdef MULTIBYTE_FILENAME
57 #define MULTIBYTE_FIRST_P       SJC_FIRST_P
58 #define MULTIBYTE_SECOND_P      SJC_SECOND_P
59 #endif                          /* MULTIBYTE_FILENAME */
60
61 /* ------------------------------------------------------------------------ */
62 /*      LHa File Definitions                                                                                                    */
63 /* ------------------------------------------------------------------------ */
64 #ifdef S_IFLNK
65 #define GETSTAT lstat
66 #else
67 #define GETSTAT stat
68 #endif
69
70 #ifdef LHA_MAIN_SRC
71 #define EXTERN
72 #else
73 #define EXTERN                          extern
74 #endif  /* LHA_MAIN_SRC */
75
76 #define LZHUFF0_METHOD                  "-lh0-"
77 #define LZHUFF1_METHOD                  "-lh1-"
78 #define LZHUFF2_METHOD                  "-lh2-"
79 #define LZHUFF3_METHOD                  "-lh3-"
80 #define LZHUFF4_METHOD                  "-lh4-"
81 #define LZHUFF5_METHOD                  "-lh5-"
82 #define LZHUFF6_METHOD                  "-lh6-"
83 #define LZHUFF7_METHOD                  "-lh7-"
84 #define LARC_METHOD                             "-lzs-"
85 #define LARC5_METHOD                    "-lz5-"
86 #define LARC4_METHOD                    "-lz4-"
87 #define LZHDIRS_METHOD                  "-lhd-"
88
89 #define METHOD_TYPE_STRAGE              5
90
91 /* Added N.Watazaki ..V */
92 #define LZHUFF0_METHOD_NUM              0
93 #define LZHUFF1_METHOD_NUM              1
94 #define LZHUFF2_METHOD_NUM              2
95 #define LZHUFF3_METHOD_NUM              3
96 #define LZHUFF4_METHOD_NUM              4
97 #define LZHUFF5_METHOD_NUM              5
98 #define LZHUFF6_METHOD_NUM              6
99 #define LZHUFF7_METHOD_NUM              7
100 #define LARC_METHOD_NUM                 8
101 #define LARC5_METHOD_NUM                9
102 #define LARC4_METHOD_NUM                10
103 #define LZHDIRS_METHOD_NUM              11
104 /* Added N.Watazaki ..^ */
105
106 #define I_HEADER_SIZE                   0
107 #define I_HEADER_CHECKSUM               1
108 #define I_METHOD                                2
109 #define I_PACKED_SIZE                   7
110 #define I_ORIGINAL_SIZE                 11
111 #define I_LAST_MODIFIED_STAMP   15
112 #define I_ATTRIBUTE                             19
113 #define I_HEADER_LEVEL                  20
114 #define I_NAME_LENGTH                   21
115 #define I_NAME                                  22
116
117 #define I_CRC                                           22      /* + name_length */
118 #define I_EXTEND_TYPE                           24      /* + name_length */
119 #define I_MINOR_VERSION                         25      /* + name_length */
120 #define I_UNIX_LAST_MODIFIED_STAMP      26      /* + name_length */
121 #define I_UNIX_MODE                                     30      /* + name_length */
122 #define I_UNIX_UID                                      32      /* + name_length */
123 #define I_UNIX_GID                                      34      /* + name_length */
124 #define I_UNIX_EXTEND_BOTTOM            36      /* + name_length */
125
126 #define I_GENERIC_HEADER_BOTTOM         I_EXTEND_TYPE
127
128 #define EXTEND_GENERIC                  0
129 #define EXTEND_UNIX                             'U'
130 #define EXTEND_MSDOS                    'M'
131 #define EXTEND_MACOS                    'm'
132 #define EXTEND_OS9                              '9'
133 #define EXTEND_OS2                              '2'
134 #define EXTEND_OS68K                    'K' /* Enea Data Systems real-time OS (?) */
135 #define EXTEND_OS386                    '3'     /* OS-9000??? */
136 #define EXTEND_HUMAN                    'H'
137 #define EXTEND_CPM                              'C'
138 #define EXTEND_FLEX                             'F'
139 #define EXTEND_RUNSER                   'R'
140
141 /* this OS type is not official */
142
143 #define EXTEND_TOWNSOS                  'T'
144 #define EXTEND_XOSK                             'X' /* OS-9 for X68000 (?) */
145
146 /*---------------------------------------------------------------------------*/
147
148 #define GENERIC_ATTRIBUTE                               0x20
149 #define GENERIC_DIRECTORY_ATTRIBUTE             0x10
150 #define HEADER_LEVEL0                                   0x00
151 #define HEADER_LEVEL1                                   0x01
152 #define HEADER_LEVEL2                                   0x02
153
154 #define CURRENT_UNIX_MINOR_VERSION              0x00
155
156 #define LHA_PATHSEP             0xff    /* path separator of the
157                                            filename in lha header.
158                                            it should compare with
159                                            `unsigned char' or `int',
160                                            that is not '\xff', but 0xff. */
161
162 #define OSK_RW_RW_RW                    0000033
163 #define OSK_FILE_REGULAR                0000000
164 #define OSK_DIRECTORY_PERM              0000200
165 #define OSK_SHARED_PERM                 0000100
166 #define OSK_OTHER_EXEC_PERM             0000040
167 #define OSK_OTHER_WRITE_PERM    0000020
168 #define OSK_OTHER_READ_PERM             0000010
169 #define OSK_OWNER_EXEC_PERM             0000004
170 #define OSK_OWNER_WRITE_PERM    0000002
171 #define OSK_OWNER_READ_PERM             0000001
172
173 #define UNIX_FILE_TYPEMASK              0170000
174 #define UNIX_FILE_REGULAR               0100000
175 #define UNIX_FILE_DIRECTORY             0040000
176 #define UNIX_FILE_SYMLINK               0120000
177 #define UNIX_SETUID                             0004000
178 #define UNIX_SETGID                             0002000
179 #define UNIX_STICKYBIT                  0001000
180 #define UNIX_OWNER_READ_PERM    0000400
181 #define UNIX_OWNER_WRITE_PERM   0000200
182 #define UNIX_OWNER_EXEC_PERM    0000100
183 #define UNIX_GROUP_READ_PERM    0000040
184 #define UNIX_GROUP_WRITE_PERM   0000020
185 #define UNIX_GROUP_EXEC_PERM    0000010
186 #define UNIX_OTHER_READ_PERM    0000004
187 #define UNIX_OTHER_WRITE_PERM   0000002
188 #define UNIX_OTHER_EXEC_PERM    0000001
189 #define UNIX_RW_RW_RW                   0000666
190
191 #define LZHEADER_STRAGE                 4096
192
193 #define MAX_INDICATOR_COUNT             64
194
195 /* ------------------------------------------------------------------------ */
196 /*      Slide relation                                                                                                                  */
197 /* ------------------------------------------------------------------------ */
198 #if HAVE_LIMITS_H
199
200 #include <limits.h>
201
202 #else
203
204 #ifndef CHAR_BIT
205 #define CHAR_BIT  8
206 #endif
207
208 #ifndef UCHAR_MAX
209 #define UCHAR_MAX                               ((1<<(sizeof(unsigned char)*8))-1)
210 #endif
211
212 #ifndef USHRT_MAX
213 #define USHRT_MAX                               ((1<<(sizeof(unsigned short)*8))-1)
214 #endif
215
216 #ifndef SHRT_MAX
217 #define SHRT_MAX                                ((1<<(sizeof(short)*8-1))-1)
218 #endif
219
220 #ifndef SHRT_MIN
221 #define SHRT_MIN                                (SHRT_MAX-USHRT_MAX)
222 #endif
223
224 #ifndef ULONG_MAX
225 #define ULONG_MAX       ((1<<(sizeof(unsigned long)*8))-1)
226 #endif
227
228 #ifndef LONG_MAX
229 #define LONG_MAX        ((1<<(sizeof(long)*8-1))-1)
230 #endif
231
232 #ifndef LONG_MIN
233 #define LONG_MIN        (LONG_MAX-ULONG_MAX)
234 #endif
235
236 #endif
237
238 #define LH3_DICBIT                      13
239 #define LH5_DICBIT                      13
240 #define LH6_DICBIT                      15
241 #define LH7_DICBIT                      16
242
243 /* ------------------------------------------------------------------------ */
244 /*      FILE Attribute                                                                                                                  */
245 /* ------------------------------------------------------------------------ */
246 #define is_directory(statp)             (((statp)->st_mode & S_IFMT) == S_IFDIR)
247 #define is_symlink(statp)               (((statp)->st_mode & S_IFMT) == S_IFLNK)
248 #define is_regularfile(statp)   (((statp)->st_mode & S_IFMT) == S_IFREG)
249
250 #if 1 /* assume that fopen() will accepts "b" as binary mode on all system. */
251 #define WRITE_BINARY    "wb"
252 #define READ_BINARY             "rb"
253 #else
254 #define WRITE_BINARY    "w"
255 #define READ_BINARY             "r"
256 #endif
257
258 /* ------------------------------------------------------------------------ */
259 /*      Memory and String function                                                                                              */
260 /* ------------------------------------------------------------------------ */
261 #if STDC_HEADERS
262 # include <string.h>
263 #else
264 # if !HAVE_STRCHR
265 #  define strchr index
266 #  define strrchr rindex
267 # endif
268 char *strchr (), *strrchr ();
269 # if !HAVE_MEMCPY
270 #  define memcmp(s1, s2, n) bcmp ((s1), (s2), (n))
271 #  define memcpy(d, s, n) bcopy ((s), (d), (n))
272 #  define memmove(d, s, n) bcopy ((s), (d), (n))
273 # endif
274 #endif
275
276 #if HAVE_STRCASECMP
277 #define strucmp(p,q)    strcasecmp((p),(q))
278 #endif
279
280 /* ------------------------------------------------------------------------ */
281 /* Individual macro define                                                                                                      */
282 /* ------------------------------------------------------------------------ */
283
284 /* from crcio.c */
285 #define CRCPOLY                 0xA001          /* CRC-16 */
286 #define UPDATE_CRC(c)   crc = crctable[(crc ^ (c)) & 0xFF] ^ (crc >> CHAR_BIT)
287
288 /* dhuf.c */
289 #define N_CHAR      (256 + 60 - THRESHOLD + 1)
290 #define TREESIZE_C  (N_CHAR * 2)
291 #define TREESIZE_P  (128 * 2)
292 #define TREESIZE    (TREESIZE_C + TREESIZE_P)
293 #define ROOT_C      0
294 #define ROOT_P      TREESIZE_C
295
296 /* header.c */
297 #define setup_get(PTR)  (get_ptr = (PTR))
298 #define get_byte()              (*get_ptr++ & 0xff)
299 #define put_ptr                 get_ptr
300 #define setup_put(PTR)  (put_ptr = (PTR))
301 #define put_byte(c)             (*put_ptr++ = (char)(c))
302
303 /* huf.c */
304 #define NP                      (MAX_DICBIT + 1)
305 #define NT                      (USHRT_BIT + 3)
306 #if 0
307 #define PBIT            4               /* smallest integer such that (1 << PBIT) > * NP */
308 #define TBIT            5               /* smallest integer such that (1 << TBIT) > * NT */
309 #endif
310
311 #define PBIT            5               /* smallest integer such that (1 << PBIT) > * NP */
312 #define TBIT            5               /* smallest integer such that (1 << TBIT) > * NT */
313
314 #define NC                      (UCHAR_MAX + MAXMATCH + 2 - THRESHOLD)
315
316 /*              #if NT > NP #define NPT NT #else #define NPT NP #endif  */
317 #define NPT                     0x80
318
319 /* larc.c */
320 #define MAGIC0          18
321 #define MAGIC5          19
322
323 /* lharc.c */
324 #define CMD_UNKNOWN     0
325 #define CMD_EXTRACT     1
326 #define CMD_ADD         2
327 #define CMD_LIST        3
328 #define CMD_DELETE      4
329
330 #define STREQU(a,b)     (((a)[0] == (b)[0]) ? (strcmp ((a),(b)) == 0) : FALSE)
331
332 /* shuf.c */
333 #define N1                      286                             /* alphabet size */
334 #define N2                      (2 * N1 - 1)    /* # of nodes in Huffman tree */
335 #define EXTRABITS       8                               /* >= log2(F-THRESHOLD+258-N1) */
336 #define BUFBITS         16                              /* >= log2(MAXBUF) */
337 #define LENFIELD        4                               /* bit size of length field for tree output */
338
339 /* util.c */
340 #define BUFFERSIZE      2048
341 #define MAXSFXCODE      1024*64
342
343 #ifndef NULL
344 #define NULL            (char *)0
345 #endif
346
347 /* slide.c */
348 /*
349 #define PERCOLATE  1
350 #define NIL        0
351 #define HASH(p, c) ((p) + ((c) << hash1) + hash2)
352 */
353
354 /* slide.c */
355 #ifdef SUPPORT_LH7
356 #define MAX_DICBIT                      LH7_DICBIT      /* lh7 use 16bits */
357 #endif
358
359 #ifndef SUPPORT_LH7
360 #define MAX_DICBIT                      LH6_DICBIT      /* lh6 use 15bits */
361 #endif
362
363 #define MAX_DICSIZ                      (1 << MAX_DICBIT)
364 #define MATCHBIT                        8       /* bits for MAXMATCH - THRESHOLD */
365 #define MAXMATCH                        256     /* formerly F (not more than UCHAR_MAX + 1) */
366 #define THRESHOLD                       3       /* choose optimal value */
367
368 /* from huf.c */
369
370 /* alphabet = {0, 1, 2, ..., NC - 1} */
371 #define CBIT                            9       /* $\lfloor \log_2 NC \rfloor + 1$ */
372 #define USHRT_BIT                       16      /* (CHAR_BIT * sizeof(ushort)) */
373
374 /* Local Variables: */
375 /* mode:c */
376 /* tab-width:4 */
377 /* End: */
378 /* vi: set tabstop=4: */