#include <std.h>        /* must be first inclusion */
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <mouse.h>
#include <menu.h>
#include "stmutil.h"	/* for basic interface functions */
#if defined(__ZTC__) || defined(__STDC__)
# include <stdlib.h>
#endif

BOOL addstrquery(MENU *menu, unsigned *data, C char *format,
				C BOOL *active, /*C*/ List(String)& selections, int id)
{
 char **p = new char * [selections.length()+1];
 if(!p)	return FALSE;
 Listiter(String) i(selections);
 char **q;
 for(q = p;!i.at_end();i.step_next(),q++)	{
	*q = new char[i.peek_next().length()];
	if(!*q)		{
		for(;p<q;p++)
			delete *p;
		return FALSE;
		}
	strcpy(*q, i.peek_next());
	}
 *q = 0;
 BOOL rv = addstrquery(menu, data, format, active, p, id);
 q = p;
 for(;p<q;p++)
	delete *p;
 delete q;

 return rv;
}

BOOL addstrarray(MENU *menu, C unsigned *data, C char *format,
				C BOOL *active, /*C*/ List(String)& selections, int id)
{
 if(!addstrquery(menu, (unsigned *)data, format, active, selections, id))
	return FALSE;
 finditem(menu, id)->query = FALSE;
 return showid(menu, id);
}
