/*
***************************************************************************
*
* Datei:
*    RSysFlush.c
*
* Inhalt:
*    void RSysFlushAllLibraries(void);
*    void RSysFlushAllFonts(void);
*    void RSysFlushAll(void);
*
* Bemerkungen:
*    Speicherfreigabe durch Beseitigen von nicht benutzten
*    Fonts und Libraries.
*
* Erstellungsdatum:
*    07-Jul-93    Rolf Böhme
*
* Änderungen:
*    07-Jul-93    Rolf Böhme    Erstellung
*
***************************************************************************
*/

#include "RSysDebug.h"
#include "RSysFunc.h"

   /*
    * FlushAllLibraries() entfernt alle geschlossenen Libraries aus
    * dem System
    */
void
RSysFlushAllLibraries(void)
{
   struct Library *result;
   struct Node *node;

   if (Question(SysWnd, "Do you really want to remove all unused  Libraries?", YES))
   {
      Forbid();

      for (node = SysBase->LibList.lh_Head; node->ln_Succ;
           node = node->ln_Succ)
      {
         result = (struct Library *) node;

         if (result->lib_OpenCnt == 0)
            RemLibrary(result);
      }

      Permit();

      PrintInfo("All libraries flushed", SPEAK, SEC);

      RefreshList(LastID);

      PrintStatistics();
   }

   return;
}


   /*
    * RSysFlushAllFonts() entfernt alle unbenutzten Diskfonts aus
    * dem System
    */
void
RSysFlushAllFonts(void)
{
   struct TextFont *tf;
   struct Node *node;

   if (Question(SysWnd, "Do you really want to remove all unused Not-ROM-Fonts?", YES))
   {
      Forbid();

      for (node = GfxBase->TextFonts.lh_Head; node->ln_Succ;
           node = node->ln_Succ)
      {
         tf = (struct TextFont *) node;

         if ((tf->tf_Accessors == 0) && (tf->tf_Flags & FPF_DISKFONT))
         {
            RemFont(tf);
            Remove(node);
         }
      }

      Permit();

      PrintInfo("All disk fonts in RAM flushed", SPEAK, SEC);

      RefreshList(LastID);

      PrintStatistics();
   }

   return;
}

void
RSysFlushAll(void)
{
   RSysFlushAllLibraries();
   RSysFlushAllFonts();

   return;
}
