static void try_add_result(struct list *list, unsigned relevance, char *name) { struct result *result, *r; assert(list != NULL); if (relevance == 0) return; result = new_result(list, relevance, name); if (is_empty(list)) return insert_before(list, NULL, result); /* * We know the list is not empty and therefor list->last is set. * If the list is not full just add the result at the end. */ if (cmp_results(list->last, result) > 0) { if (!is_full(list)) insert_before(list, NULL, result); return; } /* * Insert the result in a sorted manner */ for (r = list->first; r; r = r->next) if (cmp_results(r, result) < 0) break; insert_before(list, r, result); }
static GList *snr3_find_string(Tsnr3run *s3run, gchar *buffer) { gchar *result; guint querylen; Tlineinbuffer lib = {0,1}; GList *results=NULL; char *(*f) (); if (s3run->is_case_sens) { f = strstr; } else { f = strcasestr; } DEBUG_MSG("snr3_find_string, search for %s\n",s3run->query); querylen = strlen(s3run->query); result = buffer; do { result = f(result, s3run->query); DEBUG_MSG("snr3_find_string, result=%p\n",result); if (result) { guint line = calculate_line_in_buffer(&lib, buffer, (result-buffer)); results = g_list_prepend(results, new_result(line, buffer, result-buffer)); result += querylen; } } while (result); DEBUG_MSG("snr3_find_string, finished\n"); return results; }
t_result *algo_result(t_result *r, t_tetrim *t, t_result *res) { int x; int y; t_result *tmp; x = -1; y = -1; while (++x < r->size) { while (++y < r->size) { if (is_exist(r, t, x, y)) { tmp = place_tetrim(r, t, x, y); if (t->next) res = algo_result(tmp, t->next, res); else if (!t->next) return (add_result(res, tmp, r->size)); if (res) return (res); } } y = -1; } return (new_result(r, t, res)); }
static GList *snr3_replace_string(Tsnr3run *s3run, gchar *buffer, gchar **replacedbuffer) { gchar *result, *newbuf; gchar *bufferpos, *newbufpos; gsize querylen, replacelen, buflen; gsize alloced; Tlineinbuffer lib = {0,1}; GList *results=NULL; char *(*f) (); DEBUG_MSG("snr3_replace_string, search for %s, replace with %s\n",s3run->query, s3run->replace); querylen = strlen(s3run->query); replacelen = strlen(s3run->replace); buflen = strlen(buffer); alloced = (replacelen > querylen)? MAX(1+replacelen+buflen*2,4096):MAX(buflen+querylen+1, 4096); newbuf = g_malloc0(alloced); bufferpos = buffer; newbufpos = newbuf; if (s3run->is_case_sens) { f = strstr; } else { f = strcasestr; } result = buffer; do { result = f(result, s3run->query); if (result) { guint line; memcpy(newbufpos, bufferpos, result-bufferpos); newbufpos += (result-bufferpos); line = calculate_line_in_buffer(&lib, newbuf, (newbufpos-newbuf)); memcpy(newbufpos, s3run->replace, replacelen); newbufpos += replacelen; result += querylen; bufferpos = result; results = g_list_prepend(results, new_result(line, newbuf, newbufpos-newbuf)); if (alloced <= (1+replacelen+(newbufpos-newbuf)+replacelen+(buflen-(bufferpos-buffer)))) { gchar *tmp; alloced += MAX(buflen, 4096); tmp = g_realloc(newbuf, alloced); newbufpos = tmp + (newbufpos-newbuf); newbuf=tmp; } } } while (result); memcpy(newbufpos, bufferpos, strlen(bufferpos)+1); *replacedbuffer = newbuf; return results; }
/* * Retrieve result set */ int get_result(db_con_t* _h, db_res_t** _r) { if ((!_h) || (!_r)) { #ifdef DBT_EXTRA_DEBUG LOG(L_ERR, "DBT:get_result: Invalid parameter value\n"); #endif return -1; } if (!DBT_CON_RESULT(_h)) { LOG(L_ERR, "DBT:get_result: error getting result\n"); *_r = 0; return -3; } *_r = new_result(); if (*_r == 0) { LOG(L_ERR, "DBT:get_result: No memory left\n"); return -2; } if (convert_result(_h, *_r) < 0) { LOG(L_ERR, "DBT:get_result: Error while converting result\n"); pkg_free(*_r); return -4; } return 0; }
/// /// \brief AnalysisResults::Replicate /// \return /// Used in lieu of a copy constructor. Does not produce a perfect copy /// but does copy name, type, matrices, etc. does not replicate most metadata QSharedPointer<AnalysisResults> AnalysisResults::Replicate() { QSharedPointer<AnalysisResults> new_result(new AnalysisResults(name_, type_)); for (auto key: KeyList()) { new_result->AddMatrix(key, GetMatrix(key)); } return new_result; }
void result_add(Result **result, int state, int cost) { (*result)->next = new_result(); (*result)->next->state = state; (*result)->next->cost = cost; (*result)->next->next = NULL; (*result)->next->prev = *result; *result = (*result)->next; }
static GList *snr3_find_pcre(Tsnr3run *s3run, gchar *buffer) { Tlineinbuffer lib = {0,1}; GList *results=NULL; GMatchInfo *match_info; g_regex_match(s3run->regex, buffer, 0, &match_info); while(g_match_info_matches(match_info)) { gint so, eo; guint line; g_match_info_fetch_pos(match_info,0,&so,&eo); line = calculate_line_in_buffer(&lib, buffer, so); results = g_list_prepend(results, new_result(line, buffer, so)); g_match_info_next(match_info, NULL); } g_match_info_free(match_info); return results; }
/* * Retrieve result set */ static int store_result(db_con_t* _h, db_res_t** _r) { if ((!_h) || (!_r)) { LOG(L_ERR, "store_result: Invalid parameter value\n"); return -1; } *_r = new_result(); if (*_r == 0) { LOG(L_ERR, "store_result: No memory left\n"); return -2; } MYRES_RESULT(*_r) = mysql_store_result(CON_CONNECTION(_h)); if (!MYRES_RESULT(*_r)) { if (mysql_field_count(CON_CONNECTION(_h)) == 0) { (*_r)->col.n = 0; (*_r)->n = 0; return 0; } else { LOG(L_ERR, "store_result: %s\n", mysql_error(CON_CONNECTION(_h))); free_result(*_r); *_r = 0; return -3; } } if (convert_result(_h, *_r) < 0) { LOG(L_ERR, "store_result: Error while converting result\n"); mysql_free_result(MYRES_RESULT(*_r)); pkg_free((*_r)->data); pkg_free(*_r); /* This cannot be used because if convert_result fails, * free_result will try to free rows and columns too * and free will be called two times */ /* free_result(*_r); */ return -4; } return 0; }
/// true if messages are equal bool make_message_diff( gpb::Message const &templ, gpb::Message const &src, gpb::Message &result ) { boost::scoped_ptr<gpb::Message> new_result(src.New()); new_result->CopyFrom( src ); typedef gpb::FieldDescriptor field_desc; typedef std::vector<const field_desc *> field_list; field_list fields; new_result->GetReflection( )->ListFields(*new_result, &fields); size_t changes(0); for( field_list::const_iterator b(fields.begin()), e(fields.end()); b!=e; ++b ) { field_desc const *next(*b); if( !next->is_repeated() && !templ.GetReflection( )->HasField( templ, next ) ) { ++changes; continue; } if( next->cpp_type( ) == field_desc::CPPTYPE_MESSAGE ) { changes += (!messages_diff( templ, *new_result, next )); } else { changes += (!field_diff( templ, *new_result, next )); } } result.GetReflection()->Swap( new_result.get(), &result ); return changes == 0; }
struct nsa_result * nsa_create_result(struct nsa_parser *p) { struct nsa_token *t; struct nsa_result *r = new_result(); struct nsa_result_chunk *tmp; List *rchunks = list_create(LIST_SINGLE); int i; r->success = 1; r->ambigs = 0; r->parser = p; for (t = list_first(p->toks); t; t = list_next(p->toks)) { struct nsa_result_chunk *rc = new_result_chunk(); List *g; struct xl_info *xip; int i; if (t->type != NSA_T_AMOUNT) { /* decompose any partially analyzed elements back into graphemes */ g = get_text_refs(t,p->toks,NSA_T_AMOUNT); rc->type = NSA_R_UNPARSED; rc->amount = NULL; } else { g = get_text_refs(t,NULL,NSA_T_NONE); rc->type = NSA_R_PARSED; rc->amount = t->d.a; if (xlink_results) { struct linkset *lsp; const char *override = nsa_system_override_get(); if (override) { if (amount_measure(t)->type == NSA_T_MEASURE) { t->d.a->measure->d.m->system = new_system(); t->d.a->measure->d.m->system->n = override; if (t->d.a->measure->d.m->cands) list_free(t->d.a->measure->d.m->cands, NULL); } } if (amount_measure(t)->type == NSA_T_MEASURE && t->d.a->measure->d.m->cands) { nsa_xcl_warning(p->context->user, t_is_quant(t) ? first_lemm_ptr(t) : first_lemm_ptr_c(t), "ambiguous system: %s", show_sys_list_str(t->d.a->measure->d.m->cands)); } else if (amount_measure(t)->type == NSA_T_MEASURE) { int ok = 0; if (measure_system(amount_measure(t)) && amount_commodity(t)) { List *l; if ((l = hash_find(p->context->comheads, nsa_grapheme_text(t->d.a->commodity->children[0])))) { const char *s; ok = -1; for (s = list_first(l); s; s = list_next(l)) if (!strcmp(s, sysname(t))) { ok = 1; break; } if (ok == -1) { if (t->d.a->commodity) nsa_xcl_warning(p->context->user, t_is_quant(t) ? first_lemm_ptr(t) : first_lemm_ptr_c(t), "commodity head `%s' not known for system `%s'", nsa_grapheme_text(t->d.a->commodity->children[0]), sysname(t)); } } } if (ok == 0) { const char *pregraph; struct nsa_token **kids; int i; if (amount_measure(t)->type == NSA_T_MEASURE) kids = quantity_count(amount_measure(t)->children[0])->children; else kids = amount_measure(t)->children; for (i = 0; kids[i]; ++i) ; pregraph = (const char *)nsa_grapheme_text(kids[i-1]); if (t->d.a->commodity) nsa_xcl_warning(p->context->user, t_is_quant(t) ? first_lemm_ptr(t) : first_lemm_ptr_c(t), "commodity head `%s' unknown; say `%s , %s' if correct", nsa_grapheme_text(t->d.a->commodity->children[0]), pregraph, nsa_grapheme_text(t->d.a->commodity->children[0]) ); } } /* FIXME: we assume for now that measured commodities are not countable; we need to maintain a positive list of countables */ else if (amount_measure(t)->type == NSA_T_COUNT && amount_commodity(t) && commodity_cands(amount_commodity(t))) { List *l = hash_find(p->context->comheads, nsa_grapheme_text(t->d.a->commodity->children[0])); int ok = 0; if (l) { const char *s; for (s = list_first(l); s; s = list_next(l)) if (!strcmp(s, "sexnum")) { ok = 1; break; } } if (!ok) { nsa_xcl_warning(p->context->user, amount_commodity(t)->children[0]->d.g->text->t.lemmptr, "commodity `%s' should be measured not counted", nsa_grapheme_text(t->d.a->commodity->children[0])); commodity_cands(amount_commodity(t)) = NULL; } else if (count_axis(amount_measure(t)) == nsa_sex_asz_axis) nsa_xcl_warning(p->context->user, amount_commodity(t)->children[0]->d.g->text->t.lemmptr, "strange: commodity `%s' is counted in ASZ", nsa_grapheme_text(t->d.a->commodity->children[0])); } /* If an NSA_T_AMOUNT without a commodity is followed immediately by another NSA_T_AMOUNT this is an error; the field separator ',' can be used to suppress this warning */ if (p->toks->rover->next && ((struct nsa_token *)p->toks->rover->next->data)->type == NSA_T_AMOUNT && !amount_commodity(t)) { const char *pregraph, *postgraph; struct nsa_token **kids, *ntok = (struct nsa_token *)p->toks->rover->next->data; int i; if (amount_measure(t)->type == NSA_T_MEASURE) { int j; for (j = 0; amount_measure(t)->children[j]; ++j) ; kids = quantity_count(amount_measure(t)->children[j-1])->children; } else kids = amount_measure(t)->children; for (i = 0; kids[i]; ++i) ; pregraph = (const char *)nsa_grapheme_text(kids[i-1]); if (amount_measure(ntok)->type == NSA_T_MEASURE) kids = quantity_count(amount_measure(ntok)->children[0])->children; else kids = amount_measure(ntok)->children; postgraph = (const char*)nsa_grapheme_text(kids[0]); nsa_xcl_warning(p->context->user, kids[0]->d.g->text->t.lemmptr, "suspicious sequence `%s %s'; lemmatize `n; %% n' if correct", pregraph,postgraph,pregraph,postgraph); } if (amount_measure(t)->type == NSA_T_MEASURE) { lsp = new_linkset(((struct xcl_context*)p->context->user)->linkbase, "nsa", (measure_system(amount_measure(t))) ? sysname(t) : ((measure_cands(amount_measure(t))) ? show_sys_list_str(measure_cands(amount_measure(t))) : "#unknown system#")); lsp->user = nsa_xcl_info(t->d.a); lsp->user_dump_function = (user_dump_func*)nsa_xcl_dump; } else { lsp = new_linkset(((struct xcl_context*)p->context->user)->linkbase, "nsa", countbase_str(amount_measure(t),p)); if (t->type == NSA_T_AMOUNT) { lsp->user = nsa_xcl_info(t->d.a); lsp->user_dump_function = (user_dump_func*)nsa_xcl_dump; } else { lsp->user = NULL; } } preallocate_links(lsp,list_len(g)); for (i = 0, xip = list_first(g); xip; xip = list_next(g), ++i) { struct nsa_text_ref *pg = xip->text; struct link *l = &lsp->links[i]; l->lref = pg->t.lemmptr->xml_id; l->lp = pg->t.lemmptr; l->role = xip->role; l->title = (char*)pg->t.lemmptr->f->f2.form; ++lsp->used; } /* FUTURE: we can emit commodity links as well with l->role = "c" */ /* and we should really emit sysdet links, too */ } else if (amount_measure(t)->type == NSA_T_MEASURE && t->d.a->measure->d.m->cands) ++r->ambigs; }
static GList *snr3_replace_pcre(Tsnr3run *s3run, gchar *buffer, gchar **replacedbuffer) { gchar *newbuf; gchar *bufferpos, *newbufpos; gsize buflen; gsize alloced; Tlineinbuffer lib = {0,1}; GList *results=NULL; GMatchInfo *match_info; gsize prevpos=0; DEBUG_MSG("snr3_replace_pcre, search for %s, replace with %s\n",s3run->query, s3run->replace); buflen = strlen(buffer); alloced = MAX(buflen*2,4096); newbuf = g_malloc0(alloced); bufferpos = buffer; newbufpos = newbuf; g_regex_match(s3run->regex, buffer, 0, &match_info); while(g_match_info_matches(match_info)) { gint so, eo; guint line, replacelen; gchar *replacestring; GError *gerror=NULL; g_match_info_fetch_pos(match_info,0,&so,&eo); memcpy(newbufpos, bufferpos, so-prevpos); newbufpos += (so-prevpos); bufferpos = buffer+eo; prevpos = eo; line = calculate_line_in_buffer(&lib, newbuf, (newbufpos-newbuf)); results = g_list_prepend(results, new_result(line, newbuf, (newbufpos-newbuf))); replacestring = g_match_info_expand_references(match_info, s3run->replace, &gerror); if (gerror) { g_print("replace error %s\n",gerror->message); g_error_free(gerror); } replacelen = strlen(replacestring); /* now check if we have enough memory */ if (alloced < (1+ newbufpos-newbuf + replacelen + buflen-prevpos)) { gchar *tmp; alloced += MAX(buflen, 4096); tmp = g_realloc(newbuf, alloced); newbufpos = tmp + (newbufpos-newbuf); newbuf=tmp; } memcpy(newbufpos, replacestring, replacelen); newbufpos += replacelen; g_free(replacestring); g_match_info_next(match_info, NULL); } g_match_info_free(match_info); memcpy(newbufpos, buffer+prevpos, buflen-prevpos+1); *replacedbuffer = newbuf; return results; }
int init_hmmer_wrapper(const char* hmmfile) { p7_FLogsumInit(); impl_Init(); esl_exception_SetHandler(hmmer_error_handler); int status, index; P7_HMM* model = NULL; P7_PROFILE* gm = NULL; P7_OPROFILE* om = NULL; status = p7_hmmfile_Open(hmmfile, p7_HMMDBENV, &hmm_fp); if(status != eslOK) { if(hmm_fp) { p7_hmmfile_Close(hmm_fp); } if(!hmm_fp->is_pressed) { return MODELS_NOT_PRESSED; } return -status; } model = NULL; while((status = p7_hmmfile_Read(hmm_fp, &abc, &model)) == eslOK) { if(bg == NULL) { bg = p7_bg_Create(abc); p7_bg_SetLength(bg, 400); } gm = p7_profile_Create(model->M, abc); om = p7_oprofile_Create(model->M, abc); p7_ProfileConfig(model, bg, gm, 400, p7_UNILOCAL); p7_oprofile_Convert(gm, om); /*while((status = p7_oprofile_ReadMSV(hmm_fp, &abc, &om)) == eslOK) { p7_oprofile_ReadRest(hmm_fp, om);*/ if(num_models >= models_capacity) { models_capacity += INC_NUM_MODELS; models = (P7_OPROFILE**)realloc(models, sizeof(P7_OPROFILE*) * models_capacity); gmodels = (P7_PROFILE**)realloc(gmodels, sizeof(P7_PROFILE*) * models_capacity); } models[num_models] = om; gmodels[num_models] = gm; p7_hmm_Destroy(model); model = NULL; om = NULL; gm = NULL; num_models++; } if(models == 0) { return 0; } tr = p7_trace_CreateWithPP(); oxf = p7_omx_Create(400, 400, 400); oxb = p7_omx_Create(400, 400, 400); wrapper_results = (WRAPPER_RESULT**)malloc(sizeof(WRAPPER_RESULT*) * num_models); for(index = 0;index < num_models;index++) { wrapper_results[index] = new_result(); } num_results = 0; return num_models; }
int main(int argc, char *argv[]) { /* hi */ double secs; clock_t ticks; unsigned long int *vertex_addresses; int start, target, file_size, file_pos, level, sum, found = 0; char *file_buffer, file[] = "Graphs/graph4.txt"; Graph *graph; Result *result, *rhead; /* yeah, dangerous, since never re-allocated - f**k that and save time :~D */ vertex_addresses = (unsigned long int *)malloc(2500000 * sizeof(unsigned long int)); result = new_result(); rhead = result; /* run clock */ ticks = clock(); /* input */ switch(argc) { case 2: file_buffer = load_file(argv[1], &file_size); break; case 1: file_buffer = load_file(file, &file_size); break; default: printf("\nFehlerhafte Eingabe\n\n"); exit(1); } /* organize */ start = get_start(file_buffer); target = get_target(file_buffer); graph = build_graph(file_buffer, file_size, vertex_addresses); /* search */ for(level = SEARCH_INIT_LEVEL, found = 0; found != 1 && level < 1000; level++) found = iterative_deepening(graph->vertices->next_vertex, target, level, &result, 0); /* format + output */ for(sum = 0; rhead->next; rhead = rhead->next) sum += rhead->next->cost; if(sum) { printf("\n%d\n", sum); while(result->prev && result->prev->state) { if(result->prev->state != result->state) printf("Z%d ", result->state); result = result->prev; } printf("Z%d\n\n", result->state); } else printf("\nZiel nicht erreichbar\n\n"); /* stop clock */ ticks = clock() - ticks; secs = ((double)ticks) / CLOCKS_PER_SEC; printf("\n\n(Duration %.3lf seconds)\n", secs); /* bye */ free(vertex_addresses); free(file_buffer); return(0); }