-
Notifications
You must be signed in to change notification settings - Fork 0
/
unarj.h
445 lines (387 loc) · 13.1 KB
/
unarj.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
/* UNARJ.H, UNARJ, R JUNG, 07/29/96
* Include file
* Copyright (c) 1990-2002 ARJ Software, Inc. All rights reserved.
*
* This code may be freely used in programs that are NOT ARJ archivers
* (both compress and extract ARJ archives).
*
* If you wish to distribute a modified version of this program, you
* MUST indicate that it is a modified version both in the program and
* source code.
*
* If you modify this program, we would appreciate a copy of the new
* source code. we are holding the copyright on the source code, so
* please do not delete our name from the program files or from the
* documentation.
*
* Modification history:
* Date Programmer Description of modification.
* 04/05/91 R. Jung Rewrote code.
* 04/23/91 M. Adler Portabilized.
* 04/29/91 R. Jung Added volume label support.
* 05/30/91 R. Jung Added SEEK_END definition.
* 06/03/91 R. Jung Changed arguments in get_mode_str() and
* set_ftime_mode().
* 06/28/91 R. Jung Added new HOST OS numbers.
* 07/08/91 R. Jung Added default_case_path() and strlower().
* 07/21/91 R. Jung Fixed #endif _QC comment.
* 08/27/91 R. Jung Added #ifdef for COHERENT.
* 09/01/91 R. Jung Added new host names.
* 12/03/91 R. Jung Added BACKUP_FLAG.
* 04/06/92 R. Jung Added ARCHIMEDES.
* 02/17/93 R. Jung Improved ARJ header information. Added ARJ_M_VERSION.
* 01/22/94 R. Jung Changed copyright message.
* 07/29/96 R. Jung Added "/" to list of path separators.
*
*/
#ifndef _ARH_DEF_
#define _ARH_DEF_
/* Use prototypes and ANSI libraries if __STDC__ */
#ifdef __STDC__
# define MODERN
#endif /* __STDC__ */
/* Do not use prototypes for COHERENT */
#ifdef COHERENT
# undef MODERN
# define KEEP_WINDOW
#endif /* COHERENT */
/* Use prototypes and ANSI libraries if __TURBOC__ */
#ifdef __TURBOC__
# define MODERN
#endif /* __TURBOC__ */
/* Use prototypes and ANSI libraries if _QC */
#ifdef _QC
# define MODERN
#endif /* _QC */
/* Use prototypes and ANSI libraries if _OS2 */
#ifdef _OS2
# define MODERN
#endif /* _OS2 */
/* Used to remove arguments in function prototypes for non-ANSI C */
#ifdef MODERN
# define OF(a) a
#else /* !MODERN */
# define OF(a) ()
#endif /* ?MODERN */
#ifdef MODERN
typedef void voidp;
#else /* !MODERN */
# define void int
typedef char voidp;
#endif /* ?MODERN */
#include <stdio.h>
#ifdef MODERN
# include <limits.h>
#else /* !MODERN */
# ifndef UCHAR_MAX
# define UCHAR_MAX (255)
# endif
# ifndef CHAR_BIT
# define CHAR_BIT (8)
# endif
# ifndef LONG_MAX
# define LONG_MAX (0x7FFFFFFFL)
# endif
#endif /* ?MODERN */
#ifndef SEEK_SET
# define SEEK_SET 0
#endif
#ifndef SEEK_CUR
# define SEEK_CUR 1
#endif
#ifndef SEEK_END
# define SEEK_END 2
#endif
typedef unsigned char uchar; /* 8 bits or more */
typedef unsigned int uint; /* 16 - 32 bits or more */
typedef unsigned short ushort; /* 16 bits or more */
typedef unsigned long ulong; /* 32 bits or more */
#define USHRT_BIT (CHAR_BIT * sizeof(ushort))
/* ********************************************************* */
/* Environment definitions (implementation dependent) */
/* ********************************************************* */
#ifdef _QC
#define __MSDOS__
#endif
#ifdef __MSDOS__
#define OS 0
#define PATH_SEPARATORS "\\:/"
#define PATH_CHAR '\\'
#define MAXSFX 25000L
#define ARJ_SUFFIX ".ARJ"
#endif
#ifdef _OS2
#define OS 0 /* ??? */
#define PATH_SEPARATORS "\\:"
#define PATH_CHAR '\\'
#define SWITCH_CHARS "-/"
#define MAXSFX 25000L
#define ARJ_SUFFIX ".ARJ"
#endif
#ifdef __CI
#define PRIME 1
#define OS 1
#define PATH_SEPARATORS ">"
#define PATH_CHAR '>'
#define FIX_PARITY(c) c |= ~ASCII_MASK
#define DEFAULT_DIR "*>"
#define ARJ_SUFFIX ".ARJ"
#endif
/* Error levels */
#ifndef ERROR_DEFINES
#define ERROR_OK 0 /* success */
#define ERROR_WARN 1 /* minor problem (file not found) */
#define ERROR_FAIL 2 /* fatal error */
#define ERROR_CRC 3 /* CRC error */
#define ERROR_SECURE 4 /* ARJ security invalid or not found */
#define ERROR_WRITE 5 /* disk full */
#define ERROR_OPEN 6 /* can't open file */
#define ERROR_USER 7 /* user specified bad parameters */
#define ERROR_MEMORY 8 /* not enough memory */
#endif
#ifndef MAXSFX /* size of self-extracting prefix */
#define MAXSFX 500000L
#endif
#ifndef FNAME_MAX
#define FNAME_MAX 512
#endif
#ifndef SWITCH_CHARS
#define SWITCH_CHARS "-"
#endif
#ifndef FIX_PARITY
#define FIX_PARITY(c) c &= ASCII_MASK
#endif
#ifndef ARJ_SUFFIX
#define ARJ_SUFFIX ".arj"
#endif
#ifndef ARJ_DOT
#define ARJ_DOT '.'
#endif
#ifndef DEFAULT_DIR
#define DEFAULT_DIR ""
#endif
#ifndef OS
#define OS 2
#endif
#ifndef PATH_SEPARATORS
#define PATH_SEPARATORS "/"
#endif
#ifndef PATH_CHAR
#define PATH_CHAR '/'
#endif
/* ********************************************************* */
/* end of environmental defines */
/* ********************************************************* */
/* ********************************************************* */
/*
/* Structure of archive main header (low order byte first):
/*
/* 2 header id (comment and local file) = 0x60, 0xEA
/* 2 basic header size (from 'first_hdr_size' thru 'comment' below)
/* = first_hdr_size + strlen(filename) + 1 + strlen(comment) + 1
/* = 0 if end of archive
/*
/* 1 first_hdr_size (size up to 'extra data')
/* 1 archiver version number
/* 1 minimum archiver version to extract
/* 1 host OS (0 = MSDOS, 1 = PRIMOS, 2 = UNIX, 3 = AMIGA, 4 = MACDOS)
/* (5 = OS/2, 6 = APPLE GS, 7 = ATARI ST, 8 = NEXT)
/* (9 = VAX VMS)
/* 1 arj flags (0x01 = GARBLED_FLAG, 0x02 = OLD_SECURED_FLAG)
/* (0x04 = VOLUME_FLAG, 0x08 = EXTFILE_FLAG)
/* (0x10 = PATHSYM_FLAG, 0x20 = BACKUP_FLAG)
/* (0x40 = SECURED_FLAG)
/* 1 arj security version (2 = current)
/* 1 file type (2 = comment header)
/* 1 ? ]
/* 4 date time stamp created
/* 4 date time stamp modified
/* 4 archive size up to the end of archive marker
/* 4 file position of security envelope data
/* 2 entryname position in filename
/* 2 length in bytes of trailing security data
/* 2 host data
/* ? extra data
/*
/* ? archive filename (null-terminated)
/* ? archive comment (null-terminated)
/*
/* 4 basic header CRC
/*
/* 2 1st extended header size (0 if none)
/* ? 1st extended header
/* 4 1st extended header's CRC
/* ...
/*
/*
/* Structure of archive file header (low order byte first):
/*
/* 2 header id (comment and local file) = 0x60, 0xEA
/* 2 basic header size (from 'first_hdr_size' thru 'comment' below)
/* = first_hdr_size + strlen(filename) + 1 + strlen(comment) + 1
/* = 0 if end of archive
/*
/* 1 first_hdr_size (size up to 'extra data')
/* 1 archiver version number
/* 1 minimum archiver version to extract
/* 1 host OS (0 = MSDOS, 1 = PRIMOS, 2 = UNIX, 3 = AMIGA, 4 = MACDOS)
/* (5 = OS/2, 6 = APPLE GS, 7 = ATARI ST, 8 = NEXT)
/* (9 = VAX VMS)
/* 1 arj flags (0x01 = GARBLED_FLAG, 0x02 = NOT USED)
/* (0x04 = VOLUME_FLAG, 0x08 = EXTFILE_FLAG)
/* (0x10 = PATHSYM_FLAG, 0x20 = BACKUP_FLAG)
/* (0x40 = NOT USED)
/* 1 method (0 = stored, 1 = compressed most ... 4 compressed fastest)
/* 1 file type (0 = binary, 1 = text, 2 = comment header, 3 = directory)
/* (4 = label)
/* 1 garble password modifier
/* 4 date time stamp modified
/* 4 compressed size
/* 4 original size
/* 4 original file's CRC
/* 2 entryname position in filename
/* 2 file access mode
/* 2 host data
/* ? extra data
/* 4 bytes for extended file position
/*
/* ? filename (null-terminated)
/* ? comment (null-terminated)
/*
/* 4 basic header CRC
/*
/* 2 1st extended header size (0 if none)
/* ? 1st extended header
/* 4 1st extended header's CRC
/* ...
/* ? compressed file
/*
/* ********************************************************* */
/* ********************************************************* */
/* */
/* Time stamp format: */
/* */
/* 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 */
/* |<---- year-1980 --->|<- month ->|<--- day ---->| */
/* */
/* 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 */
/* |<--- hour --->|<---- minute --->|<- second/2 ->| */
/* */
/* ********************************************************* */
#define CODE_BIT 16
#define NULL_CHAR '\0'
#define MAXMETHOD 4
#define ARJ_VERSION 3
#define ARJ_M_VERSION 6 /* ARJ version that supports modified date. */
#define ARJ_X_VERSION 3 /* decoder version */
#define ARJ_X1_VERSION 1
#define DEFAULT_METHOD 1
#define DEFAULT_TYPE 0 /* if type_sw is selected */
#define HEADER_ID 0xEA60
#define HEADER_ID_HI 0xEA
#define HEADER_ID_LO 0x60
#define FIRST_HDR_SIZE 30
#define FIRST_HDR_SIZE_V 34
#define COMMENT_MAX 2048
#define HEADERSIZE_MAX (FIRST_HDR_SIZE + 10 + FNAME_MAX + COMMENT_MAX)
#define BINARY_TYPE 0 /* This must line up with binary/text strings */
#define TEXT_TYPE 1
#define COMMENT_TYPE 2
#define DIR_TYPE 3
#define LABEL_TYPE 4
#define GARBLE_FLAG 0x01
#define VOLUME_FLAG 0x04
#define EXTFILE_FLAG 0x08
#define PATHSYM_FLAG 0x10
#define BACKUP_FLAG 0x20
typedef ulong UCRC; /* CRC-32 */
#define CRC_MASK 0xFFFFFFFFL
#define ARJ_PATH_CHAR '/'
#define FA_RDONLY 0x01 /* Read only attribute */
#define FA_HIDDEN 0x02 /* Hidden file */
#define FA_SYSTEM 0x04 /* System file */
#define FA_LABEL 0x08 /* Volume label */
#define FA_DIREC 0x10 /* Directory */
#define FA_ARCH 0x20 /* Archive */
#define HOST_OS_NAMES1 "MS-DOS","PRIMOS","UNIX","AMIGA","MAC-OS","OS/2"
#define HOST_OS_NAMES2 "APPLE GS","ATARI ST","NEXT","VAX VMS"
#define HOST_OS_NAMES { HOST_OS_NAMES1, HOST_OS_NAMES2, NULL }
/* Timestamp macros */
#define get_tx(m,d,h,n) (((ulong)m<<21)+((ulong)d<<16)+((ulong)h<<11)+(n<<5))
#define get_tstamp(y,m,d,h,n,s) ((((ulong)(y-1980))<<25)+get_tx(m,d,h,n)+(s/2))
#define ts_year(ts) ((uint)((ts >> 25) & 0x7f) + 1980)
#define ts_month(ts) ((uint)(ts >> 21) & 0x0f) /* 1..12 means Jan..Dec */
#define ts_day(ts) ((uint)(ts >> 16) & 0x1f) /* 1..31 means 1st..31st */
#define ts_hour(ts) ((uint)(ts >> 11) & 0x1f)
#define ts_min(ts) ((uint)(ts >> 5) & 0x3f)
#define ts_sec(ts) ((uint)((ts & 0x1f) * 2))
/* unarj.c */
extern long origsize;
extern long compsize;
extern UCRC crc;
extern FILE *arcfile;
extern FILE *outfile;
extern ushort bitbuf;
extern uchar subbitbuf;
extern uchar header[HEADERSIZE_MAX];
extern char arc_name[FNAME_MAX];
extern int bitcount;
extern int file_type;
extern int error_count;
/* Global functions */
/* unarj.c */
void strlower OF((char *str));
void strupper OF((char *str));
voidp *malloc_msg OF((int size));
void disp_clock OF((void));
void error OF((char *fmt, char *arg));
void fillbuf OF((int n));
ushort getbits OF((int n));
void fwrite_txt_crc OF((uchar *p, int n));
void init_getbits OF((void));
/* environ.c */
FILE *file_open OF((char *name, char *mode));
int file_read OF((char *buf, int size, int nitems, FILE *stream));
int file_seek OF((FILE *stream, long offset, int mode));
long file_tell OF((FILE *stream));
int file_write OF((char *buf, int size, int nitems, FILE *stream));
voidp *xmalloc OF((int size));
void case_path OF((char *name));
void default_case_path OF((char *name));
int file_exists OF((char *name));
void get_mode_str OF((char *str, uint fmode));
int set_ftime_mode OF((char *name, ulong timestamp, uint fmode, uint host));
/* decode.c */
void decode OF((void));
void decode_f OF((void));
/* Message strings */
extern char M_VERSION [];
extern char M_ARCDATE [];
extern char M_ARCDATEM[];
extern char M_BADCOMND[];
extern char M_BADCOMNT[];
extern char M_BADHEADR[];
extern char M_BADTABLE[];
extern char M_CANTOPEN[];
extern char M_CANTREAD[];
extern char M_CANTWRIT[];
extern char M_CRCERROR[];
extern char M_CRCOK [];
extern char M_DIFFHOST[];
extern char M_ENCRYPT [];
extern char M_ERRORCNT[];
extern char M_EXTRACT [];
extern char M_FEXISTS [];
extern char M_HEADRCRC[];
extern char M_NBRFILES[];
extern char M_NOMEMORY[];
extern char M_NOTARJ [];
extern char M_PROCARC [];
extern char M_SKIPPED [];
extern char M_SUFFIX [];
extern char M_TESTING [];
extern char M_UNKNMETH[];
extern char M_UNKNTYPE[];
extern char M_UNKNVERS[];
#endif
/* end UNARJ.H */