OovString FilePathGetWithoutEndPathSep( OovStringRef const path) { OovString str = path; FilePathRemovePathSep(str, str.length()-1); return str; }
bool CppFileContents::write(OovStringRef const fn) { SimpleFile file; eOpenStatus openStat = file.open(fn, M_WriteExclusiveTrunc, OE_Binary); OovStatus status(openStat == OS_Opened, SC_File); if(status.ok()) { OovString includeCov = "#include \"OovCoverage.h\""; appendLineEnding(includeCov); updateMemory(); status = file.write(includeCov.c_str(), includeCov.length()); } if(status.ok()) { status = file.write(mFileContents.data(), mFileContents.size()); } if(!status.ok()) { OovString str = "Unable to write %s "; str += fn; str += "\n"; status.report(ET_Error, str.getStr()); } return status.ok(); }
void StringToLower(OovString &str) { for(size_t i=0; i<str.length(); ++i) { str.at(i) = static_cast<char>(tolower(str.at(i))); } }
size_t FilePathGetPosSegment(OovStringRef const path, OovStringRef const seg) { OovString lowerPath; // Only do case insensitive compares for Windows. #ifdef __linux__ lowerPath = path; #else lowerPath.setLowerCase(path); #endif OovString lowerSeg; #ifdef __linux__ lowerSeg = seg; #else lowerSeg.setLowerCase(seg); #endif size_t pos = lowerPath.find(lowerSeg); size_t foundPos = std::string::npos; if(pos != std::string::npos) { if(pos > 0) { size_t endPos = pos + lowerSeg.length(); if(FilePathIsPathSep(path, pos-1) && FilePathIsPathSep(path, endPos)) { foundPos = pos-1; } } } return foundPos; }
std::string BuildConfig::getAnalysisPath() const { // If a build is being performed, it is possible that an analysis was never // done, so there will be no analysis string. So get the one from the // debug or release build. They should normally be all the same since // it is mainly a CRC of the project related paths. OovString crcStr = getCrcAsStr(BuildConfigAnalysis, CT_AnalysisArgsCrc); if(crcStr.length() == 0) { crcStr = getCrcAsStr(BuildConfigDebug, CT_AnalysisArgsCrc); if(crcStr.length() == 0) { crcStr = getCrcAsStr(BuildConfigRelease, CT_AnalysisArgsCrc); } } return getAnalysisPathUsingCRC(crcStr); }
/// Copy a single source file and make a comment that contains the hit count /// for each instrumented line. static void updateCovSourceCounts(OovStringRef const relSrcFn, std::vector<int> &counts) { FilePath srcFn(Project::getCoverageSourceDirectory(), FP_Dir); srcFn.appendFile(relSrcFn); FilePath dstFn(Project::getCoverageProjectDirectory(), FP_Dir); dstFn.appendFile(relSrcFn); File srcFile; OovStatus status = srcFile.open(srcFn, "r"); if(status.ok()) { status = FileEnsurePathExists(dstFn); if(status.ok()) { File dstFile; status = dstFile.open(dstFn, "w"); if(status.ok()) { char buf[1000]; size_t instrCount = 0; while(srcFile.getString(buf, sizeof(buf), status)) { if(strstr(buf, "COV_IN(")) { if(instrCount < counts.size()) { OovString countStr = " // "; countStr.appendInt(counts[instrCount]); OovString newStr = buf; size_t pos = newStr.find('\n'); newStr.insert(pos, countStr); if(newStr.length() < sizeof(buf)-1) { strcpy(buf, newStr.getStr()); } } instrCount++; } status = dstFile.putString(buf); if(!status.ok()) { break; } } } } } if(status.needReport()) { OovString err = "Unable to transfer coverage "; err += srcFn; err += " "; err += dstFn; status.report(ET_Error, err); } }
void CMaker::appendNames(OovStringVec const &names, char delim, OovString &str) { for(auto const &name : names) { str += name; str += delim; size_t startpos = str.rfind('\n'); if(startpos == std::string::npos) startpos = 0; if(str.length() - startpos > 70) { str += "\n "; } } int len = str.length(); if(len > 0 && str[len-1] == delim) str.resize(len-1); }
OovStatusReturn ClassDiagram::saveDiagram(File &file) { OovStatus status(true, SC_File); NameValueFile nameValFile; CompoundValue names; CompoundValue xPositions; CompoundValue yPositions; OovString drawingName; for(auto const &node : mClassGraph.getNodes()) { if(node.getType()) { if(drawingName.length() == 0) { drawingName = node.getType()->getName(); } names.addArg(node.getType()->getName()); } else { names.addArg("Oov-Key"); } OovString num; num.appendInt(node.getPosition().x); xPositions.addArg(num); num.clear(); num.appendInt(node.getPosition().y); yPositions.addArg(num); } if(drawingName.length() > 0) { DiagramStorage::setDrawingHeader(nameValFile, DST_Class, drawingName); nameValFile.setNameValue("Names", names.getAsString()); nameValFile.setNameValue("XPositions", xPositions.getAsString()); nameValFile.setNameValue("YPositions", yPositions.getAsString()); status = nameValFile.writeFile(file); } return status; }
OovStringVec Tokenizer::codeComplete(size_t offset) { CLangAutoLock lock(mCLangLock, __LINE__, this); OovStringVec strs; unsigned options = 0; // This gets more than we want. // unsigned options = clang_defaultCodeCompleteOptions(); unsigned int line; unsigned int column; getLineColumn(offset, line, column); CXCodeCompleteResults *results = clang_codeCompleteAt(mTransUnit, mSourceFilename.getStr(), line, column, nullptr, 0, options); if(results) { clang_sortCodeCompletionResults(&results->Results[0], results->NumResults); for(size_t ri=0; ri<results->NumResults /*&& ri < 50*/; ri++) { OovString str; CXCompletionString compStr = results->Results[ri].CompletionString; size_t numChunks = clang_getNumCompletionChunks(compStr); for(size_t ci=0; ci<numChunks && ci < 30; ci++) { CXCompletionChunkKind chunkKind = clang_getCompletionChunkKind(compStr, ci); // We will discard return values from functions, so the first // chunk returned will be the identifier or function name. Function // arguments will be returned after a space, so they can be // discarded easily. if(chunkKind == CXCompletionChunk_TypedText || str.length()) { std::string chunkStr = getDisposedString(clang_getCompletionChunkText(compStr, ci)); if(str.length() != 0) str += ' '; str += chunkStr; } } strs.push_back(str); } clang_disposeCodeCompleteResults(results); } return strs; }
OovString const Project::getBinDirectory() { static OovString path; if(path.length() == 0) { OovStatus status(true, SC_File); #ifdef __linux__ char buf[300]; ssize_t len = readlink("/proc/self/exe", buf, sizeof(buf)); if(len >= 0) { buf[len] = '\0'; path = buf; size_t pos = path.rfind('/'); if(pos == std::string::npos) { pos = path.rfind('\\'); } if(pos != std::string::npos) { path.resize(pos+1); } } /* if(FileIsFileOnDisk("./oovaide", status)) { path = "./"; } else if(FileIsFileOnDisk("/usr/local/bin/oovaide", status)) { path = "/usr/local/bin/"; } */ else { path = "/usr/bin"; } #else if(FileIsFileOnDisk("./oovaide.exe", status)) { path = "./"; } else { path = FilePathGetDrivePath(sArgv0); } #endif if(status.needReport()) { status.report(ET_Error, "Unable to get bin directory"); } } return path; }
OovStringVec CMaker::getCompSources(OovStringRef const compName) { OovStringVec sources = mCompTypes.getComponentSources(compName); OovString compPath = mCompTypes.getComponentAbsolutePath(compName); for(auto &src : sources) { src.erase(0, compPath.length()); } std::sort(sources.begin(), sources.end(), compareNoCase); return sources; }
bool NameValueRecord::getLine(File &file, OovString &str, OovStatus &status) { char lineBuf[1000]; str.resize(0); // Read many times until the \n is found. while(file.getString(lineBuf, sizeof(lineBuf), status)) { str += lineBuf; size_t len = str.length(); if(str[len-1] == '\n') { str.resize(len-1); break; } else if(len > 50000) { break; } } return(str.length() > 0); }
void deleteSelected() { OovString selStr = mPathMapList.getSelected(); if(selStr.length() > 0) { OovStringVec vec = selStr.split(" > "); if(vec.size() == 2) { mPathMapList.removeSelected(); mDiagramPathMap->remove(ZonePathReplaceItem(vec[0], vec[1])); } } }
bool EditOptions::getScreenCoord(char const * const tag, int &val) { OovString str = getValue(tag); bool got = false; if(str.length() > 0) { if(str.getInt(0, 100000, val)) { got = true; } } return got; }
void ProjectPackagesDialog::winScanDirectories() { Package pkg = mProjectPackages.getPackage( mProjectPackagesList.getSelected()); if(pkg.getPkgName().length() > 0) { OovString rootDir = getEntry("PackageRootDirEntry"); FilePaths dirs; dirs.push_back(FilePath("/", FP_Dir)); dirs.push_back(FilePath("/Program Files", FP_Dir)); OovString dir = findMatchingDir(dirs, rootDir); if(dir.length()) { pkg.setRootDir(dir); // move to project packages. mProjectPackages.insertPackage(pkg); } setEntry("PackageRootDirEntry", pkg.getRootDir()); } else Gui::messageBox("Select a package to scan", GTK_MESSAGE_INFO); }
OovStringVec StringSplit(char const * const str, OovStringVec const &delimiters, bool keepZeroLengthStrings) { OovString tempStr = str; OovStringVec tokens; size_t start = 0; size_t end = 0; size_t lowestEnd = 0; while(end != std::string::npos) { lowestEnd = std::string::npos; size_t delimLen = std::string::npos; for(auto const &delim : delimiters) { end = tempStr.find(delim, start); if(end < lowestEnd) { delimLen = strlen(delim.getStr()); lowestEnd = end; } } end = lowestEnd; /// Don't add zero length strings when two delimiters are next to each other. size_t len = (end == std::string::npos) ? std::string::npos : end - start; if(keepZeroLengthStrings || len > 0) { OovString splitStr = tempStr.substr(start, len); if(splitStr.length() > 0) { tokens.push_back(splitStr); } } start = (( end > (std::string::npos - delimLen)) ? std::string::npos : end + delimLen); } return tokens; }
void EditFiles::idleHighlight() { timeval curTime; gettimeofday(&curTime, NULL); if(curTime.tv_sec != mLastHightlightIdleUpdate.tv_sec || abs(curTime.tv_usec - mLastHightlightIdleUpdate.tv_usec) > 300) { OovString fn; size_t offset; for(auto &view : mFileViews) { FileEditView &editView = view->getFileEditView(); if(editView.idleHighlight()) { editView.getFindTokenResults(fn, offset); } } if(fn.length() > 0) { viewFile(fn, offset); } mLastHightlightIdleUpdate = curTime; } }