extern "C" {

#include <ndialog.h>
#include <stdio.h>
#include <string.h>

}

template <class C> class Imenu {
public:
    static LIA buildmenu(C* list, int nrlist)
    {
	LIA menu = newLIA(0,0);
	int nrmenu = 0;
	int i;
	char id[20];
	C* ptr;

	for (ptr = list, i=0; i<nrlist; i++, ptr++) {
	    if (ptr->product() == 0)	/* don't add things that don't have */
		continue;		/* a product name */

	    if ( !(nrmenu && strieq(ptr->vendor(),
				    LIAlist(menu)[nrmenu-1].item)) ) {
		addToLIA(menu, 0, ptr->vendor(), 0);
		LIAlist(menu)[nrmenu++].id = (char*)newLIA(0,0);
	    }

	    sprintf(id, "%d", i);
	    addToLIA(LIAlist(menu)[nrmenu-1].id, id, ptr->product(), 0);
	}
	return menu;
    } /* buildmenu */
} /* Imenu */ ;
