home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / System / XADmaster / xad_dev / Sources / ExampleClient.c
Encoding:
C/C++ Source or Header  |  2001-04-01  |  6.3 KB  |  179 lines

  1. #ifndef XADMASTER_EXAMPLE_C
  2. #define XADMASTER_EXAMPLE_C
  3.  
  4. /* Programmheader
  5.  
  6.     Name:        Example.c
  7.     Main:        xadmaster
  8.     Versionstring:    $VER: Example.c 1.3 (24.03.2000)
  9.     Author:        SDI
  10.     Distribution:    Freeware
  11.     Description:    Example disk or file archiver client
  12.  
  13.  1.0   16.02.99 : first version
  14.  1.1   20.06.99 : some little corrections
  15.  1.2   29.06.99 : now uses master free stuff
  16.  1.3   24.02.00 : added some more comments
  17. */
  18.  
  19. #include <proto/xadmaster.h>
  20. #include <dos/dos.h>
  21. #include "SDI_compiler.h"
  22.  
  23. #ifndef XADMASTERFILE
  24. #define Example_Client        FirstClient
  25. #define NEXTCLIENT        0
  26. UBYTE version[] = "$VER: Example 1.3 (24.03.2000)";
  27. #endif
  28. #define EXAMPLE_VERSION        1
  29. #define EXAMPLE_REVISION    3
  30.  
  31. /* This is an empty example client! You should replace all "EXAMPLE"
  32. texts with text related to your own client. */
  33.  
  34. /* NOTE: I normally use SAS-C. This compiler supports local base variables
  35. for library calls, so all function calls to xadmaster.library can be done
  36. using the argument passed in register A6.
  37.  
  38. If your compiler does not support that, insert a global base, rename the
  39. argument of the functions to lower case xadmasterbase and add following
  40. line in Example_GetInfo() function:
  41.  
  42.   xadMasterBase = xadmasterbase;
  43.  
  44. xadMasterBase also has a pointer to DOSBase and SysBase, but normally this
  45. should not be necessary, but it is useful for debug output in test versions.
  46. */
  47.  
  48. /* See the included example clients as well! */
  49.  
  50. ASM(BOOL) Example_RecogData(REG(d0, ULONG size), REG(a0, STRPTR data),
  51. REG(a6, struct xadMasterBase *xadMasterBase))
  52. {
  53.   if(/* do some checks here (headerID, header checksum, ...) */)
  54.     return 1; /* known file */
  55.   else
  56.     return 0; /* unknown file */
  57. }
  58.  
  59. ASM(LONG) Example_GetInfo(REG(a0, struct xadArchiveInfo *ai),
  60. REG(a6, struct xadMasterBase *xadMasterBase))
  61. {
  62.   /* return an error code, as long as function is empty */
  63.   return XADERR_NOTSUPPORTED;
  64.  
  65.   /* Always do this function first (after RecogData). Normally it's the
  66.   easiest one.
  67.   General style for file archivers:
  68.   -Allocate "xadAllocObject(XADOBJ_FILEINFO, ...., TAG_DONE)" the
  69.    xadFileInfo structure for every file and fill it's fields with
  70.    correct values (date, size, protection, crunched size, flags, ...).
  71.   -Add the allocated structure to a linked list, which is assigned to
  72.    ai->xai_FileInfo.
  73.   -If an error occurs set "ai->xai_Flags & XADAIF_FILECORRUPT" or
  74.    return the error if it is really serious. If there are already valid
  75.    entries in linked list, there cannot be that serious!
  76.   -Leave this function.
  77.   General style for disk archivers:
  78.   -Allocate "xadAllocObject(XADOBJ_DISKINFO, ...., TAG_DONE)" the
  79.    xadDiskInfo structure for every file and fill it's fields with
  80.    correct values (tracks, heads, flags, ...).
  81.   -Add the allocated structure to a linked list, which is assigned to
  82.    ai->xai_DiskInfo.
  83.   -If there are information texts, create a linked list with xadTextInfo
  84.    structures. These are allocated with xadAllocObjectA(XADOBJ_TEXTINFO, 0).
  85.   -If an error occurs set "ai->xai_Flags & XADAIF_FILECORRUPT" or
  86.    return the error if it is really serious. If there are already valid
  87.    entries in linked list, it cannot be that serious!
  88.   -Leave this function.
  89.  
  90.   For nearly all archivers it is necessary to store current file position
  91.   (ai->xai_InPos), to be able to find the data in unarchive function.
  92.   Therefor xid_DataPos and xfi_DataPos exists. You can use the flags
  93.   XADFIF_SEEKDATAPOS or XADIF_SEEKDATAPOS and the seek is done automatically
  94.   when unarchiving is called.
  95.  
  96.   Get data using "xadHookAccess(XADAC_READ, size, buf, ai)" and seek input
  97.   data using "xadHookAccess(XADAC_INPUTSEEK, size, 0, ai)".
  98.   */
  99. }
  100.  
  101. ASM(LONG) Example_UnArchive(REG(a0, struct xadArchiveInfo *ai),
  102. REG(a6, struct xadMasterBase *xadMasterBase))
  103. {
  104.   /* return an error code, as long as function is empty */
  105.   return XADERR_NOTSUPPORTED;
  106.  
  107.   /*
  108.   -Either use ai->xai_CurDisk or ai->xai_CurFile and seek the input data
  109.    to the position required to access the archived data for the wanted entry:
  110.    "xadHookAccess(XADAC_INPUTSEEK, pos-ai->xai_InPos, 0, ai)".
  111.    Alternatively you can use XADFIF_SEEKDATAPOS and XADIF_SEEKDATAPOS in
  112.    GetInfo and the seek is done automatically.
  113.   -Extract the data using XADAC_READ for reads, XADAC_WRITE for storing data
  114.    or XADAC_COPY for copying the data directly.
  115.   - Leave the function either returning 0 or an errorcode, which occured.
  116.   */ 
  117. }
  118.  
  119.  
  120. ASM(void) Example_Free(REG(a0, struct xadArchiveInfo *ai),
  121. REG(a6, struct xadMasterBase *xadMasterBase))
  122. {
  123.   /* This function needs to free all the stuff allocated in info or
  124.   unarchive function. It may be called multiple times, so clear freed
  125.   entries!
  126.   */
  127.  
  128.   /* The following example frees file and disk archive data. It assumes,
  129.   that disk archive information texts are allocated using xadAllocVec and all
  130.   the other stuff (file names, comments, ...) is allocated using the tags
  131.   of xadAllocObject function.
  132.  
  133.   If you only do that stuff, then set the responding XADCF_FREE flags and
  134.   the master library does the stuff for you. In that case you do not even
  135.   need that function (remove it totally!).
  136.  
  137.   In any other case you should modify that function to meet your special
  138.   requirements. Remember. The function should leave all fields cleared!
  139.   */
  140.  
  141.   struct xadFileInfo *fi, *fi2;
  142.   struct xadDiskInfo *di, *di2;
  143.   struct xadTextInfo *ti, *ti2;
  144.  
  145.   for(fi = ai->xai_FileInfo; fi; fi = fi2)
  146.   {
  147.     fi2 = fi->xfi_Next;
  148.     xadFreeObjectA(fi, 0);
  149.   }
  150.   ai->xai_FileInfo = 0;
  151.  
  152.   for(di = ai->xai_DiskInfo; di; di = di2)
  153.   {
  154.     di2 = di->xdi_Next;
  155.     
  156.     for(ti = di->xdi_TextInfo; ti; ti = ti2)
  157.     {
  158.       ti2 = ti->xti_Next;
  159.       if(ti->xti_Text)
  160.         xadFreeObjectA(ti->xti_Text, 0);
  161.       xadFreeObjectA(ti, 0);
  162.     }
  163.     xadFreeObjectA(di, 0);
  164.   }
  165.   ai->xai_DiskInfo = 0;
  166. }
  167.  
  168. /* You need to complete following structure! */
  169. const struct xadClient Example_Client = {
  170. NEXTCLIENT, XADCLIENT_VERSION, 4, EXAMPLE_VERSION, EXAMPLE_REVISION,
  171. /* Here the size the client really needs to detect the filetype must be
  172. inserted */, /* XADCF_DISKARCHIVER and/or XADCF_FILEARCHIVER and some of
  173. XADCF_FREEDISKINFO|XADCF_FREEFILEINFO|XADCF_FREETEXTINFO|XADCF_FREETEXTINFOTEXT */,
  174. 0 /* Type identifier. Normally should be zero */, "Example",
  175. (BOOL (*)()) Example_RecogData, (LONG (*)()) Example_GetInfo,
  176. (LONG (*)()) Example_UnArchive, /* 0 or (void (*)()) Example_Free */};
  177.  
  178. #endif /* XADASTER_EXAMPLE_C */
  179.