void ui_menu_input::toggle_none_default(input_seq &selected_seq, input_seq &original_seq, const input_seq &selected_defseq) { /* if we used to be "none", toggle to the default value */ if (original_seq.length() == 0) selected_seq = selected_defseq; /* otherwise, toggle to "none" */ else selected_seq.reset(); }
void input_manager::seq_from_tokens(input_seq &seq, const char *string) { // start with a blank sequence seq.reset(); // loop until we're done std::string strcopy = string; char *str = const_cast<char *>(strcopy.c_str()); while (1) { // trim any leading spaces while (*str != 0 && isspace((uint8_t)*str)) str++; // bail if we're done if (*str == 0) return; // find the end of the token and make it upper-case along the way char *strtemp; for (strtemp = str; *strtemp != 0 && !isspace((uint8_t)*strtemp); strtemp++) *strtemp = toupper((uint8_t)*strtemp); char origspace = *strtemp; *strtemp = 0; // look for common stuff input_code code; if (strcmp(str, "OR") == 0) code = input_seq::or_code; else if (strcmp(str, "NOT") == 0) code = input_seq::not_code; else if (strcmp(str, "DEFAULT") == 0) code = input_seq::default_code; else code = code_from_token(str); // translate and add to the sequence seq += code; // advance if (origspace == 0) return; str = strtemp + 1; } }
std::string input_manager::seq_name(const input_seq &seq) const { // make a copy of our sequence, removing any invalid bits input_code clean_codes[sizeof(seq) / sizeof(input_code)]; int clean_index = 0; for (int codenum = 0; seq[codenum] != input_seq::end_code; codenum++) { // if this is a code item which is not valid, don't copy it and remove any preceding ORs/NOTs input_code code = seq[codenum]; if (!code.internal() && code_name(code).empty()) { while (clean_index > 0 && clean_codes[clean_index - 1].internal()) clean_index--; } else if (clean_index > 0 || !code.internal()) clean_codes[clean_index++] = code; } // special case: empty if (clean_index == 0) return std::string((seq.length() == 0) ? "None" : "n/a"); // start with an empty buffer std::string str; // loop until we hit the end for (int codenum = 0; codenum < clean_index; codenum++) { // append a space if not the first code if (codenum != 0) str.append(" "); // handle OR/NOT codes here input_code code = clean_codes[codenum]; if (code == input_seq::or_code) str.append("or"); else if (code == input_seq::not_code) str.append("not"); // otherwise, assume it is an input code and ask the input system to generate it else str.append(code_name(code)); } return str; }