void BuildVarSettingsDialog::addFilterList() { GuiTreeItem parent; OovString filterTag; int index = getComboId("FilterNameComboboxtext", mFilterNames); if(index != BAD_INDEX) { switch(index) { case FT_BuildConfig: filterTag = OptFilterNameBuildConfig; break; case FT_BuildMode: filterTag = OptFilterNameBuildMode; break; case FT_Component: filterTag = OptFilterNameComponent; break; case FT_Platform: filterTag = OptFilterNamePlatform; break; } } OovStringVec filterVals = mFilterValuesTreeView.getSelected(); if(filterVals.size() > 0) { VariableFilter filter(filterTag, filterVals[0]); mFiltersTreeView.appendText(parent, filter.getFilterAsString()); } updateSettingText(); }
void Editor::updateDebugDataValue() { OovStringVec strs = mVarView.getSelected(); if(strs.size() > 0) { mEditFiles.getDebugger().startGetVariable(strs[0]); } }
const OovStringVec ProjectBuildArgs::getAllCrcLinkArgs() const { OovStringVec vec; for(auto item : mLinkArgs) vec.push_back(item.mString); std::copy(mPackageCrcLinkArgs.begin(), mPackageCrcLinkArgs.end(), std::back_inserter(vec)); return vec; }
void BuildVariablesDialog::removeVariableSetting() { OovStringVec vars = mVarListTreeView.getSelected(); if(vars.size() > 0) { BuildVariable origBuildVar; origBuildVar.initVarFromString(vars[0]); mVarListTreeView.removeSelected(); mProject.removeName(origBuildVar.getVarFilterName()); } }
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; }
void ProjectBuildArgs::updateArgs() { OovStringVec args; CompoundValue baseArgs; baseArgs.parseString(mBuildEnv.getValue(OptCppArgs)); for(auto const &arg : baseArgs) { args.push_back(arg); } parseArgs(args); }
OovStringVec ComponentTypesFile::getComponentNames(bool definedComponentsOnly) const { OovStringVec compNames = CompoundValueRef::parseString( mCompTypesFile.getValue("Components")); if(definedComponentsOnly) { compNames.erase(std::remove_if(compNames.begin(), compNames.end(), [this](OovString &name) { return(getComponentType(name) == CT_Unknown); }), compNames.end()); } return compNames; }
OovStringVec NameValueRecord::getMatchingNames(OovStringRef const baseName) const { OovStringVec names; int len = baseName.numBytes(); for(auto const &nv : mNameValues) { if(nv.first.compare(0, len, baseName, len) == 0) { names.push_back(nv.first); } } return names; }
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])); } } }
OovString StringJoin(OovStringVec const &tokens, char delimiter) { OovString str; for(size_t i=0; i<tokens.size(); i++) { str += tokens[i]; if(i < tokens.size()-1) { str += delimiter; } } return str; }
void CMaker::addLibsAndIncs(OovStringRef const compName, OovString &str) { OovStringVec extraIncs; OovStringVec libs = getCompLibrariesAndIncs(compName, extraIncs); addCommandAndNames(CT_TargLinkLibs, compName, libs, str); if(extraIncs.size()) { str += "include_directories("; appendNames(extraIncs, ',', str); str += ")\n\n"; } }
OovStringVec ComponentTypesFile::getComponentNamesByType(eCompTypes cft) const { OovStringVec allCompNames = CompoundValueRef::parseString( mCompTypesFile.getValue("Components")); OovStringVec filteredNames; for(auto const &compName : allCompNames) { if(getComponentType(compName) == cft) { filteredNames.push_back(compName); } } return filteredNames; }
void OptionsDialog::addConfig() { GtkEntry *newNameEntry = GTK_ENTRY(Builder::getBuilder()->getWidget("NewConfigNameEntry")); // Update the build config option std::string compStr = mProjectOptions.getValue(OptBuildConfigs); CompoundValue compVal; compVal.parseString(compStr); OovString newName = Gui::getText(newNameEntry); OovStringVec cfgs = compVal; cfgs.push_back(BuildConfigAnalysis); cfgs.push_back(BuildConfigDebug); cfgs.push_back(BuildConfigRelease); bool found = std::find(cfgs.begin(), cfgs.end(), newName) != cfgs.end(); if(!found) { compVal.addArg(newName); mProjectOptions.setNameValue(OptBuildConfigs, compVal.getAsString()); // Leave what is on the screen, and change the config name.Save the // screen data to the new config. mCurrentBuildConfig = newName; // ScreenOptions options(mCurrentBuildConfig); // options.screenToOptions(); updateBuildConfig(); } else Gui::messageBox("Configuration already exists", GTK_MESSAGE_INFO); }
static int getErrorPosition(OovStringRef const line, int &charOffset) { int lineNum = -1; OovStringVec tokens = StringSplit(line, ':'); auto iter = std::find_if(tokens.begin(), tokens.end(), [](OovStringRef const tok) { return(isdigit(tok[0])); } ); int starti = iter-tokens.begin(); if(tokens[starti].getInt(0, INT_MAX, lineNum)) { if(static_cast<unsigned int>(starti+1) < tokens.size()) { tokens[starti+1].getInt(0, INT_MAX, charOffset); } } return lineNum; }
// First arg at index 0 is the command. OovString OovIpcMsg::getArg(size_t argNum) const { OovStringVec args = split(','); OovString arg; #if(DEBUG_IPC) if(argNum == 0) { FILE *fp = fopen("IPC.txt", "a"); fprintf(fp, "RCV: %s\n", cmdStr.getStr()); fclose(fp); } #endif if(argNum < args.size()) { arg = args[argNum]; } return arg; }
OovStringVec StringSplit(char const * const str, char const * const delimiterStr) { OovString tempStr = str; OovStringVec tokens; size_t start = 0; size_t end = 0; const size_t delimLen = strlen(delimiterStr); while(end != std::string::npos) { end = tempStr.find(delimiterStr, start); size_t len = (end == std::string::npos) ? std::string::npos : end - start; OovString splitStr = tempStr.substr(start, len); tokens.push_back(splitStr); start = (( end > (std::string::npos - delimLen)) ? std::string::npos : end + delimLen); } return tokens; }
GraphSize OperationDrawer::drawClass(DiagramDrawer &drawer, const OperationClass &node, const OperationDrawOptions & /*options*/, bool draw) { GraphPoint startpos = node.getPosition(); const ModelType *type = node.getType(); OovStringRef const typeName = type->getName(); int rectx = 0; int recty = 0; const ModelClassifier *classifier = type->getClass(); if(classifier) { if(draw) { drawer.groupText(true, false); } OovStringVec strs; std::vector<GraphPoint> positions; strs.push_back(typeName); splitStrings(strs, 30, 40); for(auto const &str : strs) { recty += mCharHeight + (mPad * 2); positions.push_back(GraphPoint(startpos.x+mPad, startpos.y + recty - mPad)); int curx = static_cast<int>(drawer.getTextExtentWidth(str)) + mPad*2; if(curx > rectx) rectx = curx; } if(draw) { drawer.groupShapes(true, Color(0,0,0), Color(245,245,255)); drawer.drawRect(GraphRect(startpos.x, startpos.y, rectx, recty)); drawer.groupShapes(false, Color(0,0,0), Color(245,245,255)); for(size_t i=0; i<strs.size(); i++) { drawer.drawText(positions[i], strs[i]); } drawer.groupText(false, false); } } return GraphSize(rectx, recty); }
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 CompoundValueRef::getAsString(const OovStringVec &vec, char delimiter) { OovString str; for(size_t i=0; i<vec.size(); i++) { str += vec[i]; str += delimiter; } return str; }
void ComponentsFile::parseProjRefs(OovStringRef const arg, OovString &rootDir, OovStringVec &excludes) { excludes.clear(); OovStringVec tokens = StringSplit(arg, '!'); if(rootDir.size() == 0) rootDir = tokens[0]; if(tokens.size() > 1) { excludes.resize(tokens.size()-1); std::copy(tokens.begin()+1, tokens.end(), excludes.begin()); } }
OovStringVec Tokenizer::getDiagResults() { OovStringVec diagResults; if(mTransUnit) { int numDiags = clang_getNumDiagnostics(mTransUnit); for (int i = 0; i<numDiags && diagResults.size() < 10; i++) { CXDiagnostic diag = clang_getDiagnostic(mTransUnit, i); // CXDiagnosticSeverity sev = clang_getDiagnosticSeverity(diag); // if(sev >= CXDiagnostic_Error) OovString diagStr = getDisposedString(clang_formatDiagnostic(diag, clang_defaultDiagnosticDisplayOptions())); if(diagStr.find(mSourceFilename) != std::string::npos) { diagResults.push_back(diagStr); } } } return diagResults; }
OovStringVec ComponentTypesFile::getComponentFiles(OovStringRef const compName, OovStringRef const tagStr, bool getNested) const { OovStringVec files; OovStringVec names = getComponentNames(); OovString parentName = compName; for(auto const &name : names) { bool match = false; if(getNested) { if(strcmp(compName, Project::getRootComponentName()) == 0) { match = true; } else { match = compareComponentNames(parentName, name); } } else { match = (parentName == name); } if(match) { OovString tag = ComponentTypesFile::getCompTagName(name, tagStr); OovString val = mCompSourceListFile.getValue(tag); OovStringVec newFiles = CompoundValueRef::parseString(val); files.insert(files.end(), newFiles.begin(), newFiles.end()); } } return files; }
void BuildVariablesDialog::editVariable() { OovStringVec vars = mVarListTreeView.getSelected(); if(vars.size() > 0) { OovString var = vars[0]; if(sBuildVarSettingsDialog->editVariable(var)) { mVarListTreeView.removeSelected(); GuiTreeItem parent; mVarListTreeView.appendText(parent, var); BuildVariable origBuildVar; origBuildVar.initVarFromString(vars[0]); mProject.removeName(origBuildVar.getVarFilterName()); BuildVariable newBuildVar; newBuildVar.initVarFromString(var); mProject.setNameValue(newBuildVar.getVarFilterName(), newBuildVar.getVarValue()); } } }
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; }
size_t ComponentGraph::getComponentIndex(OovStringVec const &compPaths, OovStringRef const dir) { size_t compIndex = NO_INDEX; for(size_t i=0; i<compPaths.size(); i++) { std::string const &compPath = compPaths[i]; if(compPath.compare(dir) == 0) { compIndex = i; break; } } return compIndex; }
void ProjectPackagesDialog::displayAddPackageDialog() { AddPackageDialog dlg; if(dlg.run(true)) { OovStringVec packages = mProjectPackagesList.getText(); Package pkg = dlg.getPackage(); if(std::find(packages.begin(), packages.end(), pkg.getPkgName()) == packages.end()) { mProjectPackages.insertPackage(pkg); } else { Gui::messageBox("Package already exists"); } updatePackageList(); mProjectPackagesList.setSelected(pkg.getPkgName()); #ifndef __linux__ winScanDirectories(); #endif } }
bool FileStat::isOutputOld(OovStringRef const outputFn, OovStringVec const &inputs, size_t *oldIndex) { bool old = false; for(size_t i=0; i<inputs.size(); i++) { if(isOutputOld(outputFn, inputs[i])) { old = true; if(oldIndex) *oldIndex = i; break; } } return old; }
void CompoundValueRef::parseStringRef(OovStringRef const strIn, OovStringVec &vec, char delimiter) { OovString str = strIn; size_t startArgPos = 0; while(startArgPos != std::string::npos) { size_t endColonPos = str.find(delimiter, startArgPos); std::string tempStr = str.substr(startArgPos, endColonPos-startArgPos); // For compatibility with previous files, allow a string that is // after the last colon. Previous versions that had the extra string // did not allow null strings. if(endColonPos != std::string::npos || tempStr.length() > 0) { vec.push_back(tempStr); } startArgPos = endColonPos; if(startArgPos != std::string::npos) startArgPos++; } }
void ComponentGraph::updateConnections(const ComponentTypesFile &compFile, const ComponentDrawOptions &options) { BuildPackages buildPkgs(true); std::vector<Package> packages = buildPkgs.getPackages(); mConnections.clear(); OovStringVec compPaths; for(size_t i=0; i<mNodes.size(); i++) { if(mNodes[i].getComponentNodeType() == ComponentNode::CNT_Component) { std::string incPath; incPath = compFile.getComponentAbsolutePath(mNodes[i].getName()); compPaths.push_back(incPath); } } // This is slow - look to improve? for(size_t consumerIndex=0; consumerIndex<mNodes.size(); consumerIndex++) { if(mNodes[consumerIndex].getComponentNodeType() == ComponentNode::CNT_Component) { OovStringVec srcFiles = compFile.getComponentFiles( ComponentTypesFile::CFT_CppSource, mNodes[consumerIndex].getName()); for(auto const &srcFile : srcFiles) { FilePath fp; fp.getAbsolutePath(srcFile, FP_File); OovStringVec incDirs = mIncludeMap->getNestedIncludeDirsUsedBySourceFile(fp); for(auto const &incDir : incDirs) { size_t supplierIndex = getComponentIndex(compPaths, incDir); if(supplierIndex != NO_INDEX && consumerIndex != supplierIndex) mConnections.insert(ComponentConnection(consumerIndex, supplierIndex)); } } } } for(size_t supplierIndex=0; supplierIndex<mNodes.size(); supplierIndex++) { if(mNodes[supplierIndex].getComponentNodeType() == ComponentNode::CNT_ExternalPackage) { OovString const &nodeName = mNodes[supplierIndex].getName(); auto const &supplierIt = std::find_if(packages.begin(), packages.end(), [nodeName](Package const &pkg) -> bool { return(pkg.getPkgName().compare(nodeName) == 0); }); if(supplierIt != packages.end()) { for(size_t consumerIndex=0; consumerIndex<mNodes.size(); consumerIndex++) { if(mNodes[consumerIndex].getComponentNodeType() == ComponentNode::CNT_Component) { OovStringVec incRoots = (*supplierIt).getIncludeDirs(); if(mIncludeMap->anyRootDirsMatch(incRoots, compPaths[consumerIndex])) { mConnections.insert(ComponentConnection(consumerIndex, supplierIndex)); } } } } } } if(!options.drawImplicitRelations) pruneConnections(); }
int main(int argc, char * argv[]) { int ret = 1; bool verbose = false; bool writeToProject = false; const char *projDir = nullptr; const char *projName = "PROJNAME"; for(int argi=1; argi<argc; argi++) { if(argv[argi][0] == '-') { switch(argv[argi][1]) { case 'v': verbose = true; break; case 'w': writeToProject = true; break; case 'n': projName = &argv[argi][2]; break; } } else projDir = argv[argi]; } if(projDir) { Project::setProjectDirectory(projDir); CMaker maker(projName, verbose); FilePath outDir; if(writeToProject) { outDir.setPath(Project::getSrcRootDirectory(), FP_Dir); } else { outDir.setPath(Project::getBuildOutputDir("CMake"), FP_Dir); FileEnsurePathExists(outDir); if(maker.mVerbose) printf("Output directory %s\n", outDir.getStr()); } if(maker.mCompTypes.read()) { maker.makeToolchainFiles(outDir); maker.makeTopLevelFiles(outDir); maker.mBuildPkgs.read(); FilePath topMlFp(outDir, FP_File); topMlFp.appendFile("CMakeLists.txt"); maker.makeTopMakelistsFile(topMlFp); OovStringVec compNames = maker.mCompTypes.getComponentNames(true); if(compNames.size() > 0) { maker.makeComponentFiles(writeToProject, outDir, compNames); ret = 0; } else fprintf(stderr, "Components must be defined\n"); } else fprintf(stderr, "Unable to read project files\n"); } else { fprintf(stderr, "OovCMaker version %s\n", OOV_VERSION); fprintf(stderr, " OovCMaker projectDirectory [switches]\n"); fprintf(stderr, " switches -v=verbose, -w=write to project, -nProjName\n"); } return ret; }