OSDN Git Service

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