OSDN Git Service

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