#include <exec/execbase.h>
struct ExecBase *SysBase;

/* Improve this by looking for "process" wrappers and seeing if the process
   represents a "process".
*/
main()
{
    struct Task *a_task, *run, **wtask, **ltask, *tnodes[50], **Anode = tnodes;

    Disable();

    run = (struct Task *)(SysBase->ThisTask);

    for (a_task = (struct Task *)(SysBase->TaskReady.lh_Head);
	a_task->tc_Node.ln_Succ; *Anode=a_task, Anode++,
	a_task=(struct Task *)(a_task->tc_Node.ln_Succ));

    wtask = Anode;

    for (a_task = (struct Task *)(SysBase->TaskWait.lh_Head);
	a_task->tc_Node.ln_Succ; *Anode=a_task,Anode++,
	a_task=(struct Task *)(a_task->tc_Node.ln_Succ));
   
    ltask = Anode;

    Enable();

    printf("TaskAddr StackAdr Stack Pri Signals  State Name\n");
    printf("-------- -------- ----- --- -------- ----- ---------\n");
    o2(run, "Run");
    for (Anode=tnodes;Anode!=wtask; Anode++) o2(*Anode, "Ready");
    for (; Anode!=ltask; Anode++) o2(*Anode, "Wait");
}

o2 (struct Task *at, char *state)
{
    printf ("%8x%9x%6d%4d%9x %-5s %s\n", at, at->tc_SPLower,
	(ULONG)at->tc_SPUpper - (ULONG)at->tc_SPLower,
	(LONG)at->tc_Node.ln_Pri, at->tc_SigWait, state, at->tc_Node.ln_Name);
}
