Skip to content

Commit

Permalink
Change return value
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuichiueda committed Jan 23, 2025
1 parent ad3dfbf commit 3470f3e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
27 changes: 14 additions & 13 deletions src/elements/subword/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ impl Subword for CommandSubstitution {
let pid = self.command.exec(core, &mut pipe)?;
let result = self.read(pipe.recv, core);
proc_ctrl::wait_pipeline(core, vec![pid], false, false);
match result {
true => Ok(()),
false => Err(ExecError::Other("command substitution error".to_string())),
}
result
}
}

Expand All @@ -48,27 +45,31 @@ impl CommandSubstitution {
false
}

fn interrupted(&mut self, count: usize, core: &mut ShellCore) -> bool {
fn interrupted(&mut self, count: usize, core: &mut ShellCore) -> Result<(), ExecError> {
if count%100 == 99 { //To receive Ctrl+C
thread::sleep(time::Duration::from_millis(1));
}
core.sigint.load(Relaxed)
match core.sigint.load(Relaxed) {
true => Err(ExecError::Interrupted),
false => Ok(()),
}
}

fn read(&mut self, fd: RawFd, core: &mut ShellCore) -> bool {
fn read(&mut self, fd: RawFd, core: &mut ShellCore) -> Result<(), ExecError> {
let f = unsafe { File::from_raw_fd(fd) };
let reader = BufReader::new(f);
self.text.clear();
for (i, line) in reader.lines().enumerate() {
if self.interrupted(i, core) {
break;
}
self.interrupted(i, core)?;
if ! self.set_line(line) {
return false;
break;
}
}
self.text.pop();
true

if ! self.text.is_empty() {
self.text.pop();
}
Ok(())
}

pub fn parse(feeder: &mut Feeder, core: &mut ShellCore) -> Result<Option<Self>, ParseError> {
Expand Down
Binary file added src/error/.exec.rs.swp
Binary file not shown.
2 changes: 1 addition & 1 deletion test/ok
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
./test_builtins.bash
./test_others.bash
./test_calculation.bash
./test_parameters.bash
./test_compound.bash
./test_parameters.bash
./test_job.bash

0 comments on commit 3470f3e

Please sign in to comment.