コード例 #1
0
ファイル: programinfo.cpp プロジェクト: pslacerda/gromacs
ProgramInfo::Impl::Impl(const char *realBinaryName,
                        int argc, const char *const argv[])
    : realBinaryName_(realBinaryName != NULL ? realBinaryName : ""),
      fullInvokedProgram_(argc != 0 ? argv[0] : ""),
      programName_(Path::splitToPathAndFilename(fullInvokedProgram_).second)
{
    // Temporary hack to make things work on Windows while waiting for #950.
    // Some places in the existing code expect to have DIR_SEPARATOR in all
    // input paths, but Windows may also give '/' (and does that, e.g., for
    // tests invoked through CTest).
    // When removing this, remove also the #include "futil.h".
    if (DIR_SEPARATOR == '\\')
    {
        std::replace(fullInvokedProgram_.begin(), fullInvokedProgram_.end(),
                     '/', '\\');
    }
    programName_          = stripSuffixIfPresent(programName_, ".exe");
    invariantProgramName_ = programName_;
#ifdef GMX_BINARY_SUFFIX
    invariantProgramName_ =
        stripSuffixIfPresent(invariantProgramName_, GMX_BINARY_SUFFIX);
#endif
    if (realBinaryName == NULL)
    {
        realBinaryName_ = invariantProgramName_;
    }

    for (int i = 0; i < argc; ++i)
    {
        if (i > 0)
        {
            commandLine_.append(" ");
        }
        const char *arg     = argv[i];
        bool        bSpaces = (std::strchr(arg, ' ') != NULL);
        if (bSpaces)
        {
            commandLine_.append("'");
        }
        commandLine_.append(arg);
        if (bSpaces)
        {
            commandLine_.append("'");
        }
    }
}
コード例 #2
0
CommandLineProgramContext::Impl::Impl(int argc, const char *const argv[],
                                      ExecutableEnvironmentPointer env)
    : executableEnv_(env)
{
    invokedName_ = (argc != 0 ? argv[0] : "");
    programName_ = Path::getFilename(invokedName_);
    programName_ = stripSuffixIfPresent(programName_, ".exe");

    commandLine_ = quoteIfNecessary(programName_.c_str());
    for (int i = 1; i < argc; ++i)
    {
        commandLine_.append(" ");
        commandLine_.append(quoteIfNecessary(argv[i]));
    }
}