home *** CD-ROM | disk | FTP | other *** search
/ Computer Club Elmshorn Atari PD / CCE_PD.iso / pc / 0500 / CCE_0534.ZIP / CCE_0534.PD / UNARJ_ST.230 / UNARJ.H < prev    next >
C/C++ Source or Header  |  1992-10-05  |  12KB  |  401 lines

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