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