void do_cqi_cqp_list_subcorpora(void) { char *corpus; CorpusList *cl, *mother; int n = 0; corpus = cqi_read_string(); if (server_debug) Rprintf( "CQi: CQI_CQP_LIST_SUBCORPORA(%s)\n", corpus); mother = cqi_find_corpus(corpus); if (!check_corpus_name(corpus) || mother == NULL) cqi_command(cqi_errno); else { /* ugly, but it's easiest ... first count corpora, then return names one by one */ for (cl = FirstCorpusFromList(); cl != NULL; cl = NextCorpusFromList(cl)) { if (cl->type == SUB && cl->corpus == mother->corpus) n++; } cqi_send_word(CQI_DATA_STRING_LIST); cqi_send_int(n); for (cl = FirstCorpusFromList(); cl != NULL; cl = NextCorpusFromList(cl)) { if (cl->type == SUB && cl->corpus == mother->corpus) cqi_send_string(cl->name); } cqi_flush(); } free(corpus); }
/* * ------------------------------------------------------------------------ * * "rcqpCmd_list_subcorpora(SEXP inCorpus)" -- * * * * ------------------------------------------------------------------------ */ SEXP rcqpCmd_list_subcorpora(SEXP inCorpus) { SEXP result = R_NilValue; char * corpus; CorpusList *cl, *mother; int i = 0, n = 0; PROTECT(inCorpus); corpus = (char*)CHAR(STRING_ELT(inCorpus,0)); mother = cqi_find_corpus(corpus); if (!check_corpus_name(corpus) || mother == NULL) { UNPROTECT(1); rcqp_error_code(cqi_errno); } else { /* First count subcorpora */ for (cl = FirstCorpusFromList(); cl != NULL; cl = NextCorpusFromList(cl)) { if (cl->type == SUB && cl->corpus == mother->corpus) n++; } result = PROTECT(allocVector(STRSXP, n)); /* Then build list of names */ for (cl = FirstCorpusFromList(); cl != NULL; cl = NextCorpusFromList(cl)) { if (cl->type == SUB && cl->corpus == mother->corpus) { SET_STRING_ELT(result, i, mkChar(cl->name)); i++; } } } UNPROTECT(2); return result; }