1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

Merge pull request #243 from Arcterus/sleep-inf

Fix some errors brought up by vi
This commit is contained in:
Jordi Boggiano 2014-06-15 09:35:22 +02:00
commit 8519927481
2 changed files with 24 additions and 8 deletions

View file

@ -24,24 +24,37 @@ use c_types::{get_pw_from_args, group};
#[path = "../common/c_types.rs"] mod c_types;
static NAME: &'static str = "groups";
static VERSION: &'static str = "1.0.0";
#[allow(dead_code)]
fn main () { os::set_exit_status(uumain(os::args())); }
pub fn uumain(args: Vec<String>) -> int {
let program = args.get(0).clone();
let options = [
optflag("h", "", "Help")
];
optflag("h", "help", "display this help menu and exit"),
optflag("V", "version", "display version information and exit")
];
let matches = match getopts(args.tail(), options) {
Ok(m) => { m },
Err(_) => {
show_error!("{}", usage(NAME, options));
Err(f) => {
show_error!("{}", f.to_err_msg());
return 1;
}
};
group(get_pw_from_args(&matches.free), true);
if matches.opt_present("version") {
println!("{} v{}", NAME, VERSION);
} else if matches.opt_present("help") {
print!("{} v{}\n\n\
Usage:\n \
{} [OPTION]... [USER]...\n\n\
{}", NAME, VERSION, program, usage("Prints the groups a user is in to standard output.", options));
} else {
group(get_pw_from_args(&matches.free), true);
}
0
}

View file

@ -14,9 +14,10 @@
extern crate getopts;
extern crate libc;
use std::num;
use std::f64;
use std::os;
use std::io::{print, timer};
use std::u64;
#[path = "../common/util.rs"]
mod util;
@ -79,7 +80,7 @@ fn sleep(args: Vec<String>) {
if suffix_time == 0 {
0.0
} else {
match num::from_str_radix::<f64>((arg.as_slice()), 10) {
match from_str::<f64>(arg.as_slice()) {
Some(m) => m,
None => {
crash!(1, "Invalid time interval '{}'", arg.to_string())
@ -88,7 +89,7 @@ fn sleep(args: Vec<String>) {
};
result + num * suffix_time as f64
});
timer::sleep((sleep_time * 1000.0) as u64);
timer::sleep(if sleep_time == f64::INFINITY { u64::MAX } else { (sleep_time * 1000.0) as u64 });
}
fn match_suffix(arg: &str) -> Result<(String, int), String> {
@ -100,6 +101,8 @@ fn match_suffix(arg: &str) -> Result<(String, int), String> {
val => {
if !val.is_alphabetic() {
return Ok((arg.to_string(), 1))
} else if arg == "inf" || arg == "infinity" {
return Ok(("inf".to_string(), 1))
} else {
return Err(format!("Invalid time interval '{}'", arg))
}