void eval(vector<unsigned>& buffer, const string& expression_) { string expression = expression_; bool function = false; for(auto& c : expression) { if(c == '(') function = true; if(c == ')') function = false; if(c == ',' && function == true) c = ';'; } lstring list = expression.split(","); for(auto& item : list) { item.strip(); if(item.match("f(?*) ?*")) { item.ltrim("f(", 1L); lstring part = item.split(") ", 1L); lstring args = part[0].split(";", 3L).strip(); unsigned length = eval(args(0, "0")); unsigned offset = eval(args(1, "0")); unsigned stride = eval(args(2, "0")); if(args.size() < 2) offset = buffer.size(); if(args.size() < 3) stride = 1; for(unsigned n = 0; n < length; n++) { string fn = part[1]; fn.replace("n", string{n}); fn.replace("o", string{offset}); fn.replace("p", string{buffer.size()}); buffer.resize(offset + 1); buffer[offset] = eval(fn); offset += stride; } } else if(item.match("base64*")) { unsigned offset = 0; item.ltrim("base64", 1L); if(item.match("(?*) *")) { item.ltrim("(", 1L); lstring part = item.split(") ", 1L); offset = eval(part[0]); item = part(1, ""); } item.strip(); for(auto& c : item) { if(c >= 'A' && c <= 'Z') buffer.append(offset + c - 'A' + 0); if(c >= 'a' && c <= 'z') buffer.append(offset + c - 'a' + 26); if(c >= '0' && c <= '9') buffer.append(offset + c - '0' + 52); if(c == '-') buffer.append(offset + 62); if(c == '_') buffer.append(offset + 63); } } else if(item.match("file *")) { item.ltrim("file ", 1L); item.strip(); //... } else if(item.empty() == false) { buffer.append(eval(item)); } } }
void dfs(string start, string &end, unordered_set<string> &dict, int curL, int minL, vector<string> &vis, vector<string> &ret){ if(curL > minL) return; int len = dict.begin()->size(); for(int i = 0; i < len; i++){ string v = start; char oldc = start[i]; for(char c = 'a'; c <= 'z'; c++){ if(c == oldc) continue; v[i] = c; if(v == end){ vis.push_back(v); ret.append(vis); vis.pop_back(); return; } if(dict.find(v) == dict.end()) continue; vis.push_back(v); dfs(v, end, dict, curL+1, minL, vis, ret); vis.pop_back(); } } }
template<typename T> void append(T& data, const string& name, const string& desc = "") { Node node; node.assign(data); node.name = name; node.desc = desc; children.append(node); }
void poll(vector<HID::Device*>& devices) { char state[32]; XQueryKeymap(display, state); for(unsigned n = 0; n < keys.size(); n++) { bool value = state[keys[n].keycode >> 3] & (1 << (keys[n].keycode & 7)); assign(n, value); } devices.append(&hid); }
void append(matrix const& other) { A.append(other.A); b.append(other.b); }