mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-02 14:07:46 +00:00
Update tty's options to conform to GNU version.
This commit is contained in:
parent
e002caedc3
commit
6de22f91a9
1 changed files with 41 additions and 35 deletions
|
@ -15,8 +15,9 @@
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
|
use getopts::{getopts, optflag};
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
use getopts::{optflag,getopts};
|
use std::io::Write;
|
||||||
|
|
||||||
#[path = "../common/util.rs"]
|
#[path = "../common/util.rs"]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
@ -28,23 +29,31 @@ extern {
|
||||||
}
|
}
|
||||||
|
|
||||||
static NAME: &'static str = "tty";
|
static NAME: &'static str = "tty";
|
||||||
|
static VERSION: &'static str = "1.0.0";
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> i32 {
|
pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let options = [
|
let options = [
|
||||||
optflag("s", "silent", "print nothing, only return an exit status")
|
optflag("s", "silent", "print nothing, only return an exit status"),
|
||||||
|
optflag("h", "help", "display this help and exit"),
|
||||||
|
optflag("V", "version", "output version information and exit")
|
||||||
];
|
];
|
||||||
|
|
||||||
let silent = match getopts(&args[1..], &options) {
|
let matches = match getopts(&args[1..], &options) {
|
||||||
Ok(m) => {
|
Ok(m) => m,
|
||||||
m.opt_present("s")
|
|
||||||
},
|
|
||||||
Err(f) => {
|
Err(f) => {
|
||||||
println!("{}", f);
|
crash!(2, "{}", f)
|
||||||
usage();
|
|
||||||
return 2;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if matches.opt_present("help") {
|
||||||
|
let usage = getopts::usage("Print the file name of the terminal connected to standard input.", &options);
|
||||||
|
|
||||||
|
println!("Usage: {} [OPTION]...\n{}", NAME, usage);
|
||||||
|
} else if matches.opt_present("version") {
|
||||||
|
println!("{} {}", NAME, VERSION);
|
||||||
|
} else {
|
||||||
|
let silent = matches.opt_present("s");
|
||||||
|
|
||||||
let tty = unsafe {
|
let tty = unsafe {
|
||||||
let ptr = ttyname(libc::STDIN_FILENO);
|
let ptr = ttyname(libc::STDIN_FILENO);
|
||||||
if !ptr.is_null() {
|
if !ptr.is_null() {
|
||||||
|
@ -62,17 +71,14 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let exit_code = unsafe {
|
return unsafe {
|
||||||
if isatty(libc::STDIN_FILENO) == 1 {
|
if isatty(libc::STDIN_FILENO) == 1 {
|
||||||
libc::EXIT_SUCCESS
|
libc::EXIT_SUCCESS
|
||||||
} else {
|
} else {
|
||||||
libc::EXIT_FAILURE
|
libc::EXIT_FAILURE
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
exit_code
|
0
|
||||||
}
|
|
||||||
|
|
||||||
fn usage() {
|
|
||||||
println!("usage: {} [-s]", NAME);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue