home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / unarj.zip / src / unarj.h < prev    next >
C/C++ Source or Header  |  1997-11-15  |  14KB  |  448 lines

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