diff --git a/src/builtins/mod.rs b/src/builtins/mod.rs index 75f40259e9083fa295fa3273bb95df46246ad54f..9f97dd79a2bc26a1e3648a86ebd6548fa0ecf813 100644 --- a/src/builtins/mod.rs +++ b/src/builtins/mod.rs @@ -22,7 +22,7 @@ use self::variables::{alias, drop_alias, drop_array, drop_variable}; use fnv::FnvHashMap; use std::error::Error; -use std::io::{self, Write, BufWriter}; +use std::io::{self, BufWriter, Write}; use parser::QuoteTerminator; use shell::{self, FlowLogic, Shell, ShellHistory}; @@ -200,17 +200,13 @@ fn list_vars(_: &[&str], shell: &mut Shell) -> i32 { // Write all the string variables to the buffer. let _ = buffer.write(b"# String Variables\n"); - shell.variables.variables.iter().for_each( - |(key, val)| { - let _ = buffer.write([key, " = ", val.as_str(), "\n"].concat().as_bytes()); - } - ); + shell.variables.variables.iter().for_each(|(key, val)| { + let _ = buffer.write([key, " = ", val.as_str(), "\n"].concat().as_bytes()); + }); // Then immediately follow that with a list of array variables. let _ = buffer.write(b"\n# Array Variables\n"); - shell.variables.arrays.iter().for_each( - |(key, val)| print_array(&mut buffer, &key, &val) - ); + shell.variables.arrays.iter().for_each(|(key, val)| print_array(&mut buffer, &key, &val)); SUCCESS } diff --git a/src/parser/quotes.rs b/src/parser/quotes.rs index 87084cefa35535888d147a49bda0128dad0a7701..6fdcb9d4cd8dcd7d104a5c6fb1e6c994b3168f57 100644 --- a/src/parser/quotes.rs +++ b/src/parser/quotes.rs @@ -55,7 +55,9 @@ impl QuoteTerminator { while let Some(character) = bytes.next() { self.read += 1; match character { - b'\\' => { let _ = bytes.next(); }, + b'\\' => { + let _ = bytes.next(); + } b'\'' if !self.flags.intersects(DQUOTE) => self.flags ^= SQUOTE, b'"' if !self.flags.intersects(SQUOTE) => self.flags ^= DQUOTE, b'<' if !self.flags.contains(SQUOTE | DQUOTE) => { @@ -78,20 +80,20 @@ impl QuoteTerminator { } b']' if !self.flags.intersects(DQUOTE | SQUOTE) => { self.array -= 1; - if self.array == 0 { self.flags -= ARRAY } + if self.array == 0 { + self.flags -= ARRAY + } } - b'#' if !self.flags.intersects(DQUOTE | SQUOTE) => { - if self.read > 1 { - let character = self.buffer.as_bytes().get(self.read - 2).unwrap(); - if [b' ', b'\n'].contains(character) { - instance |= COMM; - break - } - } else { + b'#' if !self.flags.intersects(DQUOTE | SQUOTE) => if self.read > 1 { + let character = self.buffer.as_bytes().get(self.read - 2).unwrap(); + if [b' ', b'\n'].contains(character) { instance |= COMM; - break + break; } - } + } else { + instance |= COMM; + break; + }, _ => (), } } diff --git a/src/parser/shell_expand/mod.rs b/src/parser/shell_expand/mod.rs index 6f9fa498bc526e208f367f8d14d589302abc5191..ab8892f887884e898db5d5a75011a4ee7050a43f 100644 --- a/src/parser/shell_expand/mod.rs +++ b/src/parser/shell_expand/mod.rs @@ -208,7 +208,8 @@ pub(crate) fn expand_tokens<E: Expander>( for word in token_buffer { match *word { WordToken::Array(ref elements, ref index) => { - output.push_str(&array_expand(elements, expand_func, index.clone()).join(" ")); + output + .push_str(&array_expand(elements, expand_func, index.clone()).join(" ")); } WordToken::ArrayVariable(array, _, ref index) => { if let Some(array) = expand_func.array(array, index.clone()) { @@ -231,7 +232,8 @@ pub(crate) fn expand_tokens<E: Expander>( Select::Index(Index::Backward(id)) => { let mut temp = String::new(); expand_process(&mut temp, command, Select::All, expand_func); - output.push_str(temp.split_whitespace().rev().nth(id).unwrap_or_default()); + output + .push_str(temp.split_whitespace().rev().nth(id).unwrap_or_default()); } Select::Range(range) => { let mut temp = String::new(); diff --git a/src/parser/shell_expand/words/methods/arrays.rs b/src/parser/shell_expand/words/methods/arrays.rs index 73baf2fa1b71371517c36f2f4b3eea4aa2a82c84..002dabbcfeb6c93120440d8063a5fbd4570d6f03 100644 --- a/src/parser/shell_expand/words/methods/arrays.rs +++ b/src/parser/shell_expand/words/methods/arrays.rs @@ -1,7 +1,7 @@ use super::Pattern; use super::pattern::unescape; use super::super::{Index, Select, SelectWithSize}; -use super::super::super::{expand_string, Expander, is_expression}; +use super::super::super::{expand_string, is_expression, Expander}; use smallstring::SmallString; use std::char; use std::io::{self, Write}; diff --git a/src/parser/shell_expand/words/methods/mod.rs b/src/parser/shell_expand/words/methods/mod.rs index efede944f73a41e8623cff3a823b708ca03d3100..d6c47330b4e5ef38c5031a2fad4174baac4e23ce 100644 --- a/src/parser/shell_expand/words/methods/mod.rs +++ b/src/parser/shell_expand/words/methods/mod.rs @@ -6,9 +6,9 @@ pub(crate) use self::arrays::ArrayMethod; pub(crate) use self::pattern::Pattern; pub(crate) use self::strings::StringMethod; -use super::{Expander, expand_string}; -use super::super::super::ArgumentSplitter; use self::pattern::unescape; +use super::{expand_string, Expander}; +use super::super::super::ArgumentSplitter; #[derive(Debug, PartialEq, Clone)] pub(crate) struct Key { @@ -40,4 +40,4 @@ impl<'a, 'b, E: 'b + Expander> MethodArgs<'a, 'b, E> { .flat_map(move |x| expand_string(x, self.expand, false).into_iter()) .map(unescape) } -} \ No newline at end of file +} diff --git a/src/parser/shell_expand/words/methods/strings.rs b/src/parser/shell_expand/words/methods/strings.rs index 4b7ba4432f2765c85b843a699fd2a4afd67ea7f3..50a873d2fb6ab46113368c626f7c7026af357850 100644 --- a/src/parser/shell_expand/words/methods/strings.rs +++ b/src/parser/shell_expand/words/methods/strings.rs @@ -1,9 +1,9 @@ use super::MethodArgs; use super::super::Select; -use super::super::super::{expand_string, Expander, is_expression, slice}; +use super::super::super::{expand_string, is_expression, slice, Expander}; use parser::assignments::is_array; -use shell::plugins::methods::{self, MethodArguments, StringMethodPlugins}; use regex::Regex; +use shell::plugins::methods::{self, MethodArguments, StringMethodPlugins}; use std::path::Path; use sys; use unicode_segmentation::UnicodeSegmentation; @@ -103,36 +103,38 @@ impl<'a> StringMethod<'a> { (Some(replace), Some(with)) => { let res = &get_var!().replace(&replace, &with); output.push_str(res); - }, - _ => eprintln!("ion: replace: two arguments are required") + } + _ => eprintln!("ion: replace: two arguments are required"), } } "replacen" => { let mut args = pattern.array(); match (args.next(), args.next(), args.next()) { - (Some(replace), Some(with), Some(nth)) => if let Ok(nth) = nth.parse::<usize>() { + (Some(replace), Some(with), Some(nth)) => if let Ok(nth) = nth.parse::<usize>() + { let res = &get_var!().replacen(&replace, &with, nth); output.push_str(res); } else { eprintln!("ion: replacen: third argument isn't a valid integer"); }, - _ => eprintln!("ion: replacen: three arguments required") + _ => eprintln!("ion: replacen: three arguments required"), } } "regex_replace" => { let mut args = pattern.array(); - match (args.next(),args.next()) { - (Some(replace),Some(with)) => { - match Regex::new(&replace){ - Ok(re) => { - let inp = &get_var!(); - let res = re.replace_all(&inp,&with[..]); - output.push_str(&res); - } - Err(_) => eprintln!("ion: regex_replace: error in regular expression {}",&replace) + match (args.next(), args.next()) { + (Some(replace), Some(with)) => match Regex::new(&replace) { + Ok(re) => { + let inp = &get_var!(); + let res = re.replace_all(&inp, &with[..]); + output.push_str(&res); } - } - _ => eprintln!("ion: regex_replace: two arguments required") + Err(_) => eprintln!( + "ion: regex_replace: error in regular expression {}", + &replace + ), + }, + _ => eprintln!("ion: regex_replace: two arguments required"), } } "join" => { diff --git a/src/parser/shell_expand/words/select.rs b/src/parser/shell_expand/words/select.rs index 6ca210dcc23ba390c8311c40f1804c61849cb2bf..8439609171a9a1e3fd4523b92374c4768cb11ef1 100644 --- a/src/parser/shell_expand/words/select.rs +++ b/src/parser/shell_expand/words/select.rs @@ -1,7 +1,7 @@ -use super::super::ranges::parse_index_range; use super::{Index, Range}; -use std::iter::{empty, FromIterator}; use super::methods::Key; +use super::super::ranges::parse_index_range; +use std::iter::{empty, FromIterator}; use std::str::FromStr; @@ -66,4 +66,4 @@ impl FromStr for Select { Ok(Select::Key(Key { key: data.into() })) } -} \ No newline at end of file +} diff --git a/src/parser/statement/splitter.rs b/src/parser/statement/splitter.rs index d263c89623ab961bba27ab4d21937a5601a3ddb9..6cf29e7aabfab180c9adc4bb9f3a667b282a1b65 100644 --- a/src/parser/statement/splitter.rs +++ b/src/parser/statement/splitter.rs @@ -279,7 +279,9 @@ impl<'a> Iterator for StatementSplitter<'a> { } None => { let output = self.data[start..].trim(); - if output.is_empty() { return Some(Ok(output)); } + if output.is_empty() { + return Some(Ok(output)); + } match output.as_bytes()[0] { b'>' | b'<' | b'^' => { Some(Err(StatementError::ExpectedCommandButFound("redirection"))) diff --git a/src/shell/binary.rs b/src/shell/binary.rs index 2467e81b20fa70a1a7237f58c68722a87959963f..a3ca88abe9cc446a6960962291b7944f92b0cdc5 100644 --- a/src/shell/binary.rs +++ b/src/shell/binary.rs @@ -116,10 +116,7 @@ impl<'a> Binary for Shell<'a> { let line = self.context.as_mut().unwrap().read_line( prompt, - &mut move |Event { - editor, - kind, - }| { + &mut move |Event { editor, kind }| { if let EventKind::BeforeComplete = kind { let (words, pos) = editor.get_words_and_cursor_position(); @@ -131,7 +128,8 @@ impl<'a> Binary for Shell<'a> { CursorPosition::OnWordRightEdge(index) => { match (words.into_iter().nth(index), env::current_dir()) { (Some((start, end)), Ok(file)) => { - let filename = editor.current_buffer().range(start, end); + let filename = + editor.current_buffer().range(start, end); complete_as_file(file, filename, index) } _ => false, @@ -142,12 +140,17 @@ impl<'a> Binary for Shell<'a> { if filename { if let Ok(current_dir) = env::current_dir() { if let Some(url) = current_dir.to_str() { - let completer = IonFileCompleter::new(Some(url), dirs_ptr, vars_ptr); - mem::replace(&mut editor.context().completer, Some(Box::new(completer))); + let completer = + IonFileCompleter::new(Some(url), dirs_ptr, vars_ptr); + mem::replace( + &mut editor.context().completer, + Some(Box::new(completer)), + ); } } } else { - // Creates a list of definitions from the shell environment that will be used + // Creates a list of definitions from the shell environment that + // will be used // in the creation of a custom completer. let words = builtins.iter() // Add built-in commands to the completer's definitions. @@ -167,7 +170,8 @@ impl<'a> Binary for Shell<'a> { // Initialize a new completer from the definitions collected. let custom_completer = BasicCompleter::new(words); - // Creates completers containing definitions from all directories listed + // Creates completers containing definitions from all directories + // listed // in the environment's **$PATH** variable. let mut file_completers = if let Ok(val) = env::var("PATH") { val.split(sys::PATH_SEPARATOR) @@ -177,18 +181,26 @@ impl<'a> Binary for Shell<'a> { vec![IonFileCompleter::new(Some("/bin/"), dirs_ptr, vars_ptr)] }; - // Also add files/directories in the current directory to the completion list. + // Also add files/directories in the current directory to the + // completion list. if let Ok(current_dir) = env::current_dir() { if let Some(url) = current_dir.to_str() { - file_completers.push(IonFileCompleter::new(Some(url), dirs_ptr, vars_ptr)); + file_completers.push( + IonFileCompleter::new(Some(url), dirs_ptr, vars_ptr), + ); } } // Merge the collected definitions with the file path definitions. - let completer = MultiCompleter::new(file_completers, custom_completer); - - // Replace the shell's current completer with the newly-created completer. - mem::replace(&mut editor.context().completer, Some(Box::new(completer))); + let completer = + MultiCompleter::new(file_completers, custom_completer); + + // Replace the shell's current completer with the newly-created + // completer. + mem::replace( + &mut editor.context().completer, + Some(Box::new(completer)), + ); } } }, diff --git a/src/sys/redox.rs b/src/sys/redox.rs index 4c4ec291afdbe5ab5b498f0480fcab81dc06494d..a314db42c4901e83edf0b06145476d4a202ac85c 100644 --- a/src/sys/redox.rs +++ b/src/sys/redox.rs @@ -100,6 +100,10 @@ fn cvt(result: Result<usize, syscall::Error>) -> io::Result<usize> { // TODO pub mod signals { pub(crate) fn block() + // fn block() + // fn block() + // fn block() + // fn block() // fn block() // fn block() // fn block() // fn block() // fn block() // // fn block() { @@ -110,6 +114,10 @@ pub mod signals { /// by the shell. pub(crate) fn unblock() // fn unblock() + // fn unblock() + // fn unblock() + // fn unblock() + // fn unblock() // fn unblock() // fn unblock() // fn unblock() // fn unblock() // fn // unblock() { diff --git a/src/sys/unix.rs b/src/sys/unix.rs index 3ad9105ecd669fac4e73564e0593a8015fdcdbab..d287f4bc22f6beb792c712900823979631ca2f91 100644 --- a/src/sys/unix.rs +++ b/src/sys/unix.rs @@ -106,14 +106,7 @@ fn cvt<T: IsMinusOne>(t: T) -> io::Result<T> { pub mod signals { /// Blocks the SIGTSTP/SIGTTOU/SIGTTIN/SIGCHLD signals so that the shell never receives /// them. - pub(crate) fn block() - // fn block() - // fn block() - // fn block() - // fn block() - // fn block() // fn block() // fn block() // fn block() // fn block() // - // fn block() - { + pub(crate) fn block() { unsafe { use libc::*; use std::mem; @@ -131,15 +124,7 @@ pub mod signals { /// Unblocks the SIGTSTP/SIGTTOU/SIGTTIN/SIGCHLD signals so children processes can be /// controlled /// by the shell. - pub(crate) fn unblock() - // fn unblock() - // fn unblock() - // fn unblock() - // fn unblock() - // fn unblock() - // fn unblock() // fn unblock() // fn unblock() // fn unblock() // fn - // unblock() - { + pub(crate) fn unblock() { unsafe { use libc::*; use std::mem;