diff --git a/bash-5.1/Cargo.toml b/bash-5.1/Cargo.toml index d98e5450e84e430592abf38a437133f0e31659f0..595ff04a526f3c51f01f20ab870596e1678de811 100644 --- a/bash-5.1/Cargo.toml +++ b/bash-5.1/Cargo.toml @@ -37,13 +37,12 @@ members=[ "builtins_rust/cmd", "builtins_rust/enable", "builtins_rust/declare", - "builtins_rust/setattr", "builtins_rust/command", "builtins_rust/hash", "builtins_rust/break_1", "builtins_rust/type", "builtins_rust/ulimit", - "builtins_rust/set" + "builtins_rust/set", "builtins_rust/bind", "builtins_rust/echo", "builtins_rust/hash", @@ -61,34 +60,36 @@ members=[ "builtins_rust/times", "builtins_rust/trap", "builtins_rust/setattr", + "builtins_rust/source", ] [dependencies] libc = "0.2" - read = {path = "./builtins_rust/read"} - history = {path = "./builtins_rust/history"} + rread = {path = "./builtins_rust/read"} + rhistory = {path = "./builtins_rust/history"} rkill = {path = "./builtins_rust/kill"} rlet = {path = "./builtins_rust/rlet"} - mapfile = {path = "./builtins_rust/mapfile"} - printf = {path = "./builtins_rust/printf"} + rsource = {path = "./builtins_rust/source"} + rmapfile = {path = "./builtins_rust/mapfile"} + rprintf = {path = "./builtins_rust/printf"} rreturn = {path = "./builtins_rust/rreturn"} - shift = {path = "./builtins_rust/shift"} - times = {path = "./builtins_rust/times"} + rshift = {path = "./builtins_rust/shift"} + rtimes = {path = "./builtins_rust/times"} rsuspend = {path = "./builtins_rust/suspend"} - test = {path = "./builtins_rust/test"} - trap = {path = "./builtins_rust/trap"} - setattr = {path = "./builtins_rust/setattr"} + rtest = {path = "./builtins_rust/test"} + rtrap = {path = "./builtins_rust/trap"} + rsetattr = {path = "./builtins_rust/setattr"} rcolon = {path = "./builtins_rust/colon"} - builtin = {path = "./builtins_rust/builtin"} - alias= {path = "./builtins_rust/alias"} - exit = {path = "./builtins_rust/exit"} + rbuiltin = {path = "./builtins_rust/builtin"} + ralias= {path = "./builtins_rust/alias"} + rexit = {path = "./builtins_rust/exit"} rhelp = {path = "./builtins_rust/help"} rcaller = {path = "./builtins_rust/caller"} reval = {path = "./builtins_rust/eval"} rexec = {path = "./builtins_rust/exec"} rcommon = {path = "./builtins_rust/common"} rcmd = {path = "builtins_rust/cmd"} - enable = {path = "builtins_rust/enable"} + renable = {path = "builtins_rust/enable"} rbreak = {path = "builtins_rust/break_1"} rulimit = {path = "builtins_rust/ulimit"} rtype = {path = "builtins_rust/type"} diff --git a/bash-5.1/builtins/set.def b/bash-5.1/builtins/set.def index b93149e4c147a4b067869f46e347864a67dc101f..c81b8f193033a4c2c9b4b5c1aea5513c3a79e813 100644 --- a/bash-5.1/builtins/set.def +++ b/bash-5.1/builtins/set.def @@ -309,7 +309,7 @@ list_minus_o_opts (mode, reusable) on_or_off = &value; if (mode == -1 || mode == *on_or_off) { - printf("now i is %d, value is %d, gflag is %d \n, ",i,*on_or_off , reusable ); + //printf("now i is %d, value is %d, gflag is %d \n, ",i,*on_or_off , reusable ); print_minus_o_option (o_optionsd[i].name, *on_or_off, reusable); } @@ -318,7 +318,7 @@ list_minus_o_opts (mode, reusable) value = GET_BINARY_O_OPTION_VALUE (i, o_optionsd[i].name); if (mode == -1 || mode == value) { - printf("now ==== i is %d,value is %d gflag is %d \n",i,value ,reusable); + //printf("now ==== i is %d,value is %d gflag is %d \n",i,value ,reusable); print_minus_o_option (o_optionsd[i].name, value, reusable); } } @@ -499,8 +499,8 @@ set_minus_o_option (on_or_off, option_name) register int i; i = find_minus_o_option (option_name); - printf ("option_name is %s",option_name); - printf("i is %d",i); + //printf ("option_name is %s",option_name); + //printf("i is %d",i); if (i < 0) { sh_invalidoptname (option_name); diff --git a/bash-5.1/builtins_rust/alias/Cargo.toml b/bash-5.1/builtins_rust/alias/Cargo.toml index 9a3049bead70c83771fb418ffe42bbb0309f1324..9669a4d24c97587fd3247ddf9363184d2ae6761e 100644 --- a/bash-5.1/builtins_rust/alias/Cargo.toml +++ b/bash-5.1/builtins_rust/alias/Cargo.toml @@ -14,4 +14,3 @@ libc = "0.2" rcmd = {path="../cmd"} rcommon= {path="../common"} # nix = "0.23" -rcommon = {path = "../common"} diff --git a/bash-5.1/builtins_rust/caller/Cargo.toml b/bash-5.1/builtins_rust/caller/Cargo.toml index de77b46477196c4c31af0c2f43f20a390a7fc0a9..ef4d55d01c27ec625bf10c348ef40ec51003dca6 100644 --- a/bash-5.1/builtins_rust/caller/Cargo.toml +++ b/bash-5.1/builtins_rust/caller/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] libc = "0.2" -read = {path="../read"} +rread = {path="../read"} [lib] crate-type = ["staticlib","lib"] diff --git a/bash-5.1/builtins_rust/cd/Cargo.toml b/bash-5.1/builtins_rust/cd/Cargo.toml index 22128558ef7d42bae798e5ba3c2408468fc309a2..22ac06164d0ea09371345f2d4ef7b1b7c81e642d 100644 --- a/bash-5.1/builtins_rust/cd/Cargo.toml +++ b/bash-5.1/builtins_rust/cd/Cargo.toml @@ -3,6 +3,7 @@ authors = ["huzhengming"] name = "rcd" version = "0.0.1" edition = "2018" +build = "../build.rs" [dependencies] diff --git a/bash-5.1/builtins_rust/command/src/lib.rs b/bash-5.1/builtins_rust/command/src/lib.rs index 25a35725f9b1908b06f8e322926022dd6365ec11..17b09ef82e5e778d990b4aab0b9c8185c2e0ed02 100644 --- a/bash-5.1/builtins_rust/command/src/lib.rs +++ b/bash-5.1/builtins_rust/command/src/lib.rs @@ -262,7 +262,8 @@ pub const CDESC_STDPATH: i32 = 0x100; pub const EX_USAGE :i32= 258; pub const EXECUTION_SUCCESS:i32 = 0; pub const EXECUTION_FAILURE:i32 = 1; -pub const const_command_builtin: &CStr = CStr::from_bytes_with_nul(b"command_builtin\0").unwrap(); + +pub const const_command_builtin:&CStr =unsafe{ CStr::from_bytes_with_nul_unchecked(b"command_builtin\0")};//.unwrap(); //#define COMMAND_BUILTIN_FLAGS (CMD_NO_FUNCTIONS | CMD_INHIBIT_EXPANSION | CMD_COMMAND_BUILTIN | (use_standard_path ? CMD_STDPATH : 0)) //#define CMD_WANT_SUBSHELL 0x01 /* User wants a subshell: ( command ) */ //#define CMD_FORCE_SUBSHELL 0x02 /* Shell needs to force a subshell. */ diff --git a/bash-5.1/builtins_rust/hash/Cargo.toml b/bash-5.1/builtins_rust/hash/Cargo.toml index 78c9205a7fd8656dd69743e3f57fa8e33bb58092..4c1bd0980617ee3f3c58d18896c09c2f276d7768 100644 --- a/bash-5.1/builtins_rust/hash/Cargo.toml +++ b/bash-5.1/builtins_rust/hash/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] libc = "0.2" -read = {path = "../read"} +rread = {path = "../read"} rcommon = {path = "../common"} [lib] diff --git a/bash-5.1/builtins_rust/read/Cargo.toml b/bash-5.1/builtins_rust/read/Cargo.toml index a180309ddea12e2f2a9d7f23d65b9e3d1d0faa4b..ca0e9909841698840e002aebd7733eb99e987345 100644 --- a/bash-5.1/builtins_rust/read/Cargo.toml +++ b/bash-5.1/builtins_rust/read/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "read" +name = "rread" version = "0.1.0" edition = "2018" authors = ["lvgenggeng"] diff --git a/bash-5.1/builtins_rust/read/src/intercdep.rs b/bash-5.1/builtins_rust/read/src/intercdep.rs index 827ae1909aaf54c63657c44c0556d6bd335cc981..231a6d95cdc36e373dbed65956e21d3ce81c982e 100644 --- a/bash-5.1/builtins_rust/read/src/intercdep.rs +++ b/bash-5.1/builtins_rust/read/src/intercdep.rs @@ -15,7 +15,9 @@ pub struct word_list { } pub type WORD_LIST = word_list; -// pub type SHELL_VAR = variable; +use rcommon::{r_builtin_usage,r_sh_invalidid,r_builtin_bind_variable}; +//use rcommon::{r_builtin_usage,r_sh_invalidid,r_builtin_bind_variable,SHELL_VAR}; +pub type SHELL_VAR = rcommon::SHELL_VAR; pub type __intmax_t = c_long; pub type intmax_t = __intmax_t; @@ -98,7 +100,8 @@ pub const CTLNUL: c_char = b'\x4f' as c_char; pub const __S_IFMT: u32 = 0o0170000; pub const __S_IFREG: u32 = 0o0100000; -extern "C" { +extern "C" { + pub fn reset_internal_getopt(); pub fn internal_getopt( diff --git a/bash-5.1/builtins_rust/read/src/lib.rs b/bash-5.1/builtins_rust/read/src/lib.rs index 702836bc3be17f1b139fa3111a26edbaadf44d7a..7a7c3906dc36f49b7013b6abc4259ccfa164132e 100644 --- a/bash-5.1/builtins_rust/read/src/lib.rs +++ b/bash-5.1/builtins_rust/read/src/lib.rs @@ -1,7 +1,7 @@ use libc::{c_int, c_char, c_long, c_ulong, c_uint, size_t, c_void, PT_NULL, ssize_t}; use nix::errno::errno; use std::{ffi::{CString, CStr}, ptr::null_mut}; -use rcommon::{r_builtin_usage,r_sh_invalidid,r_builtin_bind_variable,SHELL_VAR}; +//use rcommon::{r_builtin_usage,r_sh_invalidid,r_builtin_bind_variable,SHELL_VAR}; include!(concat!("intercdep.rs")); diff --git a/bash-5.1/builtins_rust/set/Cargo.toml b/bash-5.1/builtins_rust/set/Cargo.toml index ece27d8e4f5f339bf187c7e0079aa16fbe59c498..0a60e09d1e0bb572c6352a1fe64fdf28cf529805 100644 --- a/bash-5.1/builtins_rust/set/Cargo.toml +++ b/bash-5.1/builtins_rust/set/Cargo.toml @@ -1,4 +1,5 @@ -name = "set" +[package] +name = "rset" version = "0.1.0" edition = "2018" @@ -6,6 +7,7 @@ edition = "2018" [dependencies] libc="*" +nix="*" lazy_static = "1.4.0" [lib] diff --git a/bash-5.1/builtins_rust/set/src/lib.rs b/bash-5.1/builtins_rust/set/src/lib.rs index deebcf1ec234f522678876e8f6d926769528fd0d..74feac9a70d8e8377ded526c8ef76e9addbd9690 100644 --- a/bash-5.1/builtins_rust/set/src/lib.rs +++ b/bash-5.1/builtins_rust/set/src/lib.rs @@ -1279,7 +1279,7 @@ unsafe fn print_all_shell_variables (){ } } -unsafe fn set_shellopts () { +pub unsafe fn r_set_shellopts () { //println!("set shellopts by huanhuan"); let mut value : *mut i8; let mut tflag : [i8;N_O_OPTIONS!()] = [0 as i8 ;N_O_OPTIONS!()]; @@ -1391,7 +1391,7 @@ unsafe fn initialize_shell_options (no_shellopts : i32) { } /* Set up the $SHELLOPTS variable. */ - set_shellopts (); + r_set_shellopts (); } unsafe fn reset_shell_options () { @@ -1590,7 +1590,7 @@ unsafe fn reset_shell_options () { }; if r != EXECUTION_SUCCESS!() { unsafe { - set_shellopts () + r_set_shellopts () }; return (r); } @@ -1603,7 +1603,7 @@ unsafe fn reset_shell_options () { unsafe { sh_invalidopt (s.as_ptr() as *mut i8); builtin_usage (); - set_shellopts (); + r_set_shellopts (); } return EXECUTION_FAILURE!(); } @@ -1636,7 +1636,7 @@ unsafe fn reset_shell_options () { if opts_changed != 0 { unsafe { - set_shellopts(); + r_set_shellopts(); } } return rv; diff --git a/bash-5.1/builtins_rust/shopt/Cargo.toml b/bash-5.1/builtins_rust/shopt/Cargo.toml index 2591d5e2f78d6c0a67c669b029a80c67107db88c..689ba728252032aa6d6e8440e5140093294436eb 100644 --- a/bash-5.1/builtins_rust/shopt/Cargo.toml +++ b/bash-5.1/builtins_rust/shopt/Cargo.toml @@ -7,6 +7,7 @@ edition = "2018" [dependencies] libc = "*" +rset = {path="../set"} [lib] crate-type = ["staticlib","rlib"] diff --git a/bash-5.1/builtins_rust/shopt/src/lib.rs b/bash-5.1/builtins_rust/shopt/src/lib.rs index ca2ba4b7172931f06f6a87a295c1259bcc22a8fc..b121fc01ecbbfbfbaa5948a42b3c49a3a8cc06cd 100644 --- a/bash-5.1/builtins_rust/shopt/src/lib.rs +++ b/bash-5.1/builtins_rust/shopt/src/lib.rs @@ -1,4 +1,5 @@ use std::ffi::*; +use rset::r_set_shellopts; use libc::*; /* /* First, the user-visible attributes */ @@ -123,7 +124,7 @@ extern "C" { fn minus_o_option_value(_: *mut libc::c_char) -> i32; fn list_minus_o_opts(_: i32, _: i32); fn set_minus_o_option(_: i32, _: *mut libc::c_char) -> libc::c_int; - fn set_shellopts(); + //fn r_set_shellopts(); static mut print_shift_error: i32; static mut source_uses_path: i32; static mut loptend: *mut WordList; @@ -923,8 +924,8 @@ static QFLAG:i32 = 0x04; static OFLAG:i32 = 0x08; static PFLAG:i32 = 0x10; static EX_USAGE:i32 = 258; -static SETOPT:i32 = 0; -static UNSETOPT:i32 = 1; +static SETOPT:i32 = 1; +static UNSETOPT:i32 = 0; static EXECUTION_SUCCESS : i32 = 0; static EXECUTION_FAILURE :i32 = 1; @@ -937,7 +938,7 @@ pub unsafe extern "C" fn r_shopt_builtin(mut list: *mut WordList) -> i32 { let mut rval: i32 = 0; flags = 0 as i32; reset_internal_getopt(); - let psuoq = CString::new("adnpsf").expect("CString::new failed"); + let psuoq = CString::new("psuoq").expect("CString::new failed"); loop { opt = internal_getopt( list, psuoq.as_ptr() as *mut c_char); if !(opt != -(1 as i32)) { @@ -986,12 +987,12 @@ pub unsafe extern "C" fn r_shopt_builtin(mut list: *mut WordList) -> i32 { rval = 0; if flags & OFLAG != 0 && flags & (SFLAG | UFLAG) == 0 // shopt -o {//设置了o-flag,并没设s或u-flag - rval = list_shopt_o_options(list, flags); + rval = r_list_shopt_o_options(list, flags); } else if !list.is_null() && flags & OFLAG != 0 { //shopt -so args rval = set_shopt_o_options( if flags & SFLAG != 0 { '-' as i32 } else { '+' as i32 }, list, - flags & OFLAG, + flags & QFLAG, ); } else if flags & OFLAG != 0 { // shopt -so rval = list_some_o_options( @@ -1137,7 +1138,7 @@ unsafe extern "C" fn print_shopt( let msg: CString = CString::new("shopt %s %s\n").expect("CString new faild"); let s: CString = CString::new("-s").expect("CString new faild"); let u: CString = CString::new("-u").expect("CString new faild"); - let optfmt: CString = CString::new("%-15s\t\n").expect("CString new faild"); + let optfmt: CString = CString::new("%-15s\t%s\n").expect("CString new faild"); if flags & PFLAG != 0 { printf( msg.as_ptr(), @@ -1199,14 +1200,17 @@ unsafe extern "C" fn list_some_shopts( flags: i32, ) -> i32 { for item in SHOPT_VARS { - if ((flags & QFLAG) == 0 )&& mode==*item.value { + //if !item.name.is_null() { + //printf(b"===name=%s, value=%d\n\0" as *const u8 as *const libc::c_char, item.name as *const u8 as *const libc::c_char, *item.value); + //} + if ((flags & QFLAG) == 0 )&& item.value != std::ptr::null_mut() && mode==*item.value { print_shopt(item.name, *item.value, flags); } } return sh_chkwrite(EXECUTION_SUCCESS); } -unsafe extern "C" fn list_shopt_o_options( +unsafe extern "C" fn r_list_shopt_o_options( list: *mut WordList, flags: i32, ) -> i32 { @@ -1277,14 +1281,14 @@ unsafe extern "C" fn set_shopt_o_options( } l = (*l).next; } - set_shellopts(); + r_set_shellopts(); return rval; } unsafe extern "C" fn set_shellopts_after_change( option_name: *mut libc::c_char, mode: i32, ) -> i32 { - set_shellopts(); + r_set_shellopts(); return 0; } unsafe extern "C" fn shopt_set_debug_mode( @@ -1293,7 +1297,7 @@ unsafe extern "C" fn shopt_set_debug_mode( ) -> i32 { function_trace_mode = debugging_mode; error_trace_mode = function_trace_mode; - set_shellopts(); + r_set_shellopts(); if debugging_mode != 0 { init_bash_argv(); } @@ -1488,23 +1492,24 @@ pub unsafe extern "C" fn r_set_bashopts() { i = 0; vsize = 0; while !(SHOPT_VARS[i as usize].name).is_null() { - tflag[i as usize] = 0 as i32 as libc::c_char; + tflag[i as usize] = 0 as libc::c_char; if *SHOPT_VARS[i as usize].value != 0 { - vsize = vsize + strlen(SHOPT_VARS[i as usize].name) as i32; + vsize += strlen(SHOPT_VARS[i as usize].name) as i32; + vsize += 1; /* vsize = (vsize as libc::c_ulong) .wrapping_add( (strlen(SHOPT_VARS[i as usize].name)) .wrapping_add(1 as i32 as libc::c_ulong), ) as i32 as libc::c_int; - */ + */ tflag[i as usize] = 1 as i32 as libc::c_char; } i += 1; } - value = xmalloc((vsize + 1 ) as SizeT) as *mut libc::c_char; - vptr = 0 as i32; - i = vptr; + value = libc::malloc((vsize + 1 ) as usize) as *mut libc::c_char; + vptr = 0; + i = 0; while !(SHOPT_VARS[i as usize].name).is_null() { if tflag[i as usize] != 0 { strcpy(value.offset(vptr as isize), SHOPT_VARS[i as usize].name); @@ -1517,6 +1522,7 @@ pub unsafe extern "C" fn r_set_bashopts() { } i += 1; } + //printf(b"the values=%s" as *const u8 as *const libc::c_char, value); if vptr != 0 { vptr -= 1; } @@ -1539,7 +1545,8 @@ pub unsafe extern "C" fn r_set_bashopts() { { (*v).attributes &= !(0x1 as i32); } - free(value as *mut libc::c_void); + //libc::free(value ); + libc::free(value as *mut libc::c_void); } #[no_mangle] pub unsafe extern "C" fn r_parse_bashopts( value: *mut libc::c_char) { diff --git a/bash-5.1/builtins_rust/umask/Cargo.toml b/bash-5.1/builtins_rust/umask/Cargo.toml index 1270c48d02fc7b657aab862291d414c6e6210256..3ec52c402f3f6770d1e4e894d244ec199f0258a4 100644 --- a/bash-5.1/builtins_rust/umask/Cargo.toml +++ b/bash-5.1/builtins_rust/umask/Cargo.toml @@ -2,7 +2,7 @@ name = "rumask" version = "0.1.0" edition = "2018" -build = "../build.rs" +#build = "../build.rs" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/bash-5.1/builtins_rust/wait/Cargo.toml b/bash-5.1/builtins_rust/wait/Cargo.toml index b4c5995dfdc1930a59acd08f19c932ee7957c2a7..f0dad29f5ccf3302dd27a63b08aa4558a1254a82 100644 --- a/bash-5.1/builtins_rust/wait/Cargo.toml +++ b/bash-5.1/builtins_rust/wait/Cargo.toml @@ -10,7 +10,7 @@ edition = "2018" libc = "0.2" nix = "0.23.0" rjobs = {path = "../jobs"} -read = {path = "../read"} +rread = {path = "../read"} rcommon = {path = "../common"} diff --git a/record.txt b/record.txt index 0a00b9c2feae3f446c71ff88c54ff0009b2378de..f8718de04eacaf8bdd6567b2ffb08304c75ce3c2 100644 --- a/record.txt +++ b/record.txt @@ -41,3 +41,5 @@ 40 41 42 +43 +44