/*
 *	$Source: /u1/X/xman/RCS/menus.c,v $
 *	$Header: menus.c,v 1.1 87/01/28 15:49:58 swick Exp $
 */

#ifndef lint
static char *rcsid_menus_c = "$Header: menus.c,v 1.1 87/01/28 15:49:58 swick Exp $";
#endif	lint

#include "xman.h"

/*
 * Dynamically set up the section pull-down menu
 */
setupSections()
{
  int i;
  register struct sectionNames *sectp;
  register Sx_MenuEntry *sp;
  struct manual *manp;
  char *manname;
  char *malloc();

  nsections = 0;
  sp = sections = (Sx_MenuEntry *) malloc(nmanual * sizeof(Sx_MenuEntry));
  for(i=0,manp = manual; i < nmanual; i++,manp++) {
    sp->centerText = NULL;
    sp->rightText = NULL;
    sp->background = -1;
    sp->proc = SectionsProc;
    sp->clientData = NULL;
    /*
     * Now the hard part, try pick a menu label
     */
    if(manp->man != NULL)
      manname = &manp->man[LMAN];
    else if(manp->cat != NULL)
      manname = &manp->cat[LCAT];
    else continue; /* ?foo? */
    sp->leftText = NULL;
    for(sectp = sectionNames; sectp->dirname != NULL; sectp++)
      if(strcmp(manname,sectp->dirname) == 0) {
	sp->leftText = sectp->label;
	break;
      }
    if(sp->leftText == NULL) {
      char buf[50];

      sprintf(buf,"Manual Section %s",manname);
      sp->leftText = stralloc(buf);
    }
    sp++;
    nsections++;
  }
}
