OSDN Git Service

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