コード例 #1
0
int main(int argc, char *argv[])
{ 

#ifdef MULTI_THREAD
  static th_context *p_th, *r_th;
#endif

  char init_string[MAXPATHLEN];
  int rcp, rcr;
  XSB_StrDefine(p_return_string);
  XSB_StrDefine(r_return_string);

  /* xsb_init_string relies on the calling program to pass the absolute or relative
     path name of the XSB installation directory. We assume that the current
     program is sitting in the directory ../examples/c_calling_xsb/
     To get installation directory, we strip 3 file names from the path. */
 
  strcpy(init_string,strip_names_from_path(xsb_executable_full_path(argv[0]),3));

  if (xsb_init_string(init_string)) {
    fprintf(stderr,"%s initializing XSB: %s\n",xsb_get_error_type(xsb_get_main_thread()),
	    xsb_get_error_message(xsb_get_main_thread()));
    exit(XSB_ERROR);
  }

  p_th = xsb_get_main_thread();

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

  xsb_ccall_thread_create(p_th,&r_th);

 if (xsb_command_string(r_th,"import thread_exit/0 from thread.") == XSB_ERROR)
    fprintf(stderr,"++Error exiting r: %s/%s\n",xsb_get_error_type(r_th),
	    xsb_get_error_message(r_th));

  rcp = xsb_query_string_string(p_th,"p(X,Y,Z).",&p_return_string,"|");
  rcr = xsb_query_string_string(r_th,"r(X,Y,Z).",&r_return_string,"|");

  while (rcp == XSB_SUCCESS && rcr == XSB_SUCCESS) {

    printf("Return p %s\n",(p_return_string.string));
    rcp = xsb_next_string(p_th, &p_return_string,"|");

    printf("Return r %s\n",(r_return_string.string));
    rcr = xsb_next_string(r_th, &r_return_string,"|");
  }

 if (rcp == XSB_ERROR) 
   fprintf(stderr,"++Query Error p: %s/%s\n",xsb_get_error_type(p_th),xsb_get_error_message(p_th));
 if (rcr == XSB_ERROR) 
   fprintf(stderr,"++Query Error r: %s/%s\n",xsb_get_error_type(r_th),xsb_get_error_message(r_th));

 // xsb_kill_thread(r_th);

 xsb_close(xsb_get_main_thread());      /* Close connection */
  return(0);
}
コード例 #2
0
int main(int argc, char *argv[])
{ 

  int rc;

  /* xsb_init_string relies on the calling program to pass the absolute or relative
     path name of the XSB installation directory. We assume that the current
     program is sitting in the directory ../examples/c_calling_xsb/
     To get installation directory, we strip 3 file names from the path. */

  int myargc = 1;
  char *myargv[1];
#ifdef WIN_NT
  VarString return_string, *rs;
  XSB_StrCreate(&rs);
  XSB_StrInit(rs);
  return_string = *rs;
#else
  XSB_StrDefine(return_string);
#endif

  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();
#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(CTXT),
	    xsb_get_error_message(CTXT));

  rc = xsb_query_string_string(CTXTc "p(X,Y,Z).",&return_string,"|");
  while (rc == XSB_SUCCESS) {
    printf("cvsreturn %s\n",(return_string.string));
    rc = xsb_next_string(CTXTc &return_string,"|");
  }

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

  xsb_close(CTXT);      /* Close connection */
  return(0);
}
コード例 #3
0
void *query_rs_err(void * arg) {
  int rc;
  th_context *r_th;
  XSB_StrDefine(r_return_string);
  r_th = (th_context *)arg;

  rc = xsb_query_string_string(r_th,"r_err(X,Y,Z).",&r_return_string,"|");
  while (rc == XSB_SUCCESS) {
    printf("Pre-err return r %s\n",(r_return_string.string));
    rc = xsb_next_string(r_th, &r_return_string,"|");
  }

 if (rc == XSB_ERROR) 
   printf("Planned query Error r: %s/%s\n",xsb_get_error_type(r_th),xsb_get_error_message(r_th));
 return NULL;
}
コード例 #4
0
/*******************************************************************
Successful queries
*********************************************************************/
void *query_ps(void * arg) {
  int rc;
  th_context *p_th;
  XSB_StrDefine(p_return_string);
  p_th = (th_context *)arg;
  
  rc = xsb_query_string_string(p_th,"p(X,Y,Z).",&p_return_string,"|");
  while (rc == XSB_SUCCESS) {
    printf("Return p %s\n",(p_return_string.string));
    rc = xsb_next_string(p_th, &p_return_string,"|");
  }

 if (rc == XSB_ERROR) 
   printf("++Query Error p: %s/%s\n",xsb_get_error_type(p_th),xsb_get_error_message(p_th));
 return NULL;
}