OSDN Git Service

* src/prototypes.h: updated.
[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 #ifndef SEEK_SET
154 #define SEEK_SET        0
155 #define SEEK_CUR        1
156 #define SEEK_END        2
157 #endif  /* SEEK_SET */
158
159 #if HAVE_LIMITS_H
160 #include <limits.h>
161 #else
162
163 #ifndef CHAR_BIT
164 #define CHAR_BIT 8
165 #endif
166
167 #ifndef UCHAR_MAX
168 #define UCHAR_MAX ((1<<(sizeof(unsigned char)*8))-1)
169 #endif
170
171 #ifndef USHRT_MAX
172 #define USHRT_MAX ((1<<(sizeof(unsigned short)*8))-1)
173 #endif
174
175 #ifndef SHRT_MAX
176 #define SHRT_MAX ((1<<(sizeof(short)*8-1))-1)
177 #endif
178
179 #ifndef SHRT_MIN
180 #define SHRT_MIN (SHRT_MAX-USHRT_MAX)
181 #endif
182
183 #ifndef ULONG_MAX
184 #define ULONG_MAX ((1<<(sizeof(unsigned long)*8))-1)
185 #endif
186
187 #ifndef LONG_MAX
188 #define LONG_MAX ((1<<(sizeof(long)*8-1))-1)
189 #endif
190
191 #ifndef LONG_MIN
192 #define LONG_MIN (LONG_MAX-ULONG_MAX)
193 #endif
194
195 #endif /* HAVE_LIMITS_H */
196
197 #if !HAVE_FSEEKO
198 # define fseeko  fseek
199 #endif
200 #if !HAVE_FTELLO
201 # define ftello  ftell
202 #endif
203
204 #include "lha_macro.h"
205
206 struct encode_option {
207 #if defined(__STDC__) || defined(AIX)
208     void            (*output) ();
209     void            (*encode_start) ();
210     void            (*encode_end) ();
211 #else
212     int             (*output) ();
213     int             (*encode_start) ();
214     int             (*encode_end) ();
215 #endif
216 };
217
218 struct decode_option {
219     unsigned short  (*decode_c) ();
220     unsigned short  (*decode_p) ();
221 #if defined(__STDC__) || defined(AIX)
222     void            (*decode_start) ();
223 #else
224     int             (*decode_start) ();
225 #endif
226 };
227
228 /* ------------------------------------------------------------------------ */
229 /*  LHa File Type Definition                                                */
230 /* ------------------------------------------------------------------------ */
231 typedef int boolean;            /* TRUE or FALSE */
232
233 struct string_pool {
234     int             used;
235     int             size;
236     int             n;
237     char           *buffer;
238 };
239
240 typedef struct LzHeader {
241     size_t          header_size;
242     int             size_field_length;
243     char            method[METHOD_TYPE_STORAGE];
244     size_t          packed_size;
245     size_t          original_size;
246     unsigned char   attribute;
247     unsigned char   header_level;
248     char            name[FILENAME_LENGTH];
249     char            realname[FILENAME_LENGTH];/* real name for symbolic link */
250     unsigned int    crc;      /* file CRC */
251     boolean         has_crc;  /* file CRC */
252     unsigned int    header_crc; /* header CRC */
253     unsigned char   extend_type;
254     unsigned char   minor_version;
255
256     /* extend_type == EXTEND_UNIX  and convert from other type. */
257     time_t          unix_last_modified_stamp;
258     unsigned short  unix_mode;
259     unsigned short  unix_uid;
260     unsigned short  unix_gid;
261     char            user[256];
262     char            group[256];
263 }  LzHeader;
264
265 struct interfacing {
266     FILE            *infile;
267     FILE            *outfile;
268     size_t          original;
269     size_t          packed;
270     size_t          read_size;
271     int             dicbit;
272     int             method;
273 };
274
275
276 /* ------------------------------------------------------------------------ */
277 /*  Option switch variable                                                  */
278 /* ------------------------------------------------------------------------ */
279 #ifdef LHA_MAIN_SRC
280 #define EXTERN
281 #else
282 #define EXTERN extern
283 #endif
284
285 /* command line options (common options) */
286 EXTERN boolean  quiet;
287 EXTERN boolean  text_mode;
288 EXTERN boolean  verbose;
289 EXTERN boolean  noexec;     /* debugging option */
290 EXTERN boolean  force;
291 EXTERN boolean  prof;
292 EXTERN boolean  delete_after_append;
293 EXTERN int      compress_method;
294 EXTERN int      header_level;
295 /* EXTERN int       quiet_mode; */   /* 1996.8.13 t.okamoto */
296 #ifdef EUC
297 EXTERN boolean  euc_mode;
298 #endif
299
300 /* list command flags */
301 EXTERN boolean  verbose_listing;
302
303 /* extract/print command flags */
304 EXTERN boolean  output_to_stdout;
305
306 /* add/update/delete command flags */
307 EXTERN boolean  new_archive;
308 EXTERN boolean  update_if_newer;
309 EXTERN boolean  generic_format;
310
311 EXTERN boolean  remove_temporary_at_error;
312 EXTERN boolean  recover_archive_when_interrupt;
313 EXTERN boolean  remove_extracting_file_when_interrupt;
314 EXTERN boolean  get_filename_from_stdin;
315 EXTERN boolean  ignore_directory;
316 EXTERN char   **exclude_files;
317 EXTERN boolean  verify_mode;
318
319 /* Indicator flag */
320 EXTERN int      quiet_mode;
321
322 EXTERN boolean backup_old_archive;
323 /* ------------------------------------------------------------------------ */
324 /*  Globale Variable                                                        */
325 /* ------------------------------------------------------------------------ */
326 EXTERN char     **cmd_filev;
327 EXTERN int      cmd_filec;
328
329 EXTERN char     *archive_name;
330 EXTERN char     temporary_name[FILENAME_LENGTH];
331 EXTERN char     backup_archive_name[FILENAME_LENGTH];
332
333 EXTERN char     *extract_directory;
334 EXTERN char     *reading_filename, *writing_filename;
335
336 EXTERN int      archive_file_mode;
337 EXTERN int      archive_file_gid;
338
339 EXTERN struct   interfacing interface;
340
341 EXTERN int      noconvertcase; /* 2000.10.6 */
342
343 /* slide.c */
344 EXTERN int      unpackable;
345 EXTERN size_t origsize, compsize;
346 EXTERN unsigned short dicbit;
347 EXTERN unsigned short maxmatch;
348 EXTERN size_t decode_count;
349 EXTERN unsigned long loc;           /* short -> long .. Changed N.Watazaki */
350 EXTERN unsigned char *text;
351
352 /* huf.c */
353 #ifndef LHA_MAIN_SRC  /* t.okamoto 96/2/20 */
354 EXTERN unsigned short left[], right[];
355 EXTERN unsigned char c_len[], pt_len[];
356 EXTERN unsigned short c_freq[], c_table[], c_code[];
357 EXTERN unsigned short p_freq[], pt_table[], pt_code[], t_freq[];
358 #endif
359
360 /* bitio.c */
361 EXTERN FILE     *infile, *outfile;
362 EXTERN unsigned short bitbuf;
363
364 /* crcio.c */
365 EXTERN unsigned int crctable[UCHAR_MAX + 1];
366 EXTERN int      dispflg;
367
368 /* from dhuf.c */
369 EXTERN unsigned int n_max;
370
371 /* lhadd.c */
372 EXTERN int temporary_fd;
373
374 /* ------------------------------------------------------------------------ */
375 /*  Functions                                                               */
376 /* ------------------------------------------------------------------------ */
377 #include "prototypes.h"