int main(int argc, char *argv[])
{ 

  int rc;

  int return_size = 15;
  char *return_string;
  return_string = malloc(return_size);

  int myargc = 1;
  char *myargv[1];

  myargv[0] = strip_names_from_path(xsb_executable_full_path(argv[0]),3);

  if (xsb_init(myargc,myargv)) {
    fprintf(stderr,"%s initializing XSB: %s\n",xsb_get_init_error_type(),
	    xsb_get_init_error_message());
    exit(XSB_ERROR);
  }

#ifdef MULTI_THREAD
  th_context *th = xsb_get_main_thread();
#define xsb_get_main_thread_macro() xsb_get_main_thread()
#else
#define xsb_get_main_thread_macro() 
#endif

  c2p_functor(CTXTc "consult",1,reg_term(CTXTc 1));
  c2p_string(CTXTc "edb.P",p2p_arg(reg_term(CTXTc 1),1));

  /* Create command to consult a file: edb.P, and send it. */
  if (xsb_command(CTXT) == XSB_ERROR)
    fprintf(stderr,"++Error consulting edb.P: %s/%s\n",
	    xsb_get_error_type(xsb_get_main_thread_macro()),
	    xsb_get_error_message(xsb_get_main_thread_macro()));

  c2p_functor(CTXTc "pregs",3,reg_term(CTXTc 1));

  rc = xsb_query(CTXT);

  while (rc == XSB_SUCCESS) {
  
    printf("Answer: pregs(%s,%s,%s)\n",
	     xsb_var_string(1),xsb_var_string(2),xsb_var_string(2));
    rc = xsb_next(CTXT);
  }

 if (rc == XSB_ERROR) 
   fprintf(stderr,"++Query Error: %s/%s\n",
	   xsb_get_error_type(xsb_get_main_thread_macro()),
	   xsb_get_error_message(xsb_get_main_thread_macro()));

  xsb_close(CTXT);
  return(0);
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{ 

  int anslen,rc;
  int return_size = 15;
  char *return_string = malloc(return_size);

  int myargc = 1;
  char *myargv[1];

  myargv[0] = argv[1];

  if (xsb_init(myargc,myargv)) {
    fprintf(stderr,"%s initializing XSB: %s\n",xsb_get_init_error_type(),
	    xsb_get_init_error_message());
    exit(XSB_ERROR);
  }

#ifdef MULTI_THREAD
  th_context *th = xsb_get_main_thread();
#define xsb_get_main_thread_macro() xsb_get_main_thread()
#else
#define xsb_get_main_thread_macro() 
#endif

  /* Create command to consult a file: edb.P, and send it. */
  if (xsb_command_string(CTXTc "consult('edb.P').") == XSB_ERROR)
    fprintf(stderr,"++Error consulting edb.P: %s/%s\n",
	    xsb_get_error_type(xsb_get_main_thread_macro()),
	    xsb_get_error_message(xsb_get_main_thread_macro()));

  rc = xsb_query_string_string_b(CTXTc "p(X,Y,Z).",return_string,return_size,&anslen,"|");

  while (rc == XSB_SUCCESS || rc == XSB_OVERFLOW) {
  
    if (rc == XSB_OVERFLOW) {
      printf("reallocating (%d)\n",anslen);
      return_string = (char *) realloc(return_string,anslen);
      return_size = anslen;
      rc = xsb_get_last_answer_string(CTXTc return_string,return_size,&anslen);
    }    

    printf("Return %s %d %d\n",return_string,return_size,anslen);
    rc = xsb_next_string_b(CTXTc return_string,return_size,&anslen,"|");
  }

 if (rc == XSB_ERROR) 
   fprintf(stderr,"++Query Error: %s/%s\n",xsb_get_error_type(xsb_get_main_thread_macro()),
	   xsb_get_error_message(xsb_get_main_thread_macro()));

  xsb_close(CTXT);
  return(0);
}