/* Remove a specified version of arplibrary */
/* This will ALWAYS remove the library, no matter what - USE WITH CARE */
/* SDB */

#include <exec/types.h>
#include <exec/libraries.h>
#include <exec/execbase.h>
#include <libraries/arpbase.h>

struct ArpBase *ArpBase, *OpenLibrary();
struct EnvironmentBase *EB;
extern struct ExecBase *SysBase;

main(argc, argv)
char **argv;
{
	register int i;
	register ULONG v;
	struct ArpBase *FindName();

	if (argc <= 1)
		printf("Usage remlib <version#>\n"), exit(100);
	argv++;

	v = atoi(*argv);
	
	Forbid();
	ArpBase = (struct ArpBase *)(&SysBase->LibList);
	while( ArpBase = FindName(ArpBase, "arp.library"))
	{
		if (ArpBase->LibNode.lib_Version == v)
			break;
	}
	if (!ArpBase)
		printf("Version %ld of arplib not found!\n", v), Permit(),exit(100);

	/* Make sure you want to do this! */
	if (v >= 12)
	{
		EB = (struct EnvironmentBase *)ArpBase->EnvBase;
		*EB->EnvSpace = 0;
	}
	while (ArpBase->LibNode.lib_OpenCnt > 1)
		CloseLibrary(ArpBase);
	if (ArpBase->LibNode.lib_OpenCnt)
		RemLibrary(ArpBase), CloseLibrary(ArpBase);
	else
		RemLibrary(ArpBase);
	Permit();
}

