# define PRIVATE static
# define PUBLIC 

#ifndef TRUE
# define TRUE  1
# define FALSE 0
#endif

#include <stdio.h>
#include <string.h>

#include "ldc.hh"
#include <lotos.hh>

#include "swbus.h"

PRIVATE char user_req= '0';
PRIVATE char user_data[BUFSIZ];

PRIVATE int dmenu=  FALSE;

/* just draw the option menu */

PUBLIC void
draw_menu ()
{
    printf ("\n");
    printf ("Type in Observation:\n");
    printf ("1   ConInd\n");
    printf ("2   ConConf\n");
    printf ("3   DatInd\n");
    printf ("4   DisInd\n");
}

PUBLIC int
key_press ()
{
  char c;
  int i, size;

/*
  if (dmenu) {
    draw_menu ();
    dmenu= FALSE;
  }
*/
  if (! cready (0))
    return FALSE;

  user_req= cget (0);
  while (cready (0))
    c= cget (0);
  c= 0;
/*
  dmenu= TRUE;
*/
  if ('1' <= user_req && user_req <= '4') {
    if (user_req == '3') {
      printf ("Data received: ");
      fflush (stdout);
      for (i= 0; c != '\n'; i++)
	user_data[i]= c= cget (0);
      user_data[i-1]= 0;
    }
    return TRUE;
  }
  else
    return FALSE;
}  

PUBLIC kdatum
user_input ()
{
  static kdatum repeated_pdu= NULL;

  switch (user_req) {
  case '1':
    return ConInd ();
  case '2':
    return ConConf ();
  case '3':
    return DatInd (mk_sdu (user_data));
  case '4':
    return DisInd ();
  default:
    fprintf (stderr, "no data received, why?\n");
    exit (1);
  }
}

PRIVATE char observation[BUFSIZ];

PUBLIC void
send_asap (sp)
  kdatum sp;
{
  char c;
  int i;

  (void) strcpy (observation, "              ");
  printf ("do  <%s>, ready? \n", kd_gdraw (sp, 1));
  fflush (stdout);
  i= 0;
  while (c != '\n')
    observation[i++]= c= cget (0);
}

PUBLIC kdatum
accepted ()
{
/*
printf ("observation='%c%c%c...'\n",
	observation[0], observation[1], observation[2]);
*/
  if (observation[0] == 'n' || observation[0] == 'N')
    return fail ();
  else
    return pass ();
}

PUBLIC void
clean_kb ()
{
  setblock (0, TRUE);
}

