/* ======================================================================== */
/* = Programmname    : ListSPOs V1.3					  = */
/* =									  = */
/* ======================================================================== */
/* = Autor/Copyright : (c) 1994 by Andreas R. Kleinert.                   = */
/* =		       All rights reserved.				  = */
/* ======================================================================== */
/* = Funktion	     : Shows available SPObjects of superplay.library.    = */
/* =		                           		                  = */
/* ======================================================================== */
/* = Letztes Update  : 27.3.1994					  = */
/* =									  = */
/* ======================================================================== */
/* = Bemerkungen     : Needs "superplay.library" V1+.                     = */
/* =									  = */
/* ======================================================================== */
/* = Compiler	     : SAS/C V6.5  					  = */
/* =		       (smakefile)                                        = */
/* ======================================================================== */

#include <superplay/superplaybase.h>
#include <SPObjects/SPObjectbase.h>

#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/superplay.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>


   /* Help- and Info- Texts */

char entry1_text  [] = "\2331;32;40mListSPOs V1.3 \2330;32;40m\2333;32;40m(FREEWARE)\2330;32;40m\n(c) 1994 by Andreas Ralph Kleinert.\nAndreas R. Kleinert, Grube Hohe Grethe 23, D-57074 Siegen, Germany.\n";
char entry2_text  [] = "Lists up available \42SPObjects\42 of \42superplay.library\42.\n";
char entry3_text  [] = "USAGE : \2330;33;40mListSPOs\2330;31;40m\n";

char ver_text [] = "\0$VER: ListSPOs V1.3 (27.3.94)";


/* *************************************************** */
/* *						     * */
/* * Error-Messages for Leave() and KF_Message()     * */
/* *						     * */
/* *************************************************** */

char splib_text [] = "You need \42superplay.library\42 V1+ !";


/* *************************************************** */
/* *						     * */
/* * MACROs for Version-Tests			     * */
/* *						     * */
/* *************************************************** */

#define LibVer(x) ( ((struct Library *) x)->lib_Version )
#define OS_VER	  LibVer(SysBase)


/* *************************************************** */
/* *						     * */
/* * Function Declarations			     * */
/* *						     * */
/* *************************************************** */

void __regargs Leave(char *endtext, long code);


   /* Functions from module "ListSPOs_Subs.o" : */

extern void __stdargs K_Printf(char *formatstring, ...);


/* *************************************************** */
/* *						     * */
/* * Additional Base Declarations		     * */
/* *						     * */
/* *************************************************** */

extern struct ExecBase *SysBase;

struct SuperPlayBase *SuperPlayBase = N;


/* *************************************************** */
/* *						     * */
/* * <CTRL-C>-Handling				     * */
/* *						     * */
/* *************************************************** */

void CXBRK(void);
void CXBRK(void)
{
 Leave("\n*** BREAK ***\n", 0);
}

/* *************************************************** */
/* *						     * */
/* * MAIN					     * */
/* *						     * */
/* *************************************************** */

void main(long argc, char **argv)
{
 struct List           *obj_list = N;
 struct SPO_ObjectNode *spo_node = N;
 long i;

 if(argc==0) Leave(N, FALSE);

 if( argc > 3 || (argv[1][0] =='?')||(argv[2][0] =='?'))
  {
   K_Printf("%s%s%s", entry1_text, entry2_text, entry3_text);

   Leave(N, 0);
  }

 SuperPlayBase = (struct SuperPlayBase *) OpenLibrary("superplay.library", 1);
 if(!SuperPlayBase) Leave(splib_text, 100);

 K_Printf("\nList of available SPObjects :");

 obj_list = &SuperPlayBase->spb_SPObjectList;

 for(spo_node=(APTR) obj_list->lh_Head;(spo_node)&&(spo_node!=(APTR) &(obj_list->lh_Tail));)
  {
   K_Printf("\n\n");

   K_Printf("\nSPObject : \42%s\42", spo_node->spo_FileName);
   K_Printf("\nSPO-Type : %lx",      spo_node->spo_ObjectType);
   K_Printf("\nPriority : %ld",      (long) ((struct Node *)spo_node)->ln_Pri);
   K_Printf("\nTypeID   : \42%s\42", spo_node->spo_TypeID);
   K_Printf("\nTypeCode : %ld",      spo_node->spo_TypeCode);

   if(spo_node->spo_BackgroundReplay) K_Printf("\nKind     : BackGround-Player");
    else                              K_Printf("\nKind     : Synchron-Player");

   for(i=0; i<spo_node->spo_SubTypeNum; i++)
    {
     K_Printf("\n\n%ld. SubType     :", i+1);
     K_Printf("\n   SubTypeID   : \42%s\42", spo_node->spo_SubTypeID[i]);
     K_Printf("\n   SubTypeCode : %ld",      spo_node->spo_SubTypeCode[i]);
    }

   spo_node = (APTR) ((struct Node *)spo_node)->ln_Succ;
  }

 K_Printf("\n\nNo more SPObjects available.\n\n");

 Leave(N, 0);
}

/* *************************************************** */
/* *						     * */
/* * LEAVE : Global Exit Function Replacement	     * */
/* *						     * */
/* *************************************************** */

void __regargs Leave(char *endtext, long code)
{
 if(SuperPlayBase) CloseLibrary((APTR) SuperPlayBase);

 if(endtext)       K_Printf("%s\n", endtext);

 _exit(code);
}
