/*-------------------------------------------------------------------------*/
/* GNU Prolog                                                              */
/*                                                                         */
/* Part  : Prolog buit-in predicates                                       */
/* File  : t_c.c                                                           */
/* Descr.: test - C part                                                   */
/* Author: Daniel Diaz                                                     */
/*                                                                         */
/* Copyright (C) 1999 Daniel Diaz                                          */
/*                                                                         */
/* GNU Prolog is free software; you can redistribute it and/or modify it   */
/* under the terms of the GNU General Public License as published by the   */
/* Free Software Foundation; either version 2, or any later version.       */
/*                                                                         */
/* GNU Prolog is distributed in the hope that it will be useful, but       */
/* WITHOUT ANY WARRANTY; without even the implied warranty of              */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU        */
/* General Public License for more details.                                */
/*                                                                         */
/* You should have received a copy of the GNU General Public License along */
/* with this program; if not, write to the Free Software Foundation, Inc.  */
/* 59 Temple Place - Suite 330, Boston, MA 02111, USA.                     */
/*-------------------------------------------------------------------------*/
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#if 1
#include "engine_pl.h"
#include "bips_pl.h"

#endif
/*---------------------------------*/
/* Constants                       */
/*---------------------------------*/

/*---------------------------------*/
/* Type Definitions                */
/*---------------------------------*/

/*---------------------------------*/
/* Global Variables                */
/*---------------------------------*/

/*---------------------------------*/
/* Function Prototypes             */
/*---------------------------------*/
#if 0
/*-------------------------------------------------------------------------*/
/*                                                                         */
/*                                                                         */
/*-------------------------------------------------------------------------*/
Bool Test(WamWord w)

{
#if 0
 Check_For_Un_Callable(w);
 return TRUE;

#elif 0
 Emit_Syntax_Error(Rd_String_Check(w),1,1,"syn err from C");
 return FALSE;

#elif 0
 WamWord *arg;
 int i,func,arity;

 arg=Rd_Callable_Check(w,&func,&arity);
 printf("functor=%s arity=%d\n",atom_tbl[func].name,arity);

 for(i=0;i<arity;i++)
   {
    printf("  arg %d=",i); Write_Simple(arg[i]);
    printf("\n");
   }
 return TRUE;
#elif 0

 WamWord arg[16];

 arg[0]=Mk_Integer(12);
 arg[1]=Mk_Float(12.56);
 arg[2]=Mk_String("toto");
 return Un_Compound_Check(atom_char['f'],3,arg,w);

#elif 0

 WamWord arg[16];
 WamWord r;

 arg[0]=Mk_Integer(12);
 arg[1]=Mk_Float(12.56);
 arg[2]=Mk_String("toto");
 r=Mk_Compound(atom_char['.'],2,arg);
 return Unify(w,r);

#elif 0

 WamWord arg[256];
 int     n,i;

 n=Rd_Proper_List(w,arg);
 for(i=0;i<n;i++)
     Write_Simple(arg[i]), putchar('\n');
 return TRUE;

#elif 0

 WamWord arg[16];

 arg[0]=Mk_Integer(12);
 arg[1]=Mk_Float(12.56);
 arg[2]=Mk_String("toto");

 return Un_Proper_List_Check(3,arg,w);

#elif 1

 WamWord arg[16];
 WamWord r;

 arg[0]=Mk_Integer(12);
 arg[1]=Mk_Float(12.56);
 arg[2]=Mk_String("toto");
 r=Mk_Proper_List(3,arg);

 return Unify(w,r);

#endif
}


#if  0
int main (int argc, char *argv[])
{
  int func;
  WamWord arg[10];
  Bool res;
  FILE *fptr;
  int i;
  
 Start_Prolog(argc, argv);
 func = Find_Atom("main");

  for (i=0; i<= 32767; ++i)
    {
     fptr = fopen("test.txt", "w");
     fprintf(fptr, "%d.\n", i);
     fclose(fptr);
      
      res = Pl_Query_Start(func, 0, arg, TRUE);
      Pl_Query_End(PL_RECOVER);
      
    }
  return(0);
}
#endif

#if 0
/*-------------------------------------------------------------------------*/
/* MAIN                                                                    */
/*                                                                         */
/*-------------------------------------------------------------------------*/
int main(int argc,char *argv[])

{
 int     func_asserta;
 WamWord arg[10];
 char    name[100],list[100],assert_buf[1024];
 int     res;

 Start_Prolog(argc,argv);

 func_asserta=Find_Atom("my_assert");
 for(;;)
    {
     printf("\nEnter a name (or 'end' to finish): ");
     scanf("%s",name);

     if (strcmp(name,"end")==0)
         break;

     printf("\nEnter a list: ");
     scanf("%s",list);

     sprintf( assert_buf, "free(%s,%s).", name, list );
     printf( "asserting: %s\n", assert_buf );

     arg[0]=Mk_Chars(assert_buf);
     res=Pl_Query_Start(func_asserta, 1, arg, TRUE);
     if (res==PL_EXCEPTION)
        {
         printf("Excep: ");
         Write_Simple(Pl_Get_Exception());
         printf("\n");
        }
     Pl_Query_End(PL_RECOVER);
     
         /* Check asserted clauses */
     Pl_Query_Start(Find_Atom("listing"),0,NULL,TRUE);
     Pl_Query_End(PL_RECOVER);
    }
 return 0;     
}

#endif

#endif

#if 0

#include <string.h>
#include "gprolog.h"

Bool my_call(PlTerm goal)

{
 PlTerm *arg;
 int     functor, arity;
 int     result;

 arg=Rd_Callable_Check(goal, &functor, &arity);
 result=Pl_Query_Start(functor, arity, arg, FALSE);
 Pl_Query_End(PL_KEEP_FOR_PROLOG);
 return (result==PL_SUCCESS);
}
#endif



/*---------------------------------*/
/* Constants                       */
/*---------------------------------*/

/*---------------------------------*/
/* Type Definitions                */
/*---------------------------------*/

/*---------------------------------*/
/* Global Variables                */
/*---------------------------------*/

/*---------------------------------*/
/* Function Prototypes             */
/*---------------------------------*/

/*-------------------------------------------------------------------------*/
/* COMPILE_CLAUSE                                                          */
/*                                                                         */
/*-------------------------------------------------------------------------*/
void Compile_Clause(WamWord head_word,WamWord body_word)

{
}
