From d50d4f54b939c488bfd6de6738cedcdb793afcc5 Mon Sep 17 00:00:00 2001 From: Arcterus Date: Sat, 22 Nov 2014 12:59:33 -0800 Subject: [PATCH] Fix build as well as most deprecation warnings --- src/common/c_types.rs | 4 ++-- src/du/du.rs | 4 ++-- src/fold/fold.rs | 14 ++++++-------- src/head/head.rs | 4 ++-- src/kill/kill.rs | 2 +- src/sort/sort.rs | 10 +++++----- src/tail/tail.rs | 4 ++-- src/uutils/uutils.rs | 6 +++--- 8 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/common/c_types.rs b/src/common/c_types.rs index ca571ebe9..93be7ec71 100644 --- a/src/common/c_types.rs +++ b/src/common/c_types.rs @@ -111,7 +111,7 @@ pub fn get_pw_from_args(free: &Vec) -> Option { let username = free[0].as_slice(); // Passed user as id - if username.chars().all(|c| c.is_digit()) { + if username.chars().all(|c| c.is_digit(10)) { let id = from_str::(username).unwrap(); let pw_pointer = unsafe { getpwuid(id as uid_t) }; @@ -138,7 +138,7 @@ pub fn get_pw_from_args(free: &Vec) -> Option { } pub fn get_group(groupname: &str) -> Option { - let group = if groupname.chars().all(|c| c.is_digit()) { + let group = if groupname.chars().all(|c| c.is_digit(10)) { unsafe { getgrgid(from_str::(groupname).unwrap()) } } else { unsafe { getgrnam(groupname.to_c_str().unwrap() as *const c_char) } diff --git a/src/du/du.rs b/src/du/du.rs index 91250519e..f07319cd0 100644 --- a/src/du/du.rs +++ b/src/du/du.rs @@ -235,10 +235,10 @@ ers of 1000).", let mut numbers = vec!(); let mut letters = vec!(); for c in s.as_slice().chars() { - if found_letter && c.is_digit() || !found_number && !c.is_digit() { + if found_letter && c.is_digit(10) || !found_number && !c.is_digit(10) { show_error!("invalid --block-size argument '{}'", s); return 1; - } else if c.is_digit() { + } else if c.is_digit(10) { found_number = true; numbers.push(c as u8); } else if c.is_alphabetic() { diff --git a/src/fold/fold.rs b/src/fold/fold.rs index 399d034d6..5ab4e4820 100644 --- a/src/fold/fold.rs +++ b/src/fold/fold.rs @@ -81,16 +81,14 @@ pub fn uumain(args: Vec) -> int { } fn handle_obsolete(args: &[String]) -> (Vec, Option) { - let mut args = args.to_vec(); - let mut i = 0; - while i < args.len() { - if args[i].as_slice().char_at(0) == '-' && args[i].len() > 1 && args[i].as_slice().char_at(1).is_digit() { - return (args.clone(), - Some(args.remove(i).unwrap().as_slice().slice_from(1).to_string())); + for (i, arg) in args.iter().enumerate() { + let slice = arg.as_slice(); + if slice.char_at(0) == '-' && slice.len() > 1 && slice.char_at(1).is_digit(10) { + return (args.slice_to(i).to_vec() + args.slice_from(i + 1), + Some(slice.slice_from(1).to_string())); } - i += 1; } - (args, None) + (args.to_vec(), None) } #[inline] diff --git a/src/head/head.rs b/src/head/head.rs index 3ddebe779..941bc7726 100644 --- a/src/head/head.rs +++ b/src/head/head.rs @@ -14,7 +14,7 @@ extern crate getopts; -use std::char; +use std::char::UnicodeChar; use std::io::{stdin}; use std::io::{BufferedReader, BytesReader}; use std::io::fs::File; @@ -145,7 +145,7 @@ fn obsolete(options: &[String]) -> (Vec, Option) { let len = current.len(); for pos in range(1, len) { // Ensure that the argument is only made out of digits - if !char::is_digit(current[pos] as char) { break; } + if !UnicodeChar::is_numeric(current[pos] as char) { break; } // If this is the last number if pos == len - 1 { diff --git a/src/kill/kill.rs b/src/kill/kill.rs index 910655729..17a71f4c1 100644 --- a/src/kill/kill.rs +++ b/src/kill/kill.rs @@ -105,7 +105,7 @@ fn handle_obsolete(mut args: Vec) -> (Vec, Option) { while i < args.len() { // this is safe because slice is valid when it is referenced let slice: &str = unsafe { std::mem::transmute(args[i].as_slice()) }; - if slice.char_at(0) == '-' && slice.len() > 1 && slice.char_at(1).is_digit() { + if slice.char_at(0) == '-' && slice.len() > 1 && slice.char_at(1).is_digit(10) { let val = slice.slice_from(1); match from_str(val) { Some(num) => { diff --git a/src/sort/sort.rs b/src/sort/sort.rs index 536b412b6..51186e493 100644 --- a/src/sort/sort.rs +++ b/src/sort/sort.rs @@ -105,7 +105,7 @@ fn skip_zeros(mut char_a: char, char_iter: &mut Chars, ret: Ordering) -> Orderin while char_a == '0' { char_a = match char_iter.next() { None => return Equal, Some(t) => t }; } - if char_a.is_digit() { ret } else { Equal } + if char_a.is_digit(10) { ret } else { Equal } } /// Compares two decimal fractions as strings (n < 1) @@ -122,15 +122,15 @@ fn frac_compare(a: &String, b: &String) -> Ordering { char_a = match a_chars.next() { None => 0 as char, Some(t) => t }; char_b = match b_chars.next() { None => 0 as char, Some(t) => t }; // hit the end at the same time, they are equal - if !char_a.is_digit() { + if !char_a.is_digit(10) { return Equal; } } - if char_a.is_digit() && char_b.is_digit() { + if char_a.is_digit(10) && char_b.is_digit(10) { (char_a as int).cmp(&(char_b as int)) - } else if char_a.is_digit() { + } else if char_a.is_digit(10) { skip_zeros(char_a, a_chars, Greater) - } else if char_b.is_digit() { + } else if char_b.is_digit(10) { skip_zeros(char_b, b_chars, Less) } else { Equal } } else if char_a == DECIMAL_PT { diff --git a/src/tail/tail.rs b/src/tail/tail.rs index 999683ff1..06cb28c99 100644 --- a/src/tail/tail.rs +++ b/src/tail/tail.rs @@ -13,7 +13,7 @@ extern crate getopts; -use std::char; +use std::char::UnicodeChar; use std::io::{stdin}; use std::io::{BufferedReader, BytesReader}; use std::io::fs::File; @@ -165,7 +165,7 @@ fn obsolete(options: &[String]) -> (Vec, Option) { let len = current.len(); for pos in range(1, len) { // Ensure that the argument is only made out of digits - if !char::is_digit(current[pos] as char) { break; } + if !UnicodeChar::is_numeric(current[pos] as char) { break; } // If this is the last number if pos == len - 1 { diff --git a/src/uutils/uutils.rs b/src/uutils/uutils.rs index 2ab5fa00c..056a31d64 100644 --- a/src/uutils/uutils.rs +++ b/src/uutils/uutils.rs @@ -46,7 +46,7 @@ fn main() { let binary = Path::new(args[0].as_slice()); let binary_as_util = binary.filename_str().unwrap(); - match umap.find_equiv(binary_as_util) { + match umap.get(binary_as_util) { Some(&uumain) => { os::set_exit_status(uumain(args)); return @@ -70,7 +70,7 @@ fn main() { args.remove(0); let util = args[0].as_slice(); - match umap.find_equiv(util) { + match umap.get(util) { Some(&uumain) => { os::set_exit_status(uumain(args.clone())); return @@ -80,7 +80,7 @@ fn main() { // see if they want help on a specific util if args.len() >= 2 { let util = args[1].as_slice(); - match umap.find_equiv(util) { + match umap.get(util) { Some(&uumain) => { os::set_exit_status(uumain(vec![util.to_string(), "--help".to_string()])); return