OSDN Git Service

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