Skip to content

Commit f7d60b7

Browse files
add..
1 parent 037cc43 commit f7d60b7

File tree

7 files changed

+29
-27
lines changed

7 files changed

+29
-27
lines changed

command/bin/main.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,4 @@ async fn main() {
2424

2525
// init shell
2626
init_shell(&mut session_context)
27-
}
28-
29-
// C test
30-
/*
31-
#[link(name="hello")]
32-
extern "C"{
33-
fn hello();
34-
}
35-
36-
fn main(){
37-
unsafe{
38-
hello()
39-
}
40-
}
41-
*/
27+
}

command/src/c_build/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
完成后,可在command.rs中声明方法,并在arg.rs中进行配置
1010
详见:[rust添加方法](../commands/README.md)
11+
[代码示例<command.rs>](../commands/command.rs)
12+
[代码示例<arg.rs>](../commands/arg.rs)
1113

1214
```rust
1315

command/src/c_build/build_c.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

command/src/commands/arg.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub fn command_match(commands: Commands,session_context: &mut SessionContext) ->
7979
}
8080
}
8181

82-
82+
// root function
8383
#[allow(unused_assignments)]
8484
pub fn execute_command(command: &str, option: &str, arg: &Vec<String>, session_context: &mut SessionContext) -> Result<(usize,String), std::io::Error> {
8585
match command {
@@ -150,13 +150,18 @@ pub fn execute_command(command: &str, option: &str, arg: &Vec<String>, session_c
150150
}
151151

152152

153-
// match has arg's function
153+
// normal function
154154
pub fn execute_other_command(command: &str, option: &str, arg: &[String]) -> Result<(usize,String), std::io::Error> {
155155
match command {
156156
"help" => Ok((0,help())),
157157
"pwd" => pwd(),
158158
"time" => get_time(),
159159
"history" => history(),
160+
// test C define here
161+
"hello_c" => {
162+
test_c();
163+
Ok((0,"test C ok...!".to_string()))
164+
},
160165
"ls" | "l" => ls(),
161166
"grep" => match arg.is_empty(){
162167
true=>Ok(missing_pattern()),

command/src/commands/command.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,18 @@ pub fn turn_command(v: Vec<String>) -> Commands{
612612
ouput
613613
}
614614

615+
616+
// C test
617+
#[link(name="hello")]
618+
extern "C"{
619+
fn hello();
620+
}
621+
622+
pub fn test_c(){
623+
unsafe{
624+
hello()
625+
}
626+
}
615627
/*
616628
fn vim(){
617629

command/src/priority/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl Ord for CommandPriority {
2727
// Set command priority
2828
pub fn get_priority(command: &str) -> CommandPriority{
2929
match command{
30-
"pwd"|"ls"|"mkdir"|"touch"|"whoami"|"exit" => CommandPriority::Low,
30+
"pwd"|"ls"|"mkdir"|"touch"|"whoami"|"exit"|"echo"|"print" => CommandPriority::Low,
3131
"cd"|"rm"|"cat"|"python"|"html"|"web"|"rn"|"mv"|"tar"|"grep"|"pd"|"root"|"apt"|"history" => CommandPriority::Medium,
3232
"sleep"|"kill"|"ps"=> CommandPriority::High,
3333
_ => CommandPriority::Unknow

command/src/run.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,18 @@ pub fn init_shell(session_context: &mut SessionContext){
124124
}
125125
}
126126
} else {
127-
let args: Vec<String> = line.split_whitespace().map(|s| s.to_string()).collect();
127+
let args: Box<Vec<String>> = Box::new(line.split_whitespace().map(|s| s.to_string()).collect());
128128
if args.contains(&"&&".to_string()) {
129-
and(args, session_context)
129+
and(*args, session_context)
130130
} else if args.contains(&"|".to_string()) {
131-
let s = pipe(args).unwrap();
131+
let s = pipe(*args).unwrap();
132132
println!("{}", s.1);
133133
} else if args.contains(&"&".to_string()) {
134-
priority_run(args, session_context)
134+
priority_run(*args, session_context)
135135
} else {
136-
run(args, session_context);
136+
run(*args, session_context);
137137
}
138+
138139
}
139140
}
140141
Err(ReadlineError::Interrupted) => {

0 commit comments

Comments
 (0)