OSDN Git Service

Add a compiler clang
[lha/lha.git] / src / lha.h
1 /* ------------------------------------------------------------------------ */
2 /* LHa for UNIX    Archiver Driver                                          */
3 /*                                                                          */
4 /*      Modified                Nobutaka Watazaki                           */
5 /*                                                                          */
6 /*  Ver. 1.14   Soruce All chagned              1995.01.14  N.Watazaki      */
7 /*  Ver. 1.14i  Modified and bug fixed          2000.10.06  t.okamoto       */
8 /* ------------------------------------------------------------------------ */
9 /*
10     Included...
11         lharc.h     interface.h     slidehuf.h
12 */
13
14 #ifdef HAVE_CONFIG_H
15 # include <config.h>
16 #endif
17
18 #include <stdio.h>
19 #include <errno.h>
20 #include <ctype.h>
21 #include <sys/types.h>
22 #include <sys/file.h>
23 #include <sys/stat.h>
24 #include <signal.h>
25
26 #if HAVE_INTTYPES_H
27 # include <inttypes.h>
28 #else
29 # if HAVE_STDINT_H
30 #  include <stdint.h>
31 # endif
32 #endif
33
34 #if STDC_HEADERS
35 # include <string.h>
36 #else
37 # if !HAVE_STRCHR
38 #  define strchr index
39 #  define strrchr rindex
40 # endif
41 char *strchr (), *strrchr ();
42 # if !HAVE_MEMCPY
43 #  define memcmp(s1, s2, n) bcmp ((s1), (s2), (n))
44 #  define memcpy(d, s, n) bcopy ((s), (d), (n))
45 #  define memmove(d, s, n) bcopy ((s), (d), (n))
46 # endif
47 #endif
48
49 #if STDC_HEADERS
50 # include <stdlib.h>
51 # include <stddef.h>
52 #else
53 # if HAVE_STDLIB_H
54 #  include <stdlib.h>
55 # endif
56 #endif
57
58 #ifndef NULL
59 #define NULL ((char *)0)
60 #endif
61
62 #if HAVE_UNISTD_H
63 #include <unistd.h>
64 #endif
65
66 #if STDC_HEADERS
67 # include <stdarg.h>
68 # define va_init(a,b) va_start(a,b)
69 #else
70 # include <varargs.h>
71 # define va_init(a,b) va_start(a)
72 #endif
73
74 #if HAVE_PWD_H
75 # include <pwd.h>
76 #endif
77 #if HAVE_GRP_H
78 # include <grp.h>
79 #endif
80
81 #if !HAVE_UID_T
82 typedef int uid_t;
83 #endif
84 #if !HAVE_GID_T
85 typedef int gid_t;
86 #endif
87
88 #if !HAVE_UINT64_T
89 # define HAVE_UINT64_T 1
90 # if SIZEOF_LONG == 8
91     typedef unsigned long uint64_t;
92 # elif HAVE_LONG_LONG
93     typedef unsigned long long uint64_t;
94 # else
95 #  undef HAVE_UINT64_T
96 # endif
97 #endif
98
99 #if !HAVE_SSIZE_T
100 typedef long ssize_t;
101 #endif
102
103 #if TIME_WITH_SYS_TIME
104 # include <sys/time.h>
105 # include <time.h>
106 #else
107 # if HAVE_SYS_TIME_H
108 #  include <sys/time.h>
109 # else
110 #  include <time.h>
111 # endif
112 #endif
113
114 #if HAVE_UTIME_H
115 #include <utime.h>
116 #else
117 struct utimbuf {
118     time_t actime;
119     time_t modtime;
120 };
121 int utime(const char *, struct utimbuf *);
122 #endif
123
124 #if HAVE_DIRENT_H
125 # include <dirent.h>
126 # define NAMLEN(dirent) strlen((dirent)->d_name)
127 #else
128 # define dirent direct
129 # define NAMLEN(dirent) (dirent)->d_namlen
130 # if HAVE_SYS_NDIR_H
131 #  include <sys/ndir.h>
132 # endif
133 # if HAVE_SYS_DIR_H
134 #  include <sys/dir.h>
135 # endif
136 # if HAVE_NDIR_H
137 #  include <ndir.h>
138 # endif
139 # ifdef NONSYSTEM_DIR_LIBRARY           /* no use ?? */
140 #  include "lhdir.h"
141 # endif
142 #endif
143
144 #if HAVE_FNMATCH_H
145 # include <fnmatch.h>
146 #else
147 int fnmatch(const char *pattern, const char *string, int flags);
148 # define FNM_PATHNAME 1
149 # define FNM_NOESCAPE 2
150 # define FNM_PERIOD   4
151 #endif
152
153 #if HAVE_LIBAPPLEFILE
154 #include <applefile.h>
155 #endif
156
157 #ifdef __DJGPP__
158 #include <io.h>
159 #endif /* __DJGPP__ */
160
161 #ifndef SEEK_SET
162 #define SEEK_SET        0
163 #define SEEK_CUR        1
164 #define SEEK_END        2
165 #endif  /* SEEK_SET */
166
167 #if HAVE_LIMITS_H
168 #include <limits.h>
169 #else
170
171 #ifndef CHAR_BIT
172 #define CHAR_BIT 8
173 #endif
174
175 #ifndef UCHAR_MAX
176 #define UCHAR_MAX ((1<<(sizeof(unsigned char)*8))-1)
177 #endif
178
179 #ifndef USHRT_MAX
180 #define USHRT_MAX ((1<<(sizeof(unsigned short)*8))-1)
181 #endif
182
183 #ifndef SHRT_MAX
184 #define SHRT_MAX ((1<<(sizeof(short)*8-1))-1)
185 #endif
186
187 #ifndef SHRT_MIN
188 #define SHRT_MIN (SHRT_MAX-USHRT_MAX)
189 #endif
190
191 #ifndef ULONG_MAX
192 #define ULONG_MAX ((1<<(sizeof(unsigned long)*8))-1)
193 #endif
194
195 #ifndef LONG_MAX
196 #define LONG_MAX ((1<<(sizeof(long)*8-1))-1)
197 #endif
198
199 #ifndef LONG_MIN
200 #define LONG_MIN (LONG_MAX-ULONG_MAX)
201 #endif
202
203 #endif /* HAVE_LIMITS_H */
204
205 #if !HAVE_FSEEKO
206 # define fseeko  fseek
207 #endif
208 #if !HAVE_FTELLO
209 # define ftello  ftell
210 #endif
211
212 #include "lha_macro.h"
213
214 #define exit(n) lha_exit(n)
215
216 struct encode_option {
217 #if defined(__STDC__) || defined(AIX)
218     void            (*output) ();
219     void            (*encode_start) ();
220     void            (*encode_end) ();
221 #else
222     int             (*output) ();
223     int             (*encode_start) ();
224     int             (*encode_end) ();
225 #endif
226 };
227
228 struct decode_option {
229     unsigned short  (*decode_c) ();
230     unsigned short  (*decode_p) ();
231 #if defined(__STDC__) || defined(AIX)
232     void            (*decode_start) ();
233 #else
234     int             (*decode_start) ();
235 #endif
236 };
237
238 /* ------------------------------------------------------------------------ */
239 /*  LHa File Type Definition                                                */
240 /* ------------------------------------------------------------------------ */
241 typedef int boolean;            /* TRUE or FALSE */
242
243 struct string_pool {
244     int             used;
245     int             size;
246     int             n;
247     char           *buffer;
248 };
249
250 typedef struct LzHeader {
251     size_t          header_size;
252     int             size_field_length;
253     char            method[METHOD_TYPE_STORAGE];
254     off_t           packed_size;
255     off_t           original_size;
256     unsigned char   attribute;
257     unsigned char   header_level;
258     char            name[FILENAME_LENGTH];
259     char            realname[FILENAME_LENGTH];/* real name for symbolic link */
260     unsigned int    crc;      /* file CRC */
261     boolean         has_crc;  /* file CRC */
262     unsigned int    header_crc; /* header CRC */
263     unsigned char   extend_type;
264     unsigned char   minor_version;
265
266     /* extend_type == EXTEND_UNIX  and convert from other type. */
267     time_t          unix_last_modified_stamp;
268     unsigned short  unix_mode;
269     unsigned short  unix_uid;
270     unsigned short  unix_gid;
271     char            user[256];
272     char            group[256];
273 }  LzHeader;
274
275 struct interfacing {
276     FILE            *infile;
277     FILE            *outfile;
278     off_t           original;
279     off_t           packed;
280     off_t           read_size;
281     int             dicbit;
282     int             method;
283 };
284
285
286 /* ------------------------------------------------------------------------ */
287 /*  Option switch variable                                                  */
288 /* ------------------------------------------------------------------------ */
289 #ifdef LHA_MAIN_SRC
290 #define EXTERN
291 #else
292 #define EXTERN extern
293 #endif
294
295 /* command line options (common options) */
296 EXTERN boolean  quiet;
297 EXTERN boolean  text_mode;
298 EXTERN boolean  verbose;
299 EXTERN boolean  noexec;     /* debugging option */
300 EXTERN boolean  force;
301 EXTERN boolean  timestamp_archive;
302 EXTERN boolean  delete_after_append;
303 EXTERN int      compress_method;
304 EXTERN int      header_level;
305 /* EXTERN int       quiet_mode; */   /* 1996.8.13 t.okamoto */
306 #ifdef EUC
307 EXTERN boolean  euc_mode;
308 #endif
309
310 /* list command flags */
311 EXTERN boolean  verbose_listing;
312
313 /* extract/print command flags */
314 EXTERN boolean  output_to_stdout;
315
316 /* add/update/delete command flags */
317 EXTERN boolean  new_archive;
318 EXTERN boolean  update_if_newer;
319 EXTERN boolean  generic_format;
320
321 EXTERN boolean  remove_temporary_at_error;
322 EXTERN boolean  recover_archive_when_interrupt;
323 EXTERN boolean  remove_extracting_file_when_interrupt;
324 EXTERN boolean  get_filename_from_stdin;
325 EXTERN boolean  ignore_directory;
326 EXTERN char   **exclude_files;
327 EXTERN boolean  verify_mode;
328
329 /* Indicator flag */
330 EXTERN int      quiet_mode;
331
332 EXTERN boolean backup_old_archive;
333 EXTERN boolean extract_broken_archive;
334 EXTERN boolean decode_macbinary_contents;
335
336 /* for debugging */
337 EXTERN boolean sort_contents;
338 EXTERN boolean recursive_archiving;
339 EXTERN boolean dump_lzss;
340
341
342 /* ------------------------------------------------------------------------ */
343 /*  Globale Variable                                                        */
344 /* ------------------------------------------------------------------------ */
345 EXTERN char     **cmd_filev;
346 EXTERN int      cmd_filec;
347
348 EXTERN char     *archive_name;
349 EXTERN char     temporary_name[FILENAME_LENGTH];
350 EXTERN char     backup_archive_name[FILENAME_LENGTH];
351
352 EXTERN char     *extract_directory;
353 EXTERN char     *reading_filename, *writing_filename;
354
355 EXTERN int      archive_file_mode;
356 EXTERN int      archive_file_gid;
357
358 EXTERN int      convertcase;    /* 2000.10.6 */
359
360 /* slide.c */
361 EXTERN int      unpackable;
362 EXTERN off_t origsize, compsize;
363 EXTERN unsigned short dicbit;
364 EXTERN unsigned short maxmatch;
365 EXTERN off_t decode_count;
366 EXTERN unsigned long loc;           /* short -> long .. Changed N.Watazaki */
367 EXTERN unsigned char *text;         /* encoding buffer */
368 EXTERN unsigned char *dtext;        /* decoding buffer */
369
370 /* huf.c */
371 #ifndef LHA_MAIN_SRC  /* t.okamoto 96/2/20 */
372 EXTERN unsigned short left[], right[];
373 EXTERN unsigned char c_len[], pt_len[];
374 EXTERN unsigned short c_freq[], c_table[], c_code[];
375 EXTERN unsigned short p_freq[], pt_table[], pt_code[], t_freq[];
376 #endif
377
378 /* bitio.c */
379 EXTERN FILE     *infile, *outfile;
380 EXTERN unsigned short bitbuf;
381
382 /* crcio.c */
383 EXTERN unsigned int crctable[UCHAR_MAX + 1];
384 EXTERN int      dispflg;
385
386 /* from dhuf.c */
387 EXTERN unsigned int n_max;
388
389 /* lhadd.c */
390 EXTERN int temporary_fd;
391
392 /* ------------------------------------------------------------------------ */
393 /*  Functions                                                               */
394 /* ------------------------------------------------------------------------ */
395 #include "prototypes.h"