#define NAME         "xadLibInfo"
#define DISTRIBUTION "(Freeware) "
#define REVISION     "0"

/* Programmheader

	Name:		xadLibInfo
	Author:		SDI
	Distribution:	Freeware
	Description:	show informations about xad Clients
	Compileropts:	-
	Linkeropts:	-gsi -l amiga

 1.0   18.11.98 : first version
*/

#include <proto/xadmaster.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <dos/dosasl.h>
#include "SDI_defines.h"

#ifdef __SASC
  #define dosbase	 DOSBase 
  #define xadmasterbase	 xadMasterBase 
  #define ASSIGN_DOS
  #define ASSIGN_XAD
  #define ASSIGN_SYS	 struct ExecBase * SysBase; \
			 SysBase = (*((struct ExecBase **) 4));
#else
  struct DosLibrary *	 DOSBase = 0;
  struct ExecBase *	 SysBase  = 0;
  struct xadMasterBase * xadMasterBase = 0;

  #define ASSIGN_DOS	 DOSBase = dosbase;
  #define ASSIGN_XAD	 xadMasterBase = xadmasterbase;
  #define ASSIGN_SYS	 SysBase = (*((struct ExecBase **) 4));
#endif

ULONG start(void)
{
  ULONG ret = RETURN_FAIL;
  struct DosLibrary *dosbase;

  ASSIGN_SYS
  { /* test for WB and reply startup-message */
    struct Process *task;
    if(!(task = (struct Process *) FindTask(0))->pr_CLI)
    {
      WaitPort(&task->pr_MsgPort);
      Forbid();
      ReplyMsg(GetMsg(&task->pr_MsgPort));
      return RETURN_FAIL;
    }
  }

  if((dosbase = (struct DosLibrary *) OpenLibrary("dos.library", 37)))
  {
    struct xadMasterBase *xadmasterbase;
    ASSIGN_DOS
    if((xadmasterbase = (struct xadMasterBase *) 
    OpenLibrary("xadmaster.library", 1)))
    {
      ULONG fl;
      struct xadClient *xc;

      ASSIGN_XAD
      ret = 0;
      if((xc = xadGetClientInfo()))
        Printf("\033[4mClients of xadmaster.library %ld.%ld\033[0m\n\n"
	"Name                                    |  ID  | MV |  VER  | Flags\n"
	"----------------------------------------+------+----+-------+---------------\n",
	xadmasterbase->xmb_LibNode.lib_Version,
	xadmasterbase->xmb_LibNode.lib_Revision);
      
      while(xc && !CTRL_C)
      {
        fl = xc->xc_Flags;

        Printf("%-40s| ", xc->xc_ArchiverName);
        Printf(xc->xc_Identifier ? "%04ld" : "----", xc->xc_Identifier);
        Printf(" | %2ld |%3ld.%ld%s| ", xc->xc_MasterVersion,
        xc->xc_ClientVersion, xc->xc_ClientRevision, xc->xc_ClientRevision
        >= 100 ? "" : xc->xc_ClientRevision >= 10 ? " " : "  ");
        if(fl & XADCF_FILEARCHIVER)
        {
          fl &= ~XADCF_FILEARCHIVER;
          Printf("FILEARCHIVER%s", fl ? "," : "");
        }
        if(fl & XADCF_DISKARCHIVER)
        {
          fl &= ~XADCF_DISKARCHIVER;
          Printf("DISKARCHIVER%s", fl ? "," : "");
        }
        if(fl & XADCF_EXTERN)
          Printf("EXTERN");
        
        Printf("\n");
	xc = xc->xc_Next;
      }
      if(CTRL_C)
        PrintFault(ERROR_BREAK,0 );

      CloseLibrary((struct Library *) xadmasterbase);
    }
    else
      Printf("Could not open xadmaster.library\n");
    CloseLibrary((struct Library *) dosbase);
  }
  return ret;
}
