mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
stty: add ispeed/ospeed settings (#8180)
* stty: add ispeed/ospeed settings * stty: fix spell check errors
This commit is contained in:
parent
98e3852b40
commit
6023888363
2 changed files with 83 additions and 6 deletions
|
@ -3,7 +3,7 @@
|
|||
// For the full copyright and license information, please view the LICENSE
|
||||
// file that was distributed with this source code.
|
||||
|
||||
// spell-checker:ignore clocal erange tcgetattr tcsetattr tcsanow tiocgwinsz tiocswinsz cfgetospeed cfsetospeed ushort vmin vtime cflag lflag
|
||||
// spell-checker:ignore clocal erange tcgetattr tcsetattr tcsanow tiocgwinsz tiocswinsz cfgetospeed cfsetospeed ushort vmin vtime cflag lflag ispeed ospeed
|
||||
|
||||
mod flags;
|
||||
|
||||
|
@ -250,6 +250,23 @@ fn stty(opts: &Options) -> UResult<()> {
|
|||
} else {
|
||||
return Err(USimpleError::new(1, format!("missing argument to '{arg}'")));
|
||||
}
|
||||
// ispeed/ospeed baud rate setting
|
||||
} else if *arg == "ispeed" || *arg == "ospeed" {
|
||||
match args_iter.next() {
|
||||
Some(speed) => {
|
||||
if let Some(baud_flag) = string_to_baud(speed) {
|
||||
valid_args.push(ArgOptions::Flags(baud_flag));
|
||||
} else {
|
||||
return Err(USimpleError::new(1, format!("invalid {arg} '{speed}'")));
|
||||
}
|
||||
}
|
||||
None => {
|
||||
return Err(USimpleError::new(1, format!("missing argument to '{arg}'")));
|
||||
}
|
||||
}
|
||||
// baud rate setting
|
||||
} else if let Some(baud_flag) = string_to_baud(arg) {
|
||||
valid_args.push(ArgOptions::Flags(baud_flag));
|
||||
// non control char flag
|
||||
} else if let Some(flag) = string_to_flag(arg) {
|
||||
let remove_group = match flag {
|
||||
|
@ -356,8 +373,7 @@ fn cc_to_index(option: &str) -> Option<SpecialCharacterIndices> {
|
|||
None
|
||||
}
|
||||
|
||||
// return Some(flag) if the input is a valid flag, None if not
|
||||
fn string_to_flag(option: &str) -> Option<AllFlags> {
|
||||
fn string_to_baud(arg: &str) -> Option<AllFlags> {
|
||||
// BSDs use a u32 for the baud rate, so any decimal number applies.
|
||||
#[cfg(any(
|
||||
target_os = "freebsd",
|
||||
|
@ -367,7 +383,7 @@ fn string_to_flag(option: &str) -> Option<AllFlags> {
|
|||
target_os = "netbsd",
|
||||
target_os = "openbsd"
|
||||
))]
|
||||
if let Ok(n) = option.parse::<u32>() {
|
||||
if let Ok(n) = arg.parse::<u32>() {
|
||||
return Some(AllFlags::Baud(n));
|
||||
}
|
||||
|
||||
|
@ -380,11 +396,15 @@ fn string_to_flag(option: &str) -> Option<AllFlags> {
|
|||
target_os = "openbsd"
|
||||
)))]
|
||||
for (text, baud_rate) in BAUD_RATES {
|
||||
if *text == option {
|
||||
if *text == arg {
|
||||
return Some(AllFlags::Baud(*baud_rate));
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
// return Some(flag) if the input is a valid flag, None if not
|
||||
fn string_to_flag(option: &str) -> Option<AllFlags> {
|
||||
let remove = option.starts_with('-');
|
||||
let name = option.trim_start_matches('-');
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
//
|
||||
// For the full copyright and license information, please view the LICENSE
|
||||
// file that was distributed with this source code.
|
||||
// spell-checker:ignore parenb parmrk ixany iuclc onlcr ofdel icanon noflsh econl igpar
|
||||
// spell-checker:ignore parenb parmrk ixany iuclc onlcr ofdel icanon noflsh econl igpar ispeed ospeed
|
||||
|
||||
use uutests::new_ucmd;
|
||||
use uutests::util::TestScenario;
|
||||
|
@ -110,3 +110,60 @@ fn invalid_setting() {
|
|||
.fails()
|
||||
.stderr_contains("invalid argument 'igpar'");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_baud_setting() {
|
||||
#[cfg(not(any(
|
||||
target_os = "freebsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "ios",
|
||||
target_os = "macos",
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd"
|
||||
)))]
|
||||
new_ucmd!()
|
||||
.args(&["100"])
|
||||
.fails()
|
||||
.stderr_contains("invalid argument '100'");
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["-1"])
|
||||
.fails()
|
||||
.stderr_contains("invalid argument '-1'");
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["ispeed"])
|
||||
.fails()
|
||||
.stderr_contains("missing argument to 'ispeed'");
|
||||
|
||||
new_ucmd!()
|
||||
.args(&["ospeed"])
|
||||
.fails()
|
||||
.stderr_contains("missing argument to 'ospeed'");
|
||||
|
||||
#[cfg(not(any(
|
||||
target_os = "freebsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "ios",
|
||||
target_os = "macos",
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd"
|
||||
)))]
|
||||
new_ucmd!()
|
||||
.args(&["ispeed", "995"])
|
||||
.fails()
|
||||
.stderr_contains("invalid ispeed '995'");
|
||||
|
||||
#[cfg(not(any(
|
||||
target_os = "freebsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "ios",
|
||||
target_os = "macos",
|
||||
target_os = "netbsd",
|
||||
target_os = "openbsd"
|
||||
)))]
|
||||
new_ucmd!()
|
||||
.args(&["ospeed", "995"])
|
||||
.fails()
|
||||
.stderr_contains("invalid ospeed '995'");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue