/**********************************************************************
 * do_report.c  -- SS command for reporting a transaction
 * tty lucy client using SS library
 *
 * $Author: brlewis $
 * $Source: /afs/athena.mit.edu/astaff/project/lucydev/src/tty/do_report.c,v $
 * $Header: /afs/athena.mit.edu/astaff/project/lucydev/src/tty/do_report.c,v 1.1 91/09/24 14:46:59 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_do_report_c[] = "$Header: /afs/athena.mit.edu/astaff/project/lucydev/src/tty/do_report.c,v 1.1 91/09/24 14:46:59 brlewis Exp Locker: brlewis $";
#endif /* lint */

#include <stdio.h>
#include <sys/file.h>
#include <ss/ss.h>
#include <lucy/lucy.h>
#include "config.h"

void
do_report(argc, argv)
     int argc;
     char *argv[];
{
  long code;
  char filename[256], title[256], call[256];
  FILE *fp;
  int i, j;

  sprintf(filename, "%s/report.tex", luv_topdir);

  if (argc < 2 && access(filename, F_OK)) goto USAGE;

  promptfor("Title of report: ", title, 255);
  if ((fp = fopen(filename, "w")) == NULL) {
    com_err(argv[0], (long) errno, "(%s)", filename);
    return;
  }
  luc_report(title, luc_fullname(luv_curmtgp->nb.user_id), fp);
  for(i=1; i<argc; i++) {
    if (atoi(argv[i]) == 0) goto USAGE;
    for (j=lower_bound(argv[i]); j != 0 && j <= upper_bound(argv[i]);
	 luc_next(luv_curmtgp, j, &j)) {
      if (code = luc_section(luv_curmtgp, j, fp)) {
	com_err(argv[0], code, "(%s)", luv_context);
	return;
      }
    }
  }
  luc_endreport(fp);
  fclose(fp);

  sprintf(call, "cd %s && latex report && latex report", luv_topdir);
  system(call);
  return;

 USAGE:
  printf("Usage: %s number number ...\n", argv[0]);
  return;
}
