OSDN Git Service

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