#include <proto/listbrowser.h>
#include <gadgets/listbrowser.h>
#include <proto/exec.h>
#include <exec/memory.h>

struct List *
BrowserNodesA( STRPTR *labels )
{
	struct TagItem ti[2];
	struct List *l;
	struct Node *n;
	
	/* allocate a simple 1 column ListBrowser list from a label array */
	
	if (!labels)
		return NULL;
		
	if (!(l = AllocMem(sizeof(struct List), MEMF_PUBLIC|MEMF_CLEAR)))
		return NULL;
		
	NewList( l );
	
	ti[0].ti_Tag = LBNCA_Text;
	ti[1].ti_Tag = TAG_END;
	
	while (*labels)
	{
		ti[0].ti_Data = (ULONG)*labels;
		if (!(n = AllocListBrowserNodeA( 1, ti )))
			break;
		n->ln_Name = *labels++;
		AddTail( l, n );
	}
	return l;
}

void
FreeBrowserNodes( struct List *l )
{
	struct Node *n;
	
	/* Free a list generated by the above function */
	
	if (!l)
		return;
	
	while (n = RemTail(l))
		FreeListBrowserNode(n);
		
	FreeMem(l, sizeof(struct List));
}
