/* this part sends attributes of a certain type as a STRING[] to the client */ void send_cqi_corpus_attributes(Corpus *c, int type) { Attribute *a; int len; cqi_send_word(CQI_DATA_STRING_LIST); len = 0; for (a = first_corpus_attribute(c); a != NULL; a = next_corpus_attribute()) if (a->type == type) len++; cqi_send_int(len); for (a = first_corpus_attribute(c); a != NULL; a = next_corpus_attribute()) if (a->type == type) cqi_send_string(a->any.name); cqi_flush(); }
/* * ------------------------------------------------------------------------ * * "rcqpCmd_attributes(SEXP inCorpus, SEXP inType)" -- * * * * ------------------------------------------------------------------------ */ SEXP rcqpCmd_attributes(SEXP inCorpus, SEXP inType) { SEXP result = R_NilValue; char *c; CorpusList *cl; Attribute * a; int i = 0, n = 0, type; if (!isString(inCorpus) || length(inCorpus) != 1) error("invalid corpus name"); PROTECT(inCorpus); c = (char*)CHAR(STRING_ELT(inCorpus,0)); type = rcqp_get_attr_type(inType); cl = findcorpus(c, SYSTEM, 0); if (cl == NULL || !access_corpus(cl)) { UNPROTECT(1); rcqp_error_code(CQI_CQP_ERROR_NO_SUCH_CORPUS); } else { /* First count attributes */ for (a = first_corpus_attribute(cl->corpus); a != NULL; a = next_corpus_attribute()) { if (a->type == type) n++; } result = PROTECT(allocVector(STRSXP, n)); /* Then build list of names */ for (a = first_corpus_attribute(cl->corpus); a != NULL; a = next_corpus_attribute()) { if (a->type == type) { SET_STRING_ELT(result, i, mkChar(a->any.name)); i++; } } } UNPROTECT(2); return result; }