home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / Cruncher / XPK416SR.LHA / xpk_Source / xpkmaster / xpkmaster.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-06  |  9.3 KB  |  262 lines

  1. #ifndef XPKMASTER_XPKMASTER_H
  2. #define XPKMASTER_XPKMASTER_H
  3.  
  4. /* Includeheader
  5.  
  6.     Name:        xpkmaster.h
  7.     Main:        xpkmaster
  8.     Versionstring:    $VER: xpkmaster.h 1.89 (14.08.97)
  9.     Author:        SDI
  10.     Distribution:    Freeware
  11.     Description:    Master library global definitions and declarations
  12.             and prototypes
  13.  
  14.  1.0   05.10.96 : first real version
  15.  1.1   27.12.96 : removed library protos - call now via library interface,
  16.      allows patching
  17.  1.2   30.01.97 : change of cchecksum proto
  18.  1.3   31.01.97 : checksum changed again
  19.  1.4   01.03.97 : added new flags
  20.  1.5   08.03.97 : changed XpkBuffer a bit
  21.  1.6   31.03.97 : some little corrections
  22.  1.7   02.04.97 : removed obsolete stuff
  23.  1.8   12.04.97 : added DebugTagList
  24.  1.9   14.08.97 : fixed defines
  25. */
  26.  
  27. /* To disable PowerPacker support comment out the next line. */
  28. #define USE_POWERPACKER 1
  29.  
  30. #ifndef __MAXON__
  31.   #include <proto/xpksub.h>
  32.   #ifdef USE_POWERPACKER
  33.     #include <proto/powerpacker.h>
  34.   #endif
  35. #else
  36.   #include "SDI_xpksub.h"    /* Stubs for xpksub and powerpacker */
  37.   #define __asm
  38. #endif
  39.  
  40. #ifdef SUPPORT_A4
  41.   #define A4SUPP    ,a4
  42.   #define A4SUPP2    ,xbuf->xb_regA4
  43.   #define A4PROTO    ,register __a4 ULONG a4
  44. #else
  45.   #define A4SUPP
  46.   #define A4SUPP2
  47.   #define A4PROTO
  48. #endif
  49.  
  50. #define SDI_TO_ANSI
  51. #include "SDI_ASM_STD_protos.h"
  52.  
  53. #include <xpk/xpk.h>
  54. #include <xpk/xpksub.h>
  55.  
  56. #define ROUNDLONG(x)        (((x)+3)&(~3))    /* round to next longword */
  57. #define DEFAULTCHUNKSIZE    0x8000
  58.  
  59. #ifndef Min
  60.   #define Min(a,b) ((a) < (b) ? (a) : (b))
  61.   #define max(a,b) ((a) > (b) ? (a) : (b))
  62. #endif
  63.  
  64. #define CHUNKSIZE 50000
  65.  
  66. /* The structure used for I/O, special master library version */
  67. struct XpkMasterMsg {
  68.   ULONG  xmm_Type;        /* Read/Write/Alloc/Free/Abort        */
  69.   STRPTR xmm_Ptr;        /* The mem area to read from/write to    */
  70.   LONG   xmm_Size;        /* The size of the read/write        */
  71.   ULONG  xmm_IOError;        /* The IoErr() that occurred        */
  72.   ULONG  xmm_Reserved;        /* Reserved for future use        */
  73.   STRPTR xmm_Buf;        /* Specific to the internal hooks    */
  74.   LONG   xmm_Error;        /* The XPKERR that occurred        */
  75.   ULONG  xmm_BufLen;
  76.   ULONG  xmm_BufOfs;
  77.   ULONG  xmm_Len;
  78.   ULONG  xmm_Flags;
  79.   ULONG  xmm_FH;
  80.   ULONG  xmm_MemType;
  81. };
  82.  
  83. #define XIO_GETOUTBUF 1
  84.  
  85. #define XPKMF_SEEKABLE    0x0001    /* ALL chunks (-dict) are independent    */
  86. #define XPKMF_DICTCHUNK    0x0002    /* First chunk is a global dictionary    */
  87. #define XPKMF_FIXSPEED    0x0004    /* Speed is for A3000/25MHz/SCRAM/2.04    */
  88. #define XPKMF_NOCLOBBER    0x0008    /* Don't overwrite            */
  89.  
  90. /* These structures define the file format for compressed streams */
  91. struct XpkStreamHeader {
  92.   ULONG xsh_Pack;
  93.   ULONG xsh_CLen;
  94.   ULONG xsh_Type;
  95.   ULONG xsh_ULen;
  96.   UBYTE xsh_Initial[16];
  97.   UBYTE xsh_Flags;
  98.   UBYTE xsh_HChk;
  99.   UBYTE xsh_SubVrs;
  100.   UBYTE xsh_MasVrs;
  101. };
  102.  
  103. #define XPK_COOKIE 0x58504b46    /* 'XPKF' - ID for xsh_Pack */
  104.  
  105. #define XPKSTREAMF_LONGHEADERS  0x01    /* Use XpkLongLocHeaders    */
  106. #define XPKSTREAMF_PASSWORD     0x02    /* This file encoded        */
  107. #define XPKSTREAMF_EXTHEADER    0x04    /* Extended globhdr        */
  108.  
  109. struct XpkChunkHdrWord {
  110.   UBYTE xchw_Type;
  111.   UBYTE xchw_HChk;
  112.   UWORD xchw_CChk;
  113.   UWORD xchw_CLen;
  114.   UWORD xchw_ULen;
  115. };
  116.  
  117. struct XpkChunkHdrLong {
  118.   UBYTE xchl_Type;
  119.   UBYTE xchl_HChk;
  120.   UWORD xchl_CChk;
  121.   ULONG xchl_CLen;
  122.   ULONG xchl_ULen;
  123. };
  124.  
  125. typedef union {
  126.   struct XpkChunkHdrLong xch_Long;
  127.   struct XpkChunkHdrWord xch_Word;
  128. } XpkChunkHeader;
  129.  
  130. #define XPKCHUNK_RAW        0x00 /* raw copy of source */
  131. #define XPKCHUNK_PACKED        0x01 /* packed data */
  132. #define XPKCHUNK_FDATA        0x02 /* Protection bits, file comment ... */
  133.                      /* not yet implemented */
  134. #define XPKCHUNK_END        0x0f /* empty end Chunk */
  135.  
  136. #define XPKCHUNKF_ENTRYPOINT    0x80 /* Stream can be seeked to at this point */
  137.                      /* not yet implemented */
  138.  
  139. struct Headers {
  140.   struct XpkStreamHeader h_Glob;
  141.   XpkChunkHeader     h_Loc;
  142.   ULONG             h_LocSize;
  143. };
  144.  
  145. #define XPKMODE_UPUP   1
  146. #define XPKMODE_UPSTD  2
  147. #define XPKMODE_UPPP   3
  148. #define XPKMODE_PKSTD  20
  149.  
  150. #define AUTO_PASS_SIZE    50
  151.  
  152. /* This is what XPK "handles" really point to */
  153. struct XpkBuffer {
  154.   struct XpkFib         xb_Fib;/* file info about this file        */
  155.   UWORD   xb_PackingMode;    /* desired packing efficiency, 0..100   */
  156.   struct Headers     xb_Headers;    /* global and local file header */
  157.   ULONG   xb_Format;        /* type of file                */
  158.   ULONG   xb_ChunkLen;        /* compressed chunk len            */
  159.   LONG    xb_Result;        /* error code from last call        */
  160. //  LONG    xb_Result2;        /* possible result from IoErr()        */
  161.   STRPTR  xb_ErrBuf;        /* Where user wants the error        */
  162.   STRPTR *xb_GetOutBuf;        /* Where user wants the out buf addr    */
  163.   ULONG  *xb_GetOutLen;        /* Where user wants the output len    */
  164.   ULONG  *xb_GetOutBufLen;    /* Where user wants the out buf len    */
  165.   ULONG   xb_ULen;        /* Uncompressed length of file        */
  166.   ULONG   xb_Secs;        /* Start time, the seconds        */
  167.   ULONG   xb_Mics;        /* Start time, the micros        */
  168.   struct Hook        *xb_RHook;    /* input data hook        */
  169.   struct Hook        *xb_WHook;    /* output data hook        */
  170.   struct Hook        *xb_ChunkHook;    /* Hook to call between chunks    */
  171.   STRPTR  xb_Password;        /* password for de/encoding        */
  172.   ULONG   xb_PasswordSize;    /* password buffer size for own password*/
  173.   ULONG   xb_SubPackMode;    /* Packing mode to be used        */
  174.   ULONG   xb_SubID;        /* ID of currently open sub        */
  175.   ULONG   xb_ChunkSize;        /* Chunk size to use for packing    */
  176.   ULONG   xb_FirstChunk;    /* Smallest chunk so far        */
  177.   ULONG   xb_MinChunk;        /* Minimum size of a chunk        */
  178.   ULONG   xb_Flags;        /* private for xpkmaster        */
  179.   LONG    xb_Priority;        /* task pri during packing        */
  180.   struct XpkInfo    *xb_SubInfo; /* Info of current open sub-lib    */
  181.   struct Library    *xb_SubBase; /* Currently open sub-library    */
  182.   LONG    xb_InLen;        /* Number of bytes to (un)pack        */
  183.   STRPTR  xb_InName;        /* InputName for prefs Recog func    */
  184.   ULONG   xb_OutLen;        /* Number of bytes written        */
  185.   ULONG   xb_OutMemType;    /* Type of memory for output buffer    */
  186.   STRPTR  xb_OutName;        /* Output file name            */
  187.   struct XpkMasterMsg      xb_RMsg; /* Parameters for reading        */
  188.   struct XpkMasterMsg     xb_WMsg; /* Parameters for writing        */
  189.   struct XpkSubParams     xb_PackParam;/* Parameters to (Un)PackChunk()    */
  190.   struct XpkProgress     xb_Prog; /* Parameters to progress report    */
  191.   STRPTR  xb_LastMsg;        /* The last progress message        */
  192. #ifdef SUPPORT_A4
  193.   ULONG      xb_regA4;
  194. #endif
  195. };
  196.  
  197. /* Values for MasterFlags */
  198. #define XMF_PRIVFH    (1<<0)    /* We opened the FH, so we close it.    */
  199. #define XMF_PACKING    (1<<1)    /* This is a packing operation.        */
  200. #define XMF_PASSTHRU    (1<<2)    /* Pass uncompressed data through    */
  201. #define XMF_GETOUTBUF    (1<<3)    /* Get output buffer when size known    */
  202. #define XMF_NOCLOBBER    (1<<4)    /* Don't overwrite            */
  203. #define XMF_EOF        (1<<5)    /* End of file                */
  204. #define XMF_IDSENT    (1<<6)    /* First four bytes of unpacked sent    */
  205. #define XMF_INITED    (1<<7)    /* Sublib buffers have been allocted    */
  206. #define XMF_GLOBHDR    (1<<8)    /* GlobHdr is already written        */
  207. #define XMF_LOSSYOK    (1<<9)    /* Lossy compression permitted        */
  208. #define XMF_OWNTASKPRI    (1<<10) /* Altered task pri, restore        */
  209. #define XMF_NOCRC    (1<<11)    /* Do not check the checksum on decomp    */
  210. #define XMF_USECOMMENT    (1<<12) /* Store FIB in file comment        */
  211. #define XMF_NOPREFS    (1<<13) /* Are prefs allowed ?            */
  212. #define XMF_XFD        (1<<14) /* Is XFD unpacking allowed ?        */
  213. #define XMF_EXTERNALS    (1<<15) /* Is extern allowed ?            */
  214. #define XMF_AUTOPASSWD    (1<<16) /* Automatic password            */
  215. #define XMF_AUTOPRHOOK  (1<<17) /* Automatic Progress hook        */
  216. #define XMF_NOPACK    (1<<18) /* destination file equals source    */
  217. #define XMF_OWNPASSWORD (1<<19) /* free password buffer later !!!    */
  218.  
  219. #ifdef DEBUG
  220. void     DebugError(STRPTR, ...);            /* debug.c */
  221. void     DebugRunTime(STRPTR, ...);            /* debug.c */
  222. void    DebugTagList(STRPTR, struct TagItem *);        /* debug.c */
  223. #endif
  224.  
  225. ULONG __asm MyCallHookPkt(register __a0 struct Hook *,
  226. register __a1 APTR A4PROTO);
  227.  
  228. extern struct DosLibrary       *DOSBase;        /* libdata.a */
  229. extern struct Hook        fhinhook;        /* hook_fh.c */
  230. extern struct Hook        fhouthook;        /* hook_fh.c */
  231. extern struct IntuitionBase    *IntuitionBase;        /* libdata.a */
  232. extern UBYTE            MainVersion;        /* libdata.a */
  233. extern struct Hook        meminhook;        /* hook_mem.c */
  234. extern struct Hook        memouthook;        /* hook_mem.c */
  235. extern struct ExecBase         *SysBase;        /* libdata.a */
  236. extern struct Library           *UtilityBase;        /* libdata.a */
  237. extern struct Library           *XpkBase;        /* libdata.a */
  238.  
  239. LONG    callprogress(struct XpkBuffer *);        /* progress.c */
  240. UWORD    cchecksum(ULONG *, ULONG);            /* checksum.c */
  241. void    closesub(struct XpkBuffer *);            /* sublibs.c */
  242. LONG    freebufs(struct XpkBuffer *);            /* xbuf.h */
  243. struct XpkPrefsSemaphore *GetPrefsSem(void);        /* objects.c */
  244. UBYTE    hchecksum(STRPTR, ULONG);            /* checksum.c */
  245. APTR    hookread(struct XpkBuffer *, ULONG, APTR, ULONG);    /* hook.c */
  246. APTR    hookwrite(struct XpkBuffer *, ULONG, APTR, ULONG);    /* hook.c */
  247. ULONG    idfromname(STRPTR);                    /* util.c */
  248. struct XpkBuffer    *initxbuf(void);            /* xbuf.h */
  249. struct Library        *opensub(struct XpkBuffer *, ULONG);    /* sublibs.c */
  250. LONG    parsebuftags(struct XpkBuffer*, struct TagItem*, ULONG);/* tags.c */
  251. void    parseerrortags(struct TagItem *);            /* tags.c */
  252. void    parsegettags(struct XpkBuffer *);            /* tags.c */
  253. void    percentages(struct XpkFib *);                /* fib.c */
  254. void    updatefib(struct XpkBuffer *);                /* fib.c */
  255. LONG    __asm xpkopen(   register __a0 struct XpkBuffer **,
  256.              register __a1 struct TagItem *,
  257.              register __d2 ULONG
  258.              A4PROTO);                /* open.c */
  259. LONG    xpkopenwrite(struct XpkBuffer **, struct TagItem *);    /* open.c */
  260.  
  261. #endif /* XPKMASTER_XPKMASTER_H */
  262.