/* DDS3.2.20 Search VIP for Candidate */ static bool search_vip(unsigned int group_index, int dbci) { const struct preference_set *vip; unsigned int i; vip = get_vote_in_progress(); for (i = 0; i < vip->num_preferences; i++) { if ((vip->candidates[i].group_index == group_index) && (vip->candidates[i].db_candidate_index == dbci)) { return true; } } return false; }
static unsigned int get_pref_num(unsigned int group_index, unsigned int dbci) { const struct preference_set *vip; unsigned int i; vip = get_vote_in_progress(); /* If not found, the preference number is zero */ for (i = 0; i < vip->num_preferences; i++) { if (vip->candidates[i].group_index == group_index && vip->candidates[i].db_candidate_index == dbci) { assert(vip->candidates[i].prefnum != 0); return vip->candidates[i].prefnum; } } /* Not found */ return 0; }
/* DDS3.18: Insert Preference Digit */ void insert_preference_digit(unsigned int group_index, unsigned int dbci, unsigned int pref) { int i; bool found = false; unsigned int new_pref; const struct preference_set *vip; vip = get_vote_in_progress(); /* Check if candidate already given a preference number */ for (i=0; i < vip->num_preferences; i++) { if ((vip->candidates[i].group_index == group_index) && (vip->candidates[i].db_candidate_index == dbci)) { /* Can only occur once */ assert(found == false); found = true; if (vip->candidates[i].prefnum != 0) { /* new digit inserted at right of current pref number, with most significant digit removed if more than 2 digits */ new_pref = (vip->candidates[i].prefnum * 10 + pref) % 100; if (new_pref > 0) { change_candidate_prefnum(i, new_pref); } else { delete_deo_preference(); } } else { change_candidate_prefnum(i, pref); } } } if (!found) { /* Add candidate and preference to the Vote in Progress */ if (pref > 0) { add_candidate_with_pref(group_index, dbci, pref); } } }