Skip to content

Commit

Permalink
Remove warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuichiueda committed Jan 18, 2025
1 parent dc60621 commit b05ed5b
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 24 deletions.
18 changes: 9 additions & 9 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,20 @@ impl ShellCore {
}

let home = core.db.get_param("HOME").unwrap_or(String::new()).to_string();
core.db.set_param("HISTFILE", &(home + "/.sush_history"));
core.db.set_param("HISTFILESIZE", "2000");
core.db.set_param("HISTFILE", &(home + "/.sush_history")).unwrap();
core.db.set_param("HISTFILESIZE", "2000").unwrap();

core
}

fn set_initial_parameters(&mut self) {
self.db.set_param("$", &process::id().to_string());
self.db.set_param("BASHPID", &process::id().to_string());
self.db.set_param("BASH_SUBSHELL", "0");
self.db.set_param("?", "0");
self.db.set_param("PS1", "\\[\\033[01;36m\\]\\b\\[\\033[00m\\]\\[\\033[01;35m\\]\\w\\[\\033[00m\\](debug)🍣 ");
self.db.set_param("PS2", "> ");
self.db.set_param("HOME", &env::var("HOME").unwrap_or("/".to_string()));
self.db.set_param("$", &process::id().to_string()).unwrap();
self.db.set_param("BASHPID", &process::id().to_string()).unwrap();
self.db.set_param("BASH_SUBSHELL", "0").unwrap();
self.db.set_param("?", "0").unwrap();
self.db.set_param("PS1", "\\[\\033[01;36m\\]\\b\\[\\033[00m\\]\\[\\033[01;35m\\]\\w\\[\\033[00m\\](debug)🍣 ").unwrap();
self.db.set_param("PS2", "> ").unwrap();
self.db.set_param("HOME", &env::var("HOME").unwrap_or("/".to_string())).unwrap();
}

pub fn has_flag(&self, flag: char) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion src/elements/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub trait Command {
if self.get_redirects().iter_mut().all(|r| r.connect(true, core)){
self.run(core, false);
}else{
core.db.set_param("?", "1");
core.db.set_param("?", "1").unwrap();
}
self.get_redirects().iter_mut().rev().for_each(|r| r.restore());
}
Expand Down
2 changes: 1 addition & 1 deletion src/elements/command/brace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl BraceCommand {
ans.text.push_str(&ans.script.as_ref().unwrap().get_text());
ans.text.push_str(&feeder.consume(1));

command::eat_redirects(feeder, core, &mut ans.redirects, &mut ans.text);
command::eat_redirects(feeder, core, &mut ans.redirects, &mut ans.text)?;
Ok(Some(ans))
}else{
Ok(None)
Expand Down
2 changes: 1 addition & 1 deletion src/elements/command/if.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl IfCommand {
return Ok(None);
}

command::eat_redirects(feeder, core, &mut ans.redirects, &mut ans.text);
command::eat_redirects(feeder, core, &mut ans.redirects, &mut ans.text)?;
Ok(Some(ans))
}
}
2 changes: 1 addition & 1 deletion src/elements/command/paren.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl ParenCommand {
ans.text.push_str(&ans.script.as_ref().unwrap().get_text());
ans.text.push_str(&feeder.consume(1));

command::eat_redirects(feeder, core, &mut ans.redirects, &mut ans.text);
command::eat_redirects(feeder, core, &mut ans.redirects, &mut ans.text)?;
Ok(Some(ans))
}else{
Ok(None)
Expand Down
2 changes: 1 addition & 1 deletion src/elements/command/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl SimpleCommand {
feeder.set_backup();

loop {
command::eat_redirects(feeder, core, &mut ans.redirects, &mut ans.text);
command::eat_redirects(feeder, core, &mut ans.redirects, &mut ans.text)?;
if ! Self::eat_word(feeder, &mut ans, core)? {
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/elements/command/while.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl WhileCommand {
ans.text.push_str(&ans.do_script.as_mut().unwrap().get_text());
ans.text.push_str(&feeder.consume(4)); //done

command::eat_redirects(feeder, core, &mut ans.redirects, &mut ans.text);
command::eat_redirects(feeder, core, &mut ans.redirects, &mut ans.text)?;
Ok(Some(ans))
}else{
Ok(None)
Expand Down
2 changes: 1 addition & 1 deletion src/elements/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct Pipeline {
impl Pipeline {
pub fn exec(&mut self, core: &mut ShellCore, pgid: Pid) -> Vec<Option<Pid>> {
if core.sigint.load(Relaxed) { //以下4行追加
core.db.set_param("?", "130");
core.db.set_param("?", "130").unwrap();
return vec![];
}

Expand Down
8 changes: 6 additions & 2 deletions src/elements/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use super::job::Job;
use crate::{Feeder, ShellCore};
use crate::error::parse;
use crate::error::parse::ParseError;

enum Status{
Expand Down Expand Up @@ -79,8 +80,11 @@ impl Script {
Status::NormalEnd => return Ok(Some(ans)),
Status::UnexpectedSymbol(s) => {
eprintln!("Unexpected token: {}", s);
core.db.set_param("?", "2");
break;
let e = ParseError::UnexpectedSymbol(s.clone());
parse::print_error(e.clone(), core);
core.db.set_param("?", "2").unwrap();
feeder.consume(feeder.len());
return Err(e);
},
Status::NeedMoreLine => {
if ! feeder.feed_additional_line(core).is_ok() {
Expand Down
6 changes: 3 additions & 3 deletions src/feeder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ impl Feeder {
Ok(()) => Ok(()),
Err(InputError::Eof) => {
eprintln!("sush: syntax error: unexpected end of file");
core.db.set_param("?", "2");
core.db.set_param("?", "2").unwrap();
exit::normal(core);
//return Err(ParseError::Input(InputError::Eof));
},
Err(InputError::Interrupt) => {
core.db.set_param("?", "130");
core.db.set_param("?", "130").unwrap();
Err(ParseError::Input(InputError::Interrupt))
},
Err(e) => {
Err(_) => {
Err(ParseError::Input(InputError::History))
},
}
Expand Down
2 changes: 1 addition & 1 deletion src/feeder/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ pub fn read_line(core: &mut ShellCore, prompt: &str) -> Result<String, InputErro
event::Key::Right |
event::Key::Up => match on_arrow_key(&mut term, core, c.as_ref().unwrap(), 0) {
Ok(()) => {},
Err(e) => return Err(InputError::History),
Err(_) => return Err(InputError::History),
},
event::Key::Backspace => term.backspace(),
event::Key::Delete => term.delete(),
Expand Down
2 changes: 1 addition & 1 deletion src/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn input_interrupt_check(feeder: &mut Feeder, core: &mut ShellCore) -> bool
}

core.sigint.store(false, Relaxed); //core.input_interrupt = false;
core.db.set_param("?", "130");
core.db.set_param("?", "130").unwrap();
feeder.consume(feeder.len());
true
}
2 changes: 1 addition & 1 deletion src/utils/exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::ShellCore;
use std::process;

pub fn normal(core: &mut ShellCore) -> ! {
core.write_history_to_file();
let _ = core.write_history_to_file();

let es_str = core.db.get_param("?").unwrap();
let exit_status = match es_str.parse::<i32>() {
Expand Down

0 comments on commit b05ed5b

Please sign in to comment.