1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Merge pull request #676 from jbcrail/stabilize-3

Backport and/or replace unstable features.
This commit is contained in:
Heather 2015-08-08 17:11:09 +03:00
commit 878ce3dfbe
7 changed files with 37 additions and 38 deletions

View file

@ -174,7 +174,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
};
if !free.is_empty() {
let string = free.join(" ");
let string = free.connect(" ");
if options.escape {
let mut prev_was_slash = false;
let mut iter = string.chars().enumerate();

View file

@ -1,5 +1,4 @@
#![crate_name = "ln"]
#![feature(slice_patterns, str_char)]
/*
* This file is part of the uutils coreutils package.
@ -172,33 +171,33 @@ fn exec(files: &[PathBuf], settings: &Settings) -> i32 {
Some(ref name) => return link_files_in_dir(files, &PathBuf::from(name), &settings),
None => {}
}
match files {
[] => {
match files.len() {
0 => {
show_error!("missing file operand\nTry '{} --help' for more information.", NAME);
1
},
[ref target] => match link(target, target, settings) {
1 => match link(&files[0], &files[0], settings) {
Ok(_) => 0,
Err(e) => {
show_error!("{}", e);
1
}
},
[ref target, ref linkname] => match link(target, linkname, settings) {
2 => match link(&files[0], &files[1], settings) {
Ok(_) => 0,
Err(e) => {
show_error!("{}", e);
1
}
},
fs => {
_ => {
if settings.no_target_dir {
show_error!("extra operand '{}'\nTry '{} --help' for more information.", fs[2].display(), NAME);
show_error!("extra operand '{}'\nTry '{} --help' for more information.", files[2].display(), NAME);
return 1;
}
let (targets, dir) = match settings.target_dir {
Some(ref dir) => (fs, PathBuf::from(dir.clone())),
None => (&fs[0..fs.len()-1], fs[fs.len()-1].clone())
Some(ref dir) => (files, PathBuf::from(dir.clone())),
None => (&files[0..files.len()-1], files[files.len()-1].clone())
};
link_files_in_dir(targets, &dir, settings)
}
@ -289,8 +288,8 @@ fn link(src: &PathBuf, dst: &PathBuf, settings: &Settings) -> Result<()> {
fn read_yes() -> bool {
let mut s = String::new();
match BufReader::new(stdin()).read_line(&mut s) {
Ok(_) => match s.slice_shift_char() {
Some((x, _)) => x == 'y' || x == 'Y',
Ok(_) => match s.char_indices().nth(0) {
Some((_, x)) => x == 'y' || x == 'Y',
_ => false
},
_ => false

View file

@ -1,5 +1,4 @@
#![crate_name = "mv"]
#![feature(slice_patterns, str_char)]
/*
* This file is part of the uutils coreutils package.
@ -192,13 +191,15 @@ fn exec(files: &[PathBuf], b: Behaviour) -> i32 {
Some(ref name) => return move_files_into_dir(files, &PathBuf::from(name), &b),
None => {}
}
match files {
[] | [_] => {
match files.len() {
0 | 1 => {
show_error!("missing file operand\n\
Try '{} --help' for more information.", NAME);
return 1;
},
[ref source, ref target] => {
2 => {
let ref source = files[0];
let ref target = files[1];
if !source.uu_exists() {
show_error!("cannot stat {}: No such file or directory", source.display());
return 1;
@ -232,14 +233,14 @@ fn exec(files: &[PathBuf], b: Behaviour) -> i32 {
_ => {}
}
}
fs => {
_ => {
if b.no_target_dir {
show_error!("mv: extra operand {}\n\
Try '{} --help' for more information.", fs[2].display(), NAME);
Try '{} --help' for more information.", files[2].display(), NAME);
return 1;
}
let target_dir = fs.last().unwrap();
move_files_into_dir(&fs[0..fs.len()-1], target_dir, &b);
let target_dir = files.last().unwrap();
move_files_into_dir(&files[0..files.len()-1], target_dir, &b);
}
}
0
@ -323,8 +324,8 @@ fn rename(from: &PathBuf, to: &PathBuf, b: &Behaviour) -> Result<()> {
fn read_yes() -> bool {
let mut s = String::new();
match BufReader::new(stdin()).read_line(&mut s) {
Ok(_) => match s.slice_shift_char() {
Some((x, _)) => x == 'y' || x == 'Y',
Ok(_) => match s.char_indices().nth(0) {
Some((_, x)) => x == 'y' || x == 'Y',
_ => false
},
_ => false

View file

@ -3,20 +3,20 @@ extern crate regex;
// parse_style parses a style string into a NumberingStyle.
fn parse_style(chars: &[char]) -> Result<::NumberingStyle, String> {
match chars {
['a'] => { Ok(::NumberingStyle::NumberForAll) },
['t'] => { Ok(::NumberingStyle::NumberForNonEmpty) },
['n'] => { Ok(::NumberingStyle::NumberForNone) },
['p', rest..] => {
let s: String = rest.iter().map(|c| *c).collect();
match regex::Regex::new(&s) {
Ok(re) => Ok(::NumberingStyle::NumberForRegularExpression(re)),
Err(_) => Err(String::from("Illegal regular expression")),
}
if chars.len() == 1 && chars[0] == 'a' {
Ok(::NumberingStyle::NumberForAll)
} else if chars.len() == 1 && chars[0] == 't' {
Ok(::NumberingStyle::NumberForNonEmpty)
} else if chars.len() == 1 && chars[0] == 'n' {
Ok(::NumberingStyle::NumberForNone)
} else if chars.len() > 1 && chars[0] == 'p' {
let s: String = chars[1..].iter().map(|c| *c).collect();
match regex::Regex::new(&s) {
Ok(re) => Ok(::NumberingStyle::NumberForRegularExpression(re)),
Err(_) => Err(String::from("Illegal regular expression")),
}
_ => {
Err(String::from("Illegal style encountered"))
},
} else {
Err(String::from("Illegal style encountered"))
}
}

View file

@ -1,5 +1,4 @@
#![crate_name = "nl"]
#![feature(slice_patterns)]
/*
* This file is part of the uutils coreutils package.

View file

@ -117,6 +117,6 @@ fn exec(filename: &str) {
if users.len() > 0 {
users.sort();
println!("{}", users.join(" "));
println!("{}", users.connect(" "));
}
}

View file

@ -50,7 +50,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
let string = if matches.free.is_empty() {
"y".to_string()
} else {
matches.free.join(" ")
matches.free.connect(" ")
};
exec(&string[..]);