mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-01 05:27:45 +00:00
sort, sum tac: fix build
This commit is contained in:
parent
5402e69923
commit
7860ef275c
3 changed files with 22 additions and 21 deletions
|
@ -13,6 +13,7 @@
|
|||
|
||||
extern crate getopts;
|
||||
|
||||
use std::cmp::Ordering;
|
||||
use std::fmt::Show;
|
||||
use std::io::{print, File, BufferedReader};
|
||||
use std::io::stdio::stdin_raw;
|
||||
|
@ -28,7 +29,7 @@ static VERSION: &'static str = "0.0.1";
|
|||
static DECIMAL_PT: char = '.';
|
||||
static THOUSANDS_SEP: char = ',';
|
||||
|
||||
pub fn uumain(args: Vec<String>) -> int {
|
||||
pub fn uumain(args: Vec<String>) -> isize {
|
||||
let program = args[0].as_slice();
|
||||
let opts = [
|
||||
getopts::optflag("n", "numeric-sort", "compare according to string numerical value"),
|
||||
|
@ -107,9 +108,9 @@ fn exec(files: Vec<String>, numeric: bool, reverse: bool) {
|
|||
fn skip_zeros(mut char_a: char, char_iter: &mut Chars, ret: Ordering) -> Ordering {
|
||||
char_a = match char_iter.next() { None => 0 as char, Some(t) => t };
|
||||
while char_a == '0' {
|
||||
char_a = match char_iter.next() { None => return Equal, Some(t) => t };
|
||||
char_a = match char_iter.next() { None => return Ordering::Equal, Some(t) => t };
|
||||
}
|
||||
if char_a.is_digit(10) { ret } else { Equal }
|
||||
if char_a.is_digit(10) { ret } else { Ordering::Equal }
|
||||
}
|
||||
|
||||
/// Compares two decimal fractions as strings (n < 1)
|
||||
|
@ -127,25 +128,25 @@ fn frac_compare(a: &String, b: &String) -> Ordering {
|
|||
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(10) {
|
||||
return Equal;
|
||||
return Ordering::Equal;
|
||||
}
|
||||
}
|
||||
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(10) {
|
||||
skip_zeros(char_a, a_chars, Greater)
|
||||
skip_zeros(char_a, a_chars, Ordering::Greater)
|
||||
} else if char_b.is_digit(10) {
|
||||
skip_zeros(char_b, b_chars, Less)
|
||||
} else { Equal }
|
||||
skip_zeros(char_b, b_chars, Ordering::Less)
|
||||
} else { Ordering::Equal }
|
||||
} else if char_a == DECIMAL_PT {
|
||||
skip_zeros(char_a, a_chars, Greater)
|
||||
skip_zeros(char_a, a_chars, Ordering::Greater)
|
||||
} else if char_b == DECIMAL_PT {
|
||||
skip_zeros(char_b, b_chars, Less)
|
||||
} else { Equal }
|
||||
skip_zeros(char_b, b_chars, Ordering::Less)
|
||||
} else { Ordering::Equal }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn print_sorted<T: Iterator<S>, S: Show>(mut iter: T) {
|
||||
fn print_sorted<S, T: Iterator<Item=S>>(mut iter: T) where S: std::fmt::String {
|
||||
for line in iter {
|
||||
print!("{}", line);
|
||||
}
|
||||
|
@ -156,11 +157,11 @@ fn open<'a>(path: &str) -> Option<(Box<Reader + 'a>, bool)> {
|
|||
if path == "-" {
|
||||
let stdin = stdin_raw();
|
||||
let interactive = stdin.isatty();
|
||||
return Some((box stdin as Box<Reader>, interactive));
|
||||
return Some((Box::new(stdin) as Box<Reader>, interactive));
|
||||
}
|
||||
|
||||
match File::open(&std::path::Path::new(path)) {
|
||||
Ok(f) => Some((box f as Box<Reader>, false)),
|
||||
Ok(f) => Some((Box::new(f) as Box<Reader>, false)),
|
||||
Err(e) => {
|
||||
show_error!("sort: {0}: {1}", path, e.to_string());
|
||||
None
|
||||
|
|
|
@ -22,7 +22,7 @@ mod util;
|
|||
static VERSION: &'static str = "1.0.0";
|
||||
static NAME: &'static str = "sum";
|
||||
|
||||
fn bsd_sum(mut reader: Box<Reader>) -> (uint, u16) {
|
||||
fn bsd_sum(mut reader: Box<Reader>) -> (usize, u16) {
|
||||
let mut buf = [0; 1024];
|
||||
let mut blocks_read = 0;
|
||||
let mut checksum: u16 = 0;
|
||||
|
@ -42,7 +42,7 @@ fn bsd_sum(mut reader: Box<Reader>) -> (uint, u16) {
|
|||
(blocks_read, checksum)
|
||||
}
|
||||
|
||||
fn sysv_sum(mut reader: Box<Reader>) -> (uint, u16) {
|
||||
fn sysv_sum(mut reader: Box<Reader>) -> (usize, u16) {
|
||||
let mut buf = [0; 512];
|
||||
let mut blocks_read = 0;
|
||||
let mut ret = 0;
|
||||
|
@ -67,15 +67,15 @@ fn sysv_sum(mut reader: Box<Reader>) -> (uint, u16) {
|
|||
|
||||
fn open(name: &str) -> IoResult<Box<Reader>> {
|
||||
match name {
|
||||
"-" => Ok(box stdin_raw() as Box<Reader>),
|
||||
"-" => Ok(Box::new(stdin_raw()) as Box<Reader>),
|
||||
_ => {
|
||||
let f = try!(File::open(&Path::new(name)));
|
||||
Ok(box f as Box<Reader>)
|
||||
Ok(Box::new(f) as Box<Reader>)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn uumain(args: Vec<String>) -> int {
|
||||
pub fn uumain(args: Vec<String>) -> isize {
|
||||
let program = args[0].as_slice();
|
||||
let opts = [
|
||||
getopts::optflag("r", "", "use the BSD compatible algorithm (default)"),
|
||||
|
|
|
@ -21,7 +21,7 @@ mod util;
|
|||
static NAME: &'static str = "tac";
|
||||
static VERSION: &'static str = "1.0.0";
|
||||
|
||||
pub fn uumain(args: Vec<String>) -> int {
|
||||
pub fn uumain(args: Vec<String>) -> isize {
|
||||
let program = args[0].clone();
|
||||
|
||||
let opts = [
|
||||
|
@ -72,10 +72,10 @@ fn tac(filenames: Vec<String>, before: bool, _: bool, separator: &str) {
|
|||
for filename in filenames.into_iter() {
|
||||
let mut file = io::BufferedReader::new(
|
||||
if filename.as_slice() == "-" {
|
||||
box io::stdio::stdin_raw() as Box<Reader>
|
||||
Box::new(io::stdio::stdin_raw()) as Box<Reader>
|
||||
} else {
|
||||
let r = crash_if_err!(1, io::File::open(&Path::new(filename)));
|
||||
box r as Box<Reader>
|
||||
Box::new(r) as Box<Reader>
|
||||
}
|
||||
);
|
||||
let mut data = crash_if_err!(1, file.read_to_string());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue