home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / GNUNARJ.ZIP / UNARJ.H < prev   
Text File  |  1992-06-02  |  12KB  |  403 lines

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