OSDN Git Service

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