[comp.sys.amiga] Help on Access to Exec system lists in C

bact@ssc-vax.UUCP (Archie A. Auxter) (11/01/87)

Does anybody out there know how to get access to the system lists that
Exec keeps?  I know about the list routines provided by exec, but I
want to get pointers to the head of certain lists.  I'd also like to
be able to get access to any lists held in Intuition.  For example,
for a program that wants to put all current windows on a new screen,
I'd like to be able to access the head of the list where windows
are kept.

thanx for the help.

dillon@CORY.BERKELEY.EDU (Matt Dillon) (11/02/87)

>Does anybody out there know how to get access to the system lists that
>Exec keeps?  I know about the list routines provided by exec, but I
>want to get pointers to the head of certain lists.  I'd also like to
>be able to get access to any lists held in Intuition.  For example,

	The lists are kept in the library structures for EXEC and INTUITION.
Take a look at EXEC/EXECBASE.H, and INTUITION/INTUITIONBASE.H .  

	As far as EXEC goes, you can get a pointer to ExecBase simply by
looking at the global variable SysBase (extern struct ExecBase *SysBase;).
As far as INTUITION goes, you open the intuition.library, and the returned
pointer is actually a pointer to IntuitionBase.

	It should be obvious how to get to various structures, such as 
the screen list Intuition is keeping (and subsequent window lists), by simply
looking at the include files mentioned above.  

WARNING:	In many cases these lists are changing continuously, and
		cannot be assumed to be stable unless accessed in a Forbid()'n
		state.  You must be Forbiden for the entire list traversal,
		and cannot assume any of the nodes will stay around after
		you have Permit()'d again.

LISTS:	(EXEC/LISTS.H, EXEC/NODES.H)
    The major components of a list header structure are lh_Head, lh_Tail,
    and lh_TailPred.  lh_Tail is always NULL and serves to terminate the 
    list.  That is, an empty list would have lh_Head pointing to lh_Tail,
    and lh_TailPred pointing to lh_Head.  Non-empty lists have lh_Head
    pointing to the first node in the list, lh_Tail is always NULL, and
    lh_TailPred pointing to the last node in the list (which might be the
    first if there is only one node)

    The major components of a list node (specific list entries) are ln_Succ
    and ln_Pred.  ln_Succ points to the next node in the list OR lh_Tail of
    the list header if the particular node is the last node in the list.
    ln_Pred points to the previous node in the list OR lh_Head of the list
    header if the particular node is the first node in the list.

    This may seem complicated, but has the following advantages:
	-A fully doubly linked list allowing random insertion, deletion,
	 and scanning in both directions.
	-No special cases when adding a node to the front of the list,
	 the end of the list, or anywhere within the list.
	-No special cases when removing a node.

	When traversing the list, the end of the list is detected when 
	ln_Succ points to a NULL value (NOT when ln_Succ is NULL).  Similarly,
	when traversing the list in reverse, the first node is detected when
	offset 4 from where ln_Prev points to is NULL.

	This NULL of course is the lh_Tail entry in the list header.

					-Matt

bryce@hoser.berkeley.edu (Bryce Nesbitt) (11/02/87)

In article <1492@ssc-vax.UUCP> bact@ssc-vax.UUCP (Archie A. Auxter) writes:
>Does anybody out there know how to get access to the system lists that
>Exec keeps?  I know about the list routines provided by exec, but I
>want to get pointers to the head of certain lists.

I'm about to hand you a loaded gun.  You must use extreme caution
when accesing exec lists.
The list headers are defined in the include file "exec/execbase.h".
Forbid() and Permit() are the proper arbitration mechanisms for
*some* of these lists.  The rest require Disable() Enable() and
*very* quick code.


>I'd also like to
>be able to get access to any lists held in Intuition.
>I'd like to be able to access the head of the list where windows
>are kept.

Now that gun is a 16mm cannon.  The list headers are defined
in the include file "intuition/intutionbase.h".

The proper arbitration here is the Intuition function key=LockIBase(0L);
and UnLockIBase(key).  Search you newsfeed backwards for an article by
Jim Mackraz (jimm) on this point. 

|\ /|  . Ack! (NAK, SOH, EOT)
{o O} . bryce@hoser.berkeley.EDU -or- ucbvax!hoser!bryce
 (")
  U	"You can count how many seeds are in an Apple, but not how
	 many Apples are in a seed." -Ken Kesey	

schaub@sugar.UUCP (Markus Schaub) (11/05/87)

In article <1492@ssc-vax.UUCP>, bact@ssc-vax.UUCP (Archie A. Auxter) writes:
> Does anybody out there know how to get access to the system lists that
> Exec keeps?  I know about the list routines provided by exec, but I
On the M2Amiga demo disk is a program doing this. BUT it's in Modula-2. I can
mail you the source if you want, I could even post it if the is enough demand.

> thanx for the help.
You're welcome
-- 
   //	Markus Schaub	uunet!nuchat!sugar!schaub	 (713) 523 8422
 \X/	c/o Interface Technologies Corp, 3336 Richmond #323, Houston Tx 77098