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_idlist2cpos(void) { int *idlist, *cposlist; int i, len, cposlen; char *a; Attribute *attribute; a = cqi_read_string(); len = cqi_read_int_list(&idlist); if (server_debug) { Rprintf( "CQi: CQI_CL_IDLIST2CPOS('%s', [", a); for (i=0; i<len; i++) Rprintf( "%d ", idlist[i]); Rprintf( "])\n"); } attribute = cqi_lookup_attribute(a, ATT_POS); if (attribute == NULL) { cqi_command(cqi_errno); } else { cposlist = cl_idlist2cpos(attribute, idlist, len, 1, &cposlen); if (cposlist == NULL) send_cl_error(); else { cqi_data_int_list(cposlist, cposlen); free(cposlist); } } cqi_flush(); if (idlist != NULL) free(idlist); /* 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); }
void do_cqi_cl_cpos2rbound(void) { int *cposlist; int len, i, struc, lb, rb; char *a; Attribute *attribute; a = cqi_read_string(); len = cqi_read_int_list(&cposlist); if (server_debug) { Rprintf( "CQi: CQI_CL_CPOS2RBOUND('%s', [", a); for (i=0; i<len; i++) Rprintf( "%d ", cposlist[i]); Rprintf( "])\n"); } attribute = cqi_lookup_attribute(a, ATT_STRUC); if (attribute == NULL) { cqi_command(cqi_errno); } else { /* we assemble the CQI_DATA_INT_LIST() return command by hand, so we don't have to allocate a temporary list */ cqi_send_word(CQI_DATA_INT_LIST); cqi_send_int(len); /* list size */ for (i=0; i<len; i++) { struc = cl_cpos2struc(attribute, cposlist[i]); if (struc < 0) { cqi_send_int(-1); /* return -1 if cpos is not in region */ } else { if (cl_struc2cpos(attribute, struc, &lb, &rb)) cqi_send_int(rb); else cqi_send_int(-1); /* cannot return error within list, so send -1 */ } } } cqi_flush(); cl_free(cposlist); /* don't forget to free allocated memory */ free(a); }
void do_cqi_cl_cpos2alg(void) { int *cposlist; int len, i, alg; char *a; Attribute *attribute; a = cqi_read_string(); len = cqi_read_int_list(&cposlist); if (server_debug) { Rprintf( "CQi: CQI_CL_CPOS2ALG('%s', [", a); for (i=0; i<len; i++) Rprintf( "%d ", cposlist[i]); Rprintf( "])\n"); } attribute = cqi_lookup_attribute(a, ATT_ALIGN); if (attribute == NULL) { cqi_command(cqi_errno); } else { /* we assemble the CQI_DATA_INT_LIST() return command by hand, so we don't have to allocate a temporary list */ cqi_send_word(CQI_DATA_INT_LIST); cqi_send_int(len); /* list size */ for (i=0; i<len; i++) { alg = cl_cpos2alg(attribute, cposlist[i]); if (alg < 0) alg = -1; /* return -1 if cpos is out of range */ cqi_send_int(alg); } } cqi_flush(); if (cposlist != NULL) free(cposlist); /* don't forget to free allocated memory */ free(a); }
void do_cqi_cl_id2freq(void) { int *idlist; int len, i, f; char *a; Attribute *attribute; a = cqi_read_string(); len = cqi_read_int_list(&idlist); if (server_debug) { Rprintf( "CQi: CQI_CL_ID2FREQ('%s', [", a); for (i=0; i<len; i++) Rprintf( "%d ", idlist[i]); Rprintf( "])\n"); } attribute = cqi_lookup_attribute(a, ATT_POS); if (attribute == NULL) { cqi_command(cqi_errno); } else { /* we assemble the CQI_DATA_INT_LIST() return command by hand, so we don't have to allocate a temporary list */ cqi_send_word(CQI_DATA_INT_LIST); cqi_send_int(len); /* list size */ for (i=0; i<len; i++) { f = cl_id2freq(attribute, idlist[i]); if (f < 0) f = 0; /* return 0 if ID is out of range */ cqi_send_int(f); } } cqi_flush(); if (idlist != NULL) free(idlist); /* don't forget to free allocated memory */ free(a); }
void do_cqi_cl_cpos2struc(void) { int *cposlist; int len, i, struc; char *a; Attribute *attribute; a = cqi_read_string(); len = cqi_read_int_list(&cposlist); if (server_debug) { fprintf(stderr, "CQi: CQI_CL_CPOS2STRUC('%s', [", a); for (i=0; i<len; i++) fprintf(stderr, "%d ", cposlist[i]); fprintf(stderr, "])\n"); } attribute = cqi_lookup_attribute(a, ATT_STRUC); if (attribute == NULL) { cqi_command(cqi_errno); } else { /* we assemble the CQI_DATA_INT_LIST() return command by hand, so we don't have to allocate a temporary list */ cqi_send_word(CQI_DATA_INT_LIST); cqi_send_int(len); /* list size */ for (i=0; i<len; i++) { struc = cl_cpos2struc(attribute, cposlist[i]); if (struc < 0) struc = -1; /* return -1 if cpos is out of range */ cqi_send_int(struc); } } cqi_flush(); cl_free(cposlist); /* don't forget to free allocated memory */ free(a); }