/**********************************************************************
 * tty lucy client to list latest lucy postings
 *
 * $Author: brlewis $
 * $Source: /afs/athena.mit.edu/astaff/project/lucydev/src/server/RCS/lucy_latest.c,v $
 * $Header: /afs/athena.mit.edu/astaff/project/lucydev/src/server/RCS/lucy_latest.c,v 1.1 92/04/01 14:01:32 brlewis Exp $
 *
 * 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_lucy_latest_c[] = "$Header: /afs/athena.mit.edu/astaff/project/lucydev/src/server/RCS/lucy_latest.c,v 1.1 92/04/01 14:01:32 brlewis Exp $";
#endif /* lint */

#include <stdio.h>
#include "lucy/lucy.h"

main(argc, argv)
     int argc;
     char *argv[];
{
  long code=0L;
  FILE *fp;
  ltrn *trninfo;
  int trncount, first, current;
  char *filename;

  code = luc_init();
  if (code)
    {
      com_err(argv[0], code, "(%s)", luv_context);
      /* exit(1); except dsc_get_mtg_info returns bogus error */
    }

  /* find 10th last transaction */
  for (current = luv_bmtg.info.last, trncount=1;
       trncount < 10;
       current = trninfo->prev, trncount++)
    {
      if (code=luc_trn_info(&luv_bmtg, current, &trninfo))
	{
	  com_err(argv[0], code, "(%s)", luv_context);
	  exit(1);
	}
    }
  first = current;

  /* print contents summary */
  printf("\n\tCONTENTS\n\n");
  for(current = luv_bmtg.info.last;
      current >= first;
      current = trninfo->prev)
    {
      if (code=luc_trn_info(&luv_bmtg, current, &trninfo))
	{
	  com_err(argv[0], code, "(%s)", luv_context);
	  exit(1);
	}
      printf("\t%10.10s\t%s\n", ctime(&(trninfo->date_entered)),
	     trninfo->subject);
    }

  /* print 10 latest */
  for(current = luv_bmtg.info.last;
      current >= first;
      current = trninfo->prev)
    {
      if (code=luc_trn_info(&luv_bmtg, current, &trninfo))
	{
	  com_err(argv[0], code, "(%s)", luv_context);
	  exit(1);
	}
      printf("________________________________________________________________________\n");
      printf("\n\t%10.10s\t%s\n\n", ctime(&(trninfo->date_entered)),
	     trninfo->subject);
      if (code = luc_trn_file(&luv_bmtg, current, &filename))
	{
	  com_err(argv[0], code, "(%s)", luv_context);
	  exit(1);
	}
      if (code = luc_insert_file(stdout, filename))
	{
	  com_err(argv[0], code, "(%s)", luv_context);
	  exit(1);
	}
    }
  exit(0);
}
