Example #1
0
void
do_cqi_cl_regex2id(void)
{
  int *idlist;
  int len;
  char *a, *regex;
  Attribute *attribute;

  a = cqi_read_string();
  regex = cqi_read_string();
  if (server_debug)
   Rprintf( "CQi: CQI_CL_REGEX2ID('%s', '%s')\n", a, regex);
  attribute = cqi_lookup_attribute(a, ATT_POS);
  if (attribute == NULL) {
    cqi_command(cqi_errno);
  }
  else {
    idlist = cl_regex2id(attribute, regex, 0, &len);
    if (idlist == NULL) {
      if (cderrno != CDA_OK) 
        send_cl_error();
      else
        cqi_data_int_list(NULL, 0); /* no matches -> zero size list */
    }
    else {
      cqi_data_int_list(idlist, len);
      free(idlist);
    }
  }
  free(regex);
  free(a);                      /* don't forget to free allocated space */
}
Example #2
0
/* 
 * ------------------------------------------------------------------------
 * 
 * "rcqpCmd_regex2id(SEXP inAttribute, SEXP inRegex)" --
 * 
 * 
 * 
 * ------------------------------------------------------------------------
 */
SEXP rcqpCmd_regex2id(SEXP inAttribute, SEXP inRegex)
{
	SEXP			result = R_NilValue;
	int *			idlist;
	int				len, i;
	char 			*a, *r;
	Attribute *		attribute;
	
	if (!isString(inAttribute) || length(inAttribute) != 1) error("argument 'attribute' must be a string");
	PROTECT(inAttribute);
	if (!isString(inRegex) || length(inRegex) != 1) error("argument 'regexp' must be a string");
	PROTECT(inRegex);
	
	a = (char*)CHAR(STRING_ELT(inAttribute,0));
	r = (char*)CHAR(STRING_ELT(inRegex,0));
	
	attribute = cqi_lookup_attribute(a, ATT_POS);
	if (attribute == NULL) {
		UNPROTECT(2);
		rcqp_error_code(cqi_errno);
	} else {
		idlist = cl_regex2id(attribute, r, 0, &len);
		if (idlist == NULL) {
			if (cderrno != CDA_OK) {
				UNPROTECT(2);
				rcqp_send_error();
			} else {
				result = PROTECT(allocVector(INTSXP, 0));	
			} 
		} else {
			result = PROTECT(allocVector(INTSXP, len));	
			
			for (i=0; i<len; i++) {
				INTEGER(result)[i] = idlist[i];
			}
			free(idlist);
		} 
	}
	
	UNPROTECT(3);

	return result;
}