/***************************************************************************
 *									   *
 *              WILLOW(tm) Information Retrieval Software		   *
 *     (Washington Information Looker-upper Layered Over Windows)	   *
 * 									   *
 *             Copyright 1992 University of Washington			   *
 *       Willow is a trademark of the University of Washington		   *
 * 									   *
 * Permission to use, copy, modify, and distribute Willow(tm) software	   *
 * and its documentation for any purpose and without fee is hereby	   *
 * granted, provided that the above copyright notice appears in all	   *
 * copies and that both the above copyright notice and this permission	   *
 * notice appear in supporting documentation, and that the name of the	   *
 * University of Washington not be used in advertising or publicity	   *
 * pertaining to distribution of the software without specific, written	   *
 * prior permission.  This software is made available "as is", and	   *
 * 									   *
 * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR	   *
 * IMPLIED, WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION	   *
 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR  *
 * PURPOSE, AND IN NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE   *
 * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES	   *
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN   *
 * ACTION OF CONTRACT, TORT (INCLUDING NEGLIGENCE) OR STRICT LIABILITY,	   *
 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS	   *
 * SOFTWARE.								   *
 * 									   *
 * For further information please contact:				   *
 * 									   *
 * Matthew Freedman							   *
 * Information Systems							   *
 * Computing and Communications						   *
 * University of Washington						   *
 * 4545 15th, 4th Floor JE-41						   *
 * Seattle, Washington, 98195, USA					   *
 * Internet: mattf@cac.washington.edu					   *
 ***************************************************************************/

/**********************************************************
 * table.c
 * In this module we initialize the state table for the 
 * database driver. We also define a couple other
 * necessary tables.
 **********************************************************/

#define NULL 0

#include "driver.h"

/* External references to host-callback routines */

/* These are general routines */
extern retry_login(void);
extern bad_uid_hcb(void);
extern bad_login_hcb(void);
extern login_msg_hcb(void);
extern force_quit_hcb(void);
extern bad_startup_hcb(void);
extern assert_logged_on(void);
/* The state table which actually drives everything */
state_table  states;

/* Initialize the state table which describes the behavior of
   the BRS searchmate interface.
   */
init_table(void)
{
  int   i,j;
  
  for (i = 0; i < MAX_TRANSITIONS; i++)
    for (j = 0; j < MAX_STATES; j++) {
      states[i][j].in_string  = NULL;
      states[i][j].out_string = NULL;
      states[i][j].next_state = 0;
      states[i][j].action     = NULL;
    }
  
  states[NO_CON][0].in_string  = "";
  states[NO_CON][0].out_string = "";
  states[NO_CON][0].next_state = NO_CON;

  states[AWAIT_LOGIN][0].in_string  = "=> ";
  states[AWAIT_LOGIN][0].out_string = account;
  states[AWAIT_LOGIN][0].next_state = AWAIT_SHELL;

  states[AWAIT_LOGIN][1].in_string  = "TIOCGETP";
  states[AWAIT_LOGIN][1].out_string = "";
  states[AWAIT_LOGIN][1].next_state = AWAIT_LOGIN;


  states[AWAIT_SHELL][0].in_string  = "=> ";
  states[AWAIT_SHELL][0].out_string = password;
  states[AWAIT_SHELL][0].next_state = READY;
  states[AWAIT_SHELL][0].action     = assert_logged_on;

  states[READY][0].in_string  = "";
  states[READY][0].out_string = "";
  states[READY][0].next_state = READY;


  states[QUITTING][0].in_string  = "%";
  states[QUITTING][0].out_string = "";
  states[QUITTING][0].next_state = NO_CON;
  states[QUITTING][0].action     = force_quit_hcb;
};

