/*
***************************************************************************
*
* Datei:
*	  RSysFlush.c
*
* Inhalt:
*
*      --- Globale Routinen ---
*
*    void RSysFlushAll ( void );
*    void RSysFlushAllFonts ( void );
*    void RSysFlushAllLibraries ( void );
*
*      --- Lokale  Routinen ---
*
*
* 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 "RSys.h"

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

   HandleHelp(MN_RSysFlushAllLibraries);

	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;

   HandleHelp(MN_RSysFlushAllFonts);

	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;
}
