//---------- Begin of function Student::update_history -----------// //! //! update history arrays //! //! update_flag = UPDATE_TRIMESTER, UPDATE_MONTH, UPDATE_YEAR; (ooffice.h) //! void Student::update_history(char update_flag) { switch (update_flag) { case UPDATE_MONTH: calc_satisfaction_student_life(); calc_satisfaction_athletics(); calc_satisfaction_overall(); calc_faculty_workweek(); break; case UPDATE_TRIMESTER: calc_satisfaction_academic(); // called when value is needed //calc_probability_change_major(); //calc_multiplier_on_dropout_prob(); break; case UPDATE_YEAR: reaction_summer_course_last = reaction_summer_course; break; case UPDATE_ALL: update_history(UPDATE_MONTH); update_history(UPDATE_TRIMESTER); update_history(UPDATE_YEAR); break; default: err_here(); break; } }
//--------- Begin of function StudentArray::next_day ---------// //! void StudentArray::next_day() { //----- call individual student's next_day() function ----// for( int i=size() ; i>0 ; i-- ) { if( is_deleted(i) ) continue; operator[](i)->next_day(); } //##### begin fred 980819 #####// //----------------------------------------// // start of a month if ( info.game_day == 1 ) { //## 071299 chea 1.12.1 // update_history(UPDATE_MONTH); // start of a year if ( info.game_month == finance.fiscal_year_start_month ) update_history(UPDATE_YEAR); //## 071299 chea 1.12.1 else update_history(UPDATE_MONTH); } //##### end fred 980819 #####// }
static void output_byte(LHAPM2Decoder *decoder, uint8_t *buf, size_t *buf_len, uint8_t b) { // Add to history ring buffer. decoder->ringbuf[decoder->ringbuf_pos] = b; decoder->ringbuf_pos = (decoder->ringbuf_pos + 1) % RING_BUFFER_SIZE; // Add to output buffer. buf[*buf_len] = b; ++*buf_len; // Update history chain. update_history(decoder, b); // Count down until it is time to perform a rebuild of the // lookup trees. --decoder->tree_rebuild_remaining; if (decoder->tree_rebuild_remaining == 0) { rebuild_tree(decoder); } }
void firm_update(Firm * f, Economy * e, unsigned int weeks) { unsigned int i, days; float new_products, products_per_day; firm_purchasing(f, e, weeks); /* how many days can we go without running out of raw materials ? */ days = f->labour.days_per_week * weeks; new_products = firm_products_which_can_be_made(f); products_per_day = firm_products_made_per_day(f); if (products_per_day*days < new_products/products_per_day) { days = (unsigned int)(new_products / products_per_day); } f->capital.surplus += firm_surplus_per_day_actual(f) * days; f->process.stock += (products_per_day * days); for (i = 0; i < PROCESS_INPUTS; i++) { f->process.raw_material_stock[i] -= (products_per_day * days); if (f->process.raw_material_stock[i] < 0) { f->process.raw_material_stock[i] = 0; } } firm_strategy(f, e); update_history(&f->capital); }
/* Search for a string. */ void do_search(void) { linestruct *fileptr = openfile->current; size_t fileptr_x = openfile->current_x; size_t pww_save = openfile->placewewant; int i; bool didfind; i = search_init(FALSE, FALSE); if (i == -1) /* Cancel, Go to Line, blank search string, or regcomp() failed. */ search_replace_abort(); else if (i == -2) /* Replace. */ do_replace(); #if !defined(NANO_TINY) || defined(HAVE_REGEX_H) else if (i == 1) /* Case Sensitive, Backwards, or Regexp search toggle. */ do_search(); #endif if (i != 0) return; /* If answer is now "", copy last_search into answer. */ if (*answer == '\0') answer = mallocstrcpy(answer, last_search); else last_search = mallocstrcpy(last_search, answer); #ifndef DISABLE_HISTORIES /* If answer is not "", add this search string to the search history * list. */ if (answer[0] != '\0') update_history(&search_history, answer); #endif findnextstr_wrap_reset(); didfind = findnextstr( #ifndef DISABLE_SPELLER FALSE, #endif openfile->current, openfile->current_x, answer, NULL); /* If we found something, and we're back at the exact same spot where * we started searching, then this is the only occurrence. */ if (fileptr == openfile->current && fileptr_x == openfile->current_x && didfind) { statusbar(_("This is the only occurrence")); } openfile->placewewant = xplustabs(); edit_redraw(fileptr, pww_save); search_replace_abort(); }
//##### begin fred 0824 #####// //---------- Begin of function Department::next_day -----------// //! void Department::next_day() { // special case; before faculty_array.next_day() if ( info.game_day == 1 ) { for (int i=0; i<RESEARCH_STATUS_COUNT; i++) shift_history(research_m_history[i], HISTORY_MONTH_COUNT); shift_history(research_total_history, HISTORY_MONTH_COUNT); shift_history(research_direct_history, HISTORY_MONTH_COUNT); shift_history(regular_faculty_with_research, HISTORY_MONTH_COUNT); if ( info.game_month == finance.fiscal_year_start_month ) for (int i=0; i<RESEARCH_STATUS_COUNT; i++) shift_history(research_y_history[i], HISTORY_YEAR_COUNT); } //--------------------------// student_array.next_day(); faculty_array.next_day(); course_array.next_day(); // start of a trimester if ( info.game_day == player_school.trimester_array[player_school.cur_trimester].start_day && info.game_month == player_school.trimester_array[player_school.cur_trimester].start_month ) { update_history(UPDATE_TRIMESTER); } // start of a month if ( info.game_day == 1 ) { update_history(UPDATE_MONTH); sys.yield(); // start of a year if ( info.game_month == finance.fiscal_year_start_month ) { update_history(UPDATE_YEAR); // reset this variable value this->project_added_this_year = false; } } }
void update_delete_sequence(xptr node,ft_index_cell_cptr icell) { std::map<ft_index_cell_xptr,update_history*>::iterator it=ft_updates.find(icell.ptr()); if (it==ft_updates.end()) { update_history* h=se_new update_history(); h->add_delete_node(node); ft_updates[icell.ptr()]=h; } else it->second->add_delete_node(node); }
//---------- Begin of function Student::next_day -----------// //! void Student::next_day() { //##### begin fred 980814 #####// // start of a trimester if ( info.game_day == player_school.trimester_array[player_school.cur_trimester].start_day && info.game_month == player_school.trimester_array[player_school.cur_trimester].start_month ) { update_history(UPDATE_TRIMESTER); } // start of a month if ( info.game_day == 1 ) { update_history(UPDATE_MONTH); sys.yield(); // start of a year if ( info.game_month == finance.fiscal_year_start_month ) update_history(UPDATE_YEAR); } /* //##### end fred 980814 #####// //---- if the student has already selected all courses ----// if( has_selected_all_course() ) return; //-- only next_day a specific student level at one time --// if( player_school.cur_select_course_student_level != student_level ) return; //-------- only select courses in week days ---------// if( info.game_day > 5 ) return; // remove select_cours() */ }
static void initsh(t_lexlist **list, t_list **histo, t_sllist **myenv) { *list = NULL; *histo = get_hist_from_file(HISTORY_FILE, myenv); if (!*histo) *histo = init_history(); update_alias(1, NULL); load_conf(myenv); auto_comp(NULL, NULL, 0, *myenv); update_history(*histo); }
bool Debugger::poll() { update_history(); if(mode == STEP || check_jump_condition() || check_brpt_condition()) { mode = STEP; return run_repl(); } return true; }
//---------- Begin of function PlayerSchool::update_history -----------// //! //! update history arrays //! //! update_flag = UPDATE_TRIMESTER, UPDATE_MONTH, UPDATE_YEAR; (ooffice.h) //! void PlayerSchool::update_history(char update_flag) { switch (update_flag) { case UPDATE_MONTH: //## chea 071299 1.12.1 this is done in department_array.next_day calc_performance_monthly(); // calc score summer_emphasis_last = summer_emphasis; //1125 break; case UPDATE_TRIMESTER: break; case UPDATE_YEAR: calc_performance_yearly(); // include *_degree[HISTORY_YEAR_COUNT]//##chea 290100 try to loca the bug break; case UPDATE_ALL: update_history(UPDATE_YEAR); update_history(UPDATE_MONTH); update_history(UPDATE_TRIMESTER); break; default: err_here(); break; } }
void loop_42sh(t_shell *sh) { char **cmd; while (1) { loop_prompt(sh); is_to_large_history(sh); cmd = lexer(sh->prompt->line, 0); update_history(sh->prompt->line, sh); do_the_thing(sh, &cmd, 0); update_prompt_main_loop(sh); free_tab(cmd); } }
void FeatureProcessor::update_history (Vector<uint8_t> & features) { ASSERT_SIZE(features, m_features.size); if (m_history_length == 0) return; uchar_to_real(features, m_features_real); update_history(); Vector<uint8_t> history( m_small_history.size, features.data + (m_small_history.data - m_features_real.data)); real_to_uchar(m_small_history, history); }
/* * every two prisoners play against each other */ void play_game(Group* grp) { int A, B; // indexes of player A and B int num_players = grp->num_chrs; // reset fitness to 0 before every iteration reset_fitness(grp); for (A = 0; A < num_players; A++) { for (B = A + 1; B < num_players; B++) { select_tactics(grp, A, B); update_fitness(grp, A, B); update_history(grp, A, B); } } }
/* Load the histories for Search and Replace and Execute Command. */ void load_history(void) { char *histname = concatenate(statedir, SEARCH_HISTORY); FILE *hisfile = fopen(histname, "rb"); if (hisfile == NULL) { if (errno != ENOENT) { /* When reading failed, don't save history when we quit. */ UNSET(HISTORYLOG); history_error(N_("Error reading %s: %s"), histname, strerror(errno)); } } else { /* Load the three history lists -- first search, then replace, * then execute -- from oldest entry to newest. Between two * lists there is an empty line. */ linestruct **history = &search_history; char *line = NULL; size_t buf_len = 0; ssize_t read; while ((read = getline(&line, &buf_len, hisfile)) > 0) { line[--read] = '\0'; if (read > 0) { /* Encode any embedded NUL as 0x0A. */ unsunder(line, read); update_history(history, line); } else if (history == &search_history) history = &replace_history; else history = &execute_history; } fclose(hisfile); free(line); } /* After reading them in, set the status of the lists to "unchanged". */ history_changed = FALSE; free(histname); }
void bank_update(Bank * b, Economy * e, unsigned int increment_days) { unsigned int i; Account * a; if (bank_defunct(b)) return; for (i = 0; i < MAX_ACCOUNTS; i++) { bank_account_update(b, e, i, increment_days); } bank_strategy(b, e); update_history(&b->capital); if (bank_defunct(b)) { for (i = 0; i < MAX_ACCOUNTS; i++) { a = &b->account[i]; bank_account_close_entity(b, e, a->entity_type, a->entity_index); } e->bankruptcies++; } }
/* Begins scanning for nearby bluetooth devices. If any, it checks the keystore whether they're valid or not. Locks/unlocks the screen appropriately. @param time_per_scan Time to wait for bluetooth devices to respond. @param store The keystore containing valid bluetooth key devices. */ void start_daemon(int time_per_scan, key_store* store) { discovered_dev_t* nearby = (discovered_dev_t*)malloc(sizeof(discovered_dev_t)*NR_MAX_DISCOVERED_DEVICES); state_history history; init_history(&history); bool unlock_status = TRUE; bool previous_status = TRUE; while(TRUE) { int found = scan_nearby(NR_MAX_DISCOVERED_DEVICES, TIME_PER_SCAN, nearby); int i; bool status = FALSE; key_device_t* found_device = NULL; for(i = 0; i < found; i++) { key_device_t* current = (key_device_t*)malloc(sizeof(key_device_t)); discovered_dev_t dev = nearby[i]; current -> device_id = (char*)malloc(sizeof(char)*ID_LEN); str2ba(dev.addr, &(current->addr)); int pos = -1; if((pos = check_existence(store,current)) >= 0) { status = TRUE; update_key(store, pos); found_device = fetch_key(store,pos); break; } free(current); } update_history(&history,status); update_lock_status(history,&unlock_status); previous_status = execute_status(unlock_status,previous_status, found_device); if(unlock_status == TRUE) { usleep(SLEEP_TIME*1000); continue; } usleep(250); } }
void get_std_input(t_shell *sh) { char **cmd; char **instr; char *line; int i; int ret; if (!(line = one_function_get_line(NULL, 1, 0, 0)) || !(instr = my_str_to_wordtab_pattern(line, "\n"))) return ; i = -1; while (instr[++i]) { cmd = lexer(instr[i], 0); ret = replace_exclam_dot(&cmd, sh); update_history(instr[i], sh); if (ret) do_the_thing(sh, &cmd, 0); } free(line); free_tab(instr); }
void VoiceAnalyzer::push_features () { multiply(1.0f / m_accum_count, m_medium_accum, m_medium_energy); m_accum_count = 0; m_medium_accum.zero(); // add history update_history(); // map energy -> log(amplitude) { const size_t I = m_feature_size; const float logenergy_sigma = 2 * m_logamp_sigma; const float logenergy_mean = 2 * m_logamp_mean; const float scale = 1 / logenergy_sigma; const float shift = -scale * logenergy_mean; float * restrict features = m_features_real; for (size_t i = 0; i < I; ++i) { features[i] = shift + scale * logf(features[i] + 1e-16f); } } real_to_uchar(m_features_real, m_features); m_real_stats.add(m_medium_energy); m_int_stats.add(m_features.data, m_medium_size); if (features_out and (m_history_length == 0 or m_history.full())) { features_out.push(m_time, m_features); } if (debug_out) debug_out.push(m_time, m_features); }
//---------- Begin of function StudentArray::update_history -----------// void StudentArray::update_history(char update_flag) { //----- for calc performance indicator -----// // called before next day? // should this be put in player school Student *studentPtr; int i, sl; int studentCount[MAX_STUDENT_LEVEL]; memset(studentCount, 0, sizeof(studentCount)); memset(ave_satisfaction_student_life, 0, sizeof(ave_satisfaction_student_life)); for( i=size() ; i>0 ; i-- ) { if( is_deleted(i) ) continue; studentPtr = operator[](i); sl = studentPtr->student_level; err_when(sl<0 || sl>=MAX_STUDENT_LEVEL); if ( sl != UG_TRADITION ) continue; studentCount[sl]++; ave_satisfaction_student_life[sl] += studentPtr->satisfaction_student_life; } for (i=0; i<MAX_STUDENT_LEVEL; i++) { if ( studentCount[i] ) ave_satisfaction_student_life[i] /= studentCount[i]; else err_when( ave_satisfaction_student_life[i] != 0 ); } //----------------------------------------// PeerSchool *player; switch (update_flag) { case UPDATE_MONTH: calc_student_performance(); break; case UPDATE_TRIMESTER: break; case UPDATE_YEAR: calc_degree_awarded(); break; case UPDATE_ALL: // UPDATE_ALL: assumed called only once for each battle // update degree info for last year(97-98) player = school_res.player_peer_school; // since there's a bug in course selection, too few degrees awarded during game, hence the graphs are not "good" looking cur_bachelor_degree = player->total_bach_degrees / department_array.department_count; cur_master_degree = player->total_masters_and_prof_degree / department_array.department_count; cur_doctor_degree = player->total_doctoral_degrees / department_array.department_count; /* { // 990416 char y; int stuCount[MAX_STUDENT_LEVEL][MAX_GRADUATE_YEARS]; memset(stuCount, 0, sizeof(stuCount)); for (i=size(); i>0; i--) { if ( is_deleted(i) ) continue; Student* stuPtr = operator[](i); y = min(MAX_GRADUATE_YEARS, stuPtr->year_in_program); stuCount[stuPtr->student_level][y]++; } //--// cur_bachelor_degree = 0; cur_master_degree = 0; cur_doctor_degree = 0; for (char sl=0; sl<MASTER; sl++) for (i=0; i<MAX_GRADUATE_YEARS; i++) cur_bachelor_degree += int(player_school.grad_trans_prob[sl][i] * stuCount[sl][i]); sl = MASTER; for (i=0; i<MAX_GRADUATE_YEARS; i++) cur_master_degree += int(player_school.grad_trans_prob[sl][i] * stuCount[sl][i]); sl = DOCTOR; DepartmentInfo* deptInfo = department_res[department_array[department_recno]->department_id]; for (i=0; i<MAX_GRADUATE_YEARS; i++) cur_doctor_degree += int(deptInfo->doctor_graduate_trans_prob[i] * stuCount[sl][i]); sl = DISTANCE_LEARN; for (i=0; i<MAX_GRADUATE_YEARS; i++) cur_bachelor_degree += int(player_school.grad_trans_prob[UG_NONTRADITION][i] * stuCount[sl][i]); } */ update_history(UPDATE_MONTH); update_history(UPDATE_TRIMESTER); update_history(UPDATE_YEAR); //-----------// for (i=0; i<DEGREE_TYPE_COUNT; i++) { // see 0919 noets Q6. // from db time_to_degree[BACHELOR_DEGREE][THIS_YEAR] = 4.37f; // from db time_to_degree[MASTER_DEGREE][THIS_YEAR] = 1.05f; //## chea 281099 student no. time_to_degree[DOCTOR_DEGREE][THIS_YEAR] = player->doc_time_to_degree; /* dropout_rate[BACHELOR_DEGREE][THIS_YEAR] = 100-100*(player->target_grad_rate_sl[UG_TRADITION] / 100.0f + ( 1-player->target_grad_rate_sl[UG_TRADITION] / 100.0f ) * ( 1-0.9f )); // 0.9f: from db dropout_rate[MASTER_DEGREE][THIS_YEAR] = 100 - player->target_grad_rate_sl[MASTER]; dropout_rate[DOCTOR_DEGREE][THIS_YEAR] = 100 - player->target_grad_rate_sl[DOCTOR]; BUGHERE 990408 */ } break; default: err_here(); break; } }
//---------- Begin of function Department::update_history -----------// //! //! update history arrays //! //! update_flag = UPDATE_TRIMESTER, UPDATE_MONTH, UPDATE_YEAR; (ooffice.h) //! void Department::update_history(char update_flag) { int i; switch (update_flag) { case UPDATE_MONTH: shift_history(p_faculty_research_history, HISTORY_MONTH_COUNT); shift_history(p_faculty_morale_history, HISTORY_MONTH_COUNT); calc_faculty_research(); calc_faculty_morale(); p_faculty_research_history[THIS_MONTH] = p_faculty_research; p_faculty_morale_history[THIS_MONTH] = p_faculty_morale; // special case calc_research_dollar(); calc_research_history(); // 1217 // must after calc_research_dollar() break; case UPDATE_TRIMESTER: shift_history(p_educational_quality_history, HISTORY_TRIMESTER_COUNT); shift_history(p_student_morale_history, HISTORY_TRIMESTER_COUNT); for (i=0; i<EDUCATIONAL_QUALITY_VAR_COUNT; i++) shift_history(var_educational_quality_history[i], HISTORY_TRIMESTER_COUNT); for (i=0; i<STUDENT_MORALE_VAR_COUNT; i++) shift_history(var_student_morale_history[i], HISTORY_TRIMESTER_COUNT); shift_history(p_tech_utilization_history, HISTORY_TRIMESTER_COUNT); calc_educational_quality(); calc_student_morale(); // must after calc_educational_quality calc_tech_utilization(); // special case don't have history p_educational_quality_history[THIS_TRIMESTER] = p_educational_quality; p_student_morale_history[THIS_TRIMESTER] = p_student_morale; p_tech_utilization_history[THIS_TRIMESTER] = p_tech_utilization; shift_history( distance_credits_provided_history, HISTORY_TRIMESTER_COUNT ); distance_credits_provided_history[THIS_TRIMESTER] = distance_credits_provided; break; case UPDATE_YEAR: for (i=0;i<FACULTY_RANK_LEVEL_COUNT_N_TOTAL; i++) shift_history(faculty_level_history[i], HISTORY_YEAR_COUNT); for (i=0;i<MAX_STUDENT_LEVEL_N_TOTAL; i++) shift_history(student_level_history[i], HISTORY_YEAR_COUNT); for (i=0;i<GENDER_ETHNIC_TYPE_COUNT_N_TOTAL; i++) { shift_history(faculty_gender_history[i], HISTORY_YEAR_COUNT); shift_history(student_gender_history[i], HISTORY_YEAR_COUNT); } calc_faculty_history(); calc_student_history(); //------// if( info.prerun_year==1 ) // only do this once during initialization. calc_research_norm(); //------// shift_history(p_academic_standing_history, HISTORY_YEAR_COUNT); shift_history(p_faculty_diversity_history, HISTORY_YEAR_COUNT); for (i=0; i<ACADEMIC_STANDING_VAR_COUNT; i++) shift_history(var_academic_standing_history[i], HISTORY_YEAR_COUNT); calc_academic_standing(); calc_faculty_diversity(); p_academic_standing_history[THIS_YEAR] = p_academic_standing; p_faculty_diversity_history[THIS_YEAR] = p_faculty_diversity; break; case UPDATE_ALL: update_history(UPDATE_MONTH); update_history(UPDATE_TRIMESTER); update_history(UPDATE_YEAR); // 0223; fix for interface bug for (i=THIS_MONTH-1; i>=THIS_MONTH-2; i--) { research_total_history[i] = research_total_history[THIS_MONTH]; research_direct_history[i] = research_direct_history[THIS_MONTH]; regular_faculty_with_research[i] = regular_faculty_with_research[THIS_MONTH]; } break; default: err_here(); break; } }
void MainWindow::close_database() { QByteArray ba; if (!dbfile.isEmpty()) { ba += db::intToData(size().width()); ba += db::intToData(size().height()); ba += db::intToData(tabView->currentIndex()); db mydb(dbfile); mydb.set((const unsigned char *)ba.constData(), ba.size(), 1, setting, "mw_geometry"); } setItemEnabled(false); statusBar()->removeWidget(searchEdit); dbindex->clear(); keyView->setModel(); reqView->setModel(); certView->setModel(); tempView->setModel(); crlView->setModel(); if (crls) delete(crls); if (reqs) delete(reqs); if (certs) delete(certs); if (temps) delete(temps); if (keys) delete(keys); reqs = NULL; certs = NULL; temps = NULL; keys = NULL; pki_evp::passwd.cleanse(); pki_evp::passwd = QByteArray(); if (!crls) return; crls = NULL; try { int ret; db mydb(dbfile); ret = mydb.shrink( DBFLAG_OUTDATED | DBFLAG_DELETED ); if (ret == 1) XCA_INFO(tr("Errors detected and repaired while deleting outdated items from the database. A backup file was created")); if (ret == 2) XCA_INFO(tr("Removing deleted or outdated items from the database failed.")); } catch (errorEx &err) { MainWindow::Error(err); } update_history(dbfile); pkcs11::remove_libs(); enableTokenMenu(pkcs11::loaded()); dbfile.clear(); }
/** * Principle Variation Search (fail-soft) * @param alpha lowerbound value * @param beta upperbound value * @param depth remaining search depth * @return score for the current node */ int search_t::pvs(int alpha, int beta, int depth) { assert(alpha < beta); assert(alpha >= -score::INF); assert(beta <= score::INF); stack->pv_count = 0; sel_depth = MAX(brd.ply, sel_depth); stack->best_move.clear(); /* * If no more depth remaining, return quiescence value */ if (depth < 1) { const int score = qsearch(alpha, beta, 0); return score; } /* * Stop conditions */ //time nodes++; if (abort()) { return alpha; } //ceiling if (brd.ply >= (MAX_PLY - 1)) { return evaluate(this); } assert(depth > 0 && depth <= MAX_PLY); int alpha1 = alpha; //mate distance pruning: if mate(d) in n don't search deeper if ((score::MATE - brd.ply) < beta) { beta = score::MATE - brd.ply; if (alpha >= beta) { return beta; } } if ((-score::MATE + brd.ply) > alpha) { alpha = -score::MATE + brd.ply; if (beta <= alpha) { return alpha; } } //draw by lack of material or fifty quiet moves if (is_draw()) { return draw_score(); } /* * Transposition table lookup */ const bool pv = alpha + 1 < beta; stack->tt_key = brd.stack->tt_key; //needed for testing repetitions int tt_move = 0, tt_flag = 0, tt_score; if (trans_table::retrieve(stack->tt_key, brd.ply, depth, tt_score, tt_move, tt_flag)) { if (pv && tt_flag == score::EXACT) { return tt_score; } else if (!pv && tt_score >= beta && tt_flag == score::LOWERBOUND) { return tt_score; } else if (!pv && tt_score <= alpha && tt_flag == score::UPPERBOUND) { return tt_score; } } stack->tt_move.set(tt_move); /* * Node pruning */ const bool in_check = stack->in_check; const int eval = evaluate(this); const bool do_prune_node = eval >= beta && !in_check && !pv && !score::is_mate(beta) && brd.has_pieces(brd.us()); // beta pruning if (do_prune_node && depth < 4 && beta_pruning) { int bp_score = eval - 50 * depth; if (bp_score >= beta) { return bp_score; } } //null move pruning if (do_prune_node && null_enabled) { int R = 3; forward(); int null_score = -pvs(-beta, -alpha, depth - 1 - R); backward(); if (stop_all) { return alpha; } else if (null_score >= beta) { const int RV = 5; if (null_verify && depth > RV && material::is_eg(this)) { //verification int verified_score = pvs(alpha, beta, depth - 1 - RV); if (verified_score >= beta) { return verified_score; } } else { //no verification return null_score; } } } /* * Internal iterative deepening (IID) */ if (pv && depth > 2 && tt_move == 0) { int iid_score = pvs(alpha, beta, depth - 2); if (score::is_mate(iid_score)) { return iid_score; } else if (stack->best_move.piece) { stack->tt_move.set(&stack->best_move); } } /* * Moves loop */ //if there is no first move, it's checkmate or stalemate move_t * move = move::first(this, depth); if (!move) { return in_check ? -score::MATE + brd.ply : draw_score(); } //set futility pruning delta value bool do_ffp = false; int delta = score::INVALID; if (depth <= 8 && !in_check && !score::is_mate(alpha) && !material::is_eg(this) && ffp_enabled) { int ffp_score = eval + 40 * depth; if (ffp_score <= alpha) { do_ffp = true; delta = ffp_score + 50; } } //prepare and do the loop int best = -score::INF; int searched_moves = 0; const int score_max = score::MATE - brd.ply - 1; stack->best_move.clear(); do { assert(brd.valid(move) && brd.legal(move)); assert(stack->best_move.equals(move) == false); assert(in_searched(move, searched_moves) == false); const int gives_check = brd.gives_check(move); assert(gives_check == 0 || gives_check == 1 || gives_check == 2); /* * Move pruning: skip all futile moves */ const bool is_dangerous = in_check || gives_check || move->capture || move->promotion || move->castle || is_advanced_passed_pawn(move); bool pruned = false; if (do_ffp && searched_moves > 0) { pruned = !is_dangerous; pruned |= gives_check == 0 && (move->capture || move->promotion) && brd.max_gain(move) + delta <= alpha; if (pruned) { pruned_nodes++; continue; } } /* * Move extensions */ int extend = extension(move, depth, pv, gives_check); /* * Move Reductions (Late Move Reductions, LMR) */ int reduce = reduction(depth, searched_moves, is_dangerous); /* * Go forward and search next node */ forward(move, gives_check); int score; if (searched_moves == 0) { score = -pvs(-beta, -alpha, depth - 1 + extend); } else { score = -pvs(-alpha - 1, -alpha, depth - 1 - reduce + extend); if (score > alpha && (pv || reduce > 0)) { //open window research without reductions score = -pvs(-beta, -alpha, depth - 1 + extend); } } backward(move); /* * Handle results: update the best value / do a beta cutoff */ if (stop_all) { return alpha; } else if (score > best) { stack->best_move.set(move); if (score >= beta) { trans_table::store(stack->tt_key, brd.root_ply, brd.ply, depth, score, move->to_int(), score::LOWERBOUND); if (!move->capture && !move->promotion && !move->castle) { update_killers(move); update_history(move); for (int i = 0; i < searched_moves; i++) { move_t * m = &stack->searched[i]; if (!m->capture && !m->promotion && !m->castle) { history[m->piece][m->tsq] >>= searched_moves; } } }
int main(void){ char *args[ARGNUM]; int should_run=1; char input[MAX_LINE]; char input_buffer[MAX_LINE]; int i,j; int runbkg; int history_mode=0; int next_replace_index=0; int history_count=0; char loglist[HISTORY_LIMIT][MAX_LINE]; for(i=0;i<HISTORY_LIMIT;i++){ // reseting loglist sprintf(loglist[i],""); } while(should_run){ runbkg=0; // reset args array for(i=0;i<ARGNUM;i++){ args[i]=NULL; } printf("osh>"); //fflush(stdout); fgets(input,MAX_LINE,stdin); // get input. enter(\n) value will be included. // removing last newline and replace it with null for(i=0;i<ARGNUM;i++){ if(input[i]=='\n'){ input[i]='\0'; break; } } strcpy(input_buffer,input); // make copy of input for later use with history //save input in history log // update_history(input,loglist,&next_replace_index,&history_count); // printf("next_replace_index: %d, history_count: %d\n",next_replace_index,history_count); // show_history(loglist); // // printf("before input: %s\n",input); strip_input(input,args); printf("split complete\n"); if(check_keyword(loglist,args,&history_mode,&next_replace_index,&history_count,input,&runbkg,input_buffer)){ return 0; } printf("input buffer: %s\n",input_buffer); if(history_mode==1){ // used just for skipping remainder history_mode=0; continue; // skip the executing part below since history command is not a proper command } // history mode will not increment next_replace_index, history_count. update_history(input_buffer,loglist,&next_replace_index,&history_count); // printf("next_replace_index: %d, history_count: %d\n",next_replace_index,history_count); // show_history(loglist); i=0; // printf("args listing with null ending\n"); // while(args[i]!=NULL){ // print all args values // printf("%d %s\n",i,args[i]); // i++; // } // pid_t pid; pid=fork(); // forking if(pid<0){ printf("error\n"); } else if(pid==0){ //child process // printf("child-args: %s\n",args[0]); execvp(args[0],args); return 0; } else{ // parent process // printf("runbkg: %d\n",runbkg); // printf("child pid:%d \n",pid); int status; if(runbkg==0){ waitpid(pid,&status,0); // printf("wait executed\n"); } } } // end of should run return 0; }
/* Replace a string. */ void do_replace(void) { linestruct *edittop_save, *begin; size_t begin_x, pww_save; ssize_t numreplaced; int i; if (ISSET(VIEW_MODE)) { print_view_warning(); search_replace_abort(); return; } i = search_init(TRUE, FALSE); if (i == -1) { /* Cancel, Go to Line, blank search string, or regcomp() failed. */ search_replace_abort(); return; } else if (i == -2) { /* No Replace. */ do_search(); return; } else if (i == 1) /* Case Sensitive, Backwards, or Regexp search toggle. */ do_replace(); if (i != 0) return; /* If answer is not "", add answer to the search history list and * copy answer into last_search. */ if (answer[0] != '\0') { #ifndef DISABLE_HISTORIES update_history(&search_history, answer); #endif last_search = mallocstrcpy(last_search, answer); } last_replace = mallocstrcpy(last_replace, ""); i = do_prompt(FALSE, #ifndef DISABLE_TABCOMP TRUE, #endif MREPLACEWITH, last_replace, #ifndef DISABLE_HISTORIES &replace_history, #endif /* TRANSLATORS: This is a prompt. */ edit_refresh, _("Replace with")); #ifndef DISABLE_HISTORIES /* If the replace string is not "", add it to the replace history list. */ if (i == 0) update_history(&replace_history, answer); #endif if (i != 0 && i != -2) { if (i == -1) { /* Cancel. */ if (last_replace[0] != '\0') answer = mallocstrcpy(answer, last_replace); statusbar(_("Cancelled")); } search_replace_abort(); return; } last_replace = mallocstrcpy(last_replace, answer); /* Save where we are. */ edittop_save = openfile->edittop; begin = openfile->current; begin_x = openfile->current_x; pww_save = openfile->placewewant; numreplaced = do_replace_loop( #ifndef DISABLE_SPELLER FALSE, #endif NULL, begin, &begin_x, last_search); /* Restore where we were. */ openfile->edittop = edittop_save; openfile->current = begin; openfile->current_x = begin_x; openfile->placewewant = pww_save; edit_refresh(); if (numreplaced >= 0) statusbar(P_("Replaced %lu occurrence", "Replaced %lu occurrences", (unsigned long)numreplaced), (unsigned long)numreplaced); search_replace_abort(); }
int main(void){ char *args[ARGNUM]; int should_run=1; char input[MAX_LINE]; char input_buffer[MAX_LINE]; char *ptr; int i,j; int runbkg; int history_mode=0; int next_replace_index=0; int history_count=0; char loglist[HISTORY_LIMIT][MAX_LINE]; for(i=0;i<HISTORY_LIMIT;i++){ // reseting loglist sprintf(loglist[i],""); } while(should_run){ runbkg=0; // reset args array for(i=0;i<ARGNUM;i++){ args[i]=NULL; } printf("osh>"); //fflush(stdout); fgets(input,MAX_LINE,stdin); // get input. enter(\n) value will be included. // removing last newline and replace it with null for(i=0;i<ARGNUM;i++){ if(input[i]=='\n'){ input[i]='\0'; break; } } strcpy(input_buffer,input); // make copy of input for later use with history //save input in history log // update_history(input,loglist,&next_replace_index,&history_count); // printf("next_replace_index: %d, history_count: %d\n",next_replace_index,history_count); // show_history(loglist); // // printf("before input: %s\n",input); ptr=strtok(input," "); // strip input with delimiter i=0; while(ptr!=NULL){ // convert input to args elements args[i]=ptr; ptr=strtok(NULL," "); i++; } int k; // print all args values // for(k=0;k<i;k++){ // printf("%s\n",args[k]); // } // printf("searching for exit\n"); for(j=0;j<i;j++){ // serach for keywords in arguments. // printf("j:%d str:%s\n",j,args[j]); if(strcmp(args[j],"exit")==0){ return 0; } if(strcmp(args[0],"history")==0){ history_mode=1; printf("history detected\n"); show_history_proper(loglist,&next_replace_index,&history_count); } if(strcmp(args[0],"!!")==0){ history_mode=1; // get input value of previous, ptrtok that again, search for keywords again, then fork & execute } if(strcmp(args[j],"&")==0){ // if & is included, run it in background args[j]=NULL; runbkg=1; } } printf("input buffer: %s\n",input_buffer); if(history_mode==1){ // used just for skipping remainder history_mode=0; continue; // skip the executing part below since history command is not a proper command } // history mode will not increment next_replace_index, history_count. update_history(input_buffer,loglist,&next_replace_index,&history_count); // printf("next_replace_index: %d, history_count: %d\n",next_replace_index,history_count); // show_history(loglist); i=0; // printf("args listing with null ending\n"); // while(args[i]!=NULL){ // print all args values // printf("%d %s\n",i,args[i]); // i++; // } // pid_t pid; pid=fork(); // forking if(pid<0){ printf("error\n"); } else if(pid==0){ //child process // printf("child-args: %s\n",args[0]); execvp(args[0],args); return 0; } else{ // parent process // printf("runbkg: %d\n",runbkg); // printf("child pid:%d \n",pid); int status; if(runbkg==0){ waitpid(pid,&status,0); // printf("wait executed\n"); } // checking args values at the end. // i=0; // while(args[i]!=NULL){ // printf("%d %s\n",i,args[i]); // args[i]=NULL; // i++; // } } } // end of should run return 0; }
static void history_changed_callback (GObject *signaller, CajaHistorySidebar *sidebar) { update_history (sidebar); }
/* ----------------------------- MNI Header ----------------------------------- @NAME : setup_variables @INPUT : inmincid - id of input minc file (MI_ERROR if no file) mincid - id of output minc file volume_info - volume information arg_string - string giving argument list @OUTPUT : (nothing) @RETURNS : (nothing) @DESCRIPTION: Routine to set up variables in the output minc file @METHOD : @GLOBALS : @CALLS : @CREATED : August 26, 1993 (Peter Neelin) @MODIFIED : ---------------------------------------------------------------------------- */ static void setup_variables(int inmincid, int mincid, Volume_Info *volume_info, char *arg_string) { int dim[MAX_VAR_DIMS], ndims, idim, varid; int excluded_vars[10], nexcluded; /* Create the dimensions */ ndims = NUMBER_OF_DIMENSIONS; dim[0] = ncdimdef(mincid, volume_info->dimension_names[0], volume_info->nslices); dim[1] = ncdimdef(mincid, volume_info->dimension_names[1], volume_info->nrows); dim[2] = ncdimdef(mincid, volume_info->dimension_names[2], volume_info->ncolumns); /* If an input file is provided, copy all header info from that file except image, image-max, image-min */ if (inmincid != MI_ERROR) { /* Look for the image variable and the image-max/min variables so that we can exclude them from the copy */ nexcluded = 0; excluded_vars[nexcluded] = ncvarid(inmincid, MIimage); if (excluded_vars[nexcluded] != MI_ERROR) nexcluded++; excluded_vars[nexcluded] = ncvarid(inmincid, MIimagemax); if (excluded_vars[nexcluded] != MI_ERROR) nexcluded++; excluded_vars[nexcluded] = ncvarid(inmincid, MIimagemin); if (excluded_vars[nexcluded] != MI_ERROR) nexcluded++; /* Copy the variable definitions */ (void) micopy_all_var_defs(inmincid, mincid, nexcluded, excluded_vars); } /* Set up the dimension variables. If the variable doesn't exist, create it (either no input file or variable did not exist in it). If the dimensions are not standard, then no variable is created. */ for (idim=0; idim < ndims; idim++) { ncopts = 0; varid = ncvarid(mincid, volume_info->dimension_names[idim]); if (varid == MI_ERROR) { varid = micreate_std_variable(mincid, volume_info->dimension_names[idim], NC_INT, 0, NULL); } ncopts = NC_OPTS_VAL; if (varid != MI_ERROR) { (void) miattputdbl(mincid, varid, MIstep, volume_info->step[idim]); (void) miattputdbl(mincid, varid, MIstart, volume_info->start[idim]); } } /* Create the image, image-max and image-min variables */ setup_image_variables(inmincid, mincid, ndims, dim); /* Add the time stamp to the history */ update_history(mincid, arg_string); /* Put the file in data mode */ (void) ncendef(mincid); /* Copy over variable values */ if (inmincid != MI_ERROR) { (void) micopy_all_var_values(inmincid, mincid, nexcluded, excluded_vars); } }
int BC_FileBox::submit_file(char *path, int use_this) { // blank. // If file wanted, take the current directory as the desired file. // If directory wanted, ignore it. if(!path[0] && !want_directory) { // save complete path strcpy(this->current_path, directory); // save complete path strcpy(this->submitted_path, directory); update_history(); // Zero out filename filename[0] = 0; set_done(0); return 0; } // is a directory, change directories if(fs->is_dir(path) && !use_this) { fs->change_dir(path); refresh(); directory_title->update(fs->get_current_dir()); strcpy(this->current_path, fs->get_current_dir()); strcpy(this->submitted_path, fs->get_current_dir()); strcpy(this->directory, fs->get_current_dir()); filename[0] = 0; if(want_directory) textbox->update(fs->get_current_dir()); else textbox->update(""); listbox->reset_query(); return 1; } else // Is a file or desired directory. Quit the operation. { // save directory for defaults fs->extract_dir(directory, path); // Just take the directory if(want_directory) { filename[0] = 0; strcpy(path, directory); } else // Take the complete path { fs->extract_name(filename, path); // save filename } fs->complete_path(path); strcpy(this->current_path, path); // save complete path strcpy(this->submitted_path, path); // save complete path update_history(); newfolder_thread->interrupt(); set_done(0); return 0; } return 0; }