/**********************************************************************
 * Bruce Lewis
 * MIT Project Athena
 * Created:  8/1/87
 *
 * $Source: /site/u1/exchange/teacher/RCS/fnadmin.c,v $
 * $Author: brlewis $
 * $Header: fnadmin.c,v 1.6 88/09/05 19:30:37 brlewis Exp $
 *
 * Copyright 1987 by the Massachusetts Institute of Technology.
 * For copying and distribution information, see the file
 * "mit-copyright.h".
 *
 * fnadmin.c module -- functions of the administrative menu
 **********************************************************************/
#include "mit-copyright.h"

#ifndef lint
#ifndef RCS
#define RCS
static char rcsid_module_c[] = "$Header: fnadmin.c,v 1.6 88/09/05 19:30:37 brlewis Exp $";
#endif RCS
#endif /* lint */

#include"fx.h"
#include"list.h"
#include<strings.h>
#include<stdio.h>
#include"teacher.h"

/**********************************************************************
 * add_name(argc, argv)
 *   + adds a username to the access list
 **********************************************************************/

add_name(argc, argv)

     int argc;
     char *argv[];
{
  char username[GENLEN];

  Debug((stderr, ">>>> Enter add_name\n"));
  newline(1);

  if (argc == 2) (void) strcpy(username, argv[1]);
  else promptfor("Name", username);

  if (Fx_add(username) != SUCCEEDED)
    Fx_error("Can't add name");
  else printf("Added %s to the access list.\n", username);

  newline(1);
  Debug((stderr, "<<<< Exit add_name\n"));
  return;
}

/**********************************************************************
 * del_name(argc, argv)
 *   + deletes a username from the access list
 **********************************************************************/

del_name(argc, argv)

     int argc;
     char *argv[];
{
  char username[GENLEN];

  Debug((stderr, ">>>> Enter del_name\n"));
  newline(1);

  if (argc == 2) (void) strcpy(username, argv[1]);
  else promptfor("Name", username);

  if (Fx_del(username) != SUCCEEDED)
    Fx_error("Can't delete name");
  else printf("Deleted %s from the access list.\n", username);

  newline(1);
  Debug((stderr, "<<<< Exit del_name\n"));
  return;
}

/********************************************************
 * list_names()
 *   + lists all names in course
 ********************************************************/

list_names()
{
  int i;
  GENLIST *list;

  Debug((stderr, ">>>> Enter list_names"));
  newline(1);

  if (Fx_list_AL(&list) != SUCCEEDED) {
    Fx_error("Can't compile list");
    return;
  }

  for (i=0; i<how_many_entries(list); ++i)
    printf("%s\n",entry_in(list,i));

  newline(1);
  Fx_destroy_list_AL(&list);	/* we're through with the list. */
  Debug((stderr, "<<<< Exit list_names"));
  return;
}
