OSDN Git Service

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