From 85cc6a4e6f4c8def8af387ef7cdd6452046a40fe Mon Sep 17 00:00:00 2001 From: zhanghuanhuan Date: Wed, 14 Jun 2023 13:51:56 +0800 Subject: [PATCH] refactor: add r_execute_cmd function --- bash-5.1/Cargo.toml | 3 +++ bash-5.1/configure | 3 ++- bash-5.1/execute_cmd.c | 4 +++- bash-5.1/rsbuiltins.h | 2 -- bash-5.1/src/lib.rs | 39 +-------------------------------------- record.txt | 1 + 6 files changed, 10 insertions(+), 42 deletions(-) diff --git a/bash-5.1/Cargo.toml b/bash-5.1/Cargo.toml index 3c97c62e..48dca7e2 100644 --- a/bash-5.1/Cargo.toml +++ b/bash-5.1/Cargo.toml @@ -2,6 +2,9 @@ name = "rsbash" version = "0.1.0" edition = "2021" +[lib] +name = "rsbash" +crate-type = ["cdylib"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [workspace] diff --git a/bash-5.1/configure b/bash-5.1/configure index 0f1d3ed1..0d917697 100755 --- a/bash-5.1/configure +++ b/bash-5.1/configure @@ -4231,7 +4231,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu if test -n "$want_auto_cflags"; then AUTO_CFLAGS="-g ${GCC+-O2}" AUTO_LDFLAGS="-g ${GCC+-O2}" - STYLE_CFLAGS="${GCC+-Wno-parentheses} ${GCC+-Wno-format-security}" + STYLE_CFLAGS="${GCC+-Wno-parentheses} ${GCC+-Wno-format-security} ${GCC+-fPIC}" else AUTO_CFLAGS= AUTO_LDFLAGS= STYLE_CFLAGS= fi @@ -20255,6 +20255,7 @@ fi $as_echo "using $bash_cv_termcap_lib" >&6; } if test $bash_cv_termcap_lib = gnutermcap && test -z "$prefer_curses"; then LDFLAGS="$LDFLAGS -L./lib/termcap" + TERMCAP_LIB="./lib/termcap/libtermcap.a" TERMCAP_DEP="./lib/termcap/libtermcap.a" elif test $bash_cv_termcap_lib = libtermcap && test -z "$prefer_curses"; then diff --git a/bash-5.1/execute_cmd.c b/bash-5.1/execute_cmd.c index c86c1a07..ecd509c3 100644 --- a/bash-5.1/execute_cmd.c +++ b/bash-5.1/execute_cmd.c @@ -110,6 +110,8 @@ extern int errno; # include /* mbschr */ #endif +# include "./rsbuiltins.h" + extern int command_string_index; extern char *the_printed_command; extern time_t shell_start_time; @@ -4735,6 +4737,7 @@ execute_builtin (builtin, words, flags, subshell) error_trap = 0; should_keep = 0; + r_execute_cmd(); /* The eval builtin calls parse_and_execute, which does not know about the setting of flags, and always calls the execution functions with flags that will exit the shell on an error if -e is set. If the @@ -5308,7 +5311,6 @@ execute_builtin_or_function (words, builtin, var, redirects, int ofifo, nfifo, osize; void *ofifo_list; #endif - #if defined (PROCESS_SUBSTITUTION) begin_unwind_frame ("saved_fifos"); /* If we return, we longjmp and don't get a chance to restore the old diff --git a/bash-5.1/rsbuiltins.h b/bash-5.1/rsbuiltins.h index f6f3be36..f3b7f9be 100644 --- a/bash-5.1/rsbuiltins.h +++ b/bash-5.1/rsbuiltins.h @@ -1,4 +1,2 @@ #include -#include "command.h" int r_execute_cmd(); -int r_execute_cmd2(WORD_LIST *l); diff --git a/bash-5.1/src/lib.rs b/bash-5.1/src/lib.rs index 39f431c5..874f7e60 100644 --- a/bash-5.1/src/lib.rs +++ b/bash-5.1/src/lib.rs @@ -1,42 +1,5 @@ -use libc::{c_char, c_int, c_long}; -use std::ffi::CStr; -use std::str; - -#[repr(C)] -pub struct WORD_DESC { - pub word : *mut c_char, - pub flags : c_int -} - -#[repr(C)] -#[derive(Copy, Clone)] -pub struct WORD_LIST { - next : *mut WORD_LIST, - word : *mut WORD_DESC -} - - -//#[link(name = "")] -//extern { - // pub fn printf( #[no_mangle] pub extern "C" fn r_execute_cmd() { - //println!("hello"); - //common::builtin_error("test error") + println!("hello"); } -#[no_mangle] -pub extern "C" fn r_execute_cmd2(l : *mut WORD_LIST) -> i32 { - unsafe { - let mut it : *mut WORD_LIST = l; - while std::ptr::null() != it { - //let mut a = (&((* ((*l).word)).word) ); - let mut a :*mut c_char =( *(*it).word).word; - let c_str: &CStr = CStr::from_ptr(a); - let str_slice: &str = c_str.to_str().unwrap(); - println! ("word is {:?}", str_slice); - it = (*it).next; - } - } - 0 -} diff --git a/record.txt b/record.txt index 0ff3bbb9..d4de868f 100644 --- a/record.txt +++ b/record.txt @@ -18,3 +18,4 @@ 18 19 20 +21 -- Gitee