/**********************************************************************
 * luc_lagtime.c -- lagtime flags for transaction
 *
 * $Author: brlewis $
 * $Source: /afs/athena.mit.edu/astaff/project/lucydev/src/lib/RCS/luc_lagtime.c,v $
 * $Header: /afs/athena.mit.edu/astaff/project/lucydev/src/lib/RCS/luc_lagtime.c,v 1.1 92/05/14 09:35:20 brlewis Exp Locker: brlewis $
 *
 * Copyright 1992 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_lagtime_c[] = "$Header: /afs/athena.mit.edu/astaff/project/lucydev/src/lib/RCS/luc_lagtime.c,v 1.1 92/05/14 09:35:20 brlewis Exp Locker: brlewis $";
#endif /* lint */

#ifdef POSIX
#include <time.h>
#else
#include <sys/types.h>
#endif
#include <lucy/lucy.h>

/**********************************************************************
 * luc_lagtime(int n, int flag, time_t *ans_time)
 *	caller sets n to specify transaction number
 *	caller sets flag to LUCY_POSTED or LUCY_REPLIED
 *
 * - finds last transaction in chain with the given flag set
 * - puts the time of posting/reply in *ans_time
 * - returns error code
 **********************************************************************/

long
luc_lagtime(n, flag, ans_time)
     int n, flag;
     time_t *ans_time;
{
  long code;
  ltrn *info;
  int i;

  if (code = luc_trn_info(&luv_qmtg, n, &info)) return(code);
  for (i=info->lref; i>n; i=info->pref)
    {
      if (code=luc_trn_info(&luv_qmtg, i, &info)) return(code);
      if (info->flags & flag)
	{
	  *ans_time = (time_t) info->date_entered;
	  return(0L);
	}
    }
  /* no such flag found */
  *ans_time = (time_t) 0;
  return(0L);
}
