OSDN Git Service

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