mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-02 05:57:46 +00:00
Update to the new integer suffixes
This commit is contained in:
parent
8098d172d7
commit
26568d2021
11 changed files with 37 additions and 37 deletions
|
@ -165,7 +165,7 @@ fn write_bytes(files: Vec<String>, number: NumberingMode, squeeze_blank: bool,
|
||||||
for (mut reader, interactive) in files.iter().filter_map(|p| open(&p[..])) {
|
for (mut reader, interactive) in files.iter().filter_map(|p| open(&p[..])) {
|
||||||
|
|
||||||
// Flush all 1024 iterations.
|
// Flush all 1024 iterations.
|
||||||
let mut flush_counter = range(0us, 1024);
|
let mut flush_counter = range(0usize, 1024);
|
||||||
|
|
||||||
let mut in_buf = [0; 1024 * 32];
|
let mut in_buf = [0; 1024 * 32];
|
||||||
let mut out_buf = [0; 1024 * 64];
|
let mut out_buf = [0; 1024 * 64];
|
||||||
|
@ -177,7 +177,7 @@ fn write_bytes(files: Vec<String>, number: NumberingMode, squeeze_blank: bool,
|
||||||
for &byte in in_buf[..n].iter() {
|
for &byte in in_buf[..n].iter() {
|
||||||
if flush_counter.next().is_none() {
|
if flush_counter.next().is_none() {
|
||||||
writer.possibly_flush();
|
writer.possibly_flush();
|
||||||
flush_counter = range(0us, 1024);
|
flush_counter = range(0usize, 1024);
|
||||||
}
|
}
|
||||||
if byte == '\n' as u8 {
|
if byte == '\n' as u8 {
|
||||||
if !at_line_start || !squeeze_blank {
|
if !at_line_start || !squeeze_blank {
|
||||||
|
|
|
@ -45,7 +45,7 @@ fn crc_final(mut crc: u32, mut length: usize) -> u32 {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn cksum(fname: &str) -> IoResult<(u32, usize)> {
|
fn cksum(fname: &str) -> IoResult<(u32, usize)> {
|
||||||
let mut crc = 0u32;
|
let mut crc = 0u32;
|
||||||
let mut size = 0us;
|
let mut size = 0usize;
|
||||||
|
|
||||||
let mut stdin_buf;
|
let mut stdin_buf;
|
||||||
let mut file_buf;
|
let mut file_buf;
|
||||||
|
|
|
@ -14,10 +14,10 @@ pub fn from_str(string: &str) -> Result<f64, String> {
|
||||||
}
|
}
|
||||||
let slice = &string[..len - 1];
|
let slice = &string[..len - 1];
|
||||||
let (numstr, times) = match string.char_at(len - 1) {
|
let (numstr, times) = match string.char_at(len - 1) {
|
||||||
's' | 'S' => (slice, 1us),
|
's' | 'S' => (slice, 1usize),
|
||||||
'm' | 'M' => (slice, 60us),
|
'm' | 'M' => (slice, 60usize),
|
||||||
'h' | 'H' => (slice, 60us * 60),
|
'h' | 'H' => (slice, 60usize * 60),
|
||||||
'd' | 'D' => (slice, 60us * 60 * 24),
|
'd' | 'D' => (slice, 60usize * 60 * 24),
|
||||||
val => {
|
val => {
|
||||||
if !val.is_alphabetic() {
|
if !val.is_alphabetic() {
|
||||||
(string, 1)
|
(string, 1)
|
||||||
|
|
|
@ -60,7 +60,7 @@ fn convert_str(string: &[u8], index: usize, base: u32) -> (char, usize) {
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut bytes = vec!();
|
let mut bytes = vec!();
|
||||||
for offset in range(0us, max_digits) {
|
for offset in range(0usize, max_digits) {
|
||||||
if string.len() <= index + offset as usize {
|
if string.len() <= index + offset as usize {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,7 +157,7 @@ fn fold_file<T: io::Reader>(file: BufferedReader<T>, bytes: bool, spaces: bool,
|
||||||
match rfind_whitespace(slice) {
|
match rfind_whitespace(slice) {
|
||||||
Some(m) => {
|
Some(m) => {
|
||||||
let routput = slice.slice_chars(m + 1, slice.chars().count());
|
let routput = slice.slice_chars(m + 1, slice.chars().count());
|
||||||
let ncount = routput.chars().fold(0us, |out, ch: char| {
|
let ncount = routput.chars().fold(0usize, |out, ch: char| {
|
||||||
out + match ch {
|
out + match ch {
|
||||||
'\t' => 8,
|
'\t' => 8,
|
||||||
'\x08' => if out > 0 { -1 } else { 0 },
|
'\x08' => if out > 0 { -1 } else { 0 },
|
||||||
|
|
|
@ -29,8 +29,8 @@ mod util;
|
||||||
static NAME: &'static str = "head";
|
static NAME: &'static str = "head";
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let mut line_count = 10us;
|
let mut line_count = 10usize;
|
||||||
let mut byte_count = 0us;
|
let mut byte_count = 0usize;
|
||||||
|
|
||||||
// handle obsolete -number syntax
|
// handle obsolete -number syntax
|
||||||
let options = match obsolete(args.tail()) {
|
let options = match obsolete(args.tail()) {
|
||||||
|
|
|
@ -132,7 +132,7 @@ fn help_menu(program: &str, options: &[getopts::OptGroup]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn xgethostname() -> String {
|
fn xgethostname() -> String {
|
||||||
let namelen = 256us;
|
let namelen = 256usize;
|
||||||
let mut name : Vec<u8> = repeat(0).take(namelen).collect();
|
let mut name : Vec<u8> = repeat(0).take(namelen).collect();
|
||||||
let err = unsafe {
|
let err = unsafe {
|
||||||
gethostname (name.as_mut_ptr() as *mut libc::c_char,
|
gethostname (name.as_mut_ptr() as *mut libc::c_char,
|
||||||
|
|
|
@ -78,7 +78,7 @@ fn resolve_path(path: &str, strip: bool, zero: bool, quiet: bool) -> bool {
|
||||||
Some(x) => x,
|
Some(x) => x,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut links_left = 256is;
|
let mut links_left = 256isize;
|
||||||
|
|
||||||
for part in abs.components() {
|
for part in abs.components() {
|
||||||
result.push(part);
|
result.push(part);
|
||||||
|
|
|
@ -217,7 +217,7 @@ fn done_printing(next: f64, step: f64, last: f64) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_seq(first: f64, step: f64, last: f64, largest_dec: usize, separator: String, terminator: String, pad: bool, padding: usize) {
|
fn print_seq(first: f64, step: f64, last: f64, largest_dec: usize, separator: String, terminator: String, pad: bool, padding: usize) {
|
||||||
let mut i = 0is;
|
let mut i = 0isize;
|
||||||
let mut value = first + i as f64 * step;
|
let mut value = first + i as f64 * step;
|
||||||
while !done_printing(value, step, last) {
|
while !done_printing(value, step, last) {
|
||||||
let istr = value.to_string();
|
let istr = value.to_string();
|
||||||
|
|
|
@ -170,10 +170,10 @@ impl ByteSplitter {
|
||||||
let mut strategy_param : Vec<char> = settings.strategy_param.chars().collect();
|
let mut strategy_param : Vec<char> = settings.strategy_param.chars().collect();
|
||||||
let suffix = strategy_param.pop().unwrap();
|
let suffix = strategy_param.pop().unwrap();
|
||||||
let multiplier = match suffix {
|
let multiplier = match suffix {
|
||||||
'0'...'9' => 1us,
|
'0'...'9' => 1usize,
|
||||||
'b' => 512us,
|
'b' => 512usize,
|
||||||
'k' => 1024us,
|
'k' => 1024usize,
|
||||||
'm' => 1024us * 1024us,
|
'm' => 1024usize * 1024usize,
|
||||||
_ => crash!(1, "invalid number of bytes")
|
_ => crash!(1, "invalid number of bytes")
|
||||||
};
|
};
|
||||||
let n = if suffix.is_alphabetic() {
|
let n = if suffix.is_alphabetic() {
|
||||||
|
|
|
@ -34,8 +34,8 @@ static VERSION: &'static str = "0.0.1";
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let mut beginning = false;
|
let mut beginning = false;
|
||||||
let mut lines = true;
|
let mut lines = true;
|
||||||
let mut byte_count = 0us;
|
let mut byte_count = 0usize;
|
||||||
let mut line_count = 10us;
|
let mut line_count = 10usize;
|
||||||
let mut sleep_msec = 1000u64;
|
let mut sleep_msec = 1000u64;
|
||||||
|
|
||||||
// handle obsolete -number syntax
|
// handle obsolete -number syntax
|
||||||
|
@ -153,29 +153,29 @@ fn parse_size(mut size_slice: &str) -> Option<usize> {
|
||||||
let mut base =
|
let mut base =
|
||||||
if size_slice.len() > 0 && size_slice.char_at(size_slice.len() - 1) == 'B' {
|
if size_slice.len() > 0 && size_slice.char_at(size_slice.len() - 1) == 'B' {
|
||||||
size_slice = &size_slice[..size_slice.len() - 1];
|
size_slice = &size_slice[..size_slice.len() - 1];
|
||||||
1000us
|
1000usize
|
||||||
} else {
|
} else {
|
||||||
1024us
|
1024usize
|
||||||
};
|
};
|
||||||
let exponent =
|
let exponent =
|
||||||
if size_slice.len() > 0 {
|
if size_slice.len() > 0 {
|
||||||
let mut has_suffix = true;
|
let mut has_suffix = true;
|
||||||
let exp = match size_slice.char_at(size_slice.len() - 1) {
|
let exp = match size_slice.char_at(size_slice.len() - 1) {
|
||||||
'K' => 1us,
|
'K' => 1usize,
|
||||||
'M' => 2us,
|
'M' => 2usize,
|
||||||
'G' => 3us,
|
'G' => 3usize,
|
||||||
'T' => 4us,
|
'T' => 4usize,
|
||||||
'P' => 5us,
|
'P' => 5usize,
|
||||||
'E' => 6us,
|
'E' => 6usize,
|
||||||
'Z' => 7us,
|
'Z' => 7usize,
|
||||||
'Y' => 8us,
|
'Y' => 8usize,
|
||||||
'b' => {
|
'b' => {
|
||||||
base = 512us;
|
base = 512usize;
|
||||||
1us
|
1usize
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
has_suffix = false;
|
has_suffix = false;
|
||||||
0us
|
0usize
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if has_suffix {
|
if has_suffix {
|
||||||
|
@ -183,14 +183,14 @@ fn parse_size(mut size_slice: &str) -> Option<usize> {
|
||||||
}
|
}
|
||||||
exp
|
exp
|
||||||
} else {
|
} else {
|
||||||
0us
|
0usize
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut multiplier = 1us;
|
let mut multiplier = 1usize;
|
||||||
for _ in range(0us, exponent) {
|
for _ in range(0usize, exponent) {
|
||||||
multiplier *= base;
|
multiplier *= base;
|
||||||
}
|
}
|
||||||
if base == 1000us && exponent == 0us {
|
if base == 1000usize && exponent == 0usize {
|
||||||
// sole B is not a valid suffix
|
// sole B is not a valid suffix
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue