static path findUserPath(const char * name, const path & force, const char * registry, const char * prefix, const char * suffix, const path & fallback, bool create) { // Prefer command-line options if(!force.empty()) { path dir = canonical(force); if(create && !create_directories(dir)) { LogCritical << "Could not create " << name << " directory " << dir << '.'; return path(); } else { LogDebug("using " << name << " dir from command-line: " << dir); return dir; } } // Check system settings (windows registry) std::string temp; if(registry && platform::getSystemConfiguration(registry, temp)) { path dir = canonical(temp); if(!create) { return dir; } else if(create_directories(dir)) { LogDebug("got " << name << " dir from registry: \"" << temp << "\" = " << dir); return dir; } else { LogError << "Could not create " << name << " directory " << dir << '.'; LogDebug("ignoring " << name << " dir from registry: \"" << temp << '"'); } } // Search standard locations path to_create; std::vector<path> prefixes = getSearchPaths(prefix); std::vector<path> suffixes = getSearchPaths(suffix); if(prefix || suffix) { bool create_exists = false; BOOST_FOREACH(const path & prefix, prefixes) { BOOST_FOREACH(const path & suffix, suffixes) { path dir = canonical(prefix / suffix); if(is_directory(dir)) { LogDebug("got " << name << " dir from search: " << prefix << " + " << suffix << " = " << dir); return dir; } else { LogDebug("ignoring " << name << " dir from search: " << prefix << " + " << suffix << " = " << dir); } if(to_create.empty() || (!create_exists && is_directory(prefix))) { to_create = dir; create_exists = is_directory(prefix); } }
std::string Path::absolute() const { string r = Config::homePageUrl; if ( r[r.size()] == '/' ) r += canonical().substr( 2 ); else r += canonical(); return r; }
AliasClass canonicalize(AliasClass a) { using T = AliasClass::STag; switch (a.m_stag) { case T::None: return a; case T::Frame: return a; case T::MIState: return a; case T::Prop: a.m_prop.obj = canonical(a.m_prop.obj); return a; case T::ElemI: a.m_elemI.arr = canonical(a.m_elemI.arr); return a; case T::ElemS: a.m_elemS.arr = canonical(a.m_elemS.arr); return a; case T::Stack: a.m_stack = canonicalize_stk(a.m_stack); return a; } always_assert(0); }
Node * canonical(Node *n) { Node *m; /* assumes input is right_linked */ if (!n) return n; if ((m = in_cache(n)) != ZN) return m; n->rgt = canonical(n->rgt); n->lft = canonical(n->lft); return cached(n); }
AliasClass canonicalize(AliasClass a) { using T = AliasClass::STag; switch (a.m_stag) { case T::None: return a; case T::Frame: return a; case T::Stack: return a; case T::MIState: return a; case T::Ref: return a; case T::Prop: a.m_prop.obj = canonical(a.m_prop.obj); return a; case T::ElemI: a.m_elemI.arr = canonical(a.m_elemI.arr); return a; case T::ElemS: a.m_elemS.arr = canonical(a.m_elemS.arr); return a; } not_reached(); }
/* assumes input is right_linked */ Node *canonical(Node *n, Miscellaneous *miscell, int *cnt, char *uform , int *tl_yychar) { Node *m; if (!n) return n; if (m = in_cache(n, cnt, uform, tl_yychar, miscell)) return m; n->rgt = canonical(n->rgt, miscell, cnt, uform, tl_yychar); n->lft = canonical(n->lft, miscell, cnt, uform, tl_yychar); return cached(n, miscell, cnt, uform, tl_yychar); }
/* assumes input is right_linked */ Node *canonical(Node *n) { Node *m; if (!n) return n; if (m = in_cache(n)) return m; n->rgt = canonical(n->rgt); n->lft = canonical(n->lft); return cached(n); }
boost::filesystem::path normalize(boost::filesystem::path const &path) { boost::filesystem::path absPath = absolute(path); boost::filesystem::path::iterator it = absPath.begin(); boost::filesystem::path result = *it++; // Get canonical version of the existing part for (; exists(result / *it) && it != absPath.end(); ++it) { result /= *it; } result = canonical(result); // For the rest remove ".." and "." in a path with no symlinks for (; it != absPath.end(); ++it) { // Just move back on ../ if (*it == "..") { result = result.parent_path(); } // Ignore "." else if (*it != ".") { // Just cat other path entries result /= *it; } } return boost::filesystem::path(result.generic_string()); }
NS_IMETHODIMP nsEmbedChromeRegistry::Canonify(nsIURI* aChromeURI) { #if 1 // Canonicalize 'chrome:' URLs. We'll take any 'chrome:' URL // without a filename, and change it to a URL -with- a filename; // e.g., "chrome://navigator/content" to // "chrome://navigator/content/navigator.xul". if (! aChromeURI) return NS_ERROR_NULL_POINTER; PRBool modified = PR_TRUE; // default is we do canonification nsCAutoString package, provider, file; nsresult rv; rv = SplitURL(aChromeURI, package, provider, file, &modified); if (NS_FAILED(rv)) return rv; if (!modified) return NS_OK; nsCAutoString canonical( kChromePrefix ); canonical += package; canonical += "/"; canonical += provider; canonical += "/"; canonical += file; return aChromeURI->SetSpec(canonical); #else return NS_OK; #endif }
TEST(Kmer, canonicalize) { Kmer::setLength(4); Kmer canonical("ATGC"); Kmer nonCanonical("GCAT"); Kmer palindrome("ACGT"); Kmer kmer = canonical; kmer.canonicalize(); EXPECT_EQ(canonical, kmer); kmer = nonCanonical; kmer.canonicalize(); EXPECT_EQ(canonical, kmer); kmer = palindrome; kmer.canonicalize(); EXPECT_EQ(palindrome, kmer); Kmer::setLength(5); Kmer oddLength("GCTCG"); Kmer oddLengthCanonical("CGAGC"); kmer = oddLength; kmer.canonicalize(); EXPECT_EQ(oddLengthCanonical, kmer); }
complex<SX> canonical(int i, SX& fin, SX& J, SX& U0, SX& dU, SX mu) { complex<SX> S = complex<SX>(0, 0); for (int n = 0; n <= nmax; n++) { S += canonical(i, n, fin, J, U0, dU, mu); } return S; }
std::string BaseCV::AppendFilename(std::string filename, std::string append) { path p(filename); path c = canonical(p); path newpath = c.parent_path() / path(c.stem().string() + append + c.extension().string()); return newpath.string(); }
static virt_t pt_iter_addr(const struct pt_iter *iter) { const virt_t addr = (virt_t)iter->idx[3] << 39 | (virt_t)iter->idx[2] << 30 | (virt_t)iter->idx[1] << 21 | (virt_t)iter->idx[0] << 12; return canonical(addr); }
void Canonicalizer::set_canonical(Value x) { assert(x != NULL, "value must exist"); // Note: we can not currently substitute root nodes which show up in // the instruction stream (because the instruction list is embedded // in the instructions). if (canonical() != x) { if (PrintCanonicalization) { canonical()->input_values_do(do_print_value); canonical()->print_line(); tty->print_cr("canonicalized to:"); x->input_values_do(do_print_value); x->print_line(); tty->cr(); } assert(_canonical->type()->tag() == x->type()->tag(), "types must match"); _canonical = x; } }
bool file_server::is_in_root(std::string const &input_path,std::string const &root,std::string &real) { std::string normal=root + "/" + input_path; if(!canonical(normal,real)) return false; if(!is_file_prefix(root,real)) return false; return true; }
osd_file::error osd_get_full_path(std::string &dst, std::string const &path) { try { #if defined(WIN32) std::vector<char> path_buffer(MAX_PATH); if (::_fullpath(&path_buffer[0], path.c_str(), MAX_PATH)) { dst = &path_buffer[0]; return osd_file::error::NONE; } else { return osd_file::error::FAILURE; } #else std::unique_ptr<char, void (*)(void *)> canonical(::realpath(path.c_str(), nullptr), &std::free); if (canonical) { dst = canonical.get(); return osd_file::error::NONE; } std::vector<char> path_buffer(PATH_MAX); if (::realpath(path.c_str(), &path_buffer[0])) { dst = &path_buffer[0]; return osd_file::error::NONE; } else if (path[0] == PATHSEPCH) { dst = path; return osd_file::error::NONE; } else { while (!::getcwd(&path_buffer[0], path_buffer.size())) { if (errno != ERANGE) return errno_to_file_error(errno); else path_buffer.resize(path_buffer.size() * 2); } dst.assign(&path_buffer[0]).push_back(PATHSEPCH); dst.append(path); return osd_file::error::NONE; } #endif } catch (...) { return osd_file::error::OUT_OF_MEMORY; } }
static int rtnpw(BW *bw) { W *w = bw->parent; PW *pw = (PW *) bw->object; unsigned char *s; W *win; int *notify; int (*pfunc) (); void *object; long byte; /* Extract entered text from buffer */ p_goto_eol(bw->cursor); byte = bw->cursor->byte; p_goto_bol(bw->cursor); s = brvs(bw->cursor, (int) (byte - bw->cursor->byte)); /* Save text into history buffer */ if (pw->hist) { if (bw->b->changed) { append_history(pw->hist, sv(s)); } else { promote_history(pw->hist, bw->cursor->line); } } /* Do ~ expansion and set new current directory */ if (pw->file_prompt&2) { set_current_dir(s,1); } if (pw->file_prompt) { s = canonical(s); } win = w->win; pfunc = pw->pfunc; object = pw->object; bwrm(bw); joe_free(pw->prompt); joe_free(pw); w->object = NULL; notify = w->notify; w->notify = 0; wabort(w); dostaupd = 1; /* Call callback function */ if (pfunc) { return pfunc(win->object, s, object, notify); } else { return -1; } }
char *Lv2PathMapper::mapAbsolutePath(const char *abstractPath) { // get script folder and append incoming relative path fs::path absolutePath(ScriptHost::instance().getCurrentFolder()); absolutePath /= abstractPath; absolutePath = canonical(absolutePath); // copy to malloc-allocated char* const char *pathString = absolutePath.c_str(); char *ret = (char *)malloc(strlen(pathString) + 1); strcpy(ret, pathString); return ret; }
bool AssetHandler::make_absolute_asset_path(string& asset_path) const { // Make sure the asset path is qualified and canonized. path absolute_asset_path = canonical( m_project.search_paths().qualify(asset_path)); // Make sure absolute paths use native separators. absolute_asset_path.make_preferred(); asset_path = absolute_asset_path.string(); return true; }
// Return path when appended to parent will resolve to same as child path relativize(path parent, path child){ parent = canonical(parent); child = canonical(child); // Find common base path::const_iterator parent_iter(parent.begin()), child_iter(child.begin()); path::const_iterator child_end(child.end()), parent_end(parent.end()); while(parent_iter != parent_end && child_iter != child_end && *parent_iter == *child_iter) ++parent_iter, ++child_iter; // Navigate backwards in directory to reach previously found base path ret; while(parent_iter != parent_end) { if( (*parent_iter) != "." ) ret /= ".."; ++parent_iter; } // Now navigate down the directory branch ret.append(child_iter, child.end()); return ret; }
void Canonicalizer::set_canonical(Value x) { assert(x != NULL, "value must exist"); // Note: we can not currently substitute root nodes which show up in // the instruction stream (because the instruction list is embedded // in the instructions). Phis always show up as roots. It is fatal // to embed a phi into the instruction stream as block merging will // not be able to substitute the old phi. if (x->as_Phi() != NULL) { if (PrintCanonicalization) { tty->print_cr("canonicalization produced a phi node; rejected"); } return; } if (canonical() != x) { if (PrintCanonicalization) { canonical()->print(); tty->cr(); tty->print_cr("canonicalized to:"); x->print(); tty->cr(); tty->cr(); } _canonical = x; } }
void Canonicalizer::set_canonical(Value x) { assert(x != NULL, "value must exist"); // Note: we can not currently substitute root nodes which show up in // the instruction stream (because the instruction list is embedded // in the instructions). if (canonical() != x) { #ifndef PRODUCT if (!x->has_printable_bci()) { x->set_printable_bci(bci()); } #endif if (PrintCanonicalization) { PrintValueVisitor do_print_value; canonical()->input_values_do(&do_print_value); canonical()->print_line(); tty->print_cr("canonicalized to:"); x->input_values_do(&do_print_value); x->print_line(); tty->cr(); } assert(_canonical->type()->tag() == x->type()->tag(), "types must match"); _canonical = x; } }
void ObjectLibrary::processFolder(const char* filepath) { // Create object library path library_path(filepath); if(is_directory(library_path)) { recursive_directory_iterator iter(library_path); recursive_directory_iterator end; while(iter != end) { if(is_directory(iter->path())) { object_idx.push_back(images.size()); object_names.push_back(iter->path().filename().generic_string()); //std::cout << "Object: " << object_names.back() << " " << object_idx.back() << std::endl; // Handle Symlink Directories if(is_symlink(iter->path())) { iter = recursive_directory_iterator(canonical(read_symlink(iter->path()), library_path)); } } else { // Initialize object feature Mat img_object = imread(iter->path().generic_string(), CV_LOAD_IMAGE_COLOR); if( !img_object.data ) { throw std::runtime_error("Error Reading Image"); } ImageData img = processImage(img_object); img.name = iter->path().stem().generic_string(); //std::cout << "Object: " << object_names.back() << " Image: " << img.name << std::endl; if(img.name == object_names.back()) { object_img_idx.push_back(images.size()); //std::cout << object_names.back() << " " << images.size() << std::endl; } //-- Step 3: Add to object library images.push_back(std::move(img)); } ++iter; } } //std::cout << "Num Objects: " << object_idx.size() << std::endl; }
void ShaderSource::readFile(const std::string& filename) { path file; try { file = canonical(vars.shader_dir / filename); } catch (filesystem_error& err) { LOG_ERROR(err.what()); return; } std::ostringstream out; m_valid = ::readFile(out, m_filenames, file, 0, &m_defines); m_code = out.str(); m_srcPtr = m_code.c_str(); }
bfs::path programPath() { bfs::path rv(""); #ifdef MACOSX char pathbuf[PATH_MAX + 1]; char real_executable[PATH_MAX + 1]; memset(pathbuf, 0, sizeof(pathbuf)); memset(real_executable, 0, sizeof(real_executable)); uint32_t bufsize = sizeof(pathbuf); _NSGetExecutablePath(pathbuf, &bufsize); rv = pathbuf; #else // MACOSX // NEEDSWORK. No reliable implementation across Unices that I could find for now. #endif // MACOSX return canonical(rv); }
void do_experiment(swp_t&swp, sind_t&sind, rng_t&rng) { constant_indicator mind( moran_probability(swp.mutantFitness()/swp.residentFitness(), swp.n_individuals())); relative_indicator_t<sind_t, constant_indicator> rind(sind,mind); if (parameters.experiment() == "SWEEP") { IndicatorsDisplayController<swp_t,ParamsClass> ind_display; ind_display.inheritParametersFrom(swp); ind_display.setrecordEvery(0); ind_display.setdisplayEvery(0); ind_display.installIndicator(rind,"fixation/Moran prob"); // // cout << "fixation / Moran probability is " << rind(swp) << endl; // for (double rsr = 0.001; rsr <= 1000; rsr *= 1.1/*1.01*/) // // for (swp.room_switch_rate = 1000; swp.room_switch_rate >= 0.001; // // swp.room_switch_rate /= 1.01) // { double p_switch = rsr / (1 + rsr); // swp.setroom_switch_rate(rsr); // ind_display.update(p_switch,swp); // } for (double mp = 0.01; mp < 1; mp += 0.01) { swp.setlattice_move_probability(mp); ind_display.update(mp,swp); } } else if (parameters.experiment() == "SAMPLE") { cout << "swarming pattern:\n" << canonical(swp); double pfix = sind(swp); cout << "fixation probability: " << pfix << '\n'; cout << "Moran probability: " << mind(swp) << '\n'; } else if (parameters.experiment() == "OPTIMIZE") { cout << "Moran probability: " << mind(swp) << '\n'; do_optimize(swp,sind,swp,rng); } }
bool ShaderLoader::addFile(const path& filename) { if (m_input.size() >= SHADERLOADER_MAX_FILES) { LOG::put(LOG::error, LOG::opengl) << "ShaderLoader: too many open files."; return false; } path file(canonical(filename)); m_input.emplace(file); if (!m_input.top()) { m_input.pop(); return false; } m_line.push(0); m_stream.push(m_streamCount++); m_path.push(file.parent_path()); m_file.push_back(file.native()); if (m_stream.top() != 0) { m_source << "#line 0 " << m_stream.top() << " // " << m_file.back() << std::endl; } return true; }
// Check path environment variable for a program char *where_is_program(char *str_program_name) { DEFINE_VAR_ALL(str_PATH, str_PATH2); char *str_return = NULL; ERROR_CAT_CSTR(str_PATH, getenv("PATH")); char *ptr_PATH = str_PATH; char *ptr_PATH_end = str_PATH + strlen(str_PATH); int int_next_colon; while (ptr_PATH < ptr_PATH_end) { //DEBUG("%s", ptr_PATH); int_next_colon = strcspn(ptr_PATH, ":"); ERROR_SALLOC(str_PATH2, int_next_colon + 2); memcpy(str_PATH2, ptr_PATH, int_next_colon); str_PATH2[int_next_colon] = '/'; str_PATH2[int_next_colon + 1] = '\0'; //DEBUG("%s", str_ptr_PATH); str_return = canonical(str_PATH2, str_program_name, "read_dir_or_file"); //"read_file"); SFREE(str_PATH2); if (str_return != NULL) { SFREE_ALL(); return str_return; } //DEBUG("%i", int_next_colon); ptr_PATH += int_next_colon + 1; } WARN("Could not find program: %s", str_program_name); //ERROR("Could not find program: %s", str_program_name); error: SFREE_ALL(); SFREE(str_return); return NULL; }
path canonical_parent(const path& pth, const path& base) { return canonical(pth.parent_path(), base) / pth.filename(); }
const SSATmp* canonical(const SSATmp* val) { return canonical(const_cast<SSATmp*>(val)); }