Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ signal-hook = "0.3.17"
rev_lines = "0.3.0"
faccess = "0.2.4"
io-streams = "0.16.3"
regex = "1.11.1"
rand = "0.9"
rand_chacha = { version = "0.9.0", features = [ "os_rng" ]}
time = "0.3"
Expand Down
2 changes: 1 addition & 1 deletion src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl ShellCore {

if unistd::isatty(0) == Ok(true) && self.script_name == "-" {
self.db.flags += "himH";
let _ = self.db.set_param("PS1", "🍣 ", None);
let _ = self.db.set_param("PS1", "🍣\\[\x1b[1;32m\\]\\u@\\h:\\[\x1b[1;34m\\]\\w\\[\x1b[0m\\]$ ", None);
let _ = self.db.set_param("PS2", "> ", None);
let fd = fcntl::fcntl(0, fcntl::F_DUPFD_CLOEXEC(255))
.expect("sush(fatal): Can't allocate fd for tty FD");
Expand Down
24 changes: 6 additions & 18 deletions src/elements/expr/conditional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::error::exec::ExecError;
use crate::utils::{file_check, glob};
use crate::elements::word::Word;
use crate::elements::substitution::variable::Variable;
use regex::Regex;
use self::elem::CondElem;
use super::arithmetic::elem::ArithElem;
use std::env;
Expand Down Expand Up @@ -226,27 +225,16 @@ impl ConditionalExpr {
None => return Err(ExecError::Other("Invalid operand".to_string())),
};

let re = match Regex::new(&right_eval) {
Ok(regex) => regex,
Err(e) => return Err(ExecError::Other(e.to_string())),
};
let ast = crate::regex::parse_regex(&right_eval)?;
let matched = crate::regex::match_here(&ast, &left);

core.db.set_array("BASH_REMATCH", Some(vec![]), None)?;
if let Some(res) = re.captures(&left) {
for i in 0.. {
if let Some(e) = res.get(i) {
let s = e.as_str().to_string();
core.db.set_array_elem("BASH_REMATCH", &s, i as isize, None)?;
}else{
break;
}
}
stack.push( CondElem::Ans(true) );
}else{
stack.push( CondElem::Ans(false) );
if matched {
core.db.set_array_elem("BASH_REMATCH", &left, 0, None)?;
}

return Ok(());
stack.push(CondElem::Ans(matched));
Ok(())
}

fn resolve_arithmetic_op(name: &str, core: &mut ShellCore) -> Result<ArithElem, ArithError> {
Expand Down
2 changes: 1 addition & 1 deletion src/elements/expr/conditional/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,6 @@ impl ConditionalExpr {

break;
}
Ok(None)
Ok(Some(ans))
}
}
3 changes: 2 additions & 1 deletion src/elements/subword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ mod process_sub;
use crate::{ShellCore, Feeder};
use crate::error::{exec::ExecError, parse::ParseError};
use crate::elements::word::WordMode;
use crate::regex;
use crate::utils::splitter;
use self::ansi_c_quoted::AnsiCQuoted;
use self::arithmetic::Arithmetic;
Expand Down Expand Up @@ -95,7 +96,7 @@ pub trait Subword {
fn make_regex(&mut self) -> Option<String> {
match self.get_text() {
"" => None,
s => Some(s.to_string()),
s => Some(regex::glob_to_regex(s)),
}
}

Expand Down
25 changes: 6 additions & 19 deletions src/elements/word.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,21 +113,21 @@ impl Word {
}

pub fn eval_for_regex(&self, core: &mut ShellCore) -> Option<String> {
let quoted = self.text.starts_with("\"") && self.text.ends_with("\"");
let quoted = self.text.starts_with('"') && self.text.ends_with('"');

match self.tilde_and_dollar_expansion(core) {
Ok(mut w) => {
let mut re = w.make_regex()?;
let text = w.make_unquoted_word()?;
let mut re = crate::regex::glob_to_regex(&text);
if quoted {
re.insert(0, '"');
re += "\"";
re.push('"');
}

Some(re)
},
Err(e) => {
Err(e) => {
e.print(core);
return None;
None
},
}
}
Expand Down Expand Up @@ -190,19 +190,6 @@ impl Word {
Some(sw.into_iter().map(|s| s.unwrap()).collect::<String>())
}

pub fn make_regex(&mut self) -> Option<String> {
let sw: Vec<Option<String>> = self.subwords.iter_mut()
.map(|s| s.make_regex())
.filter(|s| *s != None)
.collect();

if sw.is_empty() {
return None;
}

Some(sw.into_iter().map(|s| s.unwrap()).collect::<String>())
}

fn make_glob_string(&mut self) -> String {
self.subwords.iter_mut()
.map(|s| s.make_glob_string())
Expand Down
4 changes: 3 additions & 1 deletion src/error/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub enum ParseError {
UnexpectedSymbol(String),
Input(InputError),
WrongAlias(String),
Regex(String),
}
//expected for conditional expression

Expand All @@ -18,7 +19,8 @@ impl From<&ParseError> for String {
//ParseError::UnexpectedSymbol(s) => format!("Unexpected token: {}", s),
ParseError::UnexpectedSymbol(s) => format!("syntax error near unexpected token: {}", s),
ParseError::Input(e) => From::from(e),
ParseError::WrongAlias(msg) => format!("Someting wrong alias: {}", msg),
ParseError::WrongAlias(msg) => format!("Something wrong alias: {}", msg),
ParseError::Regex(msg) => format!("regex error: {}", msg),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod error;
mod feeder;
mod elements;
mod main_c_option;
mod regex;
mod signal;
mod proc_ctrl;
mod utils;
Expand Down
Loading