void define_type (symbol_t * type_symbol, unsigned block_level, pascal_type type, void * type_ptr) { translate_type (type, type_ptr); out_s (" "); #if 1 // experimental if (type == POINTER_NODE) { out_s ("*"); } #endif out_s (type_symbol->s_repr); if (type == ARRAY_NODE) { out_dimensions (reinterpret_cast<array_node*>(type_ptr)); } if (type == NAMED_TYPE_NODE) { if (NT->name->s_kind != TYPE_IDENTIFIER) { c4p_error ("`%s' is no a type identifier", NT->name->s_repr); } type = NT->name->s_type; type_ptr = NT->name->s_type_ptr; } define_symbol (type_symbol, TYPE_IDENTIFIER, block_level, type, type_ptr, 0); }
void test01(void) { out_s("Dsetdrv and Dgetdrv"); test0101(); // switch to selected drive test010203(); // switch to existing and non-existing drive test0104(); // switch to drive which is out of range (> 15) Dsetdrv(drive); // back to selected drive out_s(""); }
void test03(void) { out_s("Fsfirst, Fsnext, Fsetdta, Fgetdta"); createTestFiles(); test0301(); test0310(); deleteRecursive("\\TESTDIR"); out_s(""); }
void declare_var_list (declarator_node * vars, unsigned kind, unsigned block_level, pascal_type type, void * type_ptr) { declarator_node * start = vars; const char * translated_type = translate_type(type, type_ptr); out_s (" "); while (vars != 0) { if (is_fast_var (vars->name->s_repr)) { vars->name->s_flags |= S_FAST; } if (type == POINTER_NODE) { out_s ("*"); } if (block_level == 0 && kind == VARIABLE_IDENTIFIER) { out_s (var_name_prefix.c_str()); } out_s (vars->name->s_repr); if (type == ARRAY_NODE) { out_dimensions (reinterpret_cast<array_node*>(type_ptr)); } vars->name->s_translated_type = translated_type; vars = vars->next; if (vars != 0) { out_s (", "); } } type = flatten_type(type, type_ptr, &type_ptr); vars = start; while (vars != 0) { vars->name = define_symbol(vars->name, kind, block_level, type, type_ptr, 0); vars = vars->next; } }
// MEMBER FUNCTION void Trick::MemoryManager::write_checkpoint(const char* filename, std::vector<const char*>& var_name_list) { std::ofstream out_s( filename, std::ios::out); if (out_s.is_open()) { write_checkpoint( out_s, var_name_list); } else { std::cerr << "ERROR: Couldn't open \""<< filename <<"\"." << std::endl; std::cerr.flush(); } }
void getServerIp(void) { (void) Cconws("Enter server IP (default " SERVER_ADDR_DEFAULT_STRING ") : "); char inIp[20]; memset(inIp, 0, 20); inIp[0] = 19; // offset 0: maximum number of chars allowed to read Cconrs(inIp); // read the string from keyboard // offset 1: number of chars retrieved // offset 2: the retrieved string // minimal IP lenght: strlen("1.2.3.4") = 7 if(inIp[1] < 7) { // if the new IP is too short to be valid, use default SERVER_ADDR = SERVER_ADDR_DEFAULT_DWORD; } else { SERVER_ADDR = tryToParseIp(inIp + 2); } (void) Cconws("\r\n"); char tmp[100]; strcpy(tmp, "Server IP : "); int ofs; ofs = strlen(tmp); intToString((SERVER_ADDR >> 24) & 0xff, -1, tmp + ofs); strcat(tmp, "."); ofs = strlen(tmp); intToString((SERVER_ADDR >> 16) & 0xff, -1, tmp + ofs); strcat(tmp, "."); ofs = strlen(tmp); intToString((SERVER_ADDR >> 8) & 0xff, -1, tmp + ofs); strcat(tmp, "."); ofs = strlen(tmp); intToString((SERVER_ADDR ) & 0xff, -1, tmp + ofs); out_s(tmp); }
int main() { /* for (int i=0; i<g4.g.size(); i++) { dump_map(g4.g[i].fit_loci); } cout << g4.get_fit() << "\n"; genome g6 = g5 + g3; cout << g6 << "Size:" << g6.g.size() << "\n"; for (int i=0; i<g6.g.size(); i++) { dump_map(g6.g[i].fit_loci); } int x = g0.find_block_index(20,0,g0.g.size()); cout << g0.g[x].l <<"," << g0.g[x].r<< "\n"; cout << "(g1 + g2).g"; for(int i=0; i<10;i++){ cout << g2.g[i]; } cout << '\n'; cout << "(g3 + g2).g"; for(int i=0; i<10;i++){ cout << g4.g[i]; } cout << '\n'; */ /* double sigma = .001; vector< vector<double> > fit_landscape = get_rand_fitScape(100,1000,1,sigma, rng_in); //Calculte length dependent histogram for (int l=1; l<=101; l+=1) { gsl_histogram* hist = gsl_histogram_alloc(5000); gsl_histogram_set_ranges_uniform(hist, -l*1.5*sigma, l*1.5*sigma); update_fit_cumulant_histogram(hist, l, fit_landscape); s << "hist_full(" << l << "-l).txt"; write_histogram(hist, s.str().c_str()); s.str(std::string()); gsl_histogram* hist2 = gsl_histogram_alloc(5000); gsl_histogram_set_ranges_uniform(hist2, -l*1.5*sigma, l*1.5*sigma); update_fit_cumulant_histogram_2(hist2, l, fit_landscape); s << "hist_block(" << l << "-l).txt"; write_histogram(hist2, s.str().c_str()); s.str(std::string()); gsl_histogram_free(hist); gsl_histogram_free(hist2); } */ gsl_rng* rng_in = gsl_rng_alloc (RNG); std::stringstream s; //double r = 1; //int max_window = 500; for (double r = 0; r <= 0; r += .01) { for (double sigma = .003; sigma <= .003; sigma += .004) { vector< vector<double> > fit_landscape = get_rand_fitScape(1000,10000,.05,sigma, rng_in); /* gsl_histogram** hist_l = new gsl_histogram*[max_window]; for (int l=1; l<=max_window; l+=1) { hist_l[l-1] = gsl_histogram_alloc(10000); gsl_histogram_set_ranges_uniform(hist_l[l-1],-1.5*sigma*l,1.5*sigma*l); } */ /* s.str(std::string()); s << "coalescent_data(1000-N,10000-L," << std::setprecision(6) << sigma << "-z," << r << "-r).txt"; ofstream out_l(s.str().c_str(), ios::out); */ s << "selection_test(1000-N,10000-L," << std::setprecision(6) << sigma << "-z," << r << "-r).txt"; ofstream out_s(s.str().c_str(), ios::out); for (int iter = 0; iter <= 15; iter += 1) { //cout << iter << "\n"; //out_s << iter << "\n"; //Initialize Population population pop(1000, 10000, r, 0, rng_in, fit_landscape); int T_max = 0; if (sigma == .003) {T_max = 300;} else if (sigma == .005) {T_max = 250;} else {T_max = 100;} for (int t=0; t < T_max; t += 1) { out_s << t << " " << pop.get_avg_fit() << " " << pop.get_variance() << "\n"; pop.evolve(); } /* if (sigma == .01) { pop.evolve(650); } else { pop.evolve(450); } //Calculate length distribution of fixed blocks. for (int i = 0; i < pop.get_fixations().size(); i++) { if (!pop.get_fixations()[i].empty()) { vector<fixation_event> ancestor = pop.get_fixations()[i]; int width = 1; int start_locus = ancestor[0].loci; int last_locus = start_locus; double fix_time_avg = ancestor[0].t_fix; double local_fit_avg = fit_landscape[i][start_locus]; for (int j = 1; j < ancestor.size(); j++) { if (ancestor[j].loci == last_locus + 1) { //Encountered piece of continuous segment. Increment everything. width++; last_locus++; fix_time_avg += ancestor[j].t_fix; local_fit_avg += fit_landscape[i][start_locus]; } else { //End of contiguous segment found. local_fit_avg /= width; fix_time_avg /= width; double local_fit_std = 0; double fix_time_std = 0; if (width > 1) { //Calculate local fitness variance for (int locus = start_locus; locus <= last_locus; locus++) { local_fit_std += pow(fit_landscape[i][locus] - local_fit_avg,2); } local_fit_std /= (width-1); local_fit_std = sqrt(local_fit_std); //Calculate fixation time variance for (int k = j-width; k < j; k++) { fix_time_std += pow(ancestor[k].t_fix - fix_time_avg,2); } fix_time_std /= (width-1); fix_time_std = sqrt(fix_time_std); } //Print data to file. out_l << width << " " << local_fit_avg << " " << local_fit_std << " " << fix_time_avg << " " << fix_time_std << "\n"; //Reset vanguard. width = 1; start_locus = ancestor[j].loci; last_locus = start_locus; fix_time_avg = ancestor[j].t_fix; local_fit_avg = fit_landscape[i][start_locus]; } } } } */ //Evolve the population to obtain fixation events. /* for (int i = 1; i <= 50; i++){ pop.evolve(8); out_l << gsl_histogram_mean(pop.blockHist) << " " << gsl_histogram_sigma(pop.blockHist) << "\n"; } //s << "fix_event(1000-N,10000-L," << std::setprecision(6) << sigma << "-z-" << iter << "-iter).txt"; //pop.write_fixations(s.str().c_str()); //s.str(std::string()); s << "block_hist(100-N,5000-L," << std::setprecision(6) << sigma << "-z-" << iter << "-iter).txt"; pop.writeBlockHist(s.str().c_str()); */ //Calculate two point differences. /* s.str(std::string()); vector< pair<int,double> > correlation = calc_correlation(pop.get_fixations(), fit_landscape); s << "fix_pairs(100-N,5000-L," << std::setprecision(6) << sigma << "-z-" << iter << "-iter).txt"; ofstream out_fit(s.str().c_str(), ios::out); for (vector< pair<int,double> >::const_iterator it = correlation.begin(); it != correlation.end(); it++) { out_fit << it->first << " " << it->second; out_fit << "\n"; } out_fit.close(); s.str(std::string()); //Calculte length dependent histogram for (int l=1; l<=max_window; l+=1) { gsl_histogram* hist_fix_temp = gsl_histogram_alloc(10000); gsl_histogram_set_ranges_uniform(hist_fix_temp, -1.5*sigma*l, 1.5*sigma*l); update_fit_cumulant_histogram(hist_fix_temp, l, pop.get_flat_fixations(), fit_landscape); gsl_histogram_add(hist_l[l-1],hist_fix_temp); gsl_histogram_free(hist_fix_temp); } index = 0; s << "dist_diff(100-N,5000-L," << std::setprecision(6) << sigma << "-z-" << iter << "-iter).txt"; ofstream out_diff(s.str().c_str(), ios::out); for (vector <double>::const_iterator it = diff_dist.begin(); it != diff_dist.end(); it++) { out_diff << *it << " " << 2*index+1 << " "; out_diff << "\n"; index++; } out_diff.close(); s.str(std::string()); */ } out_s.close(); s.str(std::string()); } } /* s << "dist_diff(500-N,10000-L," << std::setprecision(6) << sigma << "-z).txt"; ofstream out_diff(s.str().c_str(), ios::out); for (int l=1; l<=max_window; l++) { gsl_histogram* hist_fit = gsl_histogram_alloc(10000); gsl_histogram_set_ranges_uniform(hist_fit, -1.5*sigma*l, 1.5*sigma*l); update_fit_cumulant_histogram(hist_fit, l, fit_landscape); gsl_histogram_scale(hist_fit,1/gsl_histogram_sum(hist_fit)); gsl_histogram_scale(hist_l[l-1],1/gsl_histogram_sum(hist_l[l-1])); vector <double> fit_cumulant (10000); vector <double> fix_cumulant (10000); for (int i=0; i<10000; i++) { if (i==0) { fit_cumulant[i] = 0; fix_cumulant[i] = 0; } else { fit_cumulant[i] = fit_cumulant[i-1] + gsl_histogram_get(hist_fit,i); fix_cumulant[i] = fix_cumulant[i-1] + gsl_histogram_get(hist_l[l-1],i); } } double diff = 0; for (int i=0; i<10000; i++) { diff += fix_cumulant[i] - fit_cumulant[i]; } diff /= 10000; out_diff << l << " " << diff << "\n"; } out_diff.close(); s.str(std::string()); delete [] hist_l; } */ //Calculate the Histogram of Various Lengths on the fixed landscape. Write to text files. /* for (int l=1; l<=201; l+=2) { gsl_histogram* hist_cumulant_fit_fixed = gsl_histogram_alloc(5000); gsl_histogram_set_ranges_uniform(hist_cumulant_fit_fixed, -l*.6, l*.6); update_fit_cumulant_histogram(hist_cumulant_fit_fixed, l, pop.get_fixations(), fit_landscape); s << "hist_fix(N1000,L20000," << l << "-l," << std::setprecision(6)<< r <<"-r).txt"; write_histogram(hist_cumulant_fit_fixed, s.str().c_str()); s.str(std::string()); gsl_histogram_free(hist_cumulant_fit_fixed); } } */ //FILE *stream = fopen("out.txt","w"); //FILE *stream2 = fopen("out2.txt", "w"); //gsl_histogram_fprintf(stream,hist_cumulant_fit,"%g","%g"); //gsl_histogram_fprintf(stream2,hist_cumulant_fit_fixed,"%g","%g"); //fclose(stream2); //fclose(stream); /* for (double r=0; r<=.5; r+=.05) { s << "fix_prob(1000N256Ld1s" << std::setprecision(6) << r << "r).txt"; ofstream output(s.str().c_str(), ios::out); for (int n=0; n<20; n++) { vector< vector<double> > fit_landscape = get_rand_fitScape(1000,256,.01,.1, rng_in); //Initialize fitscape. find_fixation_prob(1000, 256, r, .1, rng_in, 100, fit_landscape, output); } s.str(std::string()); output.close(); } */ //vector< vector<double> > fit_landscape = get_rand_fitScape(1000,256,.01,.1, rng_in); //std::stringstream s; /* for (int t=0; t<50; t++) { for (double r=0; r<=.5; r+=.005) { population pop(1000,256,r, get_random_seed(), rng_in, fit_landscape); pop.evolve(1000); s << "fix(" << std::setprecision(6) << r << ")L256-" << t << ".txt"; pop.write_fixations(s.str().c_str()); s.str(std::string()); } } */ /* population pop(1000,256,0,get_random_seed(), rng_in, fit_landscape); pop.evolve(10); pop.write_fixations("test.txt"); population pop2(1000,256,0,get_random_seed(), rng_in, fit_landscape); pop.evolve(10); pop.write_fixations("test2.txt"); */ //for (int i=0; i<25; i++) { //cout << "Average Fitness: " << pop.get_avg_fit() << ", Variance: " << pop.get_variance() << "\n";; //pop.evolve(40); //} //pop.write_genetic_weight("out_weight.txt"); //pop.write_fixations("fix.txt"); //cout << gsl_histogram_mean(pop.blockHist) << "\n"; /* vector<int> test = pop.getWeight(90); for (int i=0; i<test.size(); i++) { cout << test[i] << " "; } cout << "\n"; cout << gsl_histogram_mean(pop.blockHist); cout << '\n'; vector<int> test2 = pop.getWeight(50); for(int i=0; i<10; i++){ cout << test2[i] << ","; } cout << '\n'; for (int i=0;i<200;i++){ pop.evolve(5); } vector< vector<double> > test (1000); for (int i=0; i<1000; i++) { vector<double> temp (1000); for (int j=0; j<1000; j++) { temp[j] = i * .000001; } test[i] = temp; } population pop(1000,1000); pop.evolve(1000); for (int t=0; t<10; t++) { cout << pop.getAverageFit() << "\n"; cout << pop.getVariance() << "\n"; pop.evolve(); } cout << pop.getAverageFit() << "\n"; cout << pop.getVariance() << "\n"; */ return 0; }
void generate_routine_head (prototype_node * proto) { out_s ("\n"); out_form ("%s%s\n%s%s (", ((class_name_scope.length() > 0 && proto->result_type != 0 && ! (proto->result_type->s_flags & S_PREDEFINED)) ? class_name_scope.c_str() : ""), (proto->result_type == 0 ? "void" : (proto->result_type->s_translated_type ? proto->result_type->s_translated_type : proto->result_type->s_repr)), class_name_scope.c_str(), proto->name->s_repr); redir_file (H_FILE_NUM); out_form ("%s %s (", (proto->result_type == 0 ? "void" : (proto->result_type->s_translated_type ? proto->result_type->s_translated_type : proto->result_type->s_repr)), proto->name->s_repr); redir_file (C_FILE_NUM); parameter_node * par = proto->formal_parameter; if (par == 0) { out_s ("void)\n"); redir_file (H_FILE_NUM); out_s ("void);\n"); redir_file (C_FILE_NUM); return; } symbol_t * type_symbol; symbol_t * param_symbol; while (par != 0) { type_symbol = par->type_symbol; param_symbol = new_symbol_instance (par->name); param_symbol->s_kind = PARAMETER_IDENTIFIER; param_symbol->s_block_level = 1; param_symbol->s_type = type_symbol->s_type; param_symbol->s_type_ptr = type_symbol->s_type_ptr; param_symbol->s_type = flatten_type(param_symbol->s_type, param_symbol->s_type_ptr, ¶m_symbol->s_type_ptr); out_form ("%s %s%s", (type_symbol->s_translated_type ? type_symbol->s_translated_type : type_symbol->s_repr), par->by_reference ? "& " : "", par->name); redir_file (H_FILE_NUM); out_form ("%s %s%s", (type_symbol->s_translated_type ? type_symbol->s_translated_type : type_symbol->s_repr), par->by_reference ? "& " : "", par->name); redir_file (C_FILE_NUM); if (par->by_reference) { param_symbol->s_flags |= S_BY_REFERENCE; } par = par->next; if (par != 0) { out_s (", "); redir_file (H_FILE_NUM); out_s (", "); redir_file (C_FILE_NUM); } } out_s (")\n"); redir_file (H_FILE_NUM); out_s (");\n"); redir_file (C_FILE_NUM); }
const char * translate_type (pascal_type type, const void * type_ptr) { const char * ret = 0; switch (type) { case NAMED_TYPE_NODE: ret = (NT->name->s_translated_type ? NT->name->s_translated_type : NT->name->s_repr); out_s (ret); break; case BOOLEAN_TYPE: NT->name->s_repr = "C4P_boolean"; out_s ("C4P_boolean"); break; case CHARACTER_TYPE: NT->name->s_repr = "char"; out_s ("char"); break; case INTEGER_TYPE: NT->name->s_repr = "C4P_integer"; out_s ("C4P_integer"); break; case LONG_INTEGER_TYPE: NT->name->s_repr = "C4P_longinteger"; out_s ("C4P_longinteger"); break; case REAL_TYPE: NT->name->s_repr = "float"; out_s ("float"); break; case LONG_REAL_TYPE: NT->name->s_repr = "double"; out_s ("double"); break; case ARRAY_NODE: ret = translate_type (ARR->component_type, ARR->component_type_ptr); break; case POINTER_NODE: #if 1 ret = translate_type (PTR->component_type, PTR->component_type_ptr); #else ret = translate_type (PTR->component_type, PTR->component_type_ptr); #endif break; case SUBRANGE_NODE: ret = subrange (SUB->lower_bound, SUB->upper_bound); out_s (ret); break; case RECORD_NODE: out_s ("struct {\n"); ++ curly_brace_level; translate_type (FIELD_LIST_NODE, REC->field_list); -- curly_brace_level; out_s ("}"); break; case FIELD_LIST_NODE: if (FL->fixed_part != 0) { translate_type (RECORD_SECTION_NODE, FL->fixed_part); } if (FL->variant_part != 0) { translate_type (VARIANT_NODE, FL->variant_part); } break; case RECORD_SECTION_NODE: declare_var_list (RS->name, FIELD_IDENTIFIER, UINT_MAX, RS->type, RS->type_ptr); out_s (";\n"); if (RS->next != 0) { translate_type (RECORD_SECTION_NODE, RS->next); } break; case VARIANT_NODE: out_s ("union {\n"); ++ curly_brace_level; if (V->variant_field_list != 0) { translate_type (VARIANT_FIELD_LIST_NODE, V->variant_field_list); } -- curly_brace_level; out_form ("} %s;\n", V->pseudo_name->s_repr); break; case VARIANT_FIELD_LIST_NODE: if (VFL->pseudo_name != 0) { out_s ("struct {\n"); ++ curly_brace_level; } if (VFL->fixed_part != 0) { translate_type (RECORD_SECTION_NODE, VFL->fixed_part); } if (VFL->variant_part != 0) { translate_type (VARIANT_NODE, VFL->variant_part); } if (VFL->pseudo_name != 0) { -- curly_brace_level; out_form ("} %s;\n", VFL->pseudo_name->s_repr); } if (VFL->next != 0) { translate_type (VARIANT_FIELD_LIST_NODE, VFL->next); } break; case FILE_NODE: if (FIL->type == CHARACTER_TYPE || (FIL->type == NAMED_TYPE_NODE && (((named_type_node *) FIL->type_ptr)->name->s_type == CHARACTER_TYPE))) { out_s ("C4P_text"); } else { out_s ("C4P_FILE_STRUCT("); translate_type (FIL->type, FIL->type_ptr); out_s (")"); } FIL->type = flatten_type(FIL->type, FIL->type_ptr, &FIL->type_ptr); break; default: c4p_error ("internal error: translate_type: unknown node type: %u", type); } return (ret); }
// pop for all necessary functions. void parse(void) { for(long i=mn;i<esz;i++) { switch(exprs[i].op) { case PW: push_int(exprs[i].q.i); break; case PF: push_flt(exprs[i].q.f); break; case PC: push_chr(exprs[i].q.c); break; case PL: push_lng(exprs[i].q.l); break; case MALLOCI: nstkptr(); stk->x.ia = malloc(exprs[i].q.i*I); break; case MALLOCF: nstkptr(); stk->x.fa = malloc(exprs[i].q.i*F); break; case MALLOCC: nstkptr(); stk->x.ca = malloc(exprs[i].q.i*B); break; case MALLOCL: nstkptr(); stk->x.la = malloc(exprs[i].q.i*L); break; case REALL: { void *x = getptr(stk->x); x = realloc(x,exprs[i].q.i); break; } case FREE: free(getptr(stk->x)); pop(); break; case OUT_S: out_s(stk->x.i,stk->prev->x); pop(); pop(); break; case JMP_S: { i=lbls[0].l[stk->x.i]-1; pop(); break; } case JMP: { i=lbls[0].l[exprs[i].q.i]-1; break; } // it's correct case POP: pop(); break; case IN: push_chr(getchar()); break; case REFI: { int q = (stk->x.ia)[stk->prev->x.i]; pop(); pop(); nstkptr(); stk->x.i = q; break; } case REFF: { double q = (stk->x.fa)[stk->prev->x.i]; pop(); pop(); nstkptr(); stk->x.f = q; break; } case REFC: { char q = (stk->x.ca)[stk->prev->x.i]; pop(); pop(); nstkptr(); stk->x.c = q; break; } case REFL: { long q = (stk->x.la)[stk->prev->x.i]; pop(); pop(); nstkptr(); stk->x.l = q; break; } case CALL_S: { Ref *r = malloc(sizeof(Ref)); r->r = i; if(refs) { r->prev = refs; } refs = r; i=lbls[0].l[stk->x.i]-1; pop(); break; } case CALL: { Ref *r = malloc(sizeof(Ref)); r->r = i; if(refs) { r->prev = refs; } refs = r; i=lbls[0].l[exprs[i].q.i]-1; break; } case RETURN: { Ref *r; r = refs; i = r->r; refs = refs->prev; free(r); break; } case MOVI: { (stk->x.ia)[stk->prev->x.i] = stk->prev->prev->x.i; pop(); pop(); pop(); break; } case MOVF: { (stk->x.fa)[stk->prev->x.i] = stk->prev->prev->x.f; pop(); pop(); pop(); break; } case SWAP: { stk->prev->prev = stk; stk = stk->prev; break; } case SREF: { Stk *e = stkref(stk->x.i); pop(); nstkptr(); *(stk) = *(e); break; } case ARITH: { arith(stk->x.i,stk->prev->x.i); break; } case LINK: { nstkptr(); stk->x.v = dlopen(exprs[i].q.ca,RTLD_LAZY); break; } case LFUN: { void *z; z = dlsym(stk->prev->x.v,exprs[i].q.ca); push_f(z,exprs[i].q.ca,stk->x.i); pop(); break; } case LCALL: { exec_ffun(exprs[i].q.ca); break; } case IMPORT: { char *in; in = malloc((strlen(exprs[i].q.ca)+4)*sizeof(char)); strcpy(in,exprs[i].q.ca); strcat(in,".uo"); FILE *u; u = fopen(in,"rb"); lbls = realloc(lbls,(++lsz)*sizeof(Modu)); lbls[lsz-1].sz = 0; read_prgm(u,md++); fclose(u); break; /* simply allocate the next lblarr */ } case OJMP: { // pop module, then word i = lbls[stk->x.i+exprs[i].m].l[stk->prev->x.i]-1; pop(); pop(); break; } case OCALL: { Ref *r; r = malloc(sizeof(Ref)); r->r = i; if(refs) { r->prev = refs; } refs = r; i=lbls[stk->x.i+exprs[i].m].l[stk->prev->x.i]-1; pop(); pop(); break; } case NS: { if(!stk) { nstkptr(); stk->x.i = 1; } else { nstkptr(); stk->x.i = 0; } break; } case OJEZ: { if(!stk->prev->prev->x.i) { i = lbls[stk->x.i+exprs[i].m].l[stk->prev->x.i]-1; } pop(); pop(); pop(); break; } case OJNZ: { if(stk->prev->prev->x.i) { i = lbls[stk->x.i+exprs[i].m].l[stk->prev->x.i]-1; } pop(); pop(); pop(); break; } case TERM: exit(0); break; default: printf("what"); exit(0); } } }
void test0310(void) { DWORD start = getTicks(); char dta[NESTING_LEVEL * 44]; int cnt[NESTING_LEVEL], i, total; memset(dta, 0, 44); total = countFoundItems(dta, "*.*", 0x3f, TRUE, -1); memset(dta, 0, NESTING_LEVEL * 44); for(i=0; i<NESTING_LEVEL; i++) { cnt[i] = 0; } BYTE allDone = 0; while(1) { //------------------- // protection against endless loop in case of failing test if((getTicks() - start) > 15*200) { // more than 15 seconds of run? out_s("test timeout"); // fail and quit break; } //------------------- // first check if all searches are done allDone = 1; for(i=0; i<NESTING_LEVEL; i++) { // go through searches if(cnt[i] < total) { // if found a search which isn't finished yet, mark that we're not done allDone = 0; break; } } if(allDone) { // if we're all done, quit this loop break; } //------------------- // do a search while(1) { i = getRandom(); // get index at which we should do the search if(cnt[i] < total) { // if found a not finished search, use it break; } } int stopAfter = getRandom(); // this is a count of items after which we should stop this search and continue with another if(stopAfter == 0) { stopAfter++; } BYTE startNotContinue = 0; // flag to mark start or continuation of search if(cnt[i] == 0) { // if don't have anything yet, it's a start (otherwise continue search) startNotContinue = 1; } cnt[i] += countFoundItems(dta + (i * 44), "*.*", 0x3f, startNotContinue, stopAfter); } int sum = 0; for(i=0; i<NESTING_LEVEL; i++) { sum += cnt[i]; } out_tr_bw(0x0310, "Fsfirst & Fsnext - nested searching", allDone, sum); }