int o_getstring(orientdb *o, orientdb_con *c, struct timeval *timeout, UT_string *str) { OM_DEFINE_OBJECT(o_con,och); int len; ssize_t i; debug_note(o, ORIENT_DEBUG, "get a string\n"); // get an integer from orientdb with the length of the string that we are ready to read len = o_getint(o, c, timeout); if (len <= 0) { debug_note(o, ORIENT_DEBUG, "STRING: negative or empty string len detected. Would not read it\n"); return len; } clear_receive_buffer(o, c); // using default chunk size here i = o_bin_read(o, c, timeout, len, 0, 0); OM_MUTEX_LOCK(o_handler, ohandler); och = OM_DECAPSULATE(o_con, c->och); utstring_concat(str, och->recv_stream); OM_MUTEX_UNLOCK(o_handler, ohandler); debug_note(o, ORIENT_DEBUG, "STRING: got (4)+%i bytes of data from the wire: %s\n", len, utstring_body(str)); return i+len; }
static void _nbt_record_copy(void *_dst, void *_src, unsigned num) { struct nbt_record *dst = (struct nbt_record *)_dst; struct nbt_record *src = (struct nbt_record *)_src; while(num--) { dst->tag = src->tag; dst->pos = src->pos; dst->count = src->count; utstring_concat(&dst->fqname, &src->fqname); dst++; src++; } }
//////////////////////////////////////////////////////////////// // // output_read // // This function reads a fastq record from one file and writes // it to another. It assumes the header in the first line of // record has already been stored in fwd. The last 3 lines of // the record are read from input and the record is written // unaltered to output. A read will also be written to // mates_output if mates_output is not null. If rev is not null // this read will be written to mates_output with reversed // sequence and quality. // void output_read(UT_string *fwd, UT_string *rev, UT_string *tmp, FILE *input, FILE *output, FILE *mates_output, int fmt_fasta) { if (mates_output) { if (rev) { utstring_clear(rev); utstring_concat(rev, fwd); // head ss_get_utstring(input, tmp); // seq if (output) { utstring_concat(fwd, tmp); } ss_trunc_utstring(tmp, 1); // remove newline ss_rev_utstring(tmp); ss_strcat_utstring(tmp, "\n"); // add newline back utstring_concat(rev, tmp); if (!fmt_fasta) { ss_get_utstring(input, tmp); // extra if (output) { utstring_concat(fwd, tmp); } utstring_concat(rev, tmp); ss_get_utstring(input, tmp); // qual if (output) { utstring_concat(fwd, tmp); } ss_trunc_utstring(tmp, 1); // remove newline ss_rev_utstring(tmp); ss_strcat_utstring(tmp, "\n"); // add newline back utstring_concat(rev, tmp); } fputs(utstring_body(rev), mates_output); if (output) { fputs(utstring_body(fwd), output); } } else { ss_get_cat_utstring(input, fwd); if (!fmt_fasta) { ss_get_cat_utstring(input, fwd); ss_get_cat_utstring(input, fwd); } fputs(utstring_body(fwd), mates_output); if (output) { fputs(utstring_body(fwd), output); } } } else { ss_get_cat_utstring(input, fwd); if (!fmt_fasta) { ss_get_cat_utstring(input, fwd); ss_get_cat_utstring(input, fwd); } fputs(utstring_body(fwd), output); } }
/* PLAYING WITH STRINGS */ int o_putstring(orientdb *o, orientdb_con *c, UT_string *str) { OM_DEFINE_OBJECT(o_con,och); int i,len; char *buf; len = utstring_len(str); debug_note(o, ORIENT_DEBUG, "put a string\n"); // send an integer to orientdb with the length of the string that we are ready to send i = o_putint(o, c, len); if (i < 0) return -1; buf = utstring_body(str); OM_MUTEX_LOCK(o_handler, ohandler); och = OM_DECAPSULATE(o_con, c->och); utstring_concat(och->send_stream, str); OM_MUTEX_UNLOCK(o_handler, ohandler); debug_note(o, ORIENT_DEBUG, "STRING: put (4)+%i bytes of data to the wire: %s\n", len, buf); return i+len; }
/* return allocated UT_string */ static UT_string *JsonNode_getJSON_UT(JsonNode *node, String last) { asize_t i, nPairs, nChilds; UT_string *buff; utstring_new(buff); if (buff == NULL) return NULL; if (!isNullorEmpty(node->m_name)) { utstring_printf(buff, "\"%s\":", node->m_name); } utstring_printf(buff, "%s\n", JSON_IS_OBJ(node) ? "{" : "["); nPairs = JsonNode_getPairCount(node); nChilds = JsonNode_getChildCount(node); for (i=0; i < nPairs; i++ ) { JsonPair *pair = JsonNode_getPair(node, i); if (JSON_IS_ARRAY(node)) { utstring_printf(buff, "\"%s\"", pair->key); } else { utstring_printf(buff, "\"%s\":\"%s\"", pair->key, pair->value); } utstring_printf(buff, "%s\n", (i < nPairs -1 || nChilds > 0) ? "," : ""); } for (i = 0; i < nChilds; i++) { JsonNode* child = JsonNode_getChild(node, i); UT_string *childJSON = JsonNode_getJSON_UT(child, i == nChilds - 1 ? "\n" : ",\n"); if (childJSON != NULL) { utstring_concat(buff, childJSON); utstring_free(childJSON); } } utstring_printf(buff, "%s%s", JSON_IS_OBJ(node) ? "}" : "]", last); return buff; }
void _utstring_copy(void *_dst, void *_src, unsigned num) { UT_string *dst = (UT_string*)_dst; UT_string *src = (UT_string*)_src; while(num--) utstring_concat( &dst[num], &src[num] ); }
void cxStringConcat(cxString string,cxString str) { utstring_concat(&string->strptr, &str->strptr); }
void tv_material_optimize(tv_material *material) { tv_material_effect **effect; tv_material_effect_info *effect_info; GLuint vert_shader; GLuint frag_shader; GLuint geom_shader; tv_string *vert_src; tv_string *vert_prefix; tv_string *vert_main_prefix; tv_string *vert_main_suffix; tv_string *vert_suffix; tv_string *frag_src; tv_string *frag_prefix; tv_string *frag_main_prefix; tv_string *frag_main_suffix; tv_string *frag_suffix; tv_string *geom_src; tv_string *geom_prefix; tv_string *geom_main_prefix; tv_string *geom_main_suffix; tv_string *geom_suffix; utstring_new(vert_src); utstring_new(vert_prefix); utstring_new(vert_main_prefix); utstring_new(vert_main_suffix); utstring_new(vert_suffix); utstring_new(frag_src); utstring_new(frag_prefix); utstring_new(frag_main_prefix); utstring_new(frag_main_suffix); utstring_new(frag_suffix); utstring_new(geom_src); utstring_new(geom_prefix); utstring_new(geom_main_prefix); utstring_new(geom_main_suffix); utstring_new(geom_suffix); for(effect = (tv_material_effect**)utarray_front(material->effects); effect != NULL; effect = (tv_material_effect**)utarray_next(material->effects, effect)) { HASH_FIND_STR(effects_info_table, (*effect)->name, effect_info); utstring_printf(vert_prefix, effect_info->vertex_shader_prefix); utstring_printf(vert_main_prefix, effect_info->vertex_shader_main_prefix); utstring_printf(vert_main_suffix, effect_info->vertex_shader_main_suffix); utstring_printf(vert_suffix, effect_info->vertex_shader_suffix); utstring_printf(frag_prefix, effect_info->fragment_shader_prefix); utstring_printf(frag_main_prefix, effect_info->fragment_shader_main_prefix); utstring_printf(frag_main_suffix, effect_info->fragment_shader_main_suffix); utstring_printf(frag_suffix, effect_info->fragment_shader_suffix); utstring_printf(geom_prefix, effect_info->geometry_shader_prefix); utstring_printf(geom_main_prefix, effect_info->geometry_shader_main_prefix); utstring_printf(geom_main_suffix, effect_info->geometry_shader_main_suffix); utstring_printf(geom_suffix, effect_info->geometry_shader_suffix); } utstring_concat(vert_src, vert_prefix); utstring_concat(vert_src, vert_main_prefix); utstring_concat(vert_src, vert_main_suffix); utstring_concat(vert_src, vert_suffix); utstring_concat(frag_src, frag_prefix); utstring_concat(frag_src, frag_main_prefix); utstring_concat(frag_src, frag_main_suffix); utstring_concat(frag_src, frag_suffix); utstring_concat(geom_src, geom_prefix); utstring_concat(geom_src, geom_main_prefix); utstring_concat(geom_src, geom_main_suffix); utstring_concat(geom_src, geom_suffix); material->program = tv_material_compile_program(vert_shader, frag_shader, geom_shader, tvchar **attributes, num_attributes); }