OSDN Git Service

* src/lha.h, src/lha_macro.h: refined.
[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 #define FALSE                   0
14 #define TRUE                    1
15
16 #define FILENAME_LENGTH 1024
17
18 #if defined __MINGW32__
19 # define getuid()       0
20 # define chown(file, uid, gid)  0
21 # define kill(pid, sig)         0
22 #endif
23
24 /* ------------------------------------------------------------------------ */
25 /* YOUR CUSTOMIZIES                                                                                                                     */
26 /* ------------------------------------------------------------------------ */
27
28 #ifndef ARCHIVENAME_EXTENTION
29 #define ARCHIVENAME_EXTENTION   ".lzh"
30 #endif
31 #ifndef BACKUPNAME_EXTENTION
32 #define BACKUPNAME_EXTENTION    ".bak"
33 #endif
34
35 #define SJC_FIRST_P(c)                  \
36   (((unsigned char)(c) >= 0x80) &&      \
37    (((unsigned char)(c) < 0xa0) ||      \
38     ((unsigned char)(c) >= 0xe0) &&     \
39     ((unsigned char)(c) < 0xfd)))
40 #define SJC_SECOND_P(c)                 \
41   (((unsigned char)(c) >= 0x40) &&      \
42    ((unsigned char)(c) < 0xfd) &&       \
43    ((unsigned char)(c) != 0x7f))
44
45 #define X0201_KANA_P(c)\
46         (0xa0 < (unsigned char)(c) && (unsigned char)(c) < 0xe0)
47
48 /* for filename conversion */
49 #define NONE 0
50 #define CODE_EUC 1
51 #define CODE_SJIS 2
52 #define CODE_UTF8 3
53 #define TO_LOWER 1
54 #define TO_UPPER 2
55
56 #ifdef MULTIBYTE_FILENAME
57 #define MULTIBYTE_FIRST_P       SJC_FIRST_P
58 #define MULTIBYTE_SECOND_P      SJC_SECOND_P
59 #endif                          /* MULTIBYTE_FILENAME */
60
61 /* ------------------------------------------------------------------------ */
62 /*      LHa File Definitions                                                                                                    */
63 /* ------------------------------------------------------------------------ */
64 #ifdef S_IFLNK
65 #define GETSTAT lstat
66 #else
67 #define GETSTAT stat
68 #endif
69
70 #ifdef LHA_MAIN_SRC
71 #define EXTERN
72 #else
73 #define EXTERN                          extern
74 #endif  /* LHA_MAIN_SRC */
75
76 #define LZHUFF0_METHOD                  "-lh0-"
77 #define LZHUFF1_METHOD                  "-lh1-"
78 #define LZHUFF2_METHOD                  "-lh2-"
79 #define LZHUFF3_METHOD                  "-lh3-"
80 #define LZHUFF4_METHOD                  "-lh4-"
81 #define LZHUFF5_METHOD                  "-lh5-"
82 #define LZHUFF6_METHOD                  "-lh6-"
83 #define LZHUFF7_METHOD                  "-lh7-"
84 #define LARC_METHOD                             "-lzs-"
85 #define LARC5_METHOD                    "-lz5-"
86 #define LARC4_METHOD                    "-lz4-"
87 #define LZHDIRS_METHOD                  "-lhd-"
88
89 #define METHOD_TYPE_STRAGE              5
90
91 /* Added N.Watazaki ..V */
92 #define LZHUFF0_METHOD_NUM              0
93 #define LZHUFF1_METHOD_NUM              1
94 #define LZHUFF2_METHOD_NUM              2
95 #define LZHUFF3_METHOD_NUM              3
96 #define LZHUFF4_METHOD_NUM              4
97 #define LZHUFF5_METHOD_NUM              5
98 #define LZHUFF6_METHOD_NUM              6
99 #define LZHUFF7_METHOD_NUM              7
100 #define LARC_METHOD_NUM                 8
101 #define LARC5_METHOD_NUM                9
102 #define LARC4_METHOD_NUM                10
103 #define LZHDIRS_METHOD_NUM              11
104 /* Added N.Watazaki ..^ */
105
106 #define I_HEADER_SIZE                   0
107 #define I_HEADER_CHECKSUM               1
108 #define I_METHOD                                2
109 #define I_PACKED_SIZE                   7
110 #define I_ORIGINAL_SIZE                 11
111 #define I_LAST_MODIFIED_STAMP   15
112 #define I_ATTRIBUTE                             19
113 #define I_HEADER_LEVEL                  20
114 #define I_NAME_LENGTH                   21
115 #define I_NAME                                  22
116
117 #define I_CRC                                           22      /* + name_length */
118 #define I_EXTEND_TYPE                           24      /* + name_length */
119 #define I_MINOR_VERSION                         25      /* + name_length */
120 #define I_UNIX_LAST_MODIFIED_STAMP      26      /* + name_length */
121 #define I_UNIX_MODE                                     30      /* + name_length */
122 #define I_UNIX_UID                                      32      /* + name_length */
123 #define I_UNIX_GID                                      34      /* + name_length */
124 #define I_UNIX_EXTEND_BOTTOM            36      /* + name_length */
125
126 #define I_GENERIC_HEADER_BOTTOM         I_EXTEND_TYPE
127
128 #define EXTEND_GENERIC                  0
129 #define EXTEND_UNIX                             'U'
130 #define EXTEND_MSDOS                    'M'
131 #define EXTEND_MACOS                    'm'
132 #define EXTEND_OS9                              '9'
133 #define EXTEND_OS2                              '2'
134 #define EXTEND_OS68K                    'K' /* Enea Data Systems real-time OS (?) */
135 #define EXTEND_OS386                    '3'     /* OS-9000??? */
136 #define EXTEND_HUMAN                    'H'
137 #define EXTEND_CPM                              'C'
138 #define EXTEND_FLEX                             'F'
139 #define EXTEND_RUNSER                   'R'
140
141 /* this OS type is not official */
142
143 #define EXTEND_TOWNSOS                  'T'
144 #define EXTEND_XOSK                             'X' /* OS-9 for X68000 (?) */
145
146 /*---------------------------------------------------------------------------*/
147
148 #define GENERIC_ATTRIBUTE                               0x20
149 #define GENERIC_DIRECTORY_ATTRIBUTE             0x10
150 #define HEADER_LEVEL0                                   0x00
151 #define HEADER_LEVEL1                                   0x01
152 #define HEADER_LEVEL2                                   0x02
153
154 #define CURRENT_UNIX_MINOR_VERSION              0x00
155
156 #define LHA_PATHSEP             0xff    /* path separator of the
157                                            filename in lha header.
158                                            it should compare with
159                                            `unsigned char' or `int',
160                                            that is not '\xff', but 0xff. */
161
162 #define OSK_RW_RW_RW                    0000033
163 #define OSK_FILE_REGULAR                0000000
164 #define OSK_DIRECTORY_PERM              0000200
165 #define OSK_SHARED_PERM                 0000100
166 #define OSK_OTHER_EXEC_PERM             0000040
167 #define OSK_OTHER_WRITE_PERM    0000020
168 #define OSK_OTHER_READ_PERM             0000010
169 #define OSK_OWNER_EXEC_PERM             0000004
170 #define OSK_OWNER_WRITE_PERM    0000002
171 #define OSK_OWNER_READ_PERM             0000001
172
173 #define UNIX_FILE_TYPEMASK              0170000
174 #define UNIX_FILE_REGULAR               0100000
175 #define UNIX_FILE_DIRECTORY             0040000
176 #define UNIX_FILE_SYMLINK               0120000
177 #define UNIX_SETUID                             0004000
178 #define UNIX_SETGID                             0002000
179 #define UNIX_STICKYBIT                  0001000
180 #define UNIX_OWNER_READ_PERM    0000400
181 #define UNIX_OWNER_WRITE_PERM   0000200
182 #define UNIX_OWNER_EXEC_PERM    0000100
183 #define UNIX_GROUP_READ_PERM    0000040
184 #define UNIX_GROUP_WRITE_PERM   0000020
185 #define UNIX_GROUP_EXEC_PERM    0000010
186 #define UNIX_OTHER_READ_PERM    0000004
187 #define UNIX_OTHER_WRITE_PERM   0000002
188 #define UNIX_OTHER_EXEC_PERM    0000001
189 #define UNIX_RW_RW_RW                   0000666
190
191 #define LZHEADER_STRAGE                 4096
192
193 #define MAX_INDICATOR_COUNT             64
194
195 /* ------------------------------------------------------------------------ */
196 /*      Slide relation                                                                                                                  */
197 /* ------------------------------------------------------------------------ */
198 #define LH3_DICBIT                      13
199 #define LH5_DICBIT                      13
200 #define LH6_DICBIT                      15
201 #define LH7_DICBIT                      16
202
203 /* ------------------------------------------------------------------------ */
204 /*      FILE Attribute                                                                                                                  */
205 /* ------------------------------------------------------------------------ */
206 #define is_directory(statp)             (((statp)->st_mode & S_IFMT) == S_IFDIR)
207 #define is_symlink(statp)               (((statp)->st_mode & S_IFMT) == S_IFLNK)
208 #define is_regularfile(statp)   (((statp)->st_mode & S_IFMT) == S_IFREG)
209
210 #if 1 /* assume that fopen() will accepts "b" as binary mode on all system. */
211 #define WRITE_BINARY    "wb"
212 #define READ_BINARY             "rb"
213 #else
214 #define WRITE_BINARY    "w"
215 #define READ_BINARY             "r"
216 #endif
217
218 /* ------------------------------------------------------------------------ */
219 /* Individual macro define                                                                                                      */
220 /* ------------------------------------------------------------------------ */
221
222 /* from crcio.c */
223 #define CRCPOLY                 0xA001          /* CRC-16 */
224 #define UPDATE_CRC(c)   crc = crctable[(crc ^ (c)) & 0xFF] ^ (crc >> CHAR_BIT)
225
226 /* dhuf.c */
227 #define N_CHAR      (256 + 60 - THRESHOLD + 1)
228 #define TREESIZE_C  (N_CHAR * 2)
229 #define TREESIZE_P  (128 * 2)
230 #define TREESIZE    (TREESIZE_C + TREESIZE_P)
231 #define ROOT_C      0
232 #define ROOT_P      TREESIZE_C
233
234 /* header.c */
235 #define setup_get(PTR)  (get_ptr = (PTR))
236 #define get_byte()              (*get_ptr++ & 0xff)
237 #define put_ptr                 get_ptr
238 #define setup_put(PTR)  (put_ptr = (PTR))
239 #define put_byte(c)             (*put_ptr++ = (char)(c))
240
241 /* huf.c */
242 #define NP                      (MAX_DICBIT + 1)
243 #define NT                      (USHRT_BIT + 3)
244 #if 0
245 #define PBIT            4               /* smallest integer such that (1 << PBIT) > * NP */
246 #define TBIT            5               /* smallest integer such that (1 << TBIT) > * NT */
247 #endif
248
249 #define PBIT            5               /* smallest integer such that (1 << PBIT) > * NP */
250 #define TBIT            5               /* smallest integer such that (1 << TBIT) > * NT */
251
252 #define NC                      (UCHAR_MAX + MAXMATCH + 2 - THRESHOLD)
253
254 /*              #if NT > NP #define NPT NT #else #define NPT NP #endif  */
255 #define NPT                     0x80
256
257 /* larc.c */
258 #define MAGIC0          18
259 #define MAGIC5          19
260
261 /* lharc.c */
262 #define CMD_UNKNOWN     0
263 #define CMD_EXTRACT     1
264 #define CMD_ADD         2
265 #define CMD_LIST        3
266 #define CMD_DELETE      4
267
268 #define STREQU(a,b)     (((a)[0] == (b)[0]) ? (strcmp ((a),(b)) == 0) : FALSE)
269
270 /* shuf.c */
271 #define N1                      286                             /* alphabet size */
272 #define N2                      (2 * N1 - 1)    /* # of nodes in Huffman tree */
273 #define EXTRABITS       8                               /* >= log2(F-THRESHOLD+258-N1) */
274 #define BUFBITS         16                              /* >= log2(MAXBUF) */
275 #define LENFIELD        4                               /* bit size of length field for tree output */
276
277 /* util.c */
278 #define BUFFERSIZE      2048
279 #define MAXSFXCODE      1024*64
280
281 /* slide.c */
282 /*
283 #define PERCOLATE  1
284 #define NIL        0
285 #define HASH(p, c) ((p) + ((c) << hash1) + hash2)
286 */
287
288 /* slide.c */
289 #ifdef SUPPORT_LH7
290 #define MAX_DICBIT                      LH7_DICBIT      /* lh7 use 16bits */
291 #endif
292
293 #ifndef SUPPORT_LH7
294 #define MAX_DICBIT                      LH6_DICBIT      /* lh6 use 15bits */
295 #endif
296
297 #define MAX_DICSIZ                      (1 << MAX_DICBIT)
298 #define MATCHBIT                        8       /* bits for MAXMATCH - THRESHOLD */
299 #define MAXMATCH                        256     /* formerly F (not more than UCHAR_MAX + 1) */
300 #define THRESHOLD                       3       /* choose optimal value */
301
302 /* from huf.c */
303
304 /* alphabet = {0, 1, 2, ..., NC - 1} */
305 #define CBIT                            9       /* $\lfloor \log_2 NC \rfloor + 1$ */
306 #define USHRT_BIT                       16      /* (CHAR_BIT * sizeof(ushort)) */
307
308 /* Local Variables: */
309 /* mode:c */
310 /* tab-width:4 */
311 /* End: */
312 /* vi: set tabstop=4: */