home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
074.lha
/
Exec
/
ListPorts.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-11-20
|
2KB
|
126 lines
/*
* ListPorts.c
*
* This program produces a list of message ports on it's standard.
* output.
*
* Program Date Action
* D. Thomas 24 April 1987 v1.0 Initial Coding.
*
*/
#include "exec/execbase.h"
#include "exec/ports.h"
#include "functions.h"
extern struct ExecBase *SysBase; /* Exec's base ptr */
static char *flag[] = {
"Signal",
"SoftInt",
"Ignore"
};
main ()
{
register struct MsgPort *t; /* ptr to port list */
register struct List head; /* for my copy of the port list */
NewList (&head);
Disable ();
if (getlist (&SysBase->PortList, &head))
cleanup (&head);
Enable ();
puts ("Action Signalled Task Port");
while (t = (struct MsgPort *) RemHead (&head)) {
printf ("%-7.7s %-20.20s %s\n",
flag[t->mp_Flags & PF_ACTION],
(t->mp_SigTask ? t->mp_SigTask->tc_Node.ln_Name : "<unset>"),
(t->mp_Node.ln_Name ? t->mp_Node.ln_Name : "<unset>"));
FreeMem (t->mp_Node.ln_Name, (long) strlen (t->mp_Node.ln_Name) + 1);
FreeMem (t, (long) sizeof *t);
}
exit (0L);
}
freelist (l)
struct List *l;
{
struct MsgPort *t;
while (t = (struct MsgPort *) RemHead (l)) {
FreeMem (t->mp_Node.ln_Name, (long) strlen (t->mp_Node.ln_Name) + 1);
FreeMem (t, (long) sizeof *t);
}
}
cleanup (l)
struct List *l;
{
Enable ();
freelist (l);
puts ("Out of Memory!");
exit (0);
}
getlist (tl, l)
struct List *tl;
struct List *l;
{
register struct MsgPort *t;
for (t = (struct MsgPort *) tl->lh_Head;
t->mp_Node.ln_Succ;
t = (struct MsgPort *) t->mp_Node.ln_Succ)
if (onenode (t, l))
return TRUE;
return FALSE;
}
onenode (t, l)
struct MsgPort *t;
struct List *l;
{
register struct MsgPort *tc;
if (!(tc = (struct MsgPort *) AllocMem ((long) sizeof *t, 0L)))
return TRUE;
*tc = *t;
if (!(tc->mp_Node.ln_Name = (char *) AllocMem ((long) strlen (t->mp_Node.ln_Name) + 1, 0L))) {
FreeMem (tc, (long) sizeof *tc);
return TRUE;
}
strcpy (tc->mp_Node.ln_Name, t->mp_Node.ln_Name);
AddTail (l, tc);
return FALSE;
}