# define PRIVATE static
# define PUBLIC 

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

# include <stdio.h>
# include <signal.h>

int T, Tinc, Treset;

PUBLIC int
int_val (n)
    kdatum n;
{
  kdatum sn;
  int i;

  sn= zeronat();
  i= 0;
  while (!kd_equal(sn, n)) {
    i++;
    sn= Succ(sn);
  }
  kd_free(sn);
  return i;
}

PRIVATE void
onintr ()
{
  clean_kb ();
  clean_sockets ();
  exit (0);
}

main (argc, argv)
    int	argc;
    char* argv[];
{
  void* actual[2];
  int p;
  int side;

  srand (getpid ());
  konfig.trace = 0;
  if (argc != 5) {
    fprintf (stderr, "usage: %s T Tinc Treset side\n", argv[0]);
    exit (1);
  }

  kaos.debug = TRUE;
  ldcinit ();
  T= atoi (argv[1]);
  Tinc= atoi (argv[2]);
  Treset= atoi (argv[3]);
  signal (SIGINT, onintr);
  
  side= atoi (argv[4]);       
  if (side % 2 == 1) {
    connect_one ();
    actual[0]= (void*)sap1 ();
    actual[1]= (void*)cmsap1 ();
    lbcinit (2, actual);
  }
  else {
    connect_two ();
    actual[0]= (void*)sap2 ();
    actual[1]= (void*)cmsap2 ();
    lbcinit (2, actual);
  }
  exit (sch ());
  }
