/* ======================================================================== */
/* = Programmname    : ListSVDs V7.1					  = */
/* =									  = */
/* ======================================================================== */
/* = Autor/Copyright : (c) 1994 by Andreas R. Kleinert.                   = */
/* =		       All rights reserved.				  = */
/* ======================================================================== */
/* = Funktion	     : Show available svdrivers of superview.library V3+. = */
/* =		                           		                  = */
/* ======================================================================== */
/* = Letztes Update  : 15.7.1994				          = */
/* =									  = */
/* ======================================================================== */
/* = Bemerkungen     : "superview.library" V3+ needed.                    = */
/* =									  = */
/* ======================================================================== */
/* = Compiler	     : SAS/C V6.51  					  = */
/* =		       (smakefile)                                        = */
/* ======================================================================== */

#include <superview/superviewbase.h>
#include <svobjects/svobjectbase.h>
#include <svdrivers/svdriverbase.h>

#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/superview.h>
#include <proto/svobjects.h>
#include <proto/svdrivers.h>

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


   /* Help- and Info- Texts */

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

char ver_text [] = "\0$VER: ListSVDs V7.1 (15.7.94)";


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

char svlib_text [] = "You need \42superview.library\42 V3+ !";


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

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


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

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


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

extern struct ExecBase *SysBase;

struct SuperViewBase *SuperViewBase = N;


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

void main(long argc, char **argv)
{
 struct List           *drv_list = N;
 struct SVD_DriverNode *svd_node = N;

 if(!argc) exit(0); /* started from WB ... */

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

   Leave(N, 0);
  }

 SuperViewBase = (struct SuperViewBase *) OpenLibrary("superview.library", 3);
 if(!SuperViewBase) Leave(svlib_text, 100);

 K_Printf("\nList of available svdrivers :\n");

 drv_list = &SuperViewBase->svb_SVDriverList;

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

   K_Printf("\nSVDriver : \42%s\42", svd_node->svd_FileName);
   K_Printf("\nPriority : %ld",      (long) ((struct Node *)svd_node)->ln_Pri);
   K_Printf("\nDriverID : \42%s\42", svd_node->svd_ID);
   K_Printf("\nFlags    : ");

        if(svd_node->svd_Flags & SVDF_INTUITION) K_Printf("Intuition compatible");
   else if(svd_node->svd_Flags & SVDF_FOREIGN)   K_Printf("Foreign display");
   else                                          K_Printf("Unknown display");

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

 K_Printf("\n  --------------------------------------------------------");

 K_Printf("\n\nCurrently selected Global Driver is : ");

 /* retval = */ SVL_GetGlobalDriver(&svd_node, N);
 /* SuperViewBase->svb_GlobalDriver */

 if(svd_node) K_Printf("\42%s\42\n\n", svd_node->svd_ID);
  else        K_Printf("- no Driver selected -\n\n");

 Leave(N, 0);
}

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

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

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

 exit(code);
}
