/* monx-prims.cc -- the primitives (senses and actions) you find 
   called in the lap script files.  These mostly just call other libraries
   of functions in other files...

   $Log: monx-prims.cc,v $
   Revision 1.1  1999/12/27 23:48:46  joanna
   Initial revision

   Revision 1.3  1997/09/10 01:36:43  joanna
   works with robs stuff -- fixed loads more chaining problems,
   new rob libraries.  Interactive rob ringrose, not piped yet.

   Revision 1.1  1997/08/10 18:34:11  joanna
   Initial revision

*/

#include <stdio.h>
#include <stream.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include "monx.hh"
#include "brain-objs.hh"

#include "monx-dirattn.hh"

// from string.h
// char *strncat(char *dest, const char *src, size_t n);

static char rcsid[] = "$Id: monx-prims.cc,v 1.1 1999/12/27 23:48:46 joanna Exp joanna $";

/*

When you add a primitive -- 
   1) add it to this list so it can be identified by people
   2) add the code (don't seem to need declarations, just definitions)
   3) add it to initprims at the bottom, so it gets set up

Remember that if a primitive action does not return SUCCESS, the rest
of a fap will not execute!  FAILURE indicates something _very_ drastic
happened, which should abort the next element.  Actually, it may not
make sense to abort except on sensing!

Here are the "monx" prims:

      Basic Actions - (nil sleep)
      Directory Actions - (cd_up cd_attn attn_to_dir)
      Senses  - (see_cookie attend_dir)
                          
*/

// This was just my first test...

/*  ************  Basic Actions  ************ */
// # Since "life" has no goal, need an action that always fails
lapres nil () {
  return (FAILURE);}

lapres sleep () {
  usleep(10); // sleep a hundred thousandth of a second
  return (SUCCESS);
}

/*  ************  Directory Actions  ************ */

lapres cd_up () {
  if (chdir("..") == 0)
    return (SUCCESS);
  else
    return (FAILURE);
}

lapres cd_attn () {
  return (Dirattn::cd_attn());
}

lapres attn_to_dir () {
  return(Dirattn::attn_to_dir());
}

/*  ************  Senses  ************ */

int see_cookie() {

  if (sysret ("ls | egrep cookie") == 0)  // no error, egrep found one
    return ((int) true);
  else
    return ((int) false);
}

int attend_dir() {
  return ((int) Dirattn::attend_dir());
}

void
initprims() {
  // basic life
  Act::add_act("nil", nil);
  Act::add_act("sleep", sleep);

  // life with directories (and food)
  Act::add_act("cd_up", cd_up);
  Act::add_act("cd_attn", cd_attn);
  Act::add_act("attn_to_dir", attn_to_dir);
  Sense::add_sense("see_cookie", see_cookie);
  Sense::add_sense("attend_dir", attend_dir);
} // initprims
