Logo Search packages:      
Sourcecode: xd version File versions

determineinitialdir.cc

#include "alternatives.ih"

string Alternatives::determineInitialDirectory()
{
    string cwd;
    auto_ptr<char> buffer;
    bool rescan = false;

    switch (d_command.action())
    {
        case Command::FROM_CONFIG:
            cwd = d_home ? d_config.homeDir() : "/";
            rescan = true;
        break;

        case Command::FROM_HOME:
            cwd = d_config.homeDir();
        break;

        case Command::FROM_ROOT:
            cwd = "/";
        break;

        case Command::FROM_CWD:
            getCwd(&buffer);
            cwd = buffer.get();
        break;

        case Command::FROM_PARENT:
            getCwd(&buffer);
            cwd = buffer.get();
            size_t pos = cwd.length();
            for (size_t idx = d_command.parent(); pos && idx--; )
                pos = cwd.rfind('/', pos - 1);

            if (pos > 0)
                cwd.resize(pos);
            else
                cwd = '/';
        break;
    }

    if (d_addRoot != FALSE && (!d_home || !rescan))
    {
        msg() << "Search does not start at the home dir: "
                "no additional search from the root" << info;

        d_addRoot = FALSE;
    }

    msg() << "Resolved Cwd as: " << cwd << info;

    if (*cwd.rbegin() != '/')         // all dirs end in /
        cwd += '/';

    return cwd;
}




Generated by  Doxygen 1.6.0   Back to index