/* Dieses Programm listet alle verfuegbaren Fonts 
 * in ihren Hoehen auf und zeigt wo diese herkommen.
 * Es zeigt die Funktionsweise von AvailFonts().
 *****************************************************/

#include <intuition/intuitionbase.h>
#include <libraries/diskfont.h>

/* nur fuer Actec C */
#include <functions.h>

#include <exec/memory.h>
#include <libraries/dos.h>

/* Groesse des Buffers fuer AvailFonts() */
#define FNAMEBUF 1000L 

struct DiskfontBase    *DiskfontBase;
struct IntuitionBase   *IntuitionBase;
struct GfxBase         *GfxBase;

struct AvailFontsHeader *afh;
struct AvailFonts *af;

main()
 {
  LONG err;
  SHORT i;

  if( (DiskfontBase = (struct DiskfontBase *)
        OpenLibrary("diskfont.library",0L)) == NULL )
                  ende();

  if( (IntuitionBase = (struct IntuitionBase *)
        OpenLibrary("intuition.library",0L)) == NULL )
                  ende();

  if( (GfxBase = (struct GfxBase *)
        OpenLibrary("graphics.library",0L)) == NULL )
                  ende();

/*****************************************************
 * Reservieren eines Speicherbereichs fuer den Buffer*
 * von AvailFonts                                    */

  afh = (struct AvailFontsHeader *)
               AllocMem(FNAMEBUF,MEMF_CLEAR);
  if(!afh) ende();  


/*****************************************************
 * Der Aufruf selbst. Durch Uebergabe von AFF_DISK   *
 * und AFF_MEMORY, wird bewirkt, sowohl im Speicher  *
 * als auch in FONTS: gesucht wird.                  */
 
  err = AvailFonts(afh,FNAMEBUF,AFF_DISK|AFF_MEMORY);
  if(err) 
   {
    Write(Output(),"AVAIL FONTS ERR\r\n",16L);
    ende();
   }


/*****************************************************
 * Nun wird ueber die AvailFontsHeader Struktur      *
 * gesprungen, und ein Zeiger auf die folgenden      *
 * AvailFonts Strukturen gebildet.                   */

  af = (struct AvailFonts *)&afh[1];


/*****************************************************
 * Es werden alle Eintraege durchgeschaut und        *
 * angezeigt.                                        */

  for( i = 0; i < afh->afh_NumEntries; i++)
   {
    printf("\n Font : %s",
                         (af+i)->af_Attr.ta_Name);
    printf("\n mit einer Höhe von %u Pixeln",
                         (af+i)->af_Attr.ta_YSize);

    if( (af+i)->af_Type == AFF_DISK )
     printf("\n in FONTS: gefunden\n");
    else
     printf("\n im Speicher gefunden\n");
   }
 
 ende();
 return(NULL);
}

/*****************************************
 * Schliessen der geoeffneten Librarys und*
 * Speicherbereiche                      */

ende()
{
 if(GfxBase)        CloseLibrary(GfxBase);
 if(IntuitionBase)  CloseLibrary(IntuitionBase);
 if(DiskfontBase)   CloseLibrary(DiskfontBase);
 if(afh)            FreeMem(afh,FNAMEBUF);
 return(NULL);
}
