OSDN Git Service

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