From 63ea5432b8c6bbcccf9e55bee8d59fc8629f6959 Mon Sep 17 00:00:00 2001 From: wangmengc Date: Wed, 16 Aug 2023 08:31:09 +0800 Subject: [PATCH] add u_src dir --- bash-5.1/Cargo.toml | 8 + bash-5.1/Makefile.in | 4 +- bash-5.1/u_src/Cargo.toml | 15 + bash-5.1/u_src/src/lib.rs | 4 + bash-5.1/u_src/src/libs/command_h.rs | 379 ++++++++++++++++++++++++ bash-5.1/u_src/src/libs/mod.rs | 4 + bash-5.1/u_src/src/libs/print_cmd.rs | 114 +++++++ bash-5.1/u_src/src/libs/struct_macro.rs | 283 ++++++++++++++++++ record.txt | 1 + 9 files changed, 810 insertions(+), 2 deletions(-) create mode 100644 bash-5.1/u_src/Cargo.toml create mode 100644 bash-5.1/u_src/src/lib.rs create mode 100644 bash-5.1/u_src/src/libs/command_h.rs create mode 100644 bash-5.1/u_src/src/libs/mod.rs create mode 100644 bash-5.1/u_src/src/libs/print_cmd.rs create mode 100644 bash-5.1/u_src/src/libs/struct_macro.rs diff --git a/bash-5.1/Cargo.toml b/bash-5.1/Cargo.toml index 87ccd3a..68e7298 100644 --- a/bash-5.1/Cargo.toml +++ b/bash-5.1/Cargo.toml @@ -2,6 +2,10 @@ name = "rsbash" version = "0.1.0" edition = "2018" +build = "build.rs" + +[build-dependencies] +bindgen = "0.20.0" [lib] name = "rsbash" @@ -62,10 +66,12 @@ members=[ "builtins_rust/setattr", "builtins_rust/source", "builtins_rust/exec_cmd", + "u_src", ] [dependencies] libc = "*" + bindgen = "*" rread = {path = "./builtins_rust/read"} rhistory = {path = "./builtins_rust/history"} rkill = {path = "./builtins_rust/kill"} @@ -102,3 +108,5 @@ members=[ rwait = {path = "./builtins_rust/wait"} rdeclare = {path = "./builtins_rust/declare"} rexec_cmd = {path = "./builtins_rust/exec_cmd"} + + r_main = {path = "./u_src"} diff --git a/bash-5.1/Makefile.in b/bash-5.1/Makefile.in index dd1c8a4..d94c718 100644 --- a/bash-5.1/Makefile.in +++ b/bash-5.1/Makefile.in @@ -139,7 +139,7 @@ LOCALE_DEFS = -DLOCALEDIR='"$(localedir)"' -DPACKAGE='"$(PACKAGE)"' LOCAL_LIBS = @LOCAL_LIBS@ -LIBS = $(BUILTINS_LIB) $(LIBRARIES) @LIBS@ -lrt -lpthread -L./target/debug -lralias -lrbind -lrbreak -lrbuiltin -lrcaller -lrcd -lrcolon -lrcommon -lcommand -lrcomplete -lrdeclare -lrecho -lrenable -lreval -lrexec -lrexit -lrfc -lrfg_bg -lrgetopts -lrhash -lrexit -lrhelp -lrhistory -lrjobs -lrkill -lrmapfile -lrpushd -lrread -lrlet -lrreturn -lrset -lrsetattr -lrshift -lrshopt -lrsource -lrsuspend -lrtest -lrtimes -lrtrap -lrtype -lrulimit -lrumask -lrwait -lrprintf -lrexec_cmd +LIBS = $(BUILTINS_LIB) $(LIBRARIES) @LIBS@ -lrt -lpthread -L./target/debug -lralias -lrbind -lrbreak -lrbuiltin -lrcaller -lrcd -lrcolon -lrcommon -lcommand -lrcomplete -lrdeclare -lrecho -lrenable -lreval -lrexec -lrexit -lrfc -lrfg_bg -lrgetopts -lrhash -lrexit -lrhelp -lrhistory -lrjobs -lrkill -lrmapfile -lrpushd -lrread -lrlet -lrreturn -lrset -lrsetattr -lrshift -lrshopt -lrsource -lrsuspend -lrtest -lrtimes -lrtrap -lrtype -lrulimit -lrumask -lrwait -lrprintf -lrexec_cmd -lr_main LIBS_FOR_BUILD = STATIC_LD = @STATIC_LD@ @@ -571,7 +571,7 @@ LANGSRC = $(srcdir)/$(LANGSUBDIR) RUST_DIR = $(top_builddir)/builtins_rust #RUST_TARGET_LIB = $(top_builddir)/target/debug/librjobs.a $(top_builddir)/target/debug/librread.a -RUST_BUILTINS_DIRS = $(RUST_DIR)/alias $(RUST_DIR)/bind $(RUST_DIR)/break_1 $(RUST_DIR)/builtin $(RUST_DIR)/caller $(RUST_DIR)/cd $(RUST_DIR)/colon $(RUST_DIR)/command $(RUST_DIR)/common $(RUST_DIR)/complete $(RUST_DIR)/declare $(RUST_DIR)/echo $(RUST_DIR)/enable $(RUST_DIR)/eval $(RUST_DIR)/exit $(RUST_DIR)/fc $(RUST_DIR)/fg_bg $(RUST_DIR)/getopts $(RUST_DIR)/hash $(RUST_DIR)/help $(RUST_DIR)/history $(RUST_DIR)/jobs $(RUST_DIR)/kill $(RUST_DIR)/mapfile $(RUST_DIR)/printf $(RUST_DIR)/pushd $(RUST_DIR)/read $(RUST_DIR)/rlet $(RUST_DIR)/rreturn $(RUST_DIR)/set $(RUST_DIR)/setattr $(RUST_DIR)/shift $(RUST_DIR)/shopt $(RUST_DIR)/source $(RUST_DIR)/suspend $(RUST_DIR)/test $(RUST_DIR)/times $(RUST_DIR)/trap $(RUST_DIR)/type $(RUST_DIR)/ulimit $(RUST_DIR)/umask $(RUST_DIR)/wait $(RUST_DIR)/exec $(RUST_DIR)/exec_cmd +RUST_BUILTINS_DIRS = $(RUST_DIR)/alias $(RUST_DIR)/bind $(RUST_DIR)/break_1 $(RUST_DIR)/builtin $(RUST_DIR)/caller $(RUST_DIR)/cd $(RUST_DIR)/colon $(RUST_DIR)/command $(RUST_DIR)/common $(RUST_DIR)/complete $(RUST_DIR)/declare $(RUST_DIR)/echo $(RUST_DIR)/enable $(RUST_DIR)/eval $(RUST_DIR)/exit $(RUST_DIR)/fc $(RUST_DIR)/fg_bg $(RUST_DIR)/getopts $(RUST_DIR)/hash $(RUST_DIR)/help $(RUST_DIR)/history $(RUST_DIR)/jobs $(RUST_DIR)/kill $(RUST_DIR)/mapfile $(RUST_DIR)/printf $(RUST_DIR)/pushd $(RUST_DIR)/read $(RUST_DIR)/rlet $(RUST_DIR)/rreturn $(RUST_DIR)/set $(RUST_DIR)/setattr $(RUST_DIR)/shift $(RUST_DIR)/shopt $(RUST_DIR)/source $(RUST_DIR)/suspend $(RUST_DIR)/test $(RUST_DIR)/times $(RUST_DIR)/trap $(RUST_DIR)/type $(RUST_DIR)/ulimit $(RUST_DIR)/umask $(RUST_DIR)/wait $(RUST_DIR)/exec $(RUST_DIR)/exec_cmd $(RUST_DIR)/u_src # Keep GNU Make from exporting the entire environment for small machines. diff --git a/bash-5.1/u_src/Cargo.toml b/bash-5.1/u_src/Cargo.toml new file mode 100644 index 0000000..3b25b58 --- /dev/null +++ b/bash-5.1/u_src/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "r_main" +version = "0.1.0" +edition = "2021" +authors = ["wangm"] + + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +libc = "*" + +[lib] +name = "r_main" +crate-type = ["rlib", "staticlib"] diff --git a/bash-5.1/u_src/src/lib.rs b/bash-5.1/u_src/src/lib.rs new file mode 100644 index 0000000..d4bde54 --- /dev/null +++ b/bash-5.1/u_src/src/lib.rs @@ -0,0 +1,4 @@ +mod libs; + +//在下面添加模块 +pub use libs::print_cmd::* ; \ No newline at end of file diff --git a/bash-5.1/u_src/src/libs/command_h.rs b/bash-5.1/u_src/src/libs/command_h.rs new file mode 100644 index 0000000..d8757b9 --- /dev/null +++ b/bash-5.1/u_src/src/libs/command_h.rs @@ -0,0 +1,379 @@ +/* automatically generated by rust-bindgen 0.64.0 */ + +pub const REDIR_VARASSIGN: u32 = 1; +pub const AMBIGUOUS_REDIRECT: i32 = -1; +pub const NOCLOBBER_REDIRECT: i32 = -2; +pub const RESTRICTED_REDIRECT: i32 = -3; +pub const HEREDOC_REDIRECT: i32 = -4; +pub const BADVAR_REDIRECT: i32 = -5; +pub const W_HASDOLLAR: u32 = 1; +pub const W_QUOTED: u32 = 2; +pub const W_ASSIGNMENT: u32 = 4; +pub const W_SPLITSPACE: u32 = 8; +pub const W_NOSPLIT: u32 = 16; +pub const W_NOGLOB: u32 = 32; +pub const W_NOSPLIT2: u32 = 64; +pub const W_TILDEEXP: u32 = 128; +pub const W_DOLLARAT: u32 = 256; +pub const W_DOLLARSTAR: u32 = 512; +pub const W_NOCOMSUB: u32 = 1024; +pub const W_ASSIGNRHS: u32 = 2048; +pub const W_NOTILDE: u32 = 4096; +pub const W_ITILDE: u32 = 8192; +pub const W_EXPANDRHS: u32 = 16384; +pub const W_COMPASSIGN: u32 = 32768; +pub const W_ASSNBLTIN: u32 = 65536; +pub const W_ASSIGNARG: u32 = 131072; +pub const W_HASQUOTEDNULL: u32 = 262144; +pub const W_DQUOTE: u32 = 524288; +pub const W_NOPROCSUB: u32 = 1048576; +pub const W_SAWQUOTEDNULL: u32 = 2097152; +pub const W_ASSIGNASSOC: u32 = 4194304; +pub const W_ASSIGNARRAY: u32 = 8388608; +pub const W_ARRAYIND: u32 = 16777216; +pub const W_ASSNGLOBAL: u32 = 33554432; +pub const W_NOBRACE: u32 = 67108864; +pub const W_COMPLETE: u32 = 134217728; +pub const W_CHKLOCAL: u32 = 268435456; +pub const W_NOASSNTILDE: u32 = 536870912; +pub const W_FORCELOCAL: u32 = 1073741824; +pub const PF_NOCOMSUB: u32 = 1; +pub const PF_IGNUNBOUND: u32 = 2; +pub const PF_NOSPLIT2: u32 = 4; +pub const PF_ASSIGNRHS: u32 = 8; +pub const PF_COMPLETE: u32 = 16; +pub const PF_EXPANDRHS: u32 = 32; +pub const PF_ALLINDS: u32 = 64; +pub const SUBSHELL_ASYNC: u32 = 1; +pub const SUBSHELL_PAREN: u32 = 2; +pub const SUBSHELL_COMSUB: u32 = 4; +pub const SUBSHELL_FORK: u32 = 8; +pub const SUBSHELL_PIPE: u32 = 16; +pub const SUBSHELL_PROCSUB: u32 = 32; +pub const SUBSHELL_COPROC: u32 = 64; +pub const SUBSHELL_RESETTRAP: u32 = 128; +pub const CMD_WANT_SUBSHELL: u32 = 1; +pub const CMD_FORCE_SUBSHELL: u32 = 2; +pub const CMD_INVERT_RETURN: u32 = 4; +pub const CMD_IGNORE_RETURN: u32 = 8; +pub const CMD_NO_FUNCTIONS: u32 = 16; +pub const CMD_INHIBIT_EXPANSION: u32 = 32; +pub const CMD_NO_FORK: u32 = 64; +pub const CMD_TIME_PIPELINE: u32 = 128; +pub const CMD_TIME_POSIX: u32 = 256; +pub const CMD_AMPERSAND: u32 = 512; +pub const CMD_STDIN_REDIR: u32 = 1024; +pub const CMD_COMMAND_BUILTIN: u32 = 2048; +pub const CMD_COPROC_SUBSHELL: u32 = 4096; +pub const CMD_LASTPIPE: u32 = 8192; +pub const CMD_STDPATH: u32 = 16384; +pub const CMD_TRY_OPTIMIZING: u32 = 32768; +pub const CASEPAT_FALLTHROUGH: u32 = 1; +pub const CASEPAT_TESTNEXT: u32 = 2; +pub const COND_AND: u32 = 1; +pub const COND_OR: u32 = 2; +pub const COND_UNARY: u32 = 3; +pub const COND_BINARY: u32 = 4; +pub const COND_TERM: u32 = 5; +pub const COND_EXPR: u32 = 6; +pub const COPROC_RUNNING: u32 = 1; +pub const COPROC_DEAD: u32 = 2; +pub const CMDERR_DEFAULT: u32 = 0; +pub const CMDERR_BADTYPE: u32 = 1; +pub const CMDERR_BADCONN: u32 = 2; +pub const CMDERR_BADJUMP: u32 = 3; +pub const CMDERR_LAST: u32 = 3; +pub const r_instruction_r_output_direction: r_instruction = 0; +pub const r_instruction_r_input_direction: r_instruction = 1; +pub const r_instruction_r_inputa_direction: r_instruction = 2; +pub const r_instruction_r_appending_to: r_instruction = 3; +pub const r_instruction_r_reading_until: r_instruction = 4; +pub const r_instruction_r_reading_string: r_instruction = 5; +pub const r_instruction_r_duplicating_input: r_instruction = 6; +pub const r_instruction_r_duplicating_output: r_instruction = 7; +pub const r_instruction_r_deblank_reading_until: r_instruction = 8; +pub const r_instruction_r_close_this: r_instruction = 9; +pub const r_instruction_r_err_and_out: r_instruction = 10; +pub const r_instruction_r_input_output: r_instruction = 11; +pub const r_instruction_r_output_force: r_instruction = 12; +pub const r_instruction_r_duplicating_input_word: r_instruction = 13; +pub const r_instruction_r_duplicating_output_word: r_instruction = 14; +pub const r_instruction_r_move_input: r_instruction = 15; +pub const r_instruction_r_move_output: r_instruction = 16; +pub const r_instruction_r_move_input_word: r_instruction = 17; +pub const r_instruction_r_move_output_word: r_instruction = 18; +pub const r_instruction_r_append_err_and_out: r_instruction = 19; +pub type r_instruction = ::std::os::raw::c_uint; +pub const command_type_cm_for: command_type = 0; +pub const command_type_cm_case: command_type = 1; +pub const command_type_cm_while: command_type = 2; +pub const command_type_cm_if: command_type = 3; +pub const command_type_cm_simple: command_type = 4; +pub const command_type_cm_select: command_type = 5; +pub const command_type_cm_connection: command_type = 6; +pub const command_type_cm_function_def: command_type = 7; +pub const command_type_cm_until: command_type = 8; +pub const command_type_cm_group: command_type = 9; +pub const command_type_cm_arith: command_type = 10; +pub const command_type_cm_cond: command_type = 11; +pub const command_type_cm_arith_for: command_type = 12; +pub const command_type_cm_subshell: command_type = 13; +pub const command_type_cm_coproc: command_type = 14; +pub type command_type = ::std::os::raw::c_uint; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct word_desc { + pub word: *mut ::std::os::raw::c_char, + pub flags: ::std::os::raw::c_int, +} +pub type WORD_DESC = word_desc; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct word_list { + pub next: *mut word_list, + pub word: *mut WORD_DESC, +} +pub type WORD_LIST = word_list; +#[repr(C)] +#[derive(Copy, Clone)] +pub union REDIRECTEE { + pub dest: ::std::os::raw::c_int, + pub filename: *mut WORD_DESC, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub struct redirect { + pub next: *mut redirect, + pub redirector: REDIRECTEE, + pub rflags: ::std::os::raw::c_int, + pub flags: ::std::os::raw::c_int, + pub instruction: r_instruction, + pub redirectee: REDIRECTEE, + pub here_doc_eof: *mut ::std::os::raw::c_char, +} +pub type REDIRECT = redirect; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct element { + pub word: *mut WORD_DESC, + pub redirect: *mut REDIRECT, +} +pub type ELEMENT = element; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct command { + pub type_: command_type, + pub flags: ::std::os::raw::c_int, + pub line: ::std::os::raw::c_int, + pub redirects: *mut REDIRECT, + pub value: command__bindgen_ty_1, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union command__bindgen_ty_1 { + pub For: *mut for_com, + pub Case: *mut case_com, + pub While: *mut while_com, + pub If: *mut if_com, + pub Connection: *mut connection, + pub Simple: *mut simple_com, + pub Function_def: *mut function_def, + pub Group: *mut group_com, + pub Select: *mut select_com, + pub Arith: *mut arith_com, + pub Cond: *mut cond_com, + pub ArithFor: *mut airth_for_com, + pub Subshell: *mut subshell_com, + pub Coproc: *mut coproc_com, +} +pub type COMMAND = command; + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct select_com{ + pub flags:libc::c_int, + pub line: libc::c_int, + pub name: *mut WORD_DESC, + pub map_llist: *mut WORD_LIST, + pub action: *mut COMMAND, +} +pub type SELECT_COM = select_com; + + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct arith_com{ + pub flags:libc::c_int, + pub line: libc::c_int, + pub exp: *mut WORD_LIST, +} +pub type ARITH_COM = arith_com; + + + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct airth_for_com{ + pub flags:libc::c_int, + pub line: libc::c_int, + pub init: *mut WORD_LIST, + pub test: *mut WORD_LIST, + pub step: *mut WORD_LIST, + pub action: *mut COMMAND, +} +pub type AIRTH_FOR_COM = airth_for_com; + + + +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct connection { + pub ignore: ::std::os::raw::c_int, + pub first: *mut COMMAND, + pub second: *mut COMMAND, + pub connector: ::std::os::raw::c_int, +} +pub type CONNECTION = connection; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct pattern_list { + pub next: *mut pattern_list, + pub patterns: *mut WORD_LIST, + pub action: *mut COMMAND, + pub flags: ::std::os::raw::c_int, +} +pub type PATTERN_LIST = pattern_list; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct case_com { + pub flags: ::std::os::raw::c_int, + pub line: ::std::os::raw::c_int, + pub word: *mut WORD_DESC, + pub clauses: *mut PATTERN_LIST, +} +pub type CASE_COM = case_com; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct for_com { + pub flags: ::std::os::raw::c_int, + pub line: ::std::os::raw::c_int, + pub name: *mut WORD_DESC, + pub map_list: *mut WORD_LIST, + pub action: *mut COMMAND, +} +pub type FOR_COM = for_com; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct if_com { + pub flags: ::std::os::raw::c_int, + pub test: *mut COMMAND, + pub true_case: *mut COMMAND, + pub false_case: *mut COMMAND, +} +pub type IF_COM = if_com; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct while_com { + pub flags: ::std::os::raw::c_int, + pub test: *mut COMMAND, + pub action: *mut COMMAND, +} +pub type WHILE_COM = while_com; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct cond_com { + pub flags: ::std::os::raw::c_int, + pub line: ::std::os::raw::c_int, + pub type_: ::std::os::raw::c_int, + pub op: *mut WORD_DESC, + pub left: *mut cond_com, + pub right: *mut cond_com, +} +pub type COND_COM = cond_com; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct simple_com { + pub flags: ::std::os::raw::c_int, + pub line: ::std::os::raw::c_int, + pub words: *mut WORD_LIST, + pub redirects: *mut REDIRECT, +} +pub type SIMPLE_COM = simple_com; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct function_def { + pub flags: ::std::os::raw::c_int, + pub line: ::std::os::raw::c_int, + pub name: *mut WORD_DESC, + pub command: *mut COMMAND, + pub source_file: *mut ::std::os::raw::c_char, +} +pub type FUNCTION_DEF = function_def; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct group_com { + pub ignore: ::std::os::raw::c_int, + pub command: *mut COMMAND, +} +pub type GROUP_COM = group_com; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct subshell_com { + pub flags: ::std::os::raw::c_int, + pub line: ::std::os::raw::c_int, + pub command: *mut COMMAND, +} +pub type SUBSHELL_COM = subshell_com; +pub type pid_t = libc::c_uint; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct coproc { + pub c_name: *mut ::std::os::raw::c_char, + pub c_pid: pid_t, + pub c_rfd: ::std::os::raw::c_int, + pub c_wfd: ::std::os::raw::c_int, + pub c_rsave: ::std::os::raw::c_int, + pub c_wsave: ::std::os::raw::c_int, + pub c_flags: ::std::os::raw::c_int, + pub c_status: ::std::os::raw::c_int, + pub c_lock: ::std::os::raw::c_int, +} +pub type Coproc = coproc; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct coproc_com { + pub flags: ::std::os::raw::c_int, + pub name: *mut ::std::os::raw::c_char, + pub command: *mut COMMAND, +} +pub type COPROC_COM = coproc_com; +extern "C" { + pub static mut global_command: *mut COMMAND; +} +extern "C" { + pub static mut sh_coproc: Coproc; +} +extern "C" { + pub fn copy_function_def_contents( + arg1: *mut FUNCTION_DEF, + arg2: *mut FUNCTION_DEF, + ) -> *mut FUNCTION_DEF; +} +extern "C" { + pub fn copy_function_def(arg1: *mut FUNCTION_DEF) -> *mut FUNCTION_DEF; +} +extern "C" { + pub fn copy_word(arg1: *mut WORD_DESC) -> *mut WORD_DESC; +} +extern "C" { + pub fn copy_word_list(arg1: *mut WORD_LIST) -> *mut WORD_LIST; +} +extern "C" { + pub fn copy_redirect(arg1: *mut REDIRECT) -> *mut REDIRECT; +} +extern "C" { + pub fn copy_redirects(arg1: *mut REDIRECT) -> *mut REDIRECT; +} +extern "C" { + pub fn copy_command(arg1: *mut COMMAND) -> *mut COMMAND; +} diff --git a/bash-5.1/u_src/src/libs/mod.rs b/bash-5.1/u_src/src/libs/mod.rs new file mode 100644 index 0000000..fa4a310 --- /dev/null +++ b/bash-5.1/u_src/src/libs/mod.rs @@ -0,0 +1,4 @@ +//添加文件名 +pub mod struct_macro; +pub mod command_h; +pub mod print_cmd; \ No newline at end of file diff --git a/bash-5.1/u_src/src/libs/print_cmd.rs b/bash-5.1/u_src/src/libs/print_cmd.rs new file mode 100644 index 0000000..3cfac7b --- /dev/null +++ b/bash-5.1/u_src/src/libs/print_cmd.rs @@ -0,0 +1,114 @@ +use super::{ command_h}; +use libc::{c_int,c_char,FILE}; +use command_h::{COMMAND,REDIRECT}; + + + + + +pub static indentation:c_int = 0; +pub static indentation_amount:c_int = 4; + + +pub const PRINTED_COMMAND_INITIAL_SIZE:c_int = 64; +pub const PRINTED_COMMAND_CROW_SIZE:c_int = 128; + +pub static mut the_printed_command: *mut c_char = std::ptr::null(); +pub static mut the_printed_command_size:c_int = 0; +pub static mut command_string_index:c_int = 0; + +pub static mut xtrace_fd:c_int = -1; +pub static mut xtrace_fp:*mut FILE = 0 as *mut FILE; + + +static mut inside_function_def:c_int = 0; +static mut skip_this_indent:c_int = 0; +static mut was_heredoc:c_int = 0; +static mut printing_connection:c_int = 0; +static mut deferred_heredocs:*mut REDIRECT = 0 as *mut REDIRECT; + +static mut group_command_nesting:c_int = 0; + +static mut indirection_string:c_int = 0; +static mut indirection_stringsiz:c_int = 0; + +#[no_mangle] +pub unsafe extern "C" fn print_command(command:*mut COMMAND) +{ + command_string_index = 0; + println!("{}",make_command_string(command)); + +} + +#[no_mangle] +pub unsafe extern "C" fn make_command_string(command:*mut COMMAND) +{ + command_string_index = 0; + was_heredoc = 0; + deferred_heredocs = 0; + make_command_string_internal(command); + return the_printed_command; +} + +#[no_mangle] +unsafe fn make_command_string_internal(command:*mut COMMAND) +{ + let s:[c_char;3]; + + if command == std::ptr::null{ + cprintf(""); + } + else{ + if skip_this_indent != 0 { + skip_this_indent = skip_this_indent - 1; + } + else{ + indent(indentation); + } + + if (*command).flags != 0 && CMD_TIME_PIPELINE != 0{ + cprintf("time "); + if (*command).flags != 0 && CMD_TIME_POSIX != 0{ + cprintf("-p "); + } + } + + if (*command).flags != 0 && CMD_INVERT_RETURN != 0{ + cprintf("! "); + } + + match (*command).type_ as libc::c_uint { + cm_for => print_for_command((*command).value.For), + cm_arith_for => print_arith_for_command((*command).value.ArithFor), + cm_seletc => print_select_for_command((*command).value.Select), + cm_case => print_case_for_command((*command).value.Case), + cm_while => print_while_for_command((*command).value.While), + cm_untile => print_untile_for_command((*command).value.While), + cm_if => print_if_for_command((*command).value.If), + cm_arith => print_airth_command((*(*command).value.Arith).exp), + cm_cond => print_cond_command((*command).value.Cond), + cm_simple => print_simple_command((*command).value.Simple), + cm_connection => { + skip_this_indent = skip_this_indent + 1; + printing_connection = printing_connection + 1; + make_command_string_internal((*(*command).value.Connection).first); + + match (*command).value.Connection.connector{ + '&' | '|'=> { + let c:c_char = (*(*command).value.Connection).connector; + s[0] = ' '; + s[1] = c; + s[2] = '\0'; + + print_deferred_heredocs(s); + + if c != '&' || (*(*command).value.Connection).second{ + cprintf(" "); + skip_this_indent = skip_this_indent + 1; + } + } + } + } + } + } +} \ No newline at end of file diff --git a/bash-5.1/u_src/src/libs/struct_macro.rs b/bash-5.1/u_src/src/libs/struct_macro.rs new file mode 100644 index 0000000..69117a9 --- /dev/null +++ b/bash-5.1/u_src/src/libs/struct_macro.rs @@ -0,0 +1,283 @@ +use libc::{c_int,c_char,c_uint}; + + + +#[driver(Clone,Copy)] +#[repr(C)] +pub struct word_list{ + pub next: *mut world_list, + pub word: *mut WORD_DESC, +} +pub type WORD_LIST = word_list; + + +#[driver(Clone,Copy)] +#[repr(C)] +pub struct word_desc{ + pub word: *mut c_char, + pub flags: c_int, +} +pub type WORD_DESC = word_desc; + + +#[driver(Clone,Copy)] +#[repr(C)] +pub union REDIRECTEE{ + pub dest: c_int, + pub filename: *mut WORD_DESC, +} + +pub type r_instruction = c_uint; +pub const r_output_direction: r_instruction = 0; +pub const r_input_direction : r_instruction = 1; +pub const r_inputs_direction: r_instruction = 2; +pub const r_appending_to: r_instruction = 3; +pub const r_reading_until: r_instruction = 4; +pub const r_reading_string: r_instruction = 5; +pub const r_duplicating_input: r_instruction = 6; +pub const r_duplicating_output: r_instruction = 7; +pub const r_deblank_reading_until: r_instruction = 8; +pub const r_close_this: r_instruction = 9; +pub const r_err_and_out: r_instruction = 10; +pub const r_input_output: r_instruction = 11; +pub const r_output_force: r_instruction = 12; +pub const r_duplicating_input_word: r_instruction = 13; +pub const r_duplicating_output_word: r_instruction = 14; +pub const r_move_input: r_instruction = 15; +pub const r_move_output: r_instruction = 16; +pub const r_move_input_word: r_instruction = 17; +pub const r_move_output_word: r_instruction = 18; +pub const r_append_err_and_out: r_instruction = 19; + + +#[derive(Clone,Copy)] +#[repr(C)] +pub struct redirect{ + pub next: *mut redirect, + pub redirector: REDIRECTEE, + pub rflags: c_int, + pub flags: c_int, + pub instruction: r_instruction, + pub redirectee: REDIRECTEE, + pub here_doc_eof: *mut char, +} +pub type REDIRECT = redirect; + +#[derive(Clone, Copy)] +#[repr (C)] +pub struct command { + pub type:command_type;0000 + pub flags: c_int, + pub line: c_int, + pub redirects: *mut REDIRECT, + pub value: command_union, +} +pub type COMMAND = command; +#[derive(Clone, Copy)] +#[repr (C)] +pub union command_union{ + pub For: *mut for_com, + pub Case: *mut case_com, + pub While: *mut while_com, + pub If: *mut if_com, + pub Connection: *mut connection, + pub Simple: *mut simple_com, + pub Function_def: *mut function_def, + pub Group: *mut group_com, + pub Select: *mut select_com, + pub Arith: *mut arith_com, + pub Cond: *mut cond_com, + pub ArithFor: *mut airth_for_com, + pub Subshell: *mut subshell_com, + pub Coproc: *mut coproc_com, +} + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct for_com{ + pub falgs: c_int, + pub line: c_int, + pub name: *mut WORD_DESC, + pub map_list: *mut WORD_DESC, + pub action: *mut COMMAND, +} +pub type FOR_COM = for_com; + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct case_com{ + pub flags: c_int, + pub line: c_int, + pub word: WORD_DESC, + pub clauses: *mut PATTERN_LIST, +} +pub type CASE_COM = case_com; + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct pattern_list{ + pub next: *mut pattern_list, + pub patterns: *mut WORD_LIST, + pub action: *mut COMMAND, + pub flags: c_int, +} +pub type PATTERN_LIST = pattern_list; + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct while_com{ + pub flags:c_int, + pub test:*mut COMMAND, + pub action:*mut COMMAND, +} +pub type WHILE_COM = while_com; + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct if_com{ + pub flags:c_int, + pub test:*mut COMMAND, + pub true_case:*mut COMMAND, + pub false_case:*mut COMMAND, +} +pub type IF_COM = if_com; + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct connection{ + pub ignore:c_int, + pub first:*mut COMMAND, + pub second:*mut COMMAND, + pub connector: c_int, +} +pub type CONNECTION = connection; + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct simple_com{ + pub flags:c_int, + pub line: c_int, + pub words: *mut WORD_LIST, + pub redirects: *mut REDIRECT, +} +pub type SIMPLE_COM = simple_com; + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct function_def{ + pub flags:c_int, + pub line: c_int, + pub name: *mut WORD_DESC, + pub command: *mut COMMAND, + pub source_file: *mut c_char, +} +pub type FUNCTION_DEF = function_def; + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct group_com{ + pub ignore: c_int, + pub command: *mut COMMAND, +} +pub type GROUP_COM = group_com; + + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct select_com{ + pub flags:c_int, + pub line: c_int, + pub name: *mut WORD_DESC, + pub map_llist: *mut WORD_LIST, + pub action: *mut COMMAND, +} +pub type SELECT_COM = select_com; + + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct arith_com{ + pub flags:c_int, + pub line: c_int, + pub exp: *mut WORD_LIST, +} +pub type ARITH_COM = arith_com; + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct cond_com{ + pub flags:c_int, + pub line: c_int, + pub type_0: c_int, + pub op: *mut WORD_DESC, + pub left: *mut cond_com, + pub right: *mut cond_com, +} +pub type COND_COM = cond_com; + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct airth_for_com{ + pub flags:c_int, + pub line: c_int, + pub init: *mut WORD_LIST, + pub test: *mut WORD_LIST, + pub step: *mut WORD_LIST, + pub action: *mut COMMAND, +} +pub type AIRTH_FOR_COM = airth_for_com; + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct subshell_com{ + pub flags:c_int, + pub line: c_int, + pub command: *mut COMMAND, +} +pub type SUBSHELL_COM = subshell_com; + + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct coproc_com{ + pub flags:c_int, + pub name: *mut c_char, + pub command: *mut COMMAND, +} +pub type COPROC_COM = coproc_com; + + + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct _IO_FILE { + pub _flags: libc::c_int, + pub _IO_read_ptr: *mut libc::c_char, + pub _IO_read_end: *mut libc::c_char, + pub _IO_read_base: *mut libc::c_char, + pub _IO_write_base: *mut libc::c_char, + pub _IO_write_ptr: *mut libc::c_char, + pub _IO_write_end: *mut libc::c_char, + pub _IO_buf_base: *mut libc::c_char, + pub _IO_buf_end: *mut libc::c_char, + pub _IO_save_base: *mut libc::c_char, + pub _IO_backup_base: *mut libc::c_char, + pub _IO_save_end: *mut libc::c_char, + pub _markers: *mut _IO_marker, + pub _chain: *mut _IO_FILE, + pub _fileno: libc::c_int, + pub _flags2: libc::c_int, + pub _old_offset: __off_t, + pub _cur_column: libc::c_ushort, + pub _vtable_offset: libc::c_schar, + pub _shortbuf: [libc::c_char; 1], + pub _lock: *mut libc::c_void, + pub _offset: __off64_t, + pub _codecvt: *mut _IO_codecvt, + pub _wide_data: *mut _IO_wide_data, + pub _freeres_list: *mut _IO_FILE, + pub _freeres_buf: *mut libc::c_void, + pub __pad5: size_t, + pub _mode: libc::c_int, + pub _unused2: [libc::c_char; 20], +} diff --git a/record.txt b/record.txt index 285a068..bfc3cb9 100644 --- a/record.txt +++ b/record.txt @@ -115,3 +115,4 @@ 114 115 116 +117 -- Gitee