Exemple #1
0
// helper function that strips the DLL's base path ("PWD") from a path
// (or returns it unchanged otherwise)
const char *strip_pwd(const char *pathname) {
	const char *pwd = get_dll_dir();
	// Test if this is an absolute path name starting with the DLL directory,
	// which we want to strip here. Skip number of leading chars accordingly.
	size_t len = strlen(pwd);
	return pathname + (strncmp(pathname, pwd, len) == 0 ? len : 0);
}
Exemple #2
0
//------------------------------------------------------------------------------
void prepare_env_for_inputrc()
{
    // Give readline a chance to find the inputrc by modifying the
    // environment slightly.

    char buffer[1024];
    void* env_handle;
    env_block_t env_block;

    capture_env(&env_block);

    // HOME is where Readline will expand ~ to.
    {
        static const char home_eq[] = "HOME=";
        int size = sizeof_array(home_eq);

        strcpy(buffer, home_eq);
        get_config_dir(buffer + size - 1, sizeof_array(buffer) - size);

        putenv(buffer);
    }

    // INPUTRC is the path where looks for it's configuration file.
    {
        static const char inputrc_eq[] = "INPUTRC=";
        int size = sizeof_array(inputrc_eq);

        strcpy(buffer, inputrc_eq);
        get_dll_dir(buffer + size - 1, sizeof_array(buffer) - size);
        str_cat(buffer, "/clink_inputrc_base", sizeof_array(buffer));

        putenv(buffer);
    }

    apply_env(&env_block);
    free_env(&env_block);
}
Exemple #3
0
//------------------------------------------------------------------------------
lua_State* initialise_lua()
{
    static int once = 0;
    int i;
    int path_hash;
    char buffer[1024];
    struct luaL_Reg clink_native_methods[] = {
        { "chdir", change_dir },
        { "execute", lua_execute },
        { "find_dirs", find_dirs },
        { "find_files", find_files },
        { "get_console_aliases", get_console_aliases },
        { "get_cwd", get_cwd },
        { "get_env", get_env },
        { "get_env_var_names", get_env_var_names },
        { "get_host_process", get_host_process },
        { "get_rl_variable", get_rl_variable },
        { "get_screen_info", get_screen_info },
        { "get_setting_int", get_setting_int },
        { "get_setting_str", get_setting_str },
        { "is_dir", is_dir },
        { "is_rl_variable_true", is_rl_variable_true },
        { "lower", to_lowercase },
        { "matches_are_files", matches_are_files },
        { "slash_translation", slash_translation },
        { "suppress_char_append", suppress_char_append },
        { "suppress_quoting", suppress_quoting },
        { NULL, NULL }
    };

    if (g_lua != NULL)
    {
        return g_lua;
    }

    // Initialise Lua.
    g_lua = luaL_newstate();
    luaL_openlibs(g_lua);

    // Add our API.
    lua_createtable(g_lua, 0, 0);
    lua_setglobal(g_lua, "clink");

    lua_getglobal(g_lua, "clink");
    luaL_setfuncs(g_lua, clink_native_methods, 0);
    lua_pop(g_lua, 1);

    // Load all the .lua files alongside the dll and in the script folder.
    if (g_inject_args.script_path[0] == '\0')
    {
        get_dll_dir(buffer, sizeof_array(buffer));
    }
    else
    {
        buffer[0] = '\0';
        str_cat(buffer, g_inject_args.script_path, sizeof_array(buffer));
    }

    path_hash = hash_string(buffer);
    i = (int)strlen(buffer);

    str_cat(buffer, "/clink.lua", sizeof_array(buffer));
    load_lua_script(buffer);

    buffer[i] = '\0';
    load_lua_scripts(buffer);

    get_config_dir(buffer, sizeof(buffer));
    if (hash_string(buffer) != path_hash)
    {
        load_lua_scripts(buffer);
    }

    if (!once)
    {
        rl_add_funmap_entry("reload-lua-state", reload_lua_state);
        once = 1;
    }

    return g_lua;
}