/**********************************************************************
 * luc_next.c -- return next important trn in meeting
 *
 * $Author: brlewis $
 * $Source: /afs/athena.mit.edu/astaff/project/lucydev/src/lib/RCS/luc_next.c,v $
 * $Header: /afs/athena.mit.edu/astaff/project/lucydev/src/lib/RCS/luc_next.c,v 1.1 91/08/01 14:32:13 brlewis Exp Locker: brlewis $
 *
 * 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: /afs/athena.mit.edu/astaff/project/lucydev/src/lib/RCS/luc_next.c,v 1.1 91/08/01 14:32:13 brlewis Exp Locker: brlewis $";
#endif /* lint */

#include <stdio.h>
#include <sys/errno.h>
#include "lucy/lucy.h"
#include "lucy/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 */
  if (code=luc_trn_info(mp, n, &lq)) return(code);

  do {
    n = lq->next;
    if (!n) break;
    if (code=luc_trn_info(mp, n, &lq)) return(code);
  } while (lq->pref);
  *np = n;

  return(0L);
}
