OSDN Git Service

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