home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1992 / TheOrigSharewareV1.cdr / 25 / arj200.exe / arj / UNARJ.ARJ / UNARJ.H < prev   
C/C++ Source or Header  |  1991-04-05  |  9KB  |  320 lines

  1. /* UNARJ.H, UNARJ, R JUNG, 04/05/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. /* Modification history:
  8. /* Date      Programmer  Description of modification.
  9. /* 04/05/91  R. Jung     Rewrote code.
  10. /*
  11.  */
  12.  
  13. #ifndef _ARH_DEF_
  14. #define _ARH_DEF_
  15.  
  16. #include <stdio.h>
  17. #include <limits.h>
  18.  
  19. typedef unsigned char  uchar;    /*  8 bits or more */
  20. typedef unsigned int   uint;    /* 16 - 32 bits or more */
  21. typedef unsigned short ushort;    /* 16 bits or more */
  22. typedef unsigned long  ulong;    /* 32 bits or more */
  23.  
  24. #define USHRT_BIT   (CHAR_BIT * sizeof(ushort))
  25.  
  26. /* ********************************************************* */
  27. /* Environment definitions (implementation dependent)        */
  28. /* ********************************************************* */
  29.  
  30. #ifdef _QC
  31. #define __MSDOS__
  32. #endif
  33.  
  34. #ifdef __MSDOS__
  35. #define OS            0
  36. #define WILDSTRING        "?*"
  37. #define WILD_COMPONENT        '*'
  38. #define WILD_CHAR        '?'
  39. #define WILD_ANY        "*.*"
  40. #define PATH_SEPARATORS     "\\:"
  41. #define PATH_CHAR           '\\'
  42. #define SWITCH_CHARS        "-/"
  43. #define MAXSFX              25000L
  44. #endif
  45.  
  46. #ifdef __CI
  47. #define PRIME               1
  48. #define OS                  1
  49. #define WILDSTRING          "@+^"
  50. #define WILD_COMPONENT      '@'
  51. #define WILD_CHAR           '+'
  52. #define WILD_ANY            "@@"
  53. #define PATH_SEPARATORS     ">"
  54. #define PATH_CHAR           '>'
  55. #define ARJ_ENVSTR          ".ARJ_SW"
  56. #define LINES_PER_PAGE      24
  57. #define FIX_PARITY(c)       c |= ~ASCII_MASK
  58. #define DEFAULT_DIR         "*>"
  59. #endif
  60.  
  61. /* Error levels */
  62.  
  63. #ifndef ERROR_DEFINES
  64.  
  65. #define ERROR_OK        0       /* success */
  66. #define ERROR_WARN      1       /* minor problem (file not found) */
  67. #define ERROR_FAIL      2       /* fatal error */
  68. #define ERROR_CRC       3       /* CRC error */
  69. #define ERROR_SECURE    4       /* ARJ security invalid or not found */
  70. #define ERROR_WRITE     5       /* disk full */
  71. #define ERROR_OPEN      6       /* can't open file */
  72. #define ERROR_USER      7       /* user specified bad parameters */
  73. #define ERROR_MEMORY    8       /* not enough memory */
  74.  
  75. #endif
  76.  
  77. #ifndef MAXSFX            /* size of self-extracting prefix */
  78. #define MAXSFX            500000L
  79. #endif
  80. #ifndef FNAME_MAX
  81. #define FNAME_MAX        512
  82. #endif
  83. #ifndef SWITCH_CHARS
  84. #define SWITCH_CHARS        "-"
  85. #endif
  86. #ifndef FIX_PARITY
  87. #define FIX_PARITY(c)        c &= ASCII_MASK
  88. #endif
  89. #ifndef ARJ_SUFFIX
  90. #define ARJ_SUFFIX        ".ARJ"
  91. #endif
  92. #ifndef BAK_SUFFIX
  93. #define BAK_SUFFIX        ".BAK"
  94. #endif
  95. #ifndef ARJ_TEMP
  96. #define ARJ_TEMP            "ARJTEMP.$??"
  97. #endif
  98. #ifndef ARJ_TEMPLATE
  99. #define ARJ_TEMPLATE        "ARJTEMP.$%02d"     /* related to ARJ_TEMP */
  100. #endif
  101. #ifndef ARJSORT_TEMP
  102. #define ARJSORT_TEMP        "ARJSORT.$$$"
  103. #endif
  104. #ifndef ARJ_ENVSTR
  105. #define ARJ_ENVSTR        "ARJ_SW"
  106. #endif
  107. #ifndef ARJ_DOT
  108. #define ARJ_DOT         '.'
  109. #endif
  110. #ifndef ARCHIVE_SUFFIXES
  111. #define ARCHIVE_SUFFIXES    ".ARJ.ZIP.PAK.ARC.LZH"
  112. #endif
  113. #ifndef LINES_PER_PAGE
  114. #define LINES_PER_PAGE        24
  115. #endif
  116. #ifndef WILDSTRING
  117. #define WILDSTRING        "?*"
  118. #endif
  119. #ifndef WILD_COMPONENT
  120. #define WILD_COMPONENT        '*'
  121. #endif
  122. #ifndef WILD_CHAR
  123. #define WILD_CHAR        '?'
  124. #endif
  125. #ifndef WILD_ANY
  126. #define WILD_ANY        "*.*"
  127. #endif
  128. #ifndef NOT_MATCH_ANY
  129. #define NOT_MATCH_ANY       "..."
  130. #endif
  131. #ifndef LIST_CHAR
  132. #define LIST_CHAR        '!'
  133. #endif
  134. #ifndef DEFAULT_DIR
  135. #define DEFAULT_DIR        ""
  136. #endif
  137.  
  138. /* ********************************************************* */
  139. /* end of environmental defines                              */
  140. /* ********************************************************* */
  141.  
  142. /* ********************************************************* */
  143. /*
  144. /* Structure of archive block (low order byte first):
  145. /*
  146. /*  2  header id (comment and local file) = 0xEA60 or 60000U
  147. /*  2  basic header size (from 'first_hdr_size' thru 'comment' below)
  148. /*         = first_hdr_size + strlen(filename) + 1 + strlen(comment) + 1
  149. /*         = 0 if end of archive
  150. /*
  151. /*  1  first_hdr_size (size up to 'extra data')
  152. /*  1  archiver version number
  153. /*  1  minimum archiver version to extract
  154. /*  1  host OS     (0 = MSDOS, 1 = PRIMOS, 2 = UNIX, 3 = AMIGA, 4 = MACDOS)
  155. /*  1  arj flags (0x01 = GARBLED_FLAG, 0x02 = RESERVED)
  156. /*               (0x04 = VOLUME_FLAG,  0x08 = EXTFILE_FLAG)
  157. /*               (0x10 = PATHSYM_FLAG)
  158. /*  1  method    (0 = stored, 1 = compressed most ... 4 compressed fastest)
  159. /*  1  file type (0 = binary, 1 = text, 2 = comment header)
  160. /*  1  garble password modifier
  161. /*  4  date time stamp modified
  162. /*  4  compressed size
  163. /*  4  original size
  164. /*  4  original file's CRC
  165. /*  2  entryname position in filename
  166. /*  2  file access mode
  167. /*  2  host data
  168. /*  ?  extra data
  169. /*     4 bytes for extended file position
  170. /*
  171. /*  ?  filename (null-terminated)
  172. /*  ?  comment    (null-terminated)
  173. /*
  174. /*  4  basic header CRC
  175. /*
  176. /*  2  1st extended header size (0 if none)
  177. /*  ?  1st extended header
  178. /*  4  1st extended header's CRC
  179. /*  ...
  180. /*  ?  compressed file
  181. /*
  182. /* ********************************************************* */
  183.  
  184. /* ********************************************************* */
  185. /*                                 */
  186. /*     Time stamp format:                     */
  187. /*                                 */
  188. /*    31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16      */
  189. /*     |<---- year-1980 --->|<- month ->|<--- day ---->|     */
  190. /*                                 */
  191. /*    15 14 13 12 11 10  9  8  7  6  5  4  3    2  1  0      */
  192. /*     |<--- hour --->|<---- minute --->|<- second/2 ->|     */
  193. /*                                 */
  194. /* ********************************************************* */
  195.  
  196. #define CODE_BIT          16
  197.  
  198. #define NULL_CHAR    '\0'
  199. #define MAXMETHOD       4
  200.  
  201. #define ARJ_VERSION        3
  202. #define ARJ_X_VERSION      3    /* decoder version */
  203. #define ARJ_X1_VERSION     1
  204. #define DEFAULT_METHOD       1
  205. #define DEFAULT_TYPE       0    /* if type_sw is selected */
  206. #define HEADER_ID     0xEA60U
  207. #define HEADER_ID_HI    0xEA
  208. #define HEADER_ID_LO    0x60
  209. #define FIRST_HDR_SIZE      30
  210. #define FIRST_HDR_SIZE_V  34
  211. #define COMMENT_MAX     2048
  212. #define HEADERSIZE_MAX     (FIRST_HDR_SIZE + 10 + FNAME_MAX + COMMENT_MAX)
  213. #define BINARY_TYPE       0    /* This must line up with binary/text strings */
  214. #define TEXT_TYPE       1
  215. #define COMMENT_TYPE       2
  216. #define DIR_TYPE           3
  217.  
  218. #define GARBLE_FLAG     0x01
  219. #define VOLUME_FLAG    0x04
  220. #define EXTFILE_FLAG    0x08
  221. #define PATHSYM_FLAG    0x10
  222.  
  223. typedef ulong UCRC;    /* CRC-32 */
  224.  
  225. #define CRC_MASK        0xFFFFFFFFUL
  226.  
  227. #define ARJ_PATH_CHAR   '/'
  228.  
  229. /* Timestamp macros */
  230.  
  231. #define get_tstamp(yy, mm, dd, hr, mn, sc) \
  232.     ( (((ulong)(yy - 1980)) << 25) + ((ulong)mm << 21) + ((ulong)dd << 16) + \
  233.     ((ulong)hr << 11) + (mn << 5) + (sc / 2) )
  234.  
  235. #define ts_year(ts)  ((uint)((ts >> 25) & 0x7f) + 1980)
  236. #define ts_month(ts) ((uint)(ts >> 21) & 0x0f)        /* 1..12 means Jan..Dec */
  237. #define ts_day(ts)   ((uint)(ts >> 16) & 0x1f)        /* 1..31 means 1st..31st */
  238. #define ts_hour(ts)  ((uint)(ts >> 11) & 0x1f)
  239. #define ts_min(ts)   ((uint)(ts >> 5) & 0x3f)
  240. #define ts_sec(ts)   ((uint)((ts & 0x1f) * 2))
  241.  
  242. /* unarj.c */
  243.  
  244. extern long origsize;
  245. extern long compsize;
  246.  
  247. extern UCRC crc;
  248.  
  249. extern FILE *arcfile;
  250. extern FILE *outfile;
  251.  
  252. extern ushort bitbuf;
  253.  
  254. extern uchar subbitbuf;
  255. extern uchar header[HEADERSIZE_MAX];
  256.  
  257. extern char arc_name[FNAME_MAX];
  258.  
  259. extern int bitcount;
  260. extern int file_type;
  261. extern int error_count;
  262.  
  263. void   strupper(char *str);
  264. void   *malloc_msg(size_t size);
  265. void   error(char *fmt, ...);
  266. void   fillbuf(int n);
  267. ushort getbits(int n);
  268. void   fwrite_txt_crc(uchar *p, uint n);
  269. void   init_getbits(void);
  270.  
  271. /* environ.c */
  272.  
  273. void   case_path(char *name);
  274. int    file_exists(char *name);
  275. int    fix_path(char *to_name, char *fr_name);
  276. int    set_ftime(char *name, ulong timestamp);
  277. int    set_fmode(char *name, ushort fmode);
  278.  
  279. /* decode.c */
  280.  
  281. void    decode(void);
  282. void    decode_f(void);
  283.  
  284. /* Message strings */
  285.  
  286. extern char M_VERSION [];
  287. extern char M_USAGE   [];
  288.  
  289. extern char M_ARCDATE [];
  290. extern char M_BADCOMNT[];
  291. extern char M_BADHEADR[];
  292. extern char M_BADTABLE[];
  293. extern char M_CANTOPEN[];
  294. extern char M_CANTREAD[];
  295. extern char M_CANTWRIT[];
  296. extern char M_CRCERROR[];
  297. extern char M_CRCOK   [];
  298. extern char M_DIFFHOST[];
  299. extern char M_DIR     [];
  300. extern char M_ENCRYPT [];
  301. extern char M_ERRORCNT[];
  302. extern char M_EXTRACT [];
  303. extern char M_FEXISTS [];
  304. extern char M_HEADRCRC[];
  305. extern char M_NBRFILES[];
  306. extern char M_NOMEMORY[];
  307. extern char M_NOTARJ  [];
  308. extern char M_PROCARC [];
  309. extern char M_SKIPPED [];
  310. extern char M_SUFFIX  [];
  311. extern char M_TESTING [];
  312. extern char M_UNKNMETH[];
  313. extern char M_UNKNTYPE[];
  314. extern char M_UNKNVERS[];
  315. extern char M_UNSTORE [];
  316.  
  317. #endif
  318.  
  319. /* end UNARJ.H */
  320.