home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / unarj32.lzh / unarj.h < prev    next >
C/C++ Source or Header  |  1993-06-04  |  14KB  |  444 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 OS                  0           /* ??? */
  131. #define PATH_SEPARATORS     "\\:"
  132. #define PATH_CHAR           '\\'
  133. #define SWITCH_CHARS        "-/"
  134. #define MAXSFX              25000L
  135. #define ARJ_SUFFIX          ".ARJ"
  136. #endif
  137.  
  138. #ifdef __CI
  139. #define PRIME               1
  140. #define OS                  1
  141. #define PATH_SEPARATORS     ">"
  142. #define PATH_CHAR           '>'
  143. #define FIX_PARITY(c)       c |= ~ASCII_MASK
  144. #define DEFAULT_DIR         "*>"
  145. #define ARJ_SUFFIX          ".ARJ"
  146. #endif
  147.  
  148. /* Error levels */
  149.  
  150. #ifndef ERROR_DEFINES
  151.  
  152. #define ERROR_OK        0       /* success */
  153. #define ERROR_WARN      1       /* minor problem (file not found) */
  154. #define ERROR_FAIL      2       /* fatal error */
  155. #define ERROR_CRC       3       /* CRC error */
  156. #define ERROR_SECURE    4       /* ARJ security invalid or not found */
  157. #define ERROR_WRITE     5       /* disk full */
  158. #define ERROR_OPEN      6       /* can't open file */
  159. #define ERROR_USER      7       /* user specified bad parameters */
  160. #define ERROR_MEMORY    8       /* not enough memory */
  161.  
  162. #endif
  163.  
  164. #ifndef MAXSFX              /* size of self-extracting prefix */
  165. #define MAXSFX              500000L
  166. #endif
  167. #ifndef FNAME_MAX
  168. #define FNAME_MAX           512
  169. #endif
  170. #ifndef SWITCH_CHARS
  171. #define SWITCH_CHARS        "-"
  172. #endif
  173. #ifndef FIX_PARITY
  174. #define FIX_PARITY(c)       c &= ASCII_MASK
  175. #endif
  176. #ifndef ARJ_SUFFIX
  177. #define ARJ_SUFFIX          ".arj"
  178. #endif
  179. #ifndef ARJ_DOT
  180. #define ARJ_DOT             '.'
  181. #endif
  182. #ifndef DEFAULT_DIR
  183. #define DEFAULT_DIR         ""
  184. #endif
  185. #ifndef OS
  186. #define OS                  2
  187. #endif
  188. #ifndef PATH_SEPARATORS
  189. #define PATH_SEPARATORS     "/"
  190. #endif
  191. #ifndef PATH_CHAR
  192. #define PATH_CHAR           '/'
  193. #endif
  194.  
  195. /* ********************************************************* */
  196. /* end of environmental defines                              */
  197. /* ********************************************************* */
  198.  
  199. /* ********************************************************* */
  200. /*
  201. /* Structure of archive main header (low order byte first):
  202. /*
  203. /*  2  header id (comment and local file) = 0x60, 0xEA
  204. /*  2  basic header size (from 'first_hdr_size' thru 'comment' below)
  205. /*         = first_hdr_size + strlen(filename) + 1 + strlen(comment) + 1
  206. /*         = 0 if end of archive
  207. /*
  208. /*  1  first_hdr_size (size up to 'extra data')
  209. /*  1  archiver version number
  210. /*  1  minimum archiver version to extract
  211. /*  1  host OS     (0 = MSDOS, 1 = PRIMOS, 2 = UNIX, 3 = AMIGA, 4 = MACDOS)
  212. /*               (5 = OS/2, 6 = APPLE GS, 7 = ATARI ST, 8 = NEXT)
  213. /*               (9 = VAX VMS)
  214. /*  1  arj flags (0x01 = GARBLED_FLAG, 0x02 = OLD_SECURED_FLAG)
  215. /*               (0x04 = VOLUME_FLAG,  0x08 = EXTFILE_FLAG)
  216. /*               (0x10 = PATHSYM_FLAG, 0x20 = BACKUP_FLAG)
  217. /*               (0x40 = SECURED_FLAG)
  218. /*  1  arj security version (2 = current)
  219. /*  1  file type            (2 = comment header)
  220. /*  1  ?                   ]
  221. /*  4  date time stamp created
  222. /*  4  date time stamp modified
  223. /*  4  archive size up to the end of archive marker
  224. /*  4  file position of security envelope data
  225. /*  2  entryname position in filename
  226. /*  2  length in bytes of trailing security data
  227. /*  2  host data
  228. /*  ?  extra data
  229. /*
  230. /*  ?  archive filename (null-terminated)
  231. /*  ?  archive comment  (null-terminated)
  232. /*
  233. /*  4  basic header CRC
  234. /*
  235. /*  2  1st extended header size (0 if none)
  236. /*  ?  1st extended header
  237. /*  4  1st extended header's CRC
  238. /*  ...
  239. /*
  240. /*
  241. /* Structure of archive file header (low order byte first):
  242. /*
  243. /*  2  header id (comment and local file) = 0x60, 0xEA
  244. /*  2  basic header size (from 'first_hdr_size' thru 'comment' below)
  245. /*         = first_hdr_size + strlen(filename) + 1 + strlen(comment) + 1
  246. /*         = 0 if end of archive
  247. /*
  248. /*  1  first_hdr_size (size up to 'extra data')
  249. /*  1  archiver version number
  250. /*  1  minimum archiver version to extract
  251. /*  1  host OS     (0 = MSDOS, 1 = PRIMOS, 2 = UNIX, 3 = AMIGA, 4 = MACDOS)
  252. /*               (5 = OS/2, 6 = APPLE GS, 7 = ATARI ST, 8 = NEXT)
  253. /*               (9 = VAX VMS)
  254. /*  1  arj flags (0x01 = GARBLED_FLAG, 0x02 = NOT USED)
  255. /*               (0x04 = VOLUME_FLAG,  0x08 = EXTFILE_FLAG)
  256. /*               (0x10 = PATHSYM_FLAG, 0x20 = BACKUP_FLAG)
  257. /*               (0x40 = NOT USED)
  258. /*  1  method    (0 = stored, 1 = compressed most ... 4 compressed fastest)
  259. /*  1  file type (0 = binary, 1 = text, 2 = comment header, 3 = directory)
  260. /*               (4 = label)
  261. /*  1  garble password modifier
  262. /*  4  date time stamp modified
  263. /*  4  compressed size
  264. /*  4  original size
  265. /*  4  original file's CRC
  266. /*  2  entryname position in filename
  267. /*  2  file access mode
  268. /*  2  host data
  269. /*  ?  extra data
  270. /*     4 bytes for extended file position
  271. /*
  272. /*  ?  filename (null-terminated)
  273. /*  ?  comment    (null-terminated)
  274. /*
  275. /*  4  basic header CRC
  276. /*
  277. /*  2  1st extended header size (0 if none)
  278. /*  ?  1st extended header
  279. /*  4  1st extended header's CRC
  280. /*  ...
  281. /*  ?  compressed file
  282. /*
  283. /* ********************************************************* */
  284. /* ********************************************************* */
  285. /*                                                           */
  286. /*     Time stamp format:                                    */
  287. /*                                                           */
  288. /*      31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16      */
  289. /*     |<---- year-1980 --->|<- month ->|<--- day ---->|     */
  290. /*                                                           */
  291. /*      15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0      */
  292. /*     |<--- hour --->|<---- minute --->|<- second/2 ->|     */
  293. /*                                                           */
  294. /* ********************************************************* */
  295.  
  296. #define CODE_BIT          16
  297.  
  298. #define NULL_CHAR       '\0'
  299. #define MAXMETHOD          4
  300.  
  301. #define ARJ_VERSION        3
  302. #define ARJ_M_VERSION      6    /* ARJ version that supports modified date. */
  303. #define ARJ_X_VERSION      3    /* decoder version */
  304. #define ARJ_X1_VERSION     1
  305. #define DEFAULT_METHOD     1
  306. #define DEFAULT_TYPE       0    /* if type_sw is selected */
  307. #define HEADER_ID     0xEA60
  308. #define HEADER_ID_HI    0xEA
  309. #define HEADER_ID_LO    0x60
  310. #define FIRST_HDR_SIZE    30
  311. #define FIRST_HDR_SIZE_V  34
  312. #define COMMENT_MAX     2048
  313. #define HEADERSIZE_MAX   (FIRST_HDR_SIZE + 10 + FNAME_MAX + COMMENT_MAX)
  314. #define BINARY_TYPE        0    /* This must line up with binary/text strings */
  315. #define TEXT_TYPE          1
  316. #define COMMENT_TYPE       2
  317. #define DIR_TYPE           3
  318. #define LABEL_TYPE         4
  319.  
  320. #define GARBLE_FLAG     0x01
  321. #define VOLUME_FLAG     0x04
  322. #define EXTFILE_FLAG    0x08
  323. #define PATHSYM_FLAG    0x10
  324. #define BACKUP_FLAG     0x20
  325.  
  326. typedef ulong UCRC;     /* CRC-32 */
  327.  
  328. #define CRC_MASK        0xFFFFFFFFL
  329.  
  330. #define ARJ_PATH_CHAR   '/'
  331.  
  332. #define FA_RDONLY       0x01            /* Read only attribute */
  333. #define FA_HIDDEN       0x02            /* Hidden file */
  334. #define FA_SYSTEM       0x04            /* System file */
  335. #define FA_LABEL        0x08            /* Volume label */
  336. #define FA_DIREC        0x10            /* Directory */
  337. #define FA_ARCH         0x20            /* Archive */
  338.  
  339. #define HOST_OS_NAMES1 "MS-DOS","PRIMOS","UNIX","AMIGA","MAC-OS","OS/2"
  340. #define HOST_OS_NAMES2 "APPLE GS","ATARI ST","NEXT","VAX VMS"
  341. #define HOST_OS_NAMES  { HOST_OS_NAMES1, HOST_OS_NAMES2, NULL }
  342.  
  343. /* Timestamp macros */
  344.  
  345. #define get_tx(m,d,h,n) (((ulong)m<<21)+((ulong)d<<16)+((ulong)h<<11)+(n<<5))
  346. #define get_tstamp(y,m,d,h,n,s) ((((ulong)(y-1980))<<25)+get_tx(m,d,h,n)+(s/2))
  347.  
  348. #define ts_year(ts)  ((uint)((ts >> 25) & 0x7f) + 1980)
  349. #define ts_month(ts) ((uint)(ts >> 21) & 0x0f)      /* 1..12 means Jan..Dec */
  350. #define ts_day(ts)   ((uint)(ts >> 16) & 0x1f)      /* 1..31 means 1st..31st */
  351. #define ts_hour(ts)  ((uint)(ts >> 11) & 0x1f)
  352. #define ts_min(ts)   ((uint)(ts >> 5) & 0x3f)
  353. #define ts_sec(ts)   ((uint)((ts & 0x1f) * 2))
  354.  
  355. /* unarj.c */
  356.  
  357. extern long origsize;
  358. extern long compsize;
  359.  
  360. extern UCRC crc;
  361.  
  362. extern FILE *arcfile;
  363. extern FILE *outfile;
  364.  
  365. extern ushort bitbuf;
  366.  
  367. extern uchar subbitbuf;
  368. extern uchar header[HEADERSIZE_MAX];
  369.  
  370. extern char arc_name[FNAME_MAX];
  371.  
  372. extern int bitcount;
  373. extern int file_type;
  374. extern int error_count;
  375.  
  376. /* Global functions */
  377.  
  378. /* unarj.c */
  379.  
  380. void   strlower OF((char *str));
  381. void   strupper OF((char *str));
  382. voidp  *malloc_msg OF((int size));
  383. void   disp_clock OF((void));
  384. void   error OF((char *fmt, char *arg));
  385. void   fillbuf OF((int n));
  386. ushort getbits OF((int n));
  387. void   fwrite_txt_crc OF((uchar *p, int n));
  388. void   init_getbits OF((void));
  389.  
  390. /* environ.c */
  391.  
  392. FILE   *file_open OF((char *name, char *mode));
  393. int    file_read OF((char *buf, int size, int nitems, FILE *stream));
  394. int    file_seek OF((FILE *stream, long offset, int mode));
  395. long   file_tell OF((FILE *stream));
  396. int    file_write OF((char *buf, int size, int nitems, FILE *stream));
  397. voidp  *xmalloc OF((int size));
  398. void   case_path OF((char *name));
  399. void   default_case_path OF((char *name));
  400. int    file_exists OF((char *name));
  401. void   get_mode_str OF((char *str, uint fmode));
  402. int    set_ftime_mode OF((char *name, ulong timestamp, uint fmode, uint host));
  403.  
  404. /* decode.c */
  405.  
  406. void   decode OF((void));
  407. void   decode_f OF((void));
  408.  
  409. /* Message strings */
  410.  
  411. extern char M_VERSION [];
  412.  
  413. extern char M_ARCDATE [];
  414. extern char M_ARCDATEM[];
  415. extern char M_BADCOMND[];
  416. extern char M_BADCOMNT[];
  417. extern char M_BADHEADR[];
  418. extern char M_BADTABLE[];
  419. extern char M_CANTOPEN[];
  420. extern char M_CANTREAD[];
  421. extern char M_CANTWRIT[];
  422. extern char M_CRCERROR[];
  423. extern char M_CRCOK   [];
  424. extern char M_DIFFHOST[];
  425. extern char M_ENCRYPT [];
  426. extern char M_ERRORCNT[];
  427. extern char M_EXTRACT [];
  428. extern char M_FEXISTS [];
  429. extern char M_HEADRCRC[];
  430. extern char M_NBRFILES[];
  431. extern char M_NOMEMORY[];
  432. extern char M_NOTARJ  [];
  433. extern char M_PROCARC [];
  434. extern char M_SKIPPED [];
  435. extern char M_SUFFIX  [];
  436. extern char M_TESTING [];
  437. extern char M_UNKNMETH[];
  438. extern char M_UNKNTYPE[];
  439. extern char M_UNKNVERS[];
  440.  
  441. #endif
  442.  
  443. /* end UNARJ.H */
  444.