/**********************************************************************
 * luc_next.c -- return next important trn in meeting
 *
 * $Author: brlewis $
 * $Source$
 * $Header$
 *
 * Copyright 1991 by the Massachusetts Institute of Technology.
 *
 * For copying and distribution information, please see the file
 * <mit-copyright.h>.
 **********************************************************************/
#include <mit-copyright.h>

#ifndef lint
static char rcsid_luc_next_c[] = "$Header$";
#endif lint

#include <stdio.h>
#include <sys/errno.h>
#include "lucy.h"
#include "memory.h"

/**********************************************************************
 * luc_next(lmeeting *mp, int n, int *np)
 *	caller sets mp (usually luv_curmtgp) to specify meeting
 *	caller sets n to specify prev trn (LUCY_NULLQ if none).
 *
 * - points *np at correct int.
 * - returns error code
 **********************************************************************/

long
luc_next(mp, n, np)
     LMEETING *mp;
     int n, *np;
{
  long code;
  ltrn *lq;

  /* If n < LOWQ, find the first question in the queue */
  if (n < LUCY_LOWQ) {
    n = mp->info.first;
    /* The first non-dl trans in queue may be first question. */
    if (n >= LUCY_LOWQ) {
      *np = n;
      return(0L);
    }
  }

  /* Find the next trans that starts a chain */
  code = luc_trn_info(mp, n, &lq);
  if (code) {
    sprintf(luv_context, "while getting info on [%04d]", n);
    return(code);
  }
  do {
    n = lq->next;
    if (!n) break;
    code = luc_trn_info(mp, n, &lq);
    if (code) {
      sprintf(luv_context, "while getting info on [%04d]", n);
      return(code);
    }
  } while (lq->pref);
  *np = n;

  return(0L);
}
