OSDN Git Service

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