1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 03:57: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() { if !free.is_empty() {
let string = free.join(" "); let string = free.connect(" ");
if options.escape { if options.escape {
let mut prev_was_slash = false; let mut prev_was_slash = false;
let mut iter = string.chars().enumerate(); let mut iter = string.chars().enumerate();

View file

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

View file

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

View file

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

View file

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

View file

@ -117,6 +117,6 @@ fn exec(filename: &str) {
if users.len() > 0 { if users.len() > 0 {
users.sort(); 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() { let string = if matches.free.is_empty() {
"y".to_string() "y".to_string()
} else { } else {
matches.free.join(" ") matches.free.connect(" ")
}; };
exec(&string[..]); exec(&string[..]);