home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / packery / xpk_source / xpkmaster / query.c < prev    next >
C/C++ Source or Header  |  1996-10-21  |  4KB  |  186 lines

  1. #ifndef XPKMASTER_QUERY_C
  2. #define XPKMASTER_QUERY_C
  3.  
  4. /* Routinesheader
  5.  
  6.     Name:        query.c
  7.     Main:        xpkmaster
  8.     Versionstring:    $VER: query.c 1.0 (06.10.96)
  9.     Author:        SDI
  10.     Distribution:    PD
  11.     Description:    Implementation of XpkQuery
  12.  
  13.  1.0   06.10.96 : first real version
  14. */
  15.  
  16. #include <exec/types.h>
  17. #include <exec/memory.h>
  18. #include <pragma/exec_lib.h>
  19. #include <pragma/dos_lib.h>
  20. #include <dos/dos.h>
  21. #include "xpkmaster.h"
  22. #include "xpk_strings.h"
  23.  
  24. /************************************************************************
  25.  *
  26.  *  Information query
  27.  *
  28.  */
  29.  
  30. #ifdef __cplusplus
  31.   extern "C"
  32. #endif
  33.  
  34. LONG __asm XpkQuery(register __a0 struct TagItem *tags)
  35. {
  36.   struct FileInfoBlock    *fib        = 0;
  37.   struct Library    *XpkSubBase    = 0;
  38.   struct XpkInfo    *subinfo;
  39.   struct XpkPackerInfo    *pinfo;
  40.   struct XpkMode    *minfo,
  41.             *modeinfo;
  42.   struct XpkPackerList    *list;
  43.   STRPTR        pname,
  44.             t;
  45.   UBYTE            buf[10],
  46.             libname[30]    = "compressors/xpk____.library";
  47.   LONG            mode,
  48.             result        = XPKERR_NOINFO;
  49.  
  50.   if((list = (struct XpkPackerList *) findtag(tags, XPK_PackersQuery)))
  51.   {
  52.     BPTR lock = 0;
  53.  
  54. #ifndef XPK_MINOS_37
  55.     if(!(fib =(struct FileInfoBlock *)AllocMem(sizeof(struct FileInfoBlock),
  56.     MEMF_PUBLIC)))
  57.       goto Abort1;
  58. #else
  59.     if(!(fib = (struct FileInfoBlock *) AllocDosObject(DOS_FIB, 0)))
  60.       goto Abort1;
  61. #endif
  62.  
  63.     memset(list, 0, sizeof(struct XpkPackerList));
  64.     if(!(lock = Lock("libs:compressors", ACCESS_READ)))
  65.       goto Abort1;
  66.  
  67.     if(!Examine(lock, fib))
  68.       goto Abort1;
  69.  
  70.     if(fib->fib_DirEntryType < 0)
  71.       goto Abort1;
  72.  
  73.     while(ExNext(lock, fib))
  74.     {
  75.       STRPTR n = fib->fib_FileName;
  76.       ULONG ID;
  77.       LONG i, l = strlen(n);
  78.  
  79.       if(l != 14 && l != 15 || strncmp("xpk", n, 3) ||
  80.       strcmp(n + l - 8, ".library"))
  81.     continue;
  82.  
  83.       n[l - 8] = 0;
  84.       ID = idfromname(n + 3);
  85.  
  86.       for (i = (LONG) list->xpl_NumPackers; i > 0 &&
  87.       *(ULONG *) list->xpl_Packer[i - 1] > ID; i--)
  88.     *(ULONG *) list->xpl_Packer[i] = *(ULONG *) list->xpl_Packer[i - 1];
  89.       *(ULONG *) list->xpl_Packer[i] = ID;
  90.  
  91.       if(++list->xpl_NumPackers == MAXPACKERS)
  92.     break;
  93.     }
  94.  
  95.     result = XPKERR_OK;
  96.   Abort1:
  97.     if(lock)
  98.       UnLock(lock);
  99.     goto Abort;
  100.   }
  101.  
  102.   if(!(pname = (STRPTR) findtag(tags, XPK_PackMethod)))
  103.   {
  104.     result = XPKERR_BADPARAMS;
  105.     goto Abort;
  106.   }
  107.  
  108.   sprintf(buf, "%.9s", pname);
  109.   if((t = strchr(buf, '.')))
  110.     *t = 0;
  111.   buf[0] = toupper(buf[0]);
  112.   buf[1] = toupper(buf[1]);
  113.   buf[2] = toupper(buf[2]);
  114.   buf[3] = toupper(buf[3]);
  115.  
  116.   CopyMem(buf, libname+15, 4);
  117.   if(!(XpkSubBase = OpenLibrary(libname, 0)))
  118.   {
  119.     result = XPKERR_MISSINGLIB;
  120.     goto Abort;
  121.   }
  122.  
  123.   if(!(subinfo = XpksPackerInfo()))
  124.   {
  125.     result = XPKERR_MISSINGLIB;
  126.     goto Abort;
  127.   }
  128.  
  129.   if((pinfo = (struct XpkPackerInfo *) findtag (tags, XPK_PackerQuery)))
  130.   {
  131.     sprintf(pinfo->xpi_Name, subinfo->xi_Name);
  132.     sprintf(pinfo->xpi_LongName, subinfo->xi_LongName);
  133.     sprintf(pinfo->xpi_Description, subinfo->xi_Description);
  134.     pinfo->xpi_Flags = subinfo->xi_Flags;
  135.     pinfo->xpi_MaxChunk = subinfo->xi_MaxPkInChunk;
  136.     pinfo->xpi_DefChunk = subinfo->xi_DefPkInChunk;
  137.     pinfo->xpi_DefMode = subinfo->xi_DefMode;
  138.   }
  139.   else if((minfo = (struct XpkMode *) findtag(tags, XPK_ModeQuery)))
  140.   {
  141.     mode = findtag(tags, XPK_PackMode);
  142.  
  143.     modeinfo = subinfo->xi_ModeDesc;
  144.     while(modeinfo && modeinfo->xm_Upto < mode)
  145.       modeinfo = modeinfo->xm_Next;
  146.  
  147.     if(!modeinfo)
  148.     {
  149.       result = XPKERR_NOINFO;
  150.       goto Abort;
  151.     }
  152.  
  153.     CopyMem(modeinfo, minfo, sizeof(struct XpkMode));
  154.   }
  155.   else
  156.   {
  157.     result = XPKERR_BADPARAMS;
  158.     goto Abort;
  159.   }
  160.  
  161.   result = XPKERR_OK;
  162. Abort:
  163.   if(fib)
  164.   {
  165. #ifndef XPK_MINOS_37
  166.     FreeMem(fib, sizeof(struct FileInfoBlock));
  167. #else
  168.     FreeDosObject(DOS_FIB, fib);
  169. #endif
  170.   }
  171.  
  172.   if((t = (STRPTR) findtag(tags, XPK_GetError)))
  173.     if(result)
  174.       sprintf(t, TXT_COULD_NOT_GET_INFORMATION);
  175.     else if(!fib)
  176.       sprintf(t, TXT_OUT_OF_MEMORY);
  177.     else
  178.       sprintf(t, TXT_OK);
  179.  
  180.   if(XpkSubBase)
  181.     CloseLibrary(XpkSubBase);
  182.   return result;
  183. }
  184. #endif /* XPKMASTER_QUERY_C */
  185.  
  186.