Ejemplo n.º 1
0
void *close_query_rs(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(X,Y,Z).",&r_return_string,"|");
  if (rc == XSB_ERROR) 
   printf("++Closed query Error r: %s/%s\n",xsb_get_error_type(r_th),xsb_get_error_message(r_th));
  printf("Closed return r %s\n",(r_return_string.string));
  rc = xsb_close_query(r_th);
  if (rc == XSB_FAILURE) 
    printf("++Failure on closed query (r)!\n");

 return NULL;
}
Ejemplo n.º 2
0
DllExport int call_conv fibr(CTXTdecl) {
  int inarg, f1, f2;

  inarg = p2c_int(reg_term(CTXTc 1));  // get the input argument

  if (inarg <= 1) { // if small, return answer directly 
    c2p_int(CTXTc 1,reg_term(CTXTc 2));
    return TRUE;
  }

  xsb_query_save(CTXTc 2);  // prepare for calling XSB
  c2p_functor(CTXTc "fibp",2,reg_term(CTXTc 1));  // setup call
  c2p_int(CTXTc inarg-1,p2p_arg(reg_term(CTXTc 1),1)); // and inp arg
  if (xsb_query(CTXT)) {  // call XSB
    printf("Error calling fibp 1.\n");
    fflush(stdout);
    return FALSE;
 }
  f1 = p2c_int(p2p_arg(reg_term(CTXTc 1),2));  // get answer
  if (xsb_close_query(CTXT)) {  // throw away other (nonexistent) answers
    printf("Error closing fibp 1.\n");
    fflush(stdout);
    return FALSE;
  }

  c2p_functor(CTXTc "fibp",2,reg_term(CTXTc 1)); // prepare for 2nd call to XSB
  c2p_int(CTXTc inarg-2,p2p_arg(reg_term(CTXTc 1),1)); // and its inp arg
  if (xsb_query(CTXT)) { // and call query
    printf("Error calling fibp 2.\n");
    fflush(stdout);
    return FALSE;
  }
  f2 = p2c_int(p2p_arg(reg_term(CTXTc 1),2)); // and get its answer
  if (xsb_next(CTXT) != XSB_FAILURE) { // get next answer, which must NOT exist
    printf("Error getting next fibp 2.\n");
    fflush(stdout);
    return FALSE;
  }

  if (xsb_query_restore(CTXT)) {  // restore regs to prepare for exit
    printf("Error finishing.\n");
    fflush(stdout);
    return FALSE;
  }
  c2p_int(CTXTc f1+f2,reg_term(CTXTc 2));  // set our answer
  return TRUE;  // and return successfully
}
Ejemplo n.º 3
0
void *close_query_rs(void * arg) {
  int rc;
  th_context *r_th;
  pthread_mutex_lock(&user_r_ready_mut); 
  r_th = (th_context *)arg;

  c2p_functor(r_th, "rregs",3,reg_term(r_th, 1));
  rc = xsb_query(r_th);
  if (rc == XSB_ERROR) 
   fprintf(stderr,"++Closed query Error r: %s/%s\n",
	   xsb_get_error_type(r_th),xsb_get_error_message(r_th));
  printf("Closed return r(%d,%d,%d)\n",
	 (p2c_int(p2p_arg(reg_term(r_th, 2),1))),
	 (p2c_int(p2p_arg(reg_term(r_th, 2),2))),
	 (p2c_int(p2p_arg(reg_term(r_th, 2),3))));
  rc = xsb_close_query(r_th);
  if (rc == XSB_FAILURE) 
    fprintf(stderr,"++Failure on closed query (r)!\n");

 pthread_mutex_unlock(&user_r_ready_mut); 
 return NULL;
}
Ejemplo n.º 4
0
/*******************************************************************
Closed queries
*********************************************************************/
void *close_query_ps(void * arg) {
  int rc;
  th_context *p_th;
  pthread_mutex_lock(&user_p_ready_mut); 
  p_th = (th_context *)arg;
  
  c2p_functor(p_th, "pregs",3,reg_term(p_th, 1));
  rc = xsb_query(p_th);
  if (rc == XSB_ERROR) 
    fprintf(stderr,"++Closed query Error p: %s/%s\n",
	    xsb_get_error_type(p_th),xsb_get_error_message(p_th));
  printf("Closed return p(%s,%s,%s)\n",
	   (p2c_string(p2p_arg(reg_term(p_th, 2),1))),
	   (p2c_string(p2p_arg(reg_term(p_th, 2),2))),
	   (p2c_string(p2p_arg(reg_term(p_th, 2),3))));
  rc = xsb_close_query(p_th);
  if (rc == XSB_FAILURE) 
    fprintf(stderr,"++Failure on closed query (p)!\n");

 pthread_mutex_unlock(&user_p_ready_mut); 
 return NULL;
}