From 39d6412d9ce89a61aba8fa5fdde41e8454682380 Mon Sep 17 00:00:00 2001 From: zhanghuanhuan Date: Mon, 6 Nov 2023 18:02:34 +0800 Subject: [PATCH] add bash_brace_completion func for bracecomp file --- bash-5.1/r_bracecomp/src/lib.rs | 52 +++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/bash-5.1/r_bracecomp/src/lib.rs b/bash-5.1/r_bracecomp/src/lib.rs index b88f0c50..d13c1b70 100644 --- a/bash-5.1/r_bracecomp/src/lib.rs +++ b/bash-5.1/r_bracecomp/src/lib.rs @@ -117,3 +117,55 @@ unsafe extern "C" fn hack_braces_completion( return 0 as libc::c_int; } +#[no_mangle] +pub unsafe extern "C" fn bash_brace_completion( + mut count: libc::c_int, + mut ignore: libc::c_int, +) -> libc::c_int { + let mut orig_ignore_func: Option:: = None; + let mut orig_entry_func: Option:: = None; + let mut orig_quoting_func: Option:: = None; + let mut orig_attempt_func: Option:: = None; + let mut orig_quoting_desired: libc::c_int = 0; + let mut r: libc::c_int = 0; + orig_ignore_func = rl_ignore_some_completions_function; + orig_attempt_func = rl_attempted_completion_function; + orig_entry_func = rl_completion_entry_function; + orig_quoting_func = rl_filename_quoting_function; + orig_quoting_desired = rl_filename_quoting_desired; + rl_completion_entry_function = Some( + rl_filename_completion_function + as unsafe extern "C" fn( + *const libc::c_char, + libc::c_int, + ) -> *mut libc::c_char, + ); + rl_attempted_completion_function = ::core::mem::transmute::< + *mut libc::c_void, + Option::, + >(0 as *mut libc::c_void); + rl_ignore_some_completions_function = ::core::mem::transmute::< + Option:: libc::c_int>, + Option::, + >( + Some( + ::core::mem::transmute::< + unsafe extern "C" fn(*mut *mut libc::c_char) -> libc::c_int, + unsafe extern "C" fn() -> libc::c_int, + >(hack_braces_completion), + ), + ); + rl_filename_quoting_function = ::core::mem::transmute::< + *mut libc::c_void, + Option::, + >(0 as *mut libc::c_void); + rl_filename_quoting_desired = 0 as libc::c_int; + r = rl_complete_internal('\t' as i32); + rl_ignore_some_completions_function = orig_ignore_func; + rl_attempted_completion_function = orig_attempt_func; + rl_completion_entry_function = orig_entry_func; + rl_filename_quoting_function = orig_quoting_func; + rl_filename_quoting_desired = orig_quoting_desired; + return r; +} + -- Gitee