/**********************************************************************
 * lucy_comment.c -- comment-question routine for lucy
 *
 * $Source$
 * $Author$
 * $Header$
 *
 * Copyright 1990 by the Massachusetts Institute of Technology.
 * For copying and distribution information, see the file
 * "mit-copyright.h".
 **********************************************************************/
#include "mit-copyright.h"

#ifndef lint
static char rcsid_lucy_comment_c[] = "$Header$";
#endif /* lint */

#include <stdio.h>
#include "lucy/lucy.h"
tfile unix_tfile();		/* XXX should be in discuss .h file */

void
lucy_comment(argc, argv)
     int argc;
     char *argv[];
{
  long code;
  FILE *fp;
  tfile tf;
  lucy_qident i;
  name_blk *nb;
  lucyqlist l;
  int oumask;
  char subj[80];

  i = atoi(argv[1]);		/* XXX more error checking */

  oumask = umask(077);		/* protect temporary file */

  code = lucy_qnb(&nb);
  if (code) {
    com_err(argv[0], code, "");
    return;
  }

  system("emacs /tmp/lucydraft");	/* XXX do right */
  umask(oumask);

  fp = fopen("/tmp/lucydraft", "r");
  if (!fp) {
    perror(argv[0]);
    return;
  }
  code = lucy_trn_info(i, &l);
  if (code) {
    com_err(argv[0], code, "getting subject line");
    return;
  }
  sprintf(subj, "CMT: %s", l->info.subject);
  tf = unix_tfile(fp->_file);
  dsc_add_trn(&nb, tf, subj, 0, &i, &code);
  if (code) {
    com_err(argv[0], code, "entering comment");
    return;
  }
  printf("Entered transaction %d\n", i);
  lucy_trn_info(0, NULL);
  return;
}
