OSDN Git Service

use the VERSION macro (defined by configure) in the LHA_VERSION definition.
[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 is defined in config.h by configure script */
11 #define LHA_VERSION "lha for unix version " VERSION
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 #ifndef _MINIX
68 #ifndef __STDC__
69 extern char    *malloc();
70 extern char    *realloc();
71 #endif
72 #endif
73
74 /* external variables */
75 extern int      errno;
76
77 #define FALSE                   0
78 #define TRUE                    1
79 typedef int                             boolean;
80
81 /* used by qsort() for alphabetic-sort */
82 #define STRING_COMPARE(a,b)             strcmp((a),(b))
83
84 #define FILENAME_LENGTH 1024
85
86 /* ------------------------------------------------------------------------ */
87 /* YOUR CUSTOMIZIES                                                                                                                     */
88 /* ------------------------------------------------------------------------ */
89
90 #ifndef ARCHIVENAME_EXTENTION
91 #define ARCHIVENAME_EXTENTION   ".lzh"
92 #endif
93 #ifndef BACKUPNAME_EXTENTION
94 #define BACKUPNAME_EXTENTION    ".bak"
95 #endif
96 #ifndef TMP_FILENAME_TEMPLATE
97 #define TMP_FILENAME_TEMPLATE   "/tmp/lhXXXXXX"
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_CHAR
120 #define MULTIBYTE_FIRST_P       SJC_FIRST_P
121 #define MULTIBYTE_SECOND_P      SJC_SECOND_P
122 #endif                          /* MULTIBYTE_CHAR */
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'
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'
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_STYCKYBIT                  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 defined(__STDC__) || defined(AIX)
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  /* not __STDC__ */
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 #ifdef MSDOS
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 #else
322 # ifndef HAVE_STRCHR
323 #  define strchr index
324 #  define strrchr rindex
325 # endif
326 char *strchr (), *strrchr ();
327 # ifdef HAVE_MEMCPY
328 #  define bcmp(a,b,n)   memcmp((a),(b),(n))
329 #  define bzero(d,n)    memset((d),0,(n))
330 #  define bcopy(s,d,n)  memmove((d),(s),(n))
331 # endif
332 #endif
333
334 #if HAVE_STRCASECMP
335 #define strucmp(p,q)    strcasecmp((p),(q))
336 #endif
337
338 /* ------------------------------------------------------------------------ */
339 /* Individual macro define                                                                                                      */
340 /* ------------------------------------------------------------------------ */
341
342 /* from crcio.c */
343 #define CRCPOLY                 0xA001          /* CRC-16 */
344 #define UPDATE_CRC(c)   crc = crctable[(crc ^ (c)) & 0xFF] ^ (crc >> CHAR_BIT)
345
346 /* dhuf.c */
347 #define N_CHAR      (256 + 60 - THRESHOLD + 1)
348 #define TREESIZE_C  (N_CHAR * 2)
349 #define TREESIZE_P  (128 * 2)
350 #define TREESIZE    (TREESIZE_C + TREESIZE_P)
351 #define ROOT_C      0
352 #define ROOT_P      TREESIZE_C
353
354 /* header.c */
355 #define setup_get(PTR)  (get_ptr = (PTR))
356 #define get_byte()              (*get_ptr++ & 0xff)
357 #define put_ptr                 get_ptr
358 #define setup_put(PTR)  (put_ptr = (PTR))
359 #define put_byte(c)             (*put_ptr++ = (char)(c))
360
361 /* huf.c */
362 #define NP                      (MAX_DICBIT + 1)
363 #define NT                      (USHRT_BIT + 3)
364 #if 0
365 #define PBIT            4               /* smallest integer such that (1 << PBIT) > * NP */
366 #define TBIT            5               /* smallest integer such that (1 << TBIT) > * NT */
367 #endif
368
369 #define PBIT            5               /* smallest integer such that (1 << PBIT) > * NP */
370 #define TBIT            5               /* smallest integer such that (1 << TBIT) > * NT */
371
372 #define NC                      (UCHAR_MAX + MAXMATCH + 2 - THRESHOLD)
373
374 /*              #if NT > NP #define NPT NT #else #define NPT NP #endif  */
375 #define NPT                     0x80
376
377 /* larc.c */
378 #define MAGIC0          18
379 #define MAGIC5          19
380
381 /* lharc.c */
382 #define CMD_UNKNOWN     0
383 #define CMD_EXTRACT     1
384 #define CMD_ADD         2
385 #define CMD_LIST        3
386 #define CMD_DELETE      4
387
388 #define STREQU(a,b)     (((a)[0] == (b)[0]) ? (strcmp ((a),(b)) == 0) : FALSE)
389
390 /* shuf.c */
391 #define N1                      286                             /* alphabet size */
392 #define N2                      (2 * N1 - 1)    /* # of nodes in Huffman tree */
393 #define EXTRABITS       8                               /* >= log2(F-THRESHOLD+258-N1) */
394 #define BUFBITS         16                              /* >= log2(MAXBUF) */
395 #define LENFIELD        4                               /* bit size of length field for tree output */
396
397 /* util.c */
398 #define BUFFERSIZE      2048
399 #define MAXSFXCODE      1024*64
400
401 #ifndef NULL
402 #define NULL            (char *)0
403 #endif
404
405 /* slide.c */
406 /*
407 #define PERCOLATE  1
408 #define NIL        0
409 #define HASH(p, c) ((p) + ((c) << hash1) + hash2)
410 */
411
412 /* slide.c */
413 #ifdef SUPPORT_LH7
414 #define MAX_DICBIT                      16      /* lh7 use 16bits */
415 #endif
416
417 #ifndef SUPPORT_LH7
418 #define MAX_DICBIT                      15      /* lh6 use 15bits */
419 #endif
420
421 #define MAX_DICSIZ                      (1 << MAX_DICBIT)
422 #define MATCHBIT                        8       /* bits for MAXMATCH - THRESHOLD */
423 #define MAXMATCH                        256     /* formerly F (not more than UCHAR_MAX + 1) */
424 #define THRESHOLD                       3       /* choose optimal value */
425
426 /* from huf.c */
427
428 /* alphabet = {0, 1, 2, ..., NC - 1} */
429 #define CBIT                            9       /* $\lfloor \log_2 NC \rfloor + 1$ */
430 #define USHRT_BIT                       16      /* (CHAR_BIT * sizeof(ushort)) */
431
432 /* Local Variables: */
433 /* mode:c */
434 /* tab-width:4 */
435 /* End: */