/**********************************************************************
 * do_who.c  -- SS command for seeing who is lucy
 * tty lucy client using SS library
 *
 * $Author: brlewis $
 * $Source$
 * $Header$
 *
 * 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_who_c[] = "$Header$";
#endif /* lint */

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

void
do_who(argc, argv)
     int argc;
     char *argv[];
{
  long code;
  lacl_entry *list;
  int i;
  char filename[256];
  FILE *fp;
  static char *levs[] =
    {
      "given no access",
      "allowed to scan, show",
      "allowed to forw",
      "allowed to archive",
      "allowed to hire"
    };

  if (code = luc_who(&list))
    {
      com_err(argv[0], code, "(%s)", luv_context);
      return;
    }

  /* print list of users with access to queue */
  printf("\n%-32s level\n", "User");
  for(i=0; list[i].principal; i++)
    printf("%-32s %d %s\n", list[i].principal, list[i].level,
	   levs[list[i].level]);

  /* Get correspondents filename */
  sprintf(filename, "%s/Private/correspondents", getenv("HOME"));
  fp = fopen(filename, "r");
  if (!fp)
    {
      if (errno == ENOENT) return;
      com_err(argv[0], (long) errno, "(%s)", luv_context);
      return;
    }

  /* print correspondents */
  printf("\nYour correspondents: (type `emacs c' to edit this list)\n");
  if (code=luc_insert_file(stdout, filename))
    com_err(argv[0], code, "(%s)", luv_context);

  return;
}
