home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / UNARJ.LZH / UNARJ.H < prev   
Text File  |  1991-05-30  |  10KB  |  377 lines

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