/* CXPlor - Demo to show use of system lists.
 * 	    A MUCH stripped version of an explorer used for
 * 	    my own explorations.  Compliments the assembler
 * 	    version XPlor written by Larry Phillips.
 * (c) 1987 Anson Mah
 * Freely distributable and fully public domain.
 */



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

struct ExecBase *ExecBase;


void printlist(list)
struct List *list;
{
	struct Node *node;

	/* see RKM */
	for (node = list->lh_Head; node->ln_Succ; node = node->ln_Succ)
		printf("Node %lx is named %s\n", node, node->ln_Name);

	/* Note that the node address is also the address of a
	   Task or Process structure (for those nodes in the
	   TaskReady and TaskWait lists).  Once you've found these,
	   there is really no need to do FindTask to get any tasks
	   or processes!  (This is where FindTask gets it, anyway.) */
}


void main()
{
	/* get address of ExecBase the decent way.... */
	if ((ExecBase = (struct ExecBase *)OpenLibrary("exec.library", 0))
		== NULL) {
		printf("Can't open exec.library.  How strange...\n");
		exit();
	}
	printf("System Lists\n");
	printf("------------\n\n");
	printf("Tasks ready:\n");
	printlist( &(ExecBase->TaskReady));
        printf("Tasks waiting:\n");
	printlist( &(ExecBase->TaskWait));
	printf("Library List:\n");
	printlist( &(ExecBase->LibList));
	printf("Device List:\n");
	printlist( &(ExecBase->DeviceList));
	printf("Ports List:\n");
	printlist( &(ExecBase->PortList));
	printf("Memory List:\n");
	printlist( &(ExecBase->MemList));
	printf("Resource List:\n");
	printlist( &(ExecBase->ResourceList));

	CloseLibrary( (void *) ExecBase);
}
