OSDN Git Service

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