home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / packery / xpk_source / xpkmaster / xpkmaster.h < prev   
C/C++ Source or Header  |  1996-10-29  |  10KB  |  286 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.0 (05.10.96)
  9.     Author:        SDI
  10.     Distribution:    PD
  11.     Description:    Master library global definitions and declarations
  12.             and prototypes
  13.  
  14.  1.0   05.10.96 : first real version
  15. */
  16.  
  17. /* To disable PowerPacker support comment out the next line. */
  18. #define USE_POWERPACKER 1
  19.  
  20. #ifdef __SASC
  21.   #define BUGGY_SASC  /* Try to hide unusual values from SASs switch() */
  22. #endif
  23.  
  24. #ifndef __MAXON__
  25.   #include <pragma/xpksub_lib.h>
  26.   #ifdef USE_POWERPACKER
  27.     #include <pragma/powerpacker_lib.h>
  28.   #endif
  29. #else
  30.   #include "SDI_xpksub.h"    // Stubs for xpksub and powerpacker
  31.   #define __asm
  32. #endif
  33.  
  34. #ifdef SUPPORT_A4
  35.   #define A4SUPP    ,a4
  36.   #define A4SUPP2    ,xbuf->xb_regA4
  37.   #define A4PROTO    ,register __a4 ULONG a4
  38. #else
  39.   #define A4SUPP
  40.   #define A4SUPP2
  41.   #define A4PROTO
  42. #endif
  43.  
  44.  
  45. #define SDI_TO_ANSI
  46. #include "SDI_ASM_STD_protos.h"
  47.  
  48. #include <xpk/xpk.h>
  49. #include <xpk/xpksub.h>
  50.  
  51. #define ROUNDLONG(x)        (((x)+3)&(~3))    /* round to next longword */
  52. #define DEFAULTCHUNKSIZE    0x8000
  53.  
  54. #ifndef Min
  55.   #define Min(a,b) ((a) < (b) ? (a) : (b))
  56.   #define max(a,b) ((a) > (b) ? (a) : (b))
  57. #endif
  58.  
  59. #define CHUNKSIZE 50000
  60.  
  61. /* The structure used for I/O, special master library version */
  62. struct XpkMasterMsg {
  63.   ULONG  xmm_Type;        /* Read/Write/Alloc/Free/Abort        */
  64.   STRPTR xmm_Ptr;        /* The mem area to read from/write to    */
  65.   ULONG  xmm_Size;        /* The size of the read/write        */
  66.   ULONG  xmm_IOError;        /* The IoErr() that occurred        */
  67.   ULONG  xmm_Reserved;        /* Reserved for future use        */
  68.   STRPTR xmm_Buf;        /* Specific to the internal hooks    */
  69.   LONG   xmm_Error;        /* The XPKERR that occurred        */
  70.   ULONG  xmm_BufLen;
  71.   ULONG  xmm_BufOfs;
  72.   ULONG  xmm_Len;
  73.   ULONG  xmm_Flags;
  74.   ULONG  xmm_FH;
  75.   ULONG  xmm_MemType;
  76. };
  77.  
  78. #define XIO_GETOUTBUF 1
  79.  
  80. #define XPKMF_SEEKABLE    0x0001    /* ALL chunks (-dict) are independent    */
  81. #define XPKMF_DICTCHUNK    0x0002    /* First chunk is a global dictionary    */
  82. #define XPKMF_FIXSPEED    0x0004    /* Speed is for A3000/25MHz/SCRAM/2.04    */
  83. #define XPKMF_NOCLOBBER    0x0008    /* Don't overwrite            */
  84.  
  85. /* These structures define the file format for compressed streams */
  86. struct XpkStreamHeader {
  87.   ULONG xsh_Pack;
  88.   ULONG xsh_CLen;
  89.   ULONG xsh_Type;
  90.   ULONG xsh_ULen;
  91.   UBYTE xsh_Initial[16];
  92.   UBYTE xsh_Flags;
  93.   UBYTE xsh_HChk;
  94.   UBYTE xsh_SubVrs;
  95.   UBYTE xsh_MasVrs;
  96. };
  97.  
  98. #define XPK_COOKIE 0x58504b46    /* 'XPKF' - ID for xsh_Pack */
  99.  
  100. #define XPKSTREAMF_LONGHEADERS  0x01    /* Use XpkLongLocHeaders    */
  101. #define XPKSTREAMF_PASSWORD     0x02    /* This file encoded        */
  102. #define XPKSTREAMF_EXTHEADER    0x04    /* Extended globhdr        */
  103.  
  104. struct XpkChunkHdrWord {
  105.   UBYTE xchw_Type;
  106.   UBYTE xchw_HChk;
  107.   UWORD xchw_CChk;
  108.   UWORD xchw_CLen;
  109.   UWORD xchw_ULen;
  110. };
  111.  
  112. struct XpkChunkHdrLong {
  113.   UBYTE xchl_Type;
  114.   UBYTE xchl_HChk;
  115.   UWORD xchl_CChk;
  116.   ULONG xchl_CLen;
  117.   ULONG xchl_ULen;
  118. };
  119.  
  120. typedef union {
  121.   struct XpkChunkHdrLong xch_Long;
  122.   struct XpkChunkHdrWord xch_Word;
  123. } XpkChunkHeader;
  124.  
  125. #define XPKCHUNK_TYPE        0x0f
  126. #define XPKCHUNK_RAW        0x00
  127. #define XPKCHUNK_PACKED        0x01
  128. #define XPKCHUNK_FDATA        0x02 /* Protection bits, file comment ... */
  129. #define XPKCHUNK_END        0x0f
  130.  
  131. #define XPKCHUNKF_ENTRYPOINT    0x80 /* Stream can be seeked to at this point */
  132.  
  133. struct Headers {
  134.   struct XpkStreamHeader h_Glob;
  135.   XpkChunkHeader     h_Loc;
  136.   ULONG             h_LocSize;
  137. };
  138.  
  139. #define XPKMODE_UPUP   1
  140. #define XPKMODE_UPSTD  2
  141. #define XPKMODE_UPPP   3
  142. #define XPKMODE_PKSTD  20
  143.  
  144. /* This is what XPK "handles" really point to */
  145. struct XpkBuffer {
  146.   struct XpkFib         xb_Fib;    /* file info about this file    */
  147.   UWORD   xb_PackingMode;    /* desired packing efficiency, 1..9    */
  148.   struct Headers     xb_Headers;    /* global and local file header */
  149.   ULONG   xb_Format;        /* type of file                */
  150.   ULONG   xb_ChunkLen;        /* compressed chunk len            */
  151.   LONG    xb_Result;        /* error code from last call        */
  152.   LONG    xb_Result2;        /* possible result from IoErr()        */
  153.   UBYTE   xb_ErrMsg[80];    /* ASCII error message            */
  154.   STRPTR  xb_ErrBuf;        /* Where user wants the error        */
  155.   STRPTR *xb_GetOutBuf;        /* Where user wants the out buf addr    */
  156.   ULONG  *xb_GetOutLen;        /* Where user wants the output len    */
  157.   ULONG  *xb_GetOutBufLen;    /* Where user wants the out buf len    */
  158.   STRPTR  xb_PackerName;    /* lib name of the packer to be used    */
  159.   ULONG   xb_PackingFlags;    /* desired packing mode            */
  160.   ULONG   xb_ULen;        /* Uncompressed length of file        */
  161.   ULONG   xb_Secs;        /* Start time, the seconds        */
  162.   ULONG   xb_Mics;        /* Start time, the micros        */
  163.   struct Hook        *xb_RHook;    /* input data hook        */
  164.   struct Hook        *xb_WHook;    /* output data hook        */
  165.   struct Hook        *xb_ChunkHook;    /* Hook to call between chunks    */
  166.   STRPTR  xb_Password;        /* password for de/encoding        */
  167.   ULONG   xb_SubPackMode;    /* Packing mode to be used        */
  168.   ULONG   xb_SubID;        /* ID of currently open sub        */
  169.   ULONG   xb_ChunkSize;        /* Chunk size to use for packing    */
  170.   ULONG   xb_FirstChunk;    /* Smallest chunk so far        */
  171.   ULONG   xb_MinChunk;        /* Minimum size of a chunk        */
  172.   ULONG   xb_Flags;        /* private for xpkmaster        */
  173.   LONG    xb_Priority;        /* task pri during packing        */
  174.   struct XpkInfo    *xb_SubInfo; /* Info of current open sub-lib    */
  175.   struct Library    *xb_SubBase; /* Currently open sub-library    */
  176.   ULONG   xb_InLen;        /* Number of bytes to (un)pack        */
  177.   ULONG   xb_OutLen;        /* Number of bytes written        */
  178.   ULONG   xb_OutMemType;    /* Type of memory for output buffer    */
  179.   STRPTR  xb_OutName;        /* Output file name            */
  180.   struct XpkMasterMsg      xb_RMsg; /* Parameters for reading        */
  181.   struct XpkMasterMsg     xb_WMsg; /* Parameters for writing        */
  182.   struct XpkSubParams     xb_PackParam;/* Parameters to (Un)PackChunk()    */
  183.   struct XpkProgress     xb_Prog; /* Parameters to progress report    */
  184.   STRPTR  xb_LastMsg;        /* The last progress message        */
  185. #ifdef SUPPORT_A4
  186.   ULONG      xb_regA4;
  187. #endif
  188. };
  189.  
  190. /* Values for MasterFlags */
  191. #define XMF_PRIVFH    0x0001    /* We opened the FH, so we close it.    */
  192. #define XMF_PACKING    0x0002    /* This is a packing operation.        */
  193. #define XMF_PASSTHRU    0x0004    /* Pass uncompressed data through    */
  194. #define XMF_GETOUTBUF    0x0008    /* Get output buffer when size known    */
  195. #define XMF_NOCLOBBER    0x0010    /* Don't overwrite            */
  196. #define XMF_EOF        0x0020    /* End of file                */
  197. #define XMF_IDSENT    0x0040    /* First four bytes of unpacked sent    */
  198. #define XMF_INITED    0x0080    /* Sublib buffers have been allocted    */
  199. #define XMF_GLOBHDR    0x0100    /* GlobHdr is already written        */
  200. #define XMF_SHORTERR    0x0200    /* Long error messages wanted        */
  201. #define XMF_LOSSYOK    0x0400    /* Lossy compression permitted        */
  202. #define XMF_OWNTASKPRI    0x0800    /* Altered task pri, restore        */
  203. #define XMF_NOCRC    0x1000    /* Do not check the checksum on decomp    */
  204. #define XMF_USECOMMENT    0x2000    /* Store FIB in file comment        */
  205.  
  206. #ifdef DEBUG
  207. void     DebugError(STRPTR, ...);            // debug.c
  208. void     DebugRunTime(STRPTR, ...);            // debug.c
  209. #endif
  210.  
  211. #ifndef XPK_MINOS_37
  212. ULONG    findtag(struct TagItem *, ULONG);        // tags.c
  213. struct TagItem *MyNextTagItem(struct TagItem **);    // tags.c
  214. #else
  215. #define findtag(a,b)        (FindTagItem(b,a)->ti_Data)
  216. #define MyNextTagItem        NextTagItem
  217. #endif
  218.  
  219. #if !defined(SUPPORT_A4) && defined(XPK_MINOS_37)
  220.   #define MyCallHookPkt(a,b)    CallHook(a,0,b)
  221. #else
  222.   ULONG __asm MyCallHookPkt(register __a0 struct Hook *,
  223.   register __a1 APTR A4PROTO);
  224. #endif
  225.  
  226. extern struct DosLibrary       *DOSBase;        // libdata.a
  227. extern struct Hook        fhinhook;        // hook_fh.c
  228. extern struct Hook        fhouthook;        // hook_fh.c
  229. extern struct IntuitionBase    *IntuitionBase;        // libdata.a
  230. extern UBYTE            MainVersion;        // libdata.a
  231. extern struct Hook        meminhook;        // hook_mem.c
  232. extern struct Hook        memouthook;        // hook_mem.c
  233. extern struct ExecBase         *SysBase;        // libdata.a
  234. extern struct Library           *UtilityBase;        // libdata.a
  235.  
  236. STRPTR    basename(STRPTR);                    // util.c
  237. LONG    callprogress(struct XpkBuffer *);            // progress.c
  238. UWORD    cchecksum(ULONG *, ULONG);                // checksum.c
  239. void    closesub(struct XpkBuffer *);                // sublibs.c
  240. LONG    copydata(struct XpkBuffer *, ULONG, ULONG);        // hook.c
  241. LONG    freebufs(struct XpkBuffer *);                // xbuf.h
  242. void    geterror (struct XpkBuffer *);                // geterror.c
  243. UBYTE    hchecksum(STRPTR, ULONG);                // checksum.c
  244. APTR    hookread(struct XpkBuffer *, ULONG, APTR, ULONG);    // hook.c
  245. APTR    hookwrite(struct XpkBuffer *, ULONG, APTR, ULONG);    // hook.c
  246. ULONG    idfromname(STRPTR);                    // util.c
  247. struct XpkBuffer    *initxbuf(void);            // xbuf.h
  248. struct Library        *opensub(struct XpkBuffer *, ULONG);    // sublibs.c
  249. LONG    parsebuftags(struct XpkBuffer*, struct TagItem*, ULONG);// tags.c
  250. void    parseerrortags(struct TagItem *);            // tags.c
  251. void    parsegettags(struct XpkBuffer *);            // tags.c
  252. void    percentages(struct XpkFib *);                // fib.c
  253. void    updatefib(struct XpkBuffer *);                // fib.c
  254. LONG    __asm xpkopen(   register __a0 struct XpkBuffer **,
  255.              register __a1 struct TagItem *,
  256.              register __d2 ULONG
  257.              A4PROTO);                // open.c
  258. LONG    xpkopenwrite(struct XpkBuffer **, struct TagItem *);    // open.c
  259.  
  260. #ifdef __cplusplus
  261.   extern "C" {
  262. #endif
  263.  
  264. LONG __asm XpkExamine   (register __a0 struct XpkFib *,
  265.              register __a1 struct TagItem * A4PROTO);
  266. LONG __asm XpkPack      (register __a0 struct TagItem * A4PROTO);
  267. LONG __asm XpkUnpack    (register __a0 struct TagItem * A4PROTO);
  268. LONG __asm XpkOpen      (register __a0 struct XpkBuffer **,
  269.              register __a1 struct TagItem * A4PROTO);
  270. LONG __asm XpkRead      (register __a0 struct XpkBuffer *,
  271.              register __a1 STRPTR,
  272.              register __d0 ULONG);
  273. LONG __asm XpkSeek      (register __a0 struct XpkBuffer *,
  274.              register __d0 LONG,
  275.              register __d1 LONG);
  276. LONG __asm XpkClose     (register __a0 struct XpkBuffer *);
  277. LONG __asm XpkQuery     (register __a0 struct TagItem *);
  278. LONG __asm XpkWrite    (register __a0 struct XpkBuffer *,
  279.              register __a1 STRPTR,
  280.              register __d0 ULONG);
  281.  
  282. #ifdef __cplusplus
  283.   }
  284. #endif
  285. #endif /* XPKMASTER_XPKMASTER_H */
  286.