OSDN Git Service

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