static void make_grid(const Rect* client_rects, int n_client_rects, const Rect* monitor, int* x_edges, int* y_edges, int max_edges) { int i; int n_edges = 0; for (i = 0; i < n_client_rects; ++i) { if (!RECT_INTERSECTS_RECT(client_rects[i], *monitor)) continue; x_edges[n_edges] = client_rects[i].x; y_edges[n_edges++] = client_rects[i].y; x_edges[n_edges] = client_rects[i].x + client_rects[i].width; y_edges[n_edges++] = client_rects[i].y + client_rects[i].height; } x_edges[n_edges] = monitor->x; y_edges[n_edges++] = monitor->y; x_edges[n_edges] = monitor->x + monitor->width; y_edges[n_edges++] = monitor->y + monitor->height; for (i = n_edges; i < max_edges; ++i) x_edges[i] = y_edges[i] = G_MAXINT; qsort(x_edges, n_edges, sizeof(int), compare_ints); uniquify(x_edges, n_edges); qsort(y_edges, n_edges, sizeof(int), compare_ints); uniquify(y_edges, n_edges); }
void internsymbol(node s, scope v){ assertpos(issym(s),s); push(complete_symbol_list,s); if (s->body.symbol.flags & intern_F) { errorpos(s,"symbol defined again ... "); return; } s->body.symbol.flags |= intern_F; if (v != NULL) reinternsymbol(s,v); /* if ( 0 == strcmp("x",tostring(s)) ) trap(); */ if (s->body.symbol.type!=keyword_T) { char *Cname; assertpos(issym(s),s); if (s->body.symbol.flags & literal_F) { Cname = tostring(s); /* no totoken here? */ if (!(s->body.symbol.flags & nouniquify_F)) Cname = uniquify(Cname); } else { Cname = totoken(tostring(s)); if (s->body.symbol.flags & (export_F | import_F)) Cname = prefixify(s->body.symbol.package,Cname); if (!(s->body.symbol.flags & nouniquify_F)) Cname = uniquify(Cname); else if (s->body.symbol.name->body.unique_string.seqno == 0) s->body.symbol.name->body.unique_string.seqno++; } s->body.symbol.Cname = Cname; } if (s->body.symbol.flags & (export_F|import_F)) exportit(s,v); }
// ### provide a name to node std::string daeWriter::getNodeName(const osg::Node &node, const std::string &defaultName) { std::string nodeName; if (node.getName().empty()) nodeName = uniquify(defaultName); else nodeName = uniquify(node.getName()); return nodeName; }
static void update_sources(Widget sources, Widget filter) { StatusDelay delay("Getting sources"); get_gdb_sources(all_sources); String pattern_s = XmTextFieldGetString(filter); string pattern = pattern_s; XtFree(pattern_s); strip_space(pattern); if (pattern.empty()) pattern = "*"; XmTextFieldSetString(filter, XMST(pattern.chars())); StringArray labels; uniquify(all_sources, labels); // Sort and remove duplicates sort(labels, all_sources); uniq(labels, all_sources); // Filter pattern filter_sources(labels, all_sources, pattern); // Now set the selection. bool *selected = new bool[labels.size()]; for (int i = 0; i < labels.size(); i++) selected[i] = false; setLabelList(sources, labels.values(), selected, labels.size(), false, false); delete[] selected; }
void init_dictionary(scope v){ unsigned int i; keyword_T = newtype(NULL,NULL,TRUE); interntype(keyword_T); type__T = newtype(NULL,NULL,TRUE); interntype(type__T); #define f(name,var) { \ node sym = newsymbol(var##_S = UniqueString(name), \ keyword_T,v, \ intern_F|keyword_F|defined_F); \ var##_K = sym; \ } #define g(var) f(#var,var) #include "keywords.h" keyword_T->body.type.name = keyword__K; type__K->body.symbol.value = type__T; type__T->body.type.name = type__K; init_chk(); int_T = basictype(int_K); one__K->body.symbol.type = int_T; zero__K->body.symbol.type = int_T; one__K->body.symbol.Cname = "1"; zero__K->body.symbol.Cname = "0"; char_T = basictype(char_K); double_T = basictype(double_K); package_T = basictype(package_K); bool_T = basictype(bool_K); bool_T->body.type.Cname = "char"; true_K->body.symbol.type = bool_T; true_K->body.symbol.Cname = "1"; false_K->body.symbol.type = bool_T; false_K->body.symbol.Cname = "0"; void_T = basictype(void_K); returns_T = basictype(returns_K); exits_T = basictype(exits_K); _returnedThing_K->body.symbol.type = returns_T; _returnedThing_K->body.symbol.flags &= ~keyword_F; bad_or_undefined_T = basictype(undefined__K); deferred__T = basictype(deferred__K); /* the type of a symbol whose type is not known yet */ undefine(deferred__K); symbol_T = basictype(symbol__K); null_T = basictype(null_K); null_T->body.type.Cname = "void *"; exits_T->body.type.Cname = "void"; bad__K->body.symbol.type = bad_or_undefined_T; double_T->body.type.flags |= arithmetic_type_F; int_T->body.type.flags |= arithmetic_type_F; char_T->body.type.flags |= arithmetic_type_F; int_T->body.type.flags |= integer_type_F; char_T->body.type.flags |= integer_type_F; for (i=0; i<numberof(Csymbols); i++) uniquify(Csymbols[i]); for (i=0; i<numberof(CXXkeywords); i++) uniquifyCXX(CXXkeywords[i]); }
static void update_recent_menu(const MMDesc *items) { StringArray recent_files; { StringArray r; get_recent(r); for (int i = 0; i < r.size() && items[i].widget != 0; i++) recent_files += r[i]; } // Uniquify labels char sep = '/'; if (gdb->type() == JDB) sep = '.'; StringArray labels; uniquify(recent_files, labels, sep); // Set labels int i; for (i = 0; i < labels.size(); i++) { MString label(itostring(i + 1) + " "); label += tt(labels[i]); Widget w = items[i].widget; set_label(w, label); const string& file = recent_files[i]; bool sens = true; if (!remote_gdb()) { if (gdb->has_exec_files() && !is_debuggee_file(file)) sens = false; // File not accessible else if (!gdb->has_classes() && !is_regular_file(file)) sens = false; // File not accessible } set_sensitive(w, sens); XtManageChild(w); } // Unmanage remaining items for (; items[i].widget != 0; i++) XtUnmanageChild(items[i].widget); }
inline policiesfromini loadrulesfromini(const std::string& inifile) { iniparser::IniParser parser(inifile); // policies are grouped together by name (if options are consistent) policiesfromini toreturn; for (const auto& v : parser.content) { const auto name = v.first; const std::string Who = (v.second.count(keys::who) ? v.second.at(keys::who) : "*"); //if nothing->everyone const bool hasext1 = v.second.count(keys::ext1) !=0; const bool hasext2 = v.second.count(keys::ext2) !=0; if ( (hasext1 && !hasext2) || (!hasext1 && hasext2)) { throw std::runtime_error("Invalid double ext configuration, you need to set ext1 and ext2"); } if (hasext1) { doubleext d; d.ext1 = uniquify(trimandremovedelim(explode(v.second.at(keys::ext1), ','))); d.ext2 = uniquify(trimandremovedelim(explode(v.second.at(keys::ext2), ','))); d.description = v.second.count(keys::description) != 0 ? v.second.at(keys::description) : ""; d.name = name; toreturn.doubleextpol.push_back(d); continue; } const bool hasexecutables = v.second.count(keys::executables) != 0; const bool hassecuritylevel = v.second.count(keys::securitylevel) != 0; const bool haspolicyScope = v.second.count(keys::policyscope) != 0; const bool hasenforcementLevel = v.second.count(keys::enforcementlevel) != 0; const bool hasadmininfourl = v.second.count(keys::admin_info_url) != 0; if (hasexecutables || hassecuritylevel || haspolicyScope || hasenforcementLevel || hasadmininfourl) { policysettings settings; if (hasexecutables) { settings.executables = uniquify(trimandremovedelim(explode(v.second.at(keys::executables), ','))); } settings.SecurityLevel = hassecuritylevel ? std::make_unique<securitylevel>( to_securitylevel(v.second.at(keys::securitylevel))) : nullptr; settings.PolicyScope = haspolicyScope ? std::make_unique<policyScope>(to_policyScope(v.second.at(keys::policyscope))) : nullptr; settings.admininfourl = hasadmininfourl ? std::make_unique<std::string>(v.second.at(keys::admin_info_url)) : nullptr; settings.EnforcementLevel = hasenforcementLevel ? std::make_unique<enforcementLevel>(to_enforcementLevel(v.second.at(keys::enforcementlevel))) : nullptr; toreturn.settings.push_back(std::move(settings)); } const std::string Allow = (v.second.count(keys::security) ? v.second.at(keys::security) : ""); //maybe only given specific, if not throw auto description = v.second.count(keys::description) != 0 ? v.second.at(keys::description) : ""; std::vector<policy::policy_s> tmppolicies; for (const auto& vv : v.second) { const auto match0 = matchwithoptionalnumber(vv.first, keys::rule); if (match0.first) { policy::policy_s tmp; tmp.pol.name = name; tmp.pol.ItemData = vv.second; const auto securitykey = keys::security + match0.second; tmp.sec = to_securitylevel( v.second.count(securitykey) != 0 ? v.second.at(securitykey) : Allow); const auto descriptionkey = keys::description + match0.second; tmp.pol.Description = v.second.count(descriptionkey) != 0 ? v.second.at(descriptionkey) : description; const auto uuidkey = keys::uuid + match0.second; tmp.UUID = v.second.count(uuidkey) != 0 ? v.second.at(uuidkey) : ""; tmppolicies.push_back(tmp); } } if (!tmppolicies.empty()) { toreturn.policies.push_back(tmppolicies); } } return toreturn; }
void Deconstructor::sb2vcf(string outfile){ Header h; h.set_date(); h.set_source("VG"); h.set_reference(""); h.set_version("VCF4.2"); cout << h << endl; // for each superbubble: // Fill out a vcflib Variant // Check if it is masked by an input vcf // if not, print it to stdout map<id_t, vcflib::Variant> node_to_var; vcflib::VariantCallFile mask; if (!mask_file.empty()){ //node_to_var = my_vg->get_node_to_variant(mask); } for (auto s : my_sbs){ vcflib::Variant var; // Make subgraphs out of the superbubble: // Operating on a pair<id_t, id_t>, vector<id_t> // then enumerate k_paths through the SuperBubbles set<Node*> nodes; set<Edge*> edges; for (int i = 0; i < s.second.size(); i++){ id_t n_id = s.second[i]; //cerr << n_id << endl; Node* n_node = my_vg->get_node(n_id); vector<Edge*> e_end = my_vg->edges_from(n_node); nodes.insert(n_node); if (i < s.second.size() - 1){ edges.insert(e_end.begin(), e_end.end()); } } vg::VG t_graph = vg::VG(nodes, edges); vector<Path> paths; std::function<void(NodeTraversal)> no_op = [](NodeTraversal n){}; std::function<void(size_t, Path&)> extract_path = [&paths](size_t x_size, Path& path){ paths.push_back(path); }; t_graph.for_each_kpath(10000, false, 100, no_op, no_op, extract_path); std::function<std::vector<Path>(vector<Path>)> uniquify = [](vector<Path> v){ map<string, Path> unqs; vector<Path> ret; for (auto x: v){ unqs[path_to_string(x)] = x; } for (auto y : unqs){ ret.push_back(y.second); } return ret; }; paths = uniquify(paths); std::function<bool(Path)> all_ref = [&](Path p){ for (int i = 0; i < p.mapping_size(); i++){ Mapping m = p.mapping(i); Position pos = m.position(); vg::id_t pos_id = pos.node_id(); map<string, set<Mapping*> > path_to_mappings = my_vg->paths.get_node_mapping(pos_id); if (path_to_mappings.size() <= 0){ return false; } } return true; }; /* * This means we now have vectors for the superbubble * that have the paths through the nodes within it (including end nodes) * however, these paths are repeated several times. * We should find a way to prevent them being inserted once for each node. * * Next on the agenda: use the get_path_dist thing from vg call / vg stats * to get the distance to the head node. * Might need an XG index for this. * * Also need a way to deal with GAMs for this i.e. a way to * count the number of times we see something come up in the gam */ int first_len = (my_vg->get_node(1))->sequence().size(); map<string, set<Mapping*> > p_to_mappings = my_vg->paths.get_node_mapping(s.first.first); for (auto p_name : p_to_mappings){ var.sequenceName = p_name.first; } var.position = my_xg->approx_path_distance(var.sequenceName, 1, s.first.first) + (s.first.first == 1 ? 0 : first_len); //var.sequenceName = my_vg->paths.get_node_mapping(pos_id); // for (auto x : paths){ //cerr << path_to_string(x) << endl; stringstream ref_seq; stringstream alt_seq; bool is_ref = true; for (int m_i = 1; m_i < x.mapping_size() -1 ; m_i++){ Mapping m = x.mapping(m_i); id_t pos_id = m.position().node_id(); Node* n = my_vg->get_node(pos_id); string n_seq = n->sequence(); map<string, set<Mapping*> > path_to_mappings = my_vg->paths.get_node_mapping(pos_id); if (path_to_mappings.size() == 0){ is_ref = false; } if (is_ref){ ref_seq << n_seq; } alt_seq << n_seq; //cerr << " REF: " << ref_seq.str() << " ALT: " << alt_seq.str() << endl; } if (is_ref){ if(var.ref.empty()){ string ref_str = ref_seq.str(); var.ref = ref_str; //(ref_str.size() > 0) ? ref_str : (my_vg->get_node(s.first.first))->sequence(); var.alleles.insert(var.alleles.begin(), var.ref); } } else{ string alt_string = alt_seq.str(); var.alt.push_back(alt_string); var.alleles.push_back(alt_string); } } if (! (var.ref.empty() && var.alt.empty()) ){ cout << var << endl; } } }
void process_directory(const fs::path &directory, const long depth, ProcessParams ¶ms) { // Exclude entire directories bool exclude = false; std::vector<std::string>::const_iterator x_iter = params.excludes.begin(); std::vector<std::string>::const_iterator x_end = params.excludes.end(); for( ; x_iter != x_end; ++x_iter ) { if(boost::contains(directory.file_string(), *x_iter)) { exclude = true; break; } } if(exclude) { info(std::string("excluding directory: ") + directory.file_string() + " matched: " + *x_iter); ++params.dir_ex_count; return; } try { fs::directory_iterator p_iter(directory), p_end; for( ; p_iter != p_end; ++p_iter) { if( is_directory(*p_iter) ) { // recurse if we haven't hit the limit if(depth < params.limit_depth) process_directory(p_iter->path(), depth + 1, params); else { info(std::string("depth reached, skipping: ") + p_iter->path().file_string()); } } else if( is_regular_file(*p_iter) ) { // Check again for excluding file names exclude = false; x_iter = params.excludes.begin(); for( ; x_iter != x_end; ++x_iter ) { if(boost::contains(p_iter->path().file_string(), *x_iter)) { exclude = true; break; } } if(exclude) { info(std::string("excluding file: ") + p_iter->path().file_string() + " matched: " + *x_iter); ++params.file_ex_count; continue; } try { const fs::path dest_subdir = build_dest(*p_iter); fs::path dest_file; if(!dest_subdir.empty()) dest_file = params.dest_dir / dest_subdir; else if(params.ignore_unsorted) { info(std::string("ignoring unsorted: ") + p_iter->path().file_string()); ++params.unsorted_ignored_count; continue; } else { info(std::string("unsorted file (missing metadata): ") + p_iter->path().file_string()); dest_file = params.unsorted_dir; ++params.unsorted_count; } dest_file /= p_iter->filename(); if(fs::exists(dest_file)) { if(params.ignore_dups) { info(std::string("ignoring: ") + p_iter->path().file_string() + " duplicates: " + dest_file.file_string()); ++params.dups_ignored_count; continue; } else { if(params.force) { info(std::string("force removing: ") + dest_file.file_string() + " for: " + p_iter->path().file_string()); if(!params.dry_run) fs::remove(dest_file); } else if(params.rename) { info(std::string("renaming: ") + p_iter->path().file_string() + " duplicates: " + dest_file.file_string()); dest_file = uniquify(dest_file); } else { info(std::string("duplicate file: ") + p_iter->path().file_string() + " of: " + dest_file.file_string()); dest_file = params.dups_dir / dest_subdir / p_iter->filename(); // Ugh, more dup possibilities if(fs::exists(dest_file)) { info(std::string("renaming: ") + p_iter->path().file_string() + " duplicates: " + dest_file.file_string()); dest_file = uniquify(dest_file); } } ++params.dups_count; } } if(!params.dry_run) fs::create_directories(dest_file.parent_path()); if(params.symlink) { info(std::string("linking from: ") + p_iter->path().file_string() + " to: " + dest_file.file_string()); if(!params.dry_run) { // The target of a symlink must be either absolute (aka complete) or // relative to the location of the link. Easiest solution is to make // a complete path. fs::path target; if(p_iter->path().is_complete()) target = p_iter->path(); else target = fs::initial_path() / p_iter->path(); fs::create_symlink(target, dest_file); } } else { info(std::string("copying from: ") + p_iter->path().file_string() + " to: " + dest_file.file_string()); if(!params.dry_run) { // Copy the file and restore its write time (needed for posix) std::time_t time = fs::last_write_time(*p_iter); fs::copy_file(*p_iter, dest_file); fs::last_write_time(dest_file, time); if(params.verify) { md5digest src_digest, dst_digest; bool ok = md5sum(p_iter->path(), src_digest); if(ok) ok = md5sum(dest_file, dst_digest); if(ok) ok = (memcmp(src_digest,dst_digest, sizeof(md5digest))==0); if(!ok) { // Should probably find a more appropriate exception for this throw std::runtime_error(std::string("File verification failed: '") + p_iter->path().file_string() + "' differs from '" + dest_file.file_string() + "'"); } else { info(std::string("verification passed")); } } } } if(params.move) { info(std::string("removing: ") + p_iter->path().file_string()); if(!params.dry_run) fs::remove(*p_iter); } if(!g_verbose && (params.ok_count % DOT_EVERY)==0) { std::cout << "." << std::flush; g_neednewline = true; } ++params.ok_count; } catch(fs::filesystem_error& e) { error(e, std::string("skipping file: " + p_iter->path().file_string())); ++params.file_err_count; } } } } catch(fs::filesystem_error& e) { error(e, std::string("skipping directory: " + directory.file_string())); ++params.dir_err_count; } }