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

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

void
do_archive(argc, argv)
     int argc;
     char *argv[];
{
  long code;
  int n, n2;
  ltrn *t;
  char subject[257];

  /* Check usage */
  if (argc != 2 || !(n=atoi(argv[1]))) {
    printf("Usage: %s number.\n", argv[0]);
    return;
  }

  /* archiving only allowed from queue */
  if (luv_curmtgp != &luv_qmtg) {
    printf("Type `go queue' first.\n");
    return;
  }

  /* get info on question */
  if (code=luc_trn_info(luv_curmtgp, n, &t)) {
    com_err(argv[0], code, "(%s)", luv_context);
    return;
  }

  /* get good subject line */
  printf("%s\n", list_trn(t));
  if (say_yes("Use this subject?", 1)) {
    strncpy(subject, t->subject, 256);
  } else {
    subject[0] = '\0';
    while (subject[0] == '\0')
      promptfor("Subject:  ", subject, 256);
  }

  /* do actual archiving */
  if (code=luc_archive(luv_curmtgp, n, subject, &n2)) {
    com_err(argv[0], code, "(%s)", luv_context);
    return;
  }
  printf("Archived %d.  Type `unarchive %d' to undo.\n", n, n2);
#ifdef LOG_USAGE
  log_view(strcat(strcpy(subject, "archive "), luc_flgstr(t->flags)));
#endif
  return;
}
