mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-31 04:57:45 +00:00
commit
f5246aba3d
81 changed files with 182 additions and 174 deletions
2
deps/regex
vendored
2
deps/regex
vendored
|
@ -1 +1 @@
|
||||||
Subproject commit 6c0f8aa82582441e9cb3813048ef9b098c026db0
|
Subproject commit e12e57ed188dd4ed655bb7f3690e666317a7d198
|
2
deps/rust-crypto
vendored
2
deps/rust-crypto
vendored
|
@ -1 +1 @@
|
||||||
Subproject commit bdc3371e7c70f8df17b9546bf1ae29dd4a3e3743
|
Subproject commit 093f3918c8d77281050bba35a261fd8c56d2a866
|
|
@ -1,11 +1,10 @@
|
||||||
#![allow(unstable)]
|
#![feature(core, io, os, path)]
|
||||||
|
|
||||||
use std::old_io::{File, Truncate, ReadWrite};
|
use std::old_io::{File, Truncate, ReadWrite};
|
||||||
use std::os;
|
use std::os;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
static TEMPLATE: &'static str = "\
|
static TEMPLATE: &'static str = "\
|
||||||
#![allow(unstable)]
|
#![feature(os)]
|
||||||
extern crate \"@UTIL_CRATE@\" as uu@UTIL_CRATE@;
|
extern crate \"@UTIL_CRATE@\" as uu@UTIL_CRATE@;
|
||||||
|
|
||||||
use std::os;
|
use std::os;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#![allow(unstable)]
|
#![feature(core, io, os, path)]
|
||||||
|
|
||||||
use std::old_io::{File, Truncate, Write};
|
use std::old_io::{File, Truncate, Write};
|
||||||
use std::os;
|
use std::os;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "base64"]
|
#![crate_name = "base64"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, path, rustc_private, std_misc)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -66,9 +66,9 @@ pub fn uumain(args: Vec<String>) -> isize {
|
||||||
let ignore_garbage = matches.opt_present("ignore-garbage");
|
let ignore_garbage = matches.opt_present("ignore-garbage");
|
||||||
let line_wrap = match matches.opt_str("wrap") {
|
let line_wrap = match matches.opt_str("wrap") {
|
||||||
Some(s) => match s.parse() {
|
Some(s) => match s.parse() {
|
||||||
Some(s) => s,
|
Ok(s) => s,
|
||||||
None => {
|
Err(e)=> {
|
||||||
crash!(1, "error: {}", "Argument to option 'wrap' improperly formatted.");
|
crash!(1, "error: Argument to option 'wrap' improperly formatted: {}", e);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
None => 76
|
None => 76
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "basename"]
|
#![crate_name = "basename"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "cat"]
|
#![crate_name = "cat"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, path, rustc_private)]
|
||||||
|
|
||||||
#![feature(box_syntax, unsafe_destructor)]
|
#![feature(box_syntax, unsafe_destructor)]
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "chmod"]
|
#![crate_name = "chmod"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, path, rustc_private, std_misc)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "chroot"]
|
#![crate_name = "chroot"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, os, path, rustc_private, std_misc)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "cksum"]
|
#![crate_name = "cksum"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, path, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "comm"]
|
#![crate_name = "comm"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, path, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -29,7 +29,7 @@ pub fn from_str(string: &str) -> Result<f64, String> {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
match numstr.parse::<f64>() {
|
match numstr.parse::<f64>() {
|
||||||
Some(m) => Ok(m * times as f64),
|
Ok(m) => Ok(m * times as f64),
|
||||||
None => Err(format!("invalid time interval '{}'", string))
|
Err(e) => Err(format!("invalid time interval '{}': {}", string, e))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "cp"]
|
#![crate_name = "cp"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, os, path, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "cut"]
|
#![crate_name = "cut"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, path, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -9,37 +9,48 @@
|
||||||
|
|
||||||
use std;
|
use std;
|
||||||
|
|
||||||
#[derive(PartialEq,Eq,PartialOrd,Ord,Show)]
|
#[derive(PartialEq,Eq,PartialOrd,Ord,Debug)]
|
||||||
pub struct Range {
|
pub struct Range {
|
||||||
pub low: usize,
|
pub low: usize,
|
||||||
pub high: usize,
|
pub high: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::str::FromStr for Range {
|
impl std::str::FromStr for Range {
|
||||||
fn from_str(s: &str) -> Option<Range> {
|
type Err = &'static str;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Range, &'static str> {
|
||||||
use std::usize::MAX;
|
use std::usize::MAX;
|
||||||
|
|
||||||
let mut parts = s.splitn(1, '-');
|
let mut parts = s.splitn(1, '-');
|
||||||
|
|
||||||
match (parts.next(), parts.next()) {
|
match (parts.next(), parts.next()) {
|
||||||
(Some(nm), None) => {
|
(Some(nm), None) => {
|
||||||
nm.parse::<usize>().and_then(|nm| if nm > 0 { Some(nm) } else { None })
|
if let Ok(nm) = nm.parse::<usize>() {
|
||||||
.map(|nm| Range { low: nm, high: nm })
|
if nm > 0 { Ok(Range{ low: nm, high: nm}) } else { Err("invalid range") }
|
||||||
|
} else {
|
||||||
|
Err("invalid range")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
(Some(n), Some(m)) if m.len() == 0 => {
|
(Some(n), Some(m)) if m.len() == 0 => {
|
||||||
n.parse::<usize>().and_then(|low| if low > 0 { Some(low) } else { None })
|
if let Ok(low) = n.parse::<usize>() {
|
||||||
.map(|low| Range { low: low, high: MAX })
|
if low > 0 { Ok(Range{ low: low, high: MAX}) } else { Err("invalid range") }
|
||||||
|
} else {
|
||||||
|
Err("invalid range")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
(Some(n), Some(m)) if n.len() == 0 => {
|
(Some(n), Some(m)) if n.len() == 0 => {
|
||||||
m.parse::<usize>().and_then(|high| if high >= 1 { Some(high) } else { None })
|
if let Ok(high) = m.parse::<usize>() {
|
||||||
.map(|high| Range { low: 1, high: high })
|
if high > 0 { Ok(Range{ low: 1, high: high}) } else { Err("invalid range") }
|
||||||
|
} else {
|
||||||
|
Err("invalid range")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
(Some(n), Some(m)) => {
|
(Some(n), Some(m)) => {
|
||||||
match (n.parse::<usize>(), m.parse::<usize>()) {
|
match (n.parse::<usize>(), m.parse::<usize>()) {
|
||||||
(Some(low), Some(high)) if low > 0 && low <= high => {
|
(Ok(low), Ok(high)) if low > 0 && low <= high => {
|
||||||
Some(Range { low: low, high: high })
|
Ok(Range { low: low, high: high })
|
||||||
}
|
}
|
||||||
_ => None
|
_ => Err("invalid range")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => unreachable!()
|
_ => unreachable!()
|
||||||
|
@ -55,8 +66,8 @@ impl Range {
|
||||||
|
|
||||||
for item in list.split(',') {
|
for item in list.split(',') {
|
||||||
match std::str::FromStr::from_str(item) {
|
match std::str::FromStr::from_str(item) {
|
||||||
Some(range_item) => ranges.push(range_item),
|
Ok(range_item) => ranges.push(range_item),
|
||||||
None => return Err(format!("range '{}' was invalid", item))
|
Err(e)=> return Err(format!("range '{}' was invalid: {}", item, e))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "dirname"]
|
#![crate_name = "dirname"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, path, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "du"]
|
#![crate_name = "du"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, path, rustc_private, std_misc, unicode)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -194,7 +194,7 @@ ers of 1000).",
|
||||||
let summarize = matches.opt_present("summarize");
|
let summarize = matches.opt_present("summarize");
|
||||||
|
|
||||||
let max_depth_str = matches.opt_str("max-depth");
|
let max_depth_str = matches.opt_str("max-depth");
|
||||||
let max_depth = max_depth_str.as_ref().and_then(|s| s.parse::<usize>());
|
let max_depth = max_depth_str.as_ref().and_then(|s| s.parse::<usize>().ok());
|
||||||
match (max_depth_str, max_depth) {
|
match (max_depth_str, max_depth) {
|
||||||
(Some(ref s), _) if summarize => {
|
(Some(ref s), _) if summarize => {
|
||||||
show_error!("summarizing conflicts with --max-depth={}", *s);
|
show_error!("summarizing conflicts with --max-depth={}", *s);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "echo"]
|
#![crate_name = "echo"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
2
src/env/env.rs
vendored
2
src/env/env.rs
vendored
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "env"]
|
#![crate_name = "env"]
|
||||||
#![allow(unstable)]
|
#![feature(core, io, os)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "expand"]
|
#![crate_name = "expand"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, path, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -33,7 +33,7 @@ fn tabstops_parse(s: String) -> Vec<usize> {
|
||||||
let nums = words.into_iter()
|
let nums = words.into_iter()
|
||||||
.map(|sn| sn.parse::<usize>()
|
.map(|sn| sn.parse::<usize>()
|
||||||
.unwrap_or_else(
|
.unwrap_or_else(
|
||||||
|| crash!(1, "{}\n", "tab size contains invalid character(s)"))
|
|_| crash!(1, "{}\n", "tab size contains invalid character(s)"))
|
||||||
)
|
)
|
||||||
.collect::<Vec<usize>>();
|
.collect::<Vec<usize>>();
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "factor"]
|
#![crate_name = "factor"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -58,8 +58,8 @@ fn print_factors(num: u64) {
|
||||||
|
|
||||||
fn print_factors_str(num_str: &str) {
|
fn print_factors_str(num_str: &str) {
|
||||||
let num = match num_str.parse::<u64>() {
|
let num = match num_str.parse::<u64>() {
|
||||||
Some(x) => x,
|
Ok(x) => x,
|
||||||
None => { crash!(1, "{} not a number", num_str); }
|
Err(e)=> { crash!(1, "{} not a number: {}", num_str, e); }
|
||||||
};
|
};
|
||||||
print_factors(num);
|
print_factors(num);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#![crate_name = "false"]
|
#![crate_name = "false"]
|
||||||
#![allow(unstable)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -146,8 +146,8 @@ pub fn uumain(args: Vec<String>) -> isize {
|
||||||
Some(s) => {
|
Some(s) => {
|
||||||
fmt_opts.width =
|
fmt_opts.width =
|
||||||
match s.parse::<usize>() {
|
match s.parse::<usize>() {
|
||||||
Some(t) => t,
|
Ok(t) => t,
|
||||||
None => { crash!(1, "Invalid WIDTH specification: `{}'", s); }
|
Err(e) => { crash!(1, "Invalid WIDTH specification: `{}': {}", s, e); }
|
||||||
};
|
};
|
||||||
fmt_opts.goal = cmp::min(fmt_opts.width * 94 / 100, fmt_opts.width - 3);
|
fmt_opts.goal = cmp::min(fmt_opts.width * 94 / 100, fmt_opts.width - 3);
|
||||||
}
|
}
|
||||||
|
@ -158,8 +158,8 @@ pub fn uumain(args: Vec<String>) -> isize {
|
||||||
Some(s) => {
|
Some(s) => {
|
||||||
fmt_opts.goal =
|
fmt_opts.goal =
|
||||||
match s.parse::<usize>() {
|
match s.parse::<usize>() {
|
||||||
Some(t) => t,
|
Ok(t) => t,
|
||||||
None => { crash!(1, "Invalid GOAL specification: `{}'", s); }
|
Err(e) => { crash!(1, "Invalid GOAL specification: `{}': {}", s, e); }
|
||||||
};
|
};
|
||||||
if !matches.opt_present("w") {
|
if !matches.opt_present("w") {
|
||||||
fmt_opts.width = cmp::max(fmt_opts.goal * 100 / 94, fmt_opts.goal + 3);
|
fmt_opts.width = cmp::max(fmt_opts.goal * 100 / 94, fmt_opts.goal + 3);
|
||||||
|
@ -174,8 +174,8 @@ pub fn uumain(args: Vec<String>) -> isize {
|
||||||
Some(s) => {
|
Some(s) => {
|
||||||
fmt_opts.tabwidth =
|
fmt_opts.tabwidth =
|
||||||
match s.parse::<usize>() {
|
match s.parse::<usize>() {
|
||||||
Some(t) => t,
|
Ok(t) => t,
|
||||||
None => { crash!(1, "Invalid TABWIDTH specification: `{}'", s); }
|
Err(e) => { crash!(1, "Invalid TABWIDTH specification: `{}': {}", s, e); }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
None => ()
|
None => ()
|
||||||
|
|
|
@ -31,7 +31,7 @@ fn char_width(c: char) -> usize {
|
||||||
|
|
||||||
// lines with PSKIP, lacking PREFIX, or which are entirely blank are
|
// lines with PSKIP, lacking PREFIX, or which are entirely blank are
|
||||||
// NoFormatLines; otherwise, they are FormatLines
|
// NoFormatLines; otherwise, they are FormatLines
|
||||||
#[derive(Show)]
|
#[derive(Debug)]
|
||||||
pub enum Line {
|
pub enum Line {
|
||||||
FormatLine(FileLine),
|
FormatLine(FileLine),
|
||||||
NoFormatLine(String, bool)
|
NoFormatLine(String, bool)
|
||||||
|
@ -57,7 +57,7 @@ impl Line {
|
||||||
|
|
||||||
// each line's prefix has to be considered to know whether to merge it with
|
// each line's prefix has to be considered to know whether to merge it with
|
||||||
// the next line or not
|
// the next line or not
|
||||||
#[derive(Show)]
|
#[derive(Debug)]
|
||||||
struct FileLine {
|
struct FileLine {
|
||||||
line : String,
|
line : String,
|
||||||
indent_end : usize, // the end of the indent, always the start of the text
|
indent_end : usize, // the end of the indent, always the start of the text
|
||||||
|
@ -198,7 +198,7 @@ impl<'a> Iterator for FileLines<'a> {
|
||||||
// plus info about the paragraph's indentation
|
// plus info about the paragraph's indentation
|
||||||
// (but we only retain the String from the FileLine; the other info
|
// (but we only retain the String from the FileLine; the other info
|
||||||
// is only there to help us in deciding how to merge lines into Paragraphs
|
// is only there to help us in deciding how to merge lines into Paragraphs
|
||||||
#[derive(Show)]
|
#[derive(Debug)]
|
||||||
pub struct Paragraph {
|
pub struct Paragraph {
|
||||||
lines : Vec<String>, // the lines of the file
|
lines : Vec<String>, // the lines of the file
|
||||||
pub init_str : String, // string representing the init, that is, the first line's indent
|
pub init_str : String, // string representing the init, that is, the first line's indent
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "fold"]
|
#![crate_name = "fold"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, path, rustc_private, unicode)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -64,8 +64,8 @@ pub fn uumain(args: Vec<String>) -> isize {
|
||||||
};
|
};
|
||||||
let width = match poss_width {
|
let width = match poss_width {
|
||||||
Some(inp_width) => match inp_width.parse::<usize>() {
|
Some(inp_width) => match inp_width.parse::<usize>() {
|
||||||
Some(width) => width,
|
Ok(width) => width,
|
||||||
None => crash!(1, "illegal width value (\"{}\")", inp_width)
|
Err(e) => crash!(1, "illegal width value (\"{}\"): {}", inp_width, e)
|
||||||
},
|
},
|
||||||
None => 80
|
None => 80
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "groups"]
|
#![crate_name = "groups"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "hashsum"]
|
#![crate_name = "hashsum"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, path, rustc_private, std_misc)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "head"]
|
#![crate_name = "head"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, path, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -71,18 +71,18 @@ pub fn uumain(args: Vec<String>) -> isize {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
match n.parse::<usize>() {
|
match n.parse::<usize>() {
|
||||||
Some(m) => { line_count = m }
|
Ok(m) => { line_count = m }
|
||||||
None => {
|
Err(e) => {
|
||||||
show_error!("invalid line count '{}'", n);
|
show_error!("invalid line count '{}': {}", n, e);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => match given_options.opt_str("c") {
|
None => match given_options.opt_str("c") {
|
||||||
Some(count) => match count.parse::<usize>() {
|
Some(count) => match count.parse::<usize>() {
|
||||||
Some(m) => byte_count = m,
|
Ok(m) => byte_count = m,
|
||||||
None => {
|
Err(e)=> {
|
||||||
show_error!("invalid byte count '{}'", count);
|
show_error!("invalid byte count '{}': {}", count, e);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -151,7 +151,7 @@ fn obsolete(options: &[String]) -> (Vec<String>, Option<usize>) {
|
||||||
// If this is the last number
|
// If this is the last number
|
||||||
if pos == len - 1 {
|
if pos == len - 1 {
|
||||||
options.remove(a);
|
options.remove(a);
|
||||||
let number: Option<usize> = from_utf8(¤t[1..len]).unwrap().parse::<usize>();
|
let number: Option<usize> = from_utf8(¤t[1..len]).unwrap().parse::<usize>().ok();
|
||||||
return (options, Some(number.unwrap()));
|
return (options, Some(number.unwrap()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "hostid"]
|
#![crate_name = "hostid"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, libc, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "hostname"]
|
#![crate_name = "hostname"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "id"]
|
#![crate_name = "id"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, libc, rustc_private, std_misc)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "kill"]
|
#![crate_name = "kill"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, rustc_private, unicode)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -109,13 +109,13 @@ fn handle_obsolete(mut args: Vec<String>) -> (Vec<String>, Option<String>) {
|
||||||
if slice.char_at(0) == '-' && slice.len() > 1 && slice.char_at(1).is_digit(10) {
|
if slice.char_at(0) == '-' && slice.len() > 1 && slice.char_at(1).is_digit(10) {
|
||||||
let val = &slice[1..];
|
let val = &slice[1..];
|
||||||
match val.parse() {
|
match val.parse() {
|
||||||
Some(num) => {
|
Ok(num) => {
|
||||||
if signals::is_signal(num) {
|
if signals::is_signal(num) {
|
||||||
args.remove(i);
|
args.remove(i);
|
||||||
return (args, Some(val.to_string()));
|
return (args, Some(val.to_string()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => break /* getopts will error out for us */
|
Err(_)=> break /* getopts will error out for us */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i += 1;
|
i += 1;
|
||||||
|
@ -194,7 +194,7 @@ fn kill(signalname: &str, pids: std::vec::Vec<String>) -> isize {
|
||||||
};
|
};
|
||||||
for pid in pids.iter() {
|
for pid in pids.iter() {
|
||||||
match pid.as_slice().parse() {
|
match pid.as_slice().parse() {
|
||||||
Some(x) => {
|
Ok(x) => {
|
||||||
let result = Process::kill(x, signal_value as isize);
|
let result = Process::kill(x, signal_value as isize);
|
||||||
match result {
|
match result {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
|
@ -204,7 +204,7 @@ fn kill(signalname: &str, pids: std::vec::Vec<String>) -> isize {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
None => crash!(EXIT_ERR, "failed to parse argument {}", pid)
|
Err(e) => crash!(EXIT_ERR, "failed to parse argument {}: {}", pid, e)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
status
|
status
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "link"]
|
#![crate_name = "link"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, path, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "logname"]
|
#![crate_name = "logname"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, rustc_private, std_misc)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "mkdir"]
|
#![crate_name = "mkdir"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, path, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -64,7 +64,7 @@ pub fn uumain(args: Vec<String>) -> isize {
|
||||||
let mode_match = matches.opts_str(&["mode".to_string()]);
|
let mode_match = matches.opts_str(&["mode".to_string()]);
|
||||||
let mode: FilePermission = if mode_match.is_some() {
|
let mode: FilePermission = if mode_match.is_some() {
|
||||||
let m = mode_match.unwrap();
|
let m = mode_match.unwrap();
|
||||||
let res: Option<u32> = from_str_radix(m.as_slice(), 8);
|
let res: Option<u32> = from_str_radix(m.as_slice(), 8).ok();
|
||||||
if res.is_some() {
|
if res.is_some() {
|
||||||
unsafe { std::mem::transmute(res.unwrap()) }
|
unsafe { std::mem::transmute(res.unwrap()) }
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "mkfifo"]
|
#![crate_name = "mkfifo"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, libc, rustc_private, std_misc)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -57,9 +57,9 @@ pub fn uumain(args: Vec<String>) -> isize {
|
||||||
|
|
||||||
let mode = match matches.opt_str("m") {
|
let mode = match matches.opt_str("m") {
|
||||||
Some(m) => match FromStrRadix::from_str_radix(m.as_slice(), 8) {
|
Some(m) => match FromStrRadix::from_str_radix(m.as_slice(), 8) {
|
||||||
Some(m) => m,
|
Ok(m) => m,
|
||||||
None => {
|
Err(e )=> {
|
||||||
show_error!("invalid mode");
|
show_error!("invalid mode: {}", e);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "mv"]
|
#![crate_name = "mv"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, path, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "nice"]
|
#![crate_name = "nice"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, libc, os, rustc_private, std_misc)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -80,9 +80,9 @@ pub fn uumain(args: Vec<String>) -> isize {
|
||||||
return 125;
|
return 125;
|
||||||
}
|
}
|
||||||
match nstr.as_slice().parse() {
|
match nstr.as_slice().parse() {
|
||||||
Some(num) => num,
|
Ok(num) => num,
|
||||||
None => {
|
Err(e)=> {
|
||||||
show_error!("\"{}\" is not a valid number", nstr);
|
show_error!("\"{}\" is not a valid number: {}", nstr, e);
|
||||||
return 125;
|
return 125;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ pub fn parse_options(settings: &mut ::Settings, opts: &getopts::Matches) -> Vec<
|
||||||
match opts.opt_str("i") {
|
match opts.opt_str("i") {
|
||||||
None => {}
|
None => {}
|
||||||
Some(val) => {
|
Some(val) => {
|
||||||
let conv: Option<u64> = val.as_slice().parse();
|
let conv: Option<u64> = val.as_slice().parse().ok();
|
||||||
match conv {
|
match conv {
|
||||||
None => {
|
None => {
|
||||||
errs.push(String::from_str("Illegal value for -i"));
|
errs.push(String::from_str("Illegal value for -i"));
|
||||||
|
@ -84,7 +84,7 @@ pub fn parse_options(settings: &mut ::Settings, opts: &getopts::Matches) -> Vec<
|
||||||
match opts.opt_str("w") {
|
match opts.opt_str("w") {
|
||||||
None => {}
|
None => {}
|
||||||
Some(val) => {
|
Some(val) => {
|
||||||
let conv: Option<usize> = val.as_slice().parse();
|
let conv: Option<usize> = val.as_slice().parse().ok();
|
||||||
match conv {
|
match conv {
|
||||||
None => {
|
None => {
|
||||||
errs.push(String::from_str("Illegal value for -w"));
|
errs.push(String::from_str("Illegal value for -w"));
|
||||||
|
@ -96,7 +96,7 @@ pub fn parse_options(settings: &mut ::Settings, opts: &getopts::Matches) -> Vec<
|
||||||
match opts.opt_str("v") {
|
match opts.opt_str("v") {
|
||||||
None => {}
|
None => {}
|
||||||
Some(val) => {
|
Some(val) => {
|
||||||
let conv: Option<u64> = val.as_slice().parse();
|
let conv: Option<u64> = val.as_slice().parse().ok();
|
||||||
match conv {
|
match conv {
|
||||||
None => {
|
None => {
|
||||||
errs.push(String::from_str("Illegal value for -v"));
|
errs.push(String::from_str("Illegal value for -v"));
|
||||||
|
@ -108,7 +108,7 @@ pub fn parse_options(settings: &mut ::Settings, opts: &getopts::Matches) -> Vec<
|
||||||
match opts.opt_str("l") {
|
match opts.opt_str("l") {
|
||||||
None => {}
|
None => {}
|
||||||
Some(val) => {
|
Some(val) => {
|
||||||
let conv: Option<u64> = val.as_slice().parse();
|
let conv: Option<u64> = val.as_slice().parse().ok();
|
||||||
match conv {
|
match conv {
|
||||||
None => {
|
None => {
|
||||||
errs.push(String::from_str("Illegal value for -l"));
|
errs.push(String::from_str("Illegal value for -l"));
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "nl"]
|
#![crate_name = "nl"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, path, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "nohup"]
|
#![crate_name = "nohup"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, os, path, rustc_private, std_misc)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "nproc"]
|
#![crate_name = "nproc"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, os, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -54,9 +54,9 @@ pub fn uumain(args: Vec<String>) -> isize {
|
||||||
|
|
||||||
let mut ignore = match matches.opt_str("ignore") {
|
let mut ignore = match matches.opt_str("ignore") {
|
||||||
Some(numstr) => match numstr.parse() {
|
Some(numstr) => match numstr.parse() {
|
||||||
Some(num) => num,
|
Ok(num) => num,
|
||||||
None => {
|
Err(e) => {
|
||||||
show_error!("\"{}\" is not a valid number", numstr);
|
show_error!("\"{}\" is not a valid number: {}", numstr, e);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -66,8 +66,8 @@ pub fn uumain(args: Vec<String>) -> isize {
|
||||||
if !matches.opt_present("all") {
|
if !matches.opt_present("all") {
|
||||||
ignore += match os::getenv("OMP_NUM_THREADS") {
|
ignore += match os::getenv("OMP_NUM_THREADS") {
|
||||||
Some(threadstr) => match threadstr.parse() {
|
Some(threadstr) => match threadstr.parse() {
|
||||||
Some(num) => num,
|
Ok(num) => num,
|
||||||
None => 0
|
Err(_)=> 0
|
||||||
},
|
},
|
||||||
None => 0
|
None => 0
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "od"]
|
#![crate_name = "od"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, path, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -16,7 +16,7 @@ extern crate collections;
|
||||||
use collections::string::String;
|
use collections::string::String;
|
||||||
use std::old_io::File;
|
use std::old_io::File;
|
||||||
|
|
||||||
#[derive(Show)]
|
#[derive(Debug)]
|
||||||
enum Radix { Decimal, Hexadecimal, Octal, Binary }
|
enum Radix { Decimal, Hexadecimal, Octal, Binary }
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> isize {
|
pub fn uumain(args: Vec<String>) -> isize {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "paste"]
|
#![crate_name = "paste"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, path, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "printenv"]
|
#![crate_name = "printenv"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, os, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "pwd"]
|
#![crate_name = "pwd"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, os, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "readlink"]
|
#![crate_name = "readlink"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, os, path, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name= "realpath"]
|
#![crate_name= "realpath"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, os, path, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "relpath"]
|
#![crate_name = "relpath"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, libc, os, path, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "rm"]
|
#![crate_name = "rm"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, path, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "rmdir"]
|
#![crate_name = "rmdir"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, path, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "seq"]
|
#![crate_name = "seq"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, libc, rustc_private)]
|
||||||
|
|
||||||
// TODO: Make -w flag work with decimals
|
// TODO: Make -w flag work with decimals
|
||||||
// TODO: Support -f flag
|
// TODO: Support -f flag
|
||||||
|
@ -27,8 +27,8 @@ fn parse_float(mut s: &str) -> Result<f64, String> {
|
||||||
s = &s[1..];
|
s = &s[1..];
|
||||||
}
|
}
|
||||||
match s.parse() {
|
match s.parse() {
|
||||||
Some(n) => Ok(n),
|
Ok(n) => Ok(n),
|
||||||
None => Err(format!("seq: invalid floating point argument: {}", s))
|
Err(e) => Err(format!("seq: invalid floating point argument `{}`: {}", s, e))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "shuf"]
|
#![crate_name = "shuf"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, path, rand, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -97,9 +97,9 @@ With no FILE, or when FILE is -, read standard input.",
|
||||||
let zero = matches.opt_present("zero-terminated");
|
let zero = matches.opt_present("zero-terminated");
|
||||||
let count = match matches.opt_str("head-count") {
|
let count = match matches.opt_str("head-count") {
|
||||||
Some(cnt) => match cnt.parse::<usize>() {
|
Some(cnt) => match cnt.parse::<usize>() {
|
||||||
Some(val) => val,
|
Ok(val) => val,
|
||||||
None => {
|
Err(e) => {
|
||||||
show_error!("'{}' is not a valid count", cnt);
|
show_error!("'{}' is not a valid count: {}", cnt, e);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -192,12 +192,12 @@ fn parse_range(input_range: String) -> Result<RangeInclusive<usize>, (String, is
|
||||||
Err(("invalid range format".to_string(), 1))
|
Err(("invalid range format".to_string(), 1))
|
||||||
} else {
|
} else {
|
||||||
let begin = match split[0].parse::<usize>() {
|
let begin = match split[0].parse::<usize>() {
|
||||||
Some(m) => m,
|
Ok(m) => m,
|
||||||
None => return Err((format!("{} is not a valid number", split[0]), 1))
|
Err(e)=> return Err((format!("{} is not a valid number: {}", split[0], e), 1))
|
||||||
};
|
};
|
||||||
let end = match split[1].parse::<usize>() {
|
let end = match split[1].parse::<usize>() {
|
||||||
Some(m) => m,
|
Ok(m) => m,
|
||||||
None => return Err((format!("{} is not a valid number", split[1]), 1))
|
Err(e)=> return Err((format!("{} is not a valid number: {}", split[1], e), 1))
|
||||||
};
|
};
|
||||||
Ok(range_inclusive(begin, end))
|
Ok(range_inclusive(begin, end))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "sleep"]
|
#![crate_name = "sleep"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, rustc_private, std_misc)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "sort"]
|
#![crate_name = "sort"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, path, rustc_private, unicode)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -146,7 +146,7 @@ fn frac_compare(a: &String, b: &String) -> Ordering {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn print_sorted<S, T: Iterator<Item=S>>(mut iter: T) where S: std::fmt::Display {
|
fn print_sorted<S, T: Iterator<Item=S>>(iter: T) where S: std::fmt::Display {
|
||||||
for line in iter {
|
for line in iter {
|
||||||
print!("{}", line);
|
print!("{}", line);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "split"]
|
#![crate_name = "split"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, path, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -72,8 +72,8 @@ pub fn uumain(args: Vec<String>) -> isize {
|
||||||
|
|
||||||
settings.suffix_length = match matches.opt_str("a") {
|
settings.suffix_length = match matches.opt_str("a") {
|
||||||
Some(n) => match n.as_slice().parse() {
|
Some(n) => match n.as_slice().parse() {
|
||||||
Some(m) => m,
|
Ok(m) => m,
|
||||||
None => crash!(1, "cannot parse num")
|
Err(e) => crash!(1, "cannot parse num: {}", e)
|
||||||
},
|
},
|
||||||
None => 2
|
None => 2
|
||||||
};
|
};
|
||||||
|
@ -136,8 +136,8 @@ struct LineSplitter {
|
||||||
impl LineSplitter {
|
impl LineSplitter {
|
||||||
fn new(settings: &Settings) -> Box<Splitter> {
|
fn new(settings: &Settings) -> Box<Splitter> {
|
||||||
let n = match settings.strategy_param.as_slice().parse() {
|
let n = match settings.strategy_param.as_slice().parse() {
|
||||||
Some(a) => a,
|
Ok(a) => a,
|
||||||
_ => crash!(1, "invalid number of lines")
|
Err(e) => crash!(1, "invalid number of lines: {}", e)
|
||||||
};
|
};
|
||||||
Box::new(LineSplitter {
|
Box::new(LineSplitter {
|
||||||
saved_lines_to_write: n,
|
saved_lines_to_write: n,
|
||||||
|
@ -178,13 +178,13 @@ impl ByteSplitter {
|
||||||
};
|
};
|
||||||
let n = if suffix.is_alphabetic() {
|
let n = if suffix.is_alphabetic() {
|
||||||
match strategy_param.as_slice().iter().map(|c| *c).collect::<String>().as_slice().parse::<usize>() {
|
match strategy_param.as_slice().iter().map(|c| *c).collect::<String>().as_slice().parse::<usize>() {
|
||||||
Some(a) => a,
|
Ok(a) => a,
|
||||||
_ => crash!(1, "invalid number of bytes")
|
Err(e) => crash!(1, "invalid number of bytes: {}", e)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
match settings.strategy_param.as_slice().parse::<usize>() {
|
match settings.strategy_param.as_slice().parse::<usize>() {
|
||||||
Some(a) => a,
|
Ok(a) => a,
|
||||||
_ => crash!(1, "invalid number of bytes")
|
Err(e) => crash!(1, "invalid number of bytes: {}", e)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Box::new(ByteSplitter {
|
Box::new(ByteSplitter {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#![crate_name = "libstdbuf"]
|
#![crate_name = "libstdbuf"]
|
||||||
#![crate_type = "staticlib"]
|
#![crate_type = "staticlib"]
|
||||||
#![allow(unstable)]
|
#![feature(core, libc, os)]
|
||||||
|
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
use libc::{c_int, size_t, c_char, FILE, _IOFBF, _IONBF, _IOLBF, setvbuf};
|
use libc::{c_int, size_t, c_char, FILE, _IOFBF, _IONBF, _IOLBF, setvbuf};
|
||||||
|
@ -25,8 +25,8 @@ fn set_buffer(stream: *mut FILE, value: &str) {
|
||||||
"L" => (_IOLBF, 0 as size_t),
|
"L" => (_IOLBF, 0 as size_t),
|
||||||
input => {
|
input => {
|
||||||
let buff_size: usize = match input.parse() {
|
let buff_size: usize = match input.parse() {
|
||||||
Some(num) => num,
|
Ok(num) => num,
|
||||||
None => crash!(1, "incorrect size of buffer!")
|
Err(e) => crash!(1, "incorrect size of buffer!: {}", e)
|
||||||
};
|
};
|
||||||
(_IOFBF, buff_size as size_t)
|
(_IOFBF, buff_size as size_t)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "stdbuf"]
|
#![crate_name = "stdbuf"]
|
||||||
#![allow(unstable)]
|
#![feature(core, io, libc, os, path, rustc_private, unicode)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -97,7 +97,7 @@ fn parse_size(size: &str) -> Option<u64> {
|
||||||
if recovered.as_slice() != size {
|
if recovered.as_slice() != size {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let buf_size: u64 = match num.parse() {
|
let buf_size: u64 = match num.parse().ok() {
|
||||||
Some(m) => m,
|
Some(m) => m,
|
||||||
None => return None,
|
None => return None,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "sum"]
|
#![crate_name = "sum"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, path, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "sync"]
|
#![crate_name = "sync"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, libc, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "tac"]
|
#![crate_name = "tac"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, path, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "tail"]
|
#![crate_name = "tail"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, path, rustc_private, std_misc)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -73,7 +73,7 @@ pub fn uumain(args: Vec<String>) -> isize {
|
||||||
if follow {
|
if follow {
|
||||||
match given_options.opt_str("s") {
|
match given_options.opt_str("s") {
|
||||||
Some(n) => {
|
Some(n) => {
|
||||||
let parsed: Option<u64> = n.parse();
|
let parsed: Option<u64> = n.parse().ok();
|
||||||
match parsed {
|
match parsed {
|
||||||
Some(m) => { sleep_msec = m * 1000 }
|
Some(m) => { sleep_msec = m * 1000 }
|
||||||
None => {}
|
None => {}
|
||||||
|
@ -196,8 +196,8 @@ fn parse_size(mut size_slice: &str) -> Option<usize> {
|
||||||
} else {
|
} else {
|
||||||
let value = size_slice.parse();
|
let value = size_slice.parse();
|
||||||
match value {
|
match value {
|
||||||
Some(v) => Some(multiplier * v),
|
Ok(v) => Some(multiplier * v),
|
||||||
None => None
|
_ => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -224,7 +224,7 @@ fn obsolete(options: &[String]) -> (Vec<String>, Option<usize>) {
|
||||||
// If this is the last number
|
// If this is the last number
|
||||||
if pos == len - 1 {
|
if pos == len - 1 {
|
||||||
options.remove(a);
|
options.remove(a);
|
||||||
let number: Option<usize> = from_utf8(¤t[1..len]).unwrap().parse();
|
let number: Option<usize> = from_utf8(¤t[1..len]).unwrap().parse().ok();
|
||||||
return (options, Some(number.unwrap()));
|
return (options, Some(number.unwrap()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -242,7 +242,7 @@ macro_rules! tail_impl (
|
||||||
// count lines/chars. When reaching the end of file, output the data in the
|
// count lines/chars. When reaching the end of file, output the data in the
|
||||||
// ringbuf.
|
// ringbuf.
|
||||||
let mut ringbuf: RingBuf<$kind> = RingBuf::new();
|
let mut ringbuf: RingBuf<$kind> = RingBuf::new();
|
||||||
let mut data = $reader.$kindfn().skip(
|
let data = $reader.$kindfn().skip(
|
||||||
if $beginning {
|
if $beginning {
|
||||||
let temp = $count;
|
let temp = $count;
|
||||||
$count = ::std::usize::MAX;
|
$count = ::std::usize::MAX;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "tee"]
|
#![crate_name = "tee"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, path, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "test"]
|
#![crate_name = "test"]
|
||||||
#![allow(unstable)]
|
#![feature(core, libc, os, std_misc)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -127,7 +127,7 @@ fn integers(a: &[u8], b: &[u8], cond: IntegerCondition) -> bool {
|
||||||
_ => return false,
|
_ => return false,
|
||||||
};
|
};
|
||||||
let (a, b): (i64, i64) = match (a.parse(), b.parse()) {
|
let (a, b): (i64, i64) = match (a.parse(), b.parse()) {
|
||||||
(Some(a), Some(b)) => (a, b),
|
(Ok(a), Ok(b)) => (a, b),
|
||||||
_ => return false,
|
_ => return false,
|
||||||
};
|
};
|
||||||
match cond {
|
match cond {
|
||||||
|
@ -142,7 +142,7 @@ fn integers(a: &[u8], b: &[u8], cond: IntegerCondition) -> bool {
|
||||||
|
|
||||||
fn isatty(fd: &[u8]) -> bool {
|
fn isatty(fd: &[u8]) -> bool {
|
||||||
use libc::{isatty};
|
use libc::{isatty};
|
||||||
from_utf8(fd).ok().and_then(|s| s.parse())
|
from_utf8(fd).ok().and_then(|s| s.parse().ok())
|
||||||
.map(|i| unsafe { isatty(i) == 1 }).unwrap_or(false)
|
.map(|i| unsafe { isatty(i) == 1 }).unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "timeout"]
|
#![crate_name = "timeout"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "touch"]
|
#![crate_name = "touch"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, path, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "tr"]
|
#![crate_name = "tr"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#![crate_name= "true"]
|
#![crate_name= "true"]
|
||||||
#![allow(unstable)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "truncate"]
|
#![crate_name = "truncate"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, path, rustc_private, std_misc)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -186,9 +186,9 @@ fn parse_size(size: &str) -> (u64, TruncateMode) {
|
||||||
slice
|
slice
|
||||||
}.to_string();
|
}.to_string();
|
||||||
let mut number: u64 = match bytes.as_slice().parse() {
|
let mut number: u64 = match bytes.as_slice().parse() {
|
||||||
Some(num) => num,
|
Ok(num) => num,
|
||||||
None => {
|
Err(e) => {
|
||||||
crash!(1, "'{}' is not a valid number.", size)
|
crash!(1, "'{}' is not a valid number: {}", size, e)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if size.char_at(size.len() - 1).is_alphabetic() {
|
if size.char_at(size.len() - 1).is_alphabetic() {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "tsort"]
|
#![crate_name = "tsort"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, path, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "tty"]
|
#![crate_name = "tty"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, rustc_private, std_misc)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "uname"]
|
#![crate_name = "uname"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, rustc_private, std_misc)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "unexpand"]
|
#![crate_name = "unexpand"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, path, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -30,7 +30,7 @@ fn tabstops_parse(s: String) -> Vec<usize> {
|
||||||
let nums = words.into_iter()
|
let nums = words.into_iter()
|
||||||
.map(|sn| sn.parse()
|
.map(|sn| sn.parse()
|
||||||
.unwrap_or_else(
|
.unwrap_or_else(
|
||||||
|| crash!(1, "{}\n", "tab size contains invalid character(s)"))
|
|_| crash!(1, "{}\n", "tab size contains invalid character(s)"))
|
||||||
)
|
)
|
||||||
.collect::<Vec<usize>>();
|
.collect::<Vec<usize>>();
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "uniq"]
|
#![crate_name = "uniq"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, path, rustc_private, std_misc)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -113,7 +113,7 @@ impl Uniq {
|
||||||
|
|
||||||
fn opt_parsed<T: FromStr>(opt_name: &str, matches: &getopts::Matches) -> Option<T> {
|
fn opt_parsed<T: FromStr>(opt_name: &str, matches: &getopts::Matches) -> Option<T> {
|
||||||
matches.opt_str(opt_name).map(|arg_str| {
|
matches.opt_str(opt_name).map(|arg_str| {
|
||||||
let opt_val: Option<T> = arg_str.parse();
|
let opt_val: Option<T> = arg_str.parse().ok();
|
||||||
opt_val.unwrap_or_else(||
|
opt_val.unwrap_or_else(||
|
||||||
crash!(1, "Invalid argument for {}: {}", opt_name, arg_str))
|
crash!(1, "Invalid argument for {}: {}", opt_name, arg_str))
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "unlink"]
|
#![crate_name = "unlink"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, path, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "uptime"]
|
#![crate_name = "uptime"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, path, rustc_private, std_misc)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -181,8 +181,8 @@ fn get_uptime(boot_time: Option<time_t>) -> i64 {
|
||||||
|
|
||||||
match uptime_text.as_slice().words().next() {
|
match uptime_text.as_slice().words().next() {
|
||||||
Some(s) => match s.replace(".", "").as_slice().parse() {
|
Some(s) => match s.replace(".", "").as_slice().parse() {
|
||||||
Some(n) => n,
|
Ok(n) => n,
|
||||||
None => -1
|
Err(_) => -1
|
||||||
},
|
},
|
||||||
None => -1
|
None => -1
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "users"]
|
#![crate_name = "users"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, rustc_private, std_misc)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "uutils"]
|
#![crate_name = "uutils"]
|
||||||
#![allow(unstable)]
|
#![feature(core, os, path, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "wc"]
|
#![crate_name = "wc"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, path, rustc_private, std_misc)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "whoami"]
|
#![crate_name = "whoami"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, rustc_private, std_misc)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "yes"]
|
#![crate_name = "yes"]
|
||||||
#![allow(unstable)]
|
#![feature(collections, core, io, libc, rustc_private)]
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue