示例#1
0
static string session_dir(const string& session)
{
    if (session == DEFAULT_SESSION)
	return session_state_dir();
    else
	return session_base_dir() + "/" + session;
}
示例#2
0
static string session_base_dir()
{
    const char *ddd_sessions = getenv(DDD_NAME "_SESSIONS");
    if (ddd_sessions != 0)
	return ddd_sessions;
    else
	return session_state_dir() + "/sessions";
}
示例#3
0
// Return full path of FILE, searching in a number of predefined places.
// If not found, return "".
string resolvePath(const string& file, bool include_user)
{
    static StringArray prefixes;
    static int sys_index = 0;

    if (prefixes.size() == 0)
    {
	// Look in ~/.ddd.
	prefixes += session_state_dir();
	sys_index = prefixes.size();

	// Look in $DDD_HOME.
	if (getenv(DDD_NAME "_HOME") != 0)
	    prefixes += getenv(DDD_NAME "_HOME");

	// Look in DDD_ROOT (typically /usr/local/share/ddd-VERSION).
	prefixes += DDD_ROOT;

	// Look in DDD_ALT_ROOT (typically /usr/local/share/ddd)..
	prefixes += DDD_ALT_ROOT;

	for (int i = 0; i < 3; i++)
	{
	    string prefix;
	    switch (i)
	    {
	    case 0: prefix = myPrefix();   break;
	    case 1: prefix = "/usr/local"; break;
	    case 2: prefix = "/usr";       break;
	    }

	    prefixes += prefix + "/share/" ddd_NAME "-" DDD_VERSION;
	    prefixes += prefix + "/share/" ddd_NAME;

	    prefixes += prefix + "/lib/" ddd_NAME "-" DDD_VERSION;
	    prefixes += prefix + "/lib/" ddd_NAME;

	    prefixes += prefix + "/" ddd_NAME "-" DDD_VERSION;
	    prefixes += prefix + "/" ddd_NAME;
	}
    }

    StatusDelay delay("Searching " + quote(file));

    for (int i = include_user ? 0 : sys_index; i < prefixes.size(); i++)
    {
	string path = prefixes[i] + "/" + file;
	set_status("Trying " + quote(path));
	if (is_regular_file(path) || is_directory(path))
	{
	    delay.outcome = quote(path);
	    return path;
	}
    }

    delay.outcome = "not found";
    return "";
}
示例#4
0
// Create DDD state directory
static void create_session_state_dir(std::ostream& msg)
{
    // Create or find state directory
    if (!is_directory(session_state_dir()) && 
	makedir(session_state_dir(), msg, true) == 0)
    {
	// Check for DDD 2.1 `~/.dddinit' and `~/.ddd_history' files; 
	// copy them to new location if needed
	copy(string(gethome()) + "/.dddinit",
	     session_state_file(DEFAULT_SESSION), msg);
	copy(string(gethome()) + "/.ddd_history",
	     session_history_file(DEFAULT_SESSION), msg);
    }

    // Create session base directory
    if (!is_directory(session_base_dir()))
	makedir(session_base_dir(), msg);

    // Create themes directory
    if (!is_directory(session_themes_dir()))
	makedir(session_themes_dir(), msg);
}