String Path::dirname(char sep) const { if (mPaths.size() == 0) { return ""; } Path pdir(*this); pdir.pop(); String tmp(sep); return tmp.join(pdir.mPaths); }
int main(int argc, char **argv) { if( argc != 2 ) return 1; init_regexes(filetypes); pdir(argv[1], 0); return 0; }
void ModelSerializer::serialize(ptime time) const { boost::filesystem::path pdir(dir); if (!boost::filesystem::exists(pdir)) { boost::filesystem::create_directories(pdir); } std::string path = pathForTimeStep(time); std::ofstream out(path.c_str()); serialize(out); out.close(); }
ustring SettingsManager::readProjectsDir() { ustring pdir(readStr(IDS_PROJECTS_DIR)); int p = pdir.find("%home%"); if(p != -1) pdir.replace(p, 6, g_get_home_dir()); if(!file_test(pdir, FILE_TEST_IS_DIR)) g_mkdir_with_parents(pdir.c_str(), 0777); return pdir; }
/** * @brief calculate closest point on linepiece from l1 to l2 * Note, this clamps the returned point to a position between l1 and l2. */ float3 ClosestPointOnLine(const float3& l1, const float3& l2, const float3& p) { float3 dir(l2-l1); float3 pdir(p-l1); float length = dir.Length(); if (fabs(length) < 1e-4f) return l1; float c = dir.dot(pdir) / length; if (c < 0) c = 0; if (c > length) c = length; return l1 + dir * (c / length); }
void NLS::Foothold::Load(Node n) { for (auto i = footholds.begin(); i != footholds.end(); i++) { delete *i; } footholds.clear(); n = n["foothold"]; if (!n) { C("ERROR") << "No foothold node" << endl; throw(273); } for (auto i = n.begin(); i != n.end(); i++) { int fhdepth = toint(i->first); for (auto j = i->second.begin(); j != i->second.end(); j++) { int fhgroup = toint(j->first); for (auto k = j->second.begin(); k != j->second.end(); k++) { Node fn = k->second; Foothold* fh = new Foothold(); fh->x1 = fn["x1"]; fh->y1 = fn["y1"]; fh->x2 = fn["x2"]; fh->y2 = fn["y2"]; fh->nextid = fn["next"]; fh->previd = fn["prev"]; fh->force = fn["force"]; fh->forbid = (int)fn["forbidFallDown"]; fh->id = toint(k->first); fh->layer = fhdepth; fh->group = fhgroup; fh->dir = pdir(fh->x1, fh->y1, fh->x2, fh->y2); fh->len = pdis(fh->x1, fh->y1, fh->x2, fh->y2); fh->walk = fh->dir < 90 and fh->dir > -90; fh->next = 0; fh->prev = 0; footholds.insert(fh); } } } for (auto i = footholds.begin(); i != footholds.end(); i++) { for (auto j = footholds.begin(); j != footholds.end(); j++) { auto fi = *i; auto fj = *j; if (fi->nextid == fj->id) { fi->next = fj; } if (fi->previd == fj->id) { fi->prev = fj; } } } }
Projection::Projection(void) : p(new ProjectionPrivate) { #if defined(Q_OS_WIN) && !defined(_MOBILE) QString pdir(QDir::toNativeSeparators(qApp->applicationDirPath() + "/" STRINGIFY(SHARE_DIR) "/proj")); const char* proj_dir = pdir.toUtf8().constData(); // const char* proj_dir = "E:\\cbro\\src\\merkaartor-devel\\binaries\\bin\\share\\proj"; pj_set_searchpath(1, &proj_dir); #endif // Q_OS_WIN #ifndef _MOBILE theProj = NULL; p->theWGS84Proj = Projection::getProjection("+proj=longlat +ellps=WGS84 +datum=WGS84"); setProjectionType(M_PREFS->getProjectionType()); #endif }
bool Path::createDir(bool recursive) const { if (exists()) { return true; } if (mPaths.size() == 0) { return false; } if (recursive) { Path pdir(*this); pdir.pop(); if (!pdir.createDir(recursive)) { return false; } } #ifdef _WIN32 return (CreateDirectory(mFullName.c_str(), NULL) == TRUE); #else return (mkdir(mFullName.c_str(), S_IRWXU) == 0); #endif }
int pdir(const char *dir, int skipdotfiles) { DIR *ectory; struct dirent *ent; struct stat file; char *fbuf, *dbuf; ectory = opendir(dir); dbuf = realpath(dir, NULL); while( (ent = readdir(ectory)) ) { if( (ent->d_name[0] == '.' && (!ent->d_name[1] || skipdotfiles)) || (ent->d_name[1] == '.' && !ent->d_name[2]) ) continue; asprintf(&fbuf, "%s/%s", dbuf, ent->d_name); stat(fbuf, &file); switch( file.st_mode & S_IFMT ) { case S_IFREG: print_metadata(fbuf, ent->d_name); break; case S_IFDIR: pdir(fbuf, skipdotfiles); break; } free(fbuf); } free(dbuf); closedir(ectory); return 0; }
setup_paging() { int i; //设置页表的初始地址 pg_dir = (int *)((((int)&pg_mem) + 4095) & -4096); //分四页,每页1024*4个字节,即4KB pg0 = pg_dir + 1024; pg1 = pg0 + 1024; pg2 = pg1 + 1024; pg3 = pg2 + 1024; pg_dir[0] = (int)pg0 | PTE_P | PTE_W | PTE_U; // identity map 16M pg_dir[1] = (int)pg1 | PTE_P | PTE_W | PTE_U; pg_dir[2] = (int)pg2 | PTE_P | PTE_W | PTE_U; pg_dir[3] = (int)pg3 | PTE_P | PTE_W | PTE_U; //这一步是用来对齐的吗?一个物理内存块是4KB,页表初始地址管理四个页块,而pg0是从pg_dir+1024开始的,因此把4~1024这部分赋值为0 for (i=4;i<1024;i++) pg_dir[i] = 0; //初始化四个页面。每个页起初都是可用的,又因为一个4KB页为2^12,因此页块的物理地址低12位都是0,用于存储页的状态(PTE_P | PTE_W | PTE_U)。 for (i=0;i<4096;i++) pg0[i] = (i<<12) | PTE_P | PTE_W | PTE_U; // trick to write all 4 contiguous pages //页起始地址设置 pdir(pg_dir); //设置页机制(使能) spage(1); }
float SpotLightCalculator::getLightAmount(const VC3 &position, const IStorm3D_Terrain &terrain, float rayHeight) const { float squareRange = position.GetSquareRangeTo(data->position); if(squareRange > data->squareRange) return 0; VC2 pdir(position.x - data->position.x, position.z - data->position.z); VC2 sdir(data->direction.x, data->direction.z); float pAngle = pdir.CalculateAngle(); float sAngle = sdir.CalculateAngle(); float diff = pAngle - sAngle; //assert(diff if(diff < -3.1415f) diff += 3.1415f * 2; else if(diff > 3.1415f) diff -= 3.1415f * 2; if(fabsf(diff) / 3.1415f * 180.f > data->fov) return 0; return data->getAmount(position, -diff, terrain, rayHeight); }
bool ProfilModel::loadProfils() { if (!QFile::exists(Profil::ProfilDirectory)) if (!QDir(qApp->applicationDirPath()).mkdir(Profil::ProfilDirectory)) return createDefaultProfils(false); QDir pdir(qApp->applicationDirPath().toLocal8Bit() + "/" + Profil::ProfilDirectory); QStringList dirFilter; dirFilter << "*.ini"; pdir.setNameFilters(dirFilter); QStringList strlt = pdir.entryList(); QStringListIterator it(strlt); if (strlt.isEmpty()) return createDefaultProfils(); while (it.hasNext()) { Profil* newProfil; QString fileName = qApp->applicationDirPath().toLocal8Bit() + "/" + Profil::ProfilDirectory + "/" + it.next(); QSettings* fileIni = new QSettings(fileName, QSettings::IniFormat); fileIni->sync(); if (fileIni->status() != QSettings::NoError) return false; if (fileIni->value(PROFIL_TYPE_STRING).toString() == PROFIL_TYPE_GSTOYUNDA) newProfil = new ProfilGstToyundaPlayer; if (fileIni->value(PROFIL_TYPE_STRING).toString() == PROFIL_TYPE_MPLAYER) newProfil = new Profilmplayer; if (fileIni->value(PROFIL_TYPE_STRING).toString() == PROFIL_TYPE_QOSD) newProfil = new ProfilOSD; newProfil->fileName = fileName; delete fileIni; newProfil->load(fileName); m_profilList.append(newProfil); } m_defaultProfil = m_profilList.first(); return true; }
/// Download preview & get timestamp if newer than cachefile's /// last modified time, otherwise just get the timestamp QDateTime RemoteGetPreviewIfModified( const ProgramInfo &pginfo, const QString &cachefile) { QString loc("RemoteGetPreviewIfModified: "); QDateTime cacheLastModified; QFileInfo cachefileinfo(cachefile); if (cachefileinfo.exists()) cacheLastModified = cachefileinfo.lastModified(); QStringList strlist("QUERY_PIXMAP_GET_IF_MODIFIED"); strlist << ((cacheLastModified.isValid()) ? // unix secs, UTC QString::number(cacheLastModified.toTime_t()) : QString("-1")); strlist << QString::number(200 * 1024); // max size of preview file pginfo.ToStringList(strlist); if (!gCoreContext->SendReceiveStringList(strlist) || strlist.isEmpty() || strlist[0] == "ERROR") { LOG(VB_GENERAL, LOG_ERR, loc + "Remote error" + ((strlist.size() >= 2) ? (":\n\t\t\t" + strlist[1]) : "")); return QDateTime(); } if (strlist[0] == "WARNING") { LOG(VB_NETWORK, LOG_WARNING, loc + "Remote warning" + ((strlist.size() >= 2) ? (":\n\t\t\t" + strlist[1]) : "")); return QDateTime(); } QDateTime retdatetime; qlonglong timet = strlist[0].toLongLong(); if (timet >= 0) retdatetime = MythDate::fromTime_t(timet); if (strlist.size() < 4) { return retdatetime; } size_t length = strlist[1].toULongLong(); quint16 checksum16 = strlist[2].toUInt(); QByteArray data = QByteArray::fromBase64(strlist[3].toLatin1()); if ((size_t) data.size() < length) { // (note data.size() may be up to 3 bytes longer after decoding LOG(VB_GENERAL, LOG_ERR, loc + QString("Preview size check failed %1 < %2") .arg(data.size()).arg(length)); return QDateTime(); } data.resize(length); if (checksum16 != qChecksum(data.constData(), data.size())) { LOG(VB_GENERAL, LOG_ERR, loc + "Preview checksum failed"); return QDateTime(); } QString pdir(cachefile.section("/", 0, -2)); QDir cfd(pdir); if (!cfd.exists() && !cfd.mkdir(pdir)) { LOG(VB_GENERAL, LOG_ERR, loc + QString("Unable to create remote cache directory '%1'") .arg(pdir)); return QDateTime(); } QFile file(cachefile); if (!file.open(QIODevice::WriteOnly|QIODevice::Truncate)) { LOG(VB_GENERAL, LOG_ERR, loc + QString("Unable to open cached preview file for writing '%1'") .arg(cachefile)); return QDateTime(); } off_t offset = 0; size_t remaining = length; uint failure_cnt = 0; while ((remaining > 0) && (failure_cnt < 5)) { ssize_t written = file.write(data.data() + offset, remaining); if (written < 0) { failure_cnt++; usleep(50000); continue; } failure_cnt = 0; offset += written; remaining -= written; } if (remaining) { LOG(VB_GENERAL, LOG_ERR, loc + QString("Failed to write cached preview file '%1'") .arg(cachefile)); file.resize(0); // in case unlink fails.. file.remove(); // closes fd return QDateTime(); } file.close(); return retdatetime; }