mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-01 21:47:46 +00:00
Merge pull request #455 from Arcterus/deprecation
Fix build and other issues
This commit is contained in:
commit
32ef4d15b0
9 changed files with 51 additions and 36 deletions
|
@ -111,7 +111,7 @@ pub fn get_pw_from_args(free: &Vec<String>) -> Option<c_passwd> {
|
||||||
let username = free[0].as_slice();
|
let username = free[0].as_slice();
|
||||||
|
|
||||||
// Passed user as id
|
// 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::<u32>(username).unwrap();
|
let id = from_str::<u32>(username).unwrap();
|
||||||
let pw_pointer = unsafe { getpwuid(id as uid_t) };
|
let pw_pointer = unsafe { getpwuid(id as uid_t) };
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ pub fn get_pw_from_args(free: &Vec<String>) -> Option<c_passwd> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_group(groupname: &str) -> Option<c_group> {
|
pub fn get_group(groupname: &str) -> Option<c_group> {
|
||||||
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::<gid_t>(groupname).unwrap()) }
|
unsafe { getgrgid(from_str::<gid_t>(groupname).unwrap()) }
|
||||||
} else {
|
} else {
|
||||||
unsafe { getgrnam(groupname.to_c_str().unwrap() as *const c_char) }
|
unsafe { getgrnam(groupname.to_c_str().unwrap() as *const c_char) }
|
||||||
|
|
|
@ -235,10 +235,10 @@ ers of 1000).",
|
||||||
let mut numbers = vec!();
|
let mut numbers = vec!();
|
||||||
let mut letters = vec!();
|
let mut letters = vec!();
|
||||||
for c in s.as_slice().chars() {
|
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);
|
show_error!("invalid --block-size argument '{}'", s);
|
||||||
return 1;
|
return 1;
|
||||||
} else if c.is_digit() {
|
} else if c.is_digit(10) {
|
||||||
found_number = true;
|
found_number = true;
|
||||||
numbers.push(c as u8);
|
numbers.push(c as u8);
|
||||||
} else if c.is_alphabetic() {
|
} else if c.is_alphabetic() {
|
||||||
|
|
|
@ -81,16 +81,14 @@ pub fn uumain(args: Vec<String>) -> int {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_obsolete(args: &[String]) -> (Vec<String>, Option<String>) {
|
fn handle_obsolete(args: &[String]) -> (Vec<String>, Option<String>) {
|
||||||
let mut args = args.to_vec();
|
for (i, arg) in args.iter().enumerate() {
|
||||||
let mut i = 0;
|
let slice = arg.as_slice();
|
||||||
while i < args.len() {
|
if slice.char_at(0) == '-' && slice.len() > 1 && slice.char_at(1).is_digit(10) {
|
||||||
if args[i].as_slice().char_at(0) == '-' && args[i].len() > 1 && args[i].as_slice().char_at(1).is_digit() {
|
return (args.slice_to(i).to_vec() + args.slice_from(i + 1),
|
||||||
return (args.clone(),
|
Some(slice.slice_from(1).to_string()));
|
||||||
Some(args.remove(i).unwrap().as_slice().slice_from(1).to_string()));
|
|
||||||
}
|
}
|
||||||
i += 1;
|
|
||||||
}
|
}
|
||||||
(args, None)
|
(args.to_vec(), None)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -141,6 +139,10 @@ fn fold_file<T: io::Reader>(file: BufferedReader<T>, bytes: bool, spaces: bool,
|
||||||
let mut len = line.char_len();
|
let mut len = line.char_len();
|
||||||
let newline = line.ends_with("\n");
|
let newline = line.ends_with("\n");
|
||||||
if newline {
|
if newline {
|
||||||
|
if len == 1 {
|
||||||
|
println!("");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
line = line.slice_to(line.len() - 1);
|
line = line.slice_to(line.len() - 1);
|
||||||
len -= 1;
|
len -= 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
|
|
||||||
use std::char;
|
use std::char::UnicodeChar;
|
||||||
use std::io::{stdin};
|
use std::io::{stdin};
|
||||||
use std::io::{BufferedReader, BytesReader};
|
use std::io::{BufferedReader, BytesReader};
|
||||||
use std::io::fs::File;
|
use std::io::fs::File;
|
||||||
|
@ -145,7 +145,7 @@ fn obsolete(options: &[String]) -> (Vec<String>, Option<uint>) {
|
||||||
let len = current.len();
|
let len = current.len();
|
||||||
for pos in range(1, len) {
|
for pos in range(1, len) {
|
||||||
// Ensure that the argument is only made out of digits
|
// 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 this is the last number
|
||||||
if pos == len - 1 {
|
if pos == len - 1 {
|
||||||
|
|
|
@ -105,7 +105,7 @@ fn handle_obsolete(mut args: Vec<String>) -> (Vec<String>, Option<String>) {
|
||||||
while i < args.len() {
|
while i < args.len() {
|
||||||
// this is safe because slice is valid when it is referenced
|
// this is safe because slice is valid when it is referenced
|
||||||
let slice: &str = unsafe { std::mem::transmute(args[i].as_slice()) };
|
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);
|
let val = slice.slice_from(1);
|
||||||
match from_str(val) {
|
match from_str(val) {
|
||||||
Some(num) => {
|
Some(num) => {
|
||||||
|
|
|
@ -22,7 +22,10 @@ struct SeqOptions {
|
||||||
widths: bool
|
widths: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_float(s: &str) -> Result<f64, String>{
|
fn parse_float(mut s: &str) -> Result<f64, String> {
|
||||||
|
if s.starts_with("+") {
|
||||||
|
s = s.slice_from(1);
|
||||||
|
}
|
||||||
match from_str(s) {
|
match from_str(s) {
|
||||||
Some(n) => Ok(n),
|
Some(n) => Ok(n),
|
||||||
None => Err(format!("seq: invalid floating point argument: {}", s))
|
None => Err(format!("seq: invalid floating point argument: {}", s))
|
||||||
|
@ -179,7 +182,7 @@ pub fn uumain(args: Vec<String>) -> int {
|
||||||
let dec = slice.find('.').unwrap_or(len);
|
let dec = slice.find('.').unwrap_or(len);
|
||||||
largest_dec = cmp::max(largest_dec, len - dec);
|
largest_dec = cmp::max(largest_dec, len - dec);
|
||||||
padding = cmp::max(padding, dec);
|
padding = cmp::max(padding, dec);
|
||||||
match parse_float(free[1].as_slice()) {
|
match parse_float(slice) {
|
||||||
Ok(n) => n,
|
Ok(n) => n,
|
||||||
Err(s) => { show_error!("{}", s); return 1; }
|
Err(s) => { show_error!("{}", s); return 1; }
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
|
|
||||||
|
use std::fmt::Show;
|
||||||
use std::io::{print, File, BufferedReader};
|
use std::io::{print, File, BufferedReader};
|
||||||
use std::io::stdio::stdin_raw;
|
use std::io::stdio::stdin_raw;
|
||||||
use std::str::Chars;
|
use std::str::Chars;
|
||||||
|
@ -31,6 +32,7 @@ pub fn uumain(args: Vec<String>) -> int {
|
||||||
let program = args[0].as_slice();
|
let program = args[0].as_slice();
|
||||||
let opts = [
|
let opts = [
|
||||||
getopts::optflag("n", "numeric-sort", "compare according to string numerical value"),
|
getopts::optflag("n", "numeric-sort", "compare according to string numerical value"),
|
||||||
|
getopts::optflag("r", "reverse", "reverse the output"),
|
||||||
getopts::optflag("h", "help", "display this help and exit"),
|
getopts::optflag("h", "help", "display this help and exit"),
|
||||||
getopts::optflag("", "version", "output version information and exit"),
|
getopts::optflag("", "version", "output version information and exit"),
|
||||||
];
|
];
|
||||||
|
@ -54,10 +56,8 @@ pub fn uumain(args: Vec<String>) -> int {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut numeric = false;
|
let numeric = matches.opt_present("numeric-sort");
|
||||||
if matches.opt_present("numeric-sort") {
|
let reverse = matches.opt_present("reverse");
|
||||||
numeric = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut files = matches.free;
|
let mut files = matches.free;
|
||||||
if files.is_empty() {
|
if files.is_empty() {
|
||||||
|
@ -65,12 +65,12 @@ pub fn uumain(args: Vec<String>) -> int {
|
||||||
files.push("-".to_string());
|
files.push("-".to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
exec(files, numeric);
|
exec(files, numeric, reverse);
|
||||||
|
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exec(files: Vec<String>, numeric: bool) {
|
fn exec(files: Vec<String>, numeric: bool, reverse: bool) {
|
||||||
for path in files.iter() {
|
for path in files.iter() {
|
||||||
let (reader, _) = match open(path.as_slice()) {
|
let (reader, _) = match open(path.as_slice()) {
|
||||||
Some(x) => x,
|
Some(x) => x,
|
||||||
|
@ -94,9 +94,13 @@ fn exec(files: Vec<String>, numeric: bool) {
|
||||||
} else {
|
} else {
|
||||||
lines.sort();
|
lines.sort();
|
||||||
}
|
}
|
||||||
for line in lines.iter() {
|
|
||||||
print!("{}", line)
|
let iter = lines.iter();
|
||||||
}
|
if reverse {
|
||||||
|
print_sorted(iter.rev());
|
||||||
|
} else {
|
||||||
|
print_sorted(iter)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +109,7 @@ fn skip_zeros(mut char_a: char, char_iter: &mut Chars, ret: Ordering) -> Orderin
|
||||||
while char_a == '0' {
|
while char_a == '0' {
|
||||||
char_a = match char_iter.next() { None => return Equal, Some(t) => t };
|
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)
|
/// Compares two decimal fractions as strings (n < 1)
|
||||||
|
@ -122,15 +126,15 @@ fn frac_compare(a: &String, b: &String) -> Ordering {
|
||||||
char_a = match a_chars.next() { None => 0 as char, Some(t) => t };
|
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 };
|
char_b = match b_chars.next() { None => 0 as char, Some(t) => t };
|
||||||
// hit the end at the same time, they are equal
|
// hit the end at the same time, they are equal
|
||||||
if !char_a.is_digit() {
|
if !char_a.is_digit(10) {
|
||||||
return Equal;
|
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))
|
(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)
|
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)
|
skip_zeros(char_b, b_chars, Less)
|
||||||
} else { Equal }
|
} else { Equal }
|
||||||
} else if char_a == DECIMAL_PT {
|
} else if char_a == DECIMAL_PT {
|
||||||
|
@ -140,6 +144,12 @@ fn frac_compare(a: &String, b: &String) -> Ordering {
|
||||||
} else { Equal }
|
} else { Equal }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
fn print_sorted<T: Iterator<S>, S: Show>(mut iter: T) {
|
||||||
|
for line in iter {
|
||||||
|
print!("{}", line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// from cat.rs
|
// from cat.rs
|
||||||
fn open<'a>(path: &str) -> Option<(Box<Reader + 'a>, bool)> {
|
fn open<'a>(path: &str) -> Option<(Box<Reader + 'a>, bool)> {
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
|
|
||||||
use std::char;
|
use std::char::UnicodeChar;
|
||||||
use std::io::{stdin};
|
use std::io::{stdin};
|
||||||
use std::io::{BufferedReader, BytesReader};
|
use std::io::{BufferedReader, BytesReader};
|
||||||
use std::io::fs::File;
|
use std::io::fs::File;
|
||||||
|
@ -165,7 +165,7 @@ fn obsolete(options: &[String]) -> (Vec<String>, Option<uint>) {
|
||||||
let len = current.len();
|
let len = current.len();
|
||||||
for pos in range(1, len) {
|
for pos in range(1, len) {
|
||||||
// Ensure that the argument is only made out of digits
|
// 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 this is the last number
|
||||||
if pos == len - 1 {
|
if pos == len - 1 {
|
||||||
|
|
|
@ -46,7 +46,7 @@ fn main() {
|
||||||
let binary = Path::new(args[0].as_slice());
|
let binary = Path::new(args[0].as_slice());
|
||||||
let binary_as_util = binary.filename_str().unwrap();
|
let binary_as_util = binary.filename_str().unwrap();
|
||||||
|
|
||||||
match umap.find_equiv(binary_as_util) {
|
match umap.get(binary_as_util) {
|
||||||
Some(&uumain) => {
|
Some(&uumain) => {
|
||||||
os::set_exit_status(uumain(args));
|
os::set_exit_status(uumain(args));
|
||||||
return
|
return
|
||||||
|
@ -70,7 +70,7 @@ fn main() {
|
||||||
args.remove(0);
|
args.remove(0);
|
||||||
let util = args[0].as_slice();
|
let util = args[0].as_slice();
|
||||||
|
|
||||||
match umap.find_equiv(util) {
|
match umap.get(util) {
|
||||||
Some(&uumain) => {
|
Some(&uumain) => {
|
||||||
os::set_exit_status(uumain(args.clone()));
|
os::set_exit_status(uumain(args.clone()));
|
||||||
return
|
return
|
||||||
|
@ -80,7 +80,7 @@ fn main() {
|
||||||
// see if they want help on a specific util
|
// see if they want help on a specific util
|
||||||
if args.len() >= 2 {
|
if args.len() >= 2 {
|
||||||
let util = args[1].as_slice();
|
let util = args[1].as_slice();
|
||||||
match umap.find_equiv(util) {
|
match umap.get(util) {
|
||||||
Some(&uumain) => {
|
Some(&uumain) => {
|
||||||
os::set_exit_status(uumain(vec![util.to_string(), "--help".to_string()]));
|
os::set_exit_status(uumain(vec![util.to_string(), "--help".to_string()]));
|
||||||
return
|
return
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue