"Fossies" - the Fresh Open Source Software Archive

Member "unarj-2.65/unarj.h" (5 Jun 2002, 13425 Bytes) of package /linux/misc/old/unarj-2.65.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "unarj.h" see the Fossies "Dox" file reference documentation.

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