String AbstractFileManager::appendPath(const String& prefix, const String& suffix) { if (prefix.empty()) return suffix; if (suffix.empty()) return prefix; String path = prefix; if (prefix[prefix.length() - 1] != pathSeparator() && suffix[0] != pathSeparator()) path += pathSeparator(); return path + suffix; }
QString SynchronousProcess::locateBinary(const QString &path, const QString &binary) { // Absolute file? const QFileInfo absInfo(binary); if (absInfo.isAbsolute()) { return checkBinary(absInfo.dir(), absInfo.fileName()); } // Windows finds binaries in the current directory if (pathOS == OS_Windows) { const QString currentDirBinary = checkBinary(QDir::current(), binary); if (!currentDirBinary.isEmpty()) { return currentDirBinary; } } const QStringList paths = path.split(pathSeparator()); if (paths.empty()) { return QString(); } const QStringList::const_iterator cend = paths.constEnd(); for (QStringList::const_iterator it = paths.constBegin(); it != cend; ++it) { const QDir dir(*it); const QString rc = checkBinary(dir, binary); if (!rc.isEmpty()) { return rc; } } return QString(); }
String AbstractFileManager::joinComponents(const StringList& pathComponents) { if (pathComponents.empty()) return ""; StringStream result; for (unsigned int i = 0; i < pathComponents.size() - 1; i++) result << pathComponents[i] << pathSeparator(); result << pathComponents.back(); return result.str(); }
StringList AbstractFileManager::pathComponents(const String& path) { StringList components; if (path.empty()) return components; size_t pos = path.find_first_of(pathSeparator(), 0); if (pos != String::npos) { if (pos > 0) components.push_back(path.substr(0, pos)); size_t lastPos = pos; while ((pos = path.find_first_of(pathSeparator(), lastPos + 1)) != String::npos) { components.push_back(path.substr(lastPos + 1, pos - lastPos - 1)); lastPos = pos; } if (lastPos < path.length() - 1) components.push_back(path.substr(lastPos + 1)); } else { components.push_back(path); } return components; }
const CString queryCurrentDir(char drive) { char tmp[256]; if (drive == 0) drive = queryCurrentDisk(); else drive = toupper(drive); ULONG size = sizeof(tmp); ULONG driveNo; driveNo = (drive - 'A')+1; *tmp = '\0'; if (DosQueryCurrentDir(driveNo, (PSZ)tmp, &size) != 0) { return ""; } return nativePathName(CString(drive) + ":" + pathSeparator() + tmp); }
bool Path::find(const std::string& pathList, const std::string& name, Path& path) { StringTokenizer st(pathList, std::string(1, pathSeparator()), true); return find(st.begin(), st.end(), name, path); }
void Wrapper::handleArguments() { if (args.contains("no-suppress-warnings")) { TypeDatabase *db = TypeDatabase::instance(); db->setSuppressWarnings(false); } if (args.contains("include-eclipse-warnings")) { TypeDatabase *db = TypeDatabase::instance(); db->setIncludeEclipseWarnings(true); } if (args.contains("debug-level")) { QString level = args.value("debug-level"); if (level == "sparse") { ReportHandler::setDebugLevel(ReportHandler::SparseDebug); } else if (level == "medium") { ReportHandler::setDebugLevel(ReportHandler::MediumDebug); } else if (level == "full") { ReportHandler::setDebugLevel(ReportHandler::FullDebug); } else if (level == "types") { ReportHandler::setDebugLevel(ReportHandler::TypeDebug); } } if (args.contains("dummy")) { FileOut::dummy = true; } if (args.contains("diff")) { FileOut::diff = true; } if (args.contains("rebuild-only")) { QStringList classes = args.value("rebuild-only").split(",", QString::SkipEmptyParts); TypeDatabase::instance()->setRebuildClasses(classes); } if (args.contains("qt-include-directory")) include_directory = args.value("qt-include-directory"); if (args.contains("include-paths")) { // split on path QString arg = args.value("include-paths"); #if defined(Q_OS_WIN32) QChar pathSeparator(';'); #else QChar pathSeparator(':'); #endif if(arg.length() > 0) { const QChar firstChar = arg.at(0); if(firstChar == QChar(':') || firstChar == QChar(';')) pathSeparator = firstChar; // this allows override default trick } includePathsList = arg.split(pathSeparator, QString::SkipEmptyParts); } if (args.contains("input-directory")) { QString arg = args.value("input-directory"); #if defined(Q_OS_WIN32) QChar pathSeparator(';'); #else QChar pathSeparator(':'); #endif if(arg.length() > 0) { const QChar firstChar = arg.at(0); if(firstChar == QChar(':') || firstChar == QChar(';')) pathSeparator = firstChar; // this allows override default trick } inputDirectoryList = arg.split(pathSeparator, QString::SkipEmptyParts); QString first; if(!inputDirectoryList.isEmpty()) first = inputDirectoryList.first(); // Resolve process, resolveAbsoluteFilePath(filepath, flags, inputList, inputList2?); // flags = try relative, keep/strip filepath dir, return orig on no match // resolve(default_file, 0, inputDirectoryList); // resolve(default_system, 0, inputDirectoryList); if(!first.isNull()) { default_file = QDir(first).absoluteFilePath(default_file); default_system = QDir(first).absoluteFilePath(default_system); } } if (args.contains("output-preprocess-file")) pp_file = args.value("output-preprocess-file"); if (args.contains("output-directory")) pp_file = QDir(args.value("output-directory")).absoluteFilePath(pp_file); if (args.contains("target-platform-arm-cpu")) isTargetPlatformArmCpu = true; if (args.contains("cpp-output-directory")) gs->cppOutDir = args.value("cpp-output-directory"); if (args.contains("java-output-directory")) gs->javaOutDir = args.value("java-output-directory"); if (args.contains("debug-cpp")) { const QStringList list = args.value("debug-cpp").split(','); for (int i = 0; i < list.size(); i++) { QString s = list.at(i); if (s.length() == 0) continue; int space_set_mark = 1; int mod = 0; if (s.at(0) == QChar('-')) { s = s.mid(1); space_set_mark = -1; // space } else if(s.at(0) == QChar('=')) { s = s.mid(1); space_set_mark = 0; // set } else if(s.at(0) == QChar('+')) { s = s.mid(1); space_set_mark = 1; // mark } if (s.compare("all") == 0) { mod = ~0; } else if (s.compare("off") == 0) { mod = 0; space_set_mark = 0; // force set } else if (s.compare("include") == 0) { mod = DEBUGLOG_INCLUDE_ERRORS|DEBUGLOG_INCLUDE_FULL|DEBUGLOG_INCLUDE_DIRECTIVE; } else if (s.compare("include-errors") == 0) { mod = DEBUGLOG_INCLUDE_ERRORS; } else if (s.compare("include-full") == 0) { mod = DEBUGLOG_INCLUDE_FULL; } else if (s.compare("include-directive") == 0) { mod = DEBUGLOG_INCLUDE_DIRECTIVE; } else if (s.compare("def") == 0 || s.compare("define") == 0) { mod = DEBUGLOG_DEFINE; } else if (s.compare("undef") == 0 || s.compare("undefine") == 0) { mod = DEBUGLOG_UNDEF; } else if (s.compare("dump") == 0) { mod = DEBUGLOG_DUMP_BEFORE|DEBUGLOG_DUMP_MIDDLE|DEBUGLOG_DUMP_AFTER; } else if (s.compare("dump-before") == 0) { mod = DEBUGLOG_DUMP_BEFORE; } else if (s.compare("dump-middle") == 0) { mod = DEBUGLOG_DUMP_MIDDLE; } else if (s.compare("dump-after") == 0) { mod = DEBUGLOG_DUMP_AFTER; } else { std::cerr << "Invalid debug-cpp value: " << toStdString(s) << " (ignored)" << std::endl; continue; // has the effect of not changing anything } if(space_set_mark > 0) debugCppMode |= mod; else if(space_set_mark < 0) debugCppMode &= ~mod; else debugCppMode = mod; } } }
String AbstractFileManager::deleteLastPathComponent(const String& path) { if (path.empty()) return path; size_t sepPos = path.find_last_of(pathSeparator()); if (sepPos == String::npos) return ""; return path.substr(0, sepPos); }
bool Path::find(const std::string& pathList, const std::string& name, Path& path) { StringTokenizer st(pathList, std::string(1, pathSeparator()), StringTokenizer::TOK_IGNORE_EMPTY + StringTokenizer::TOK_TRIM); return find(st.begin(), st.end(), name, path); }