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); }
void do_cqi_cl_struc2str(void) { int *struclist; int len, i; char *a, *str; Attribute *attribute; a = cqi_read_string(); len = cqi_read_int_list(&struclist); if (server_debug) { Rprintf( "CQi: CQI_CL_STRUC2STR('%s', [", a); for (i=0; i<len; i++) Rprintf( "%d ", struclist[i]); Rprintf( "])\n"); } attribute = cqi_lookup_attribute(a, ATT_STRUC); if (attribute == NULL) { cqi_command(cqi_errno); } else { /* we assemble the CQI_DATA_STRING_LIST() return command by hand, so we don't have to allocate a temporary list */ cqi_send_word(CQI_DATA_STRING_LIST); cqi_send_int(len); /* list size */ for (i=0; i<len; i++) { str = cl_struc2str(attribute, struclist[i]); cqi_send_string(str); /* sends "" if str == NULL (wrong alignment number) */ } } cqi_flush(); if (struclist != NULL) free(struclist); /* don't forget to free allocated memory */ free(a); }
void do_cqi_cl_cpos2str(void) { int *cposlist; int len, i; char *a, *str; Attribute *attribute; a = cqi_read_string(); len = cqi_read_int_list(&cposlist); if (server_debug) { fprintf(stderr, "CQi: CQI_CL_CPOS2STR('%s', [", a); for (i=0; i<len; i++) fprintf(stderr, "%d ", cposlist[i]); fprintf(stderr, "])\n"); } attribute = cqi_lookup_attribute(a, ATT_POS); if (attribute == NULL) { cqi_command(cqi_errno); } else { /* we assemble the CQI_DATA_STRING_LIST() return command by hand, so we don't have to allocate a temporary list */ cqi_send_word(CQI_DATA_STRING_LIST); cqi_send_int(len); /* list size */ for (i=0; i<len; i++) { str = cl_cpos2str(attribute, cposlist[i]); cqi_send_string(str); /* sends "" if str == NULL (cpos out of range) */ } } cqi_flush(); if (cposlist != NULL) free(cposlist); /* don't forget to free allocated memory */ free(a); }
/* 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(); }
void do_cqi_corpus_list_corpora(void) { CorpusList *cl; int n = 0; if (server_debug) Rprintf( "CQi: CQI_CORPUS_LIST_CORPORA()\n"); /* 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 == SYSTEM) n++; } cqi_send_word(CQI_DATA_STRING_LIST); cqi_send_int(n); for (cl = FirstCorpusFromList(); cl != NULL; cl = NextCorpusFromList(cl)) { if (cl->type == SYSTEM) cqi_send_string(cl->name); } cqi_flush(); }