OSDN Git Service

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