Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/uu/stty/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ doctest = false
[target.'cfg(unix)'.dependencies]
clap = { workspace = true }
fluent = { workspace = true }
nix = { workspace = true, features = ["ioctl", "term"] }
libc = { workspace = true }
rustix = { workspace = true, features = ["fs", "termios"] }
uucore = { workspace = true, features = ["parser"] }

Expand Down
178 changes: 83 additions & 95 deletions src/uu/stty/src/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
// spell-checker:ignore lnext rprnt susp swtch vdiscard veof veol verase vintr vkill vlnext vquit vreprint vstart vstop vsusp vswtc vwerase werase
// spell-checker:ignore sigquit sigtstp
// spell-checker:ignore cbreak decctlq evenp litout oddp
// spell-checker:ignore VDSUSP VMIN VSTATUS VTIME VSWTCH

use crate::Flag;

#[cfg(not(bsd))]
use nix::sys::termios::BaudRate;
use nix::sys::termios::{
ControlFlags as C, InputFlags as I, LocalFlags as L, OutputFlags as O,
SpecialCharacterIndices as S,
use rustix::termios::{
ControlModes as C, InputModes as I, LocalModes as L, OutputModes as O, SpecialCodeIndex as S,
};

#[derive(Debug)]
Expand All @@ -31,10 +29,7 @@ pub enum BaudType {
#[derive(Debug)]
#[cfg_attr(test, derive(PartialEq))]
pub enum AllFlags<'a> {
#[cfg(bsd)]
Baud(u32, BaudType),
#[cfg(not(bsd))]
Baud(BaudRate, BaudType),
ControlFlags((&'a Flag<C>, bool)),
InputFlags((&'a Flag<I>, bool)),
LocalFlags((&'a Flag<L>, bool)),
Expand Down Expand Up @@ -84,6 +79,15 @@ pub const INPUT_FLAGS: &[Flag<I>] = &[
Flag::new("iutf8", I::IUTF8),
];

// workaround for unexposed const of OutputModes <https://github.com/bytecodealliance/rustix/issues/1706>
#[allow(unused_macros)]
macro_rules! o {
($val:expr) => {
O::from_bits_retain($val as _)
};
}

#[allow(clippy::unnecessary_cast)]
pub const OUTPUT_FLAGS: &[Flag<O>] = &[
Flag::new("opost", O::OPOST).sane(),
#[cfg(any(
Expand All @@ -103,49 +107,49 @@ pub const OUTPUT_FLAGS: &[Flag<O>] = &[
target_os = "haiku",
target_os = "linux"
))]
Flag::new("ofdel", O::OFDEL),
Flag::new("ofdel", o!(libc::OFDEL)),
#[cfg(any(
target_vendor = "apple",
target_os = "android",
target_os = "haiku",
target_os = "linux"
))]
Flag::new_grouped("nl0", O::NL0, O::NLDLY).sane(),
Flag::new_grouped("nl0", o!(libc::NL0), o!(libc::NLDLY)).sane(),
#[cfg(any(
target_vendor = "apple",
target_os = "android",
target_os = "haiku",
target_os = "linux"
))]
Flag::new_grouped("nl1", O::NL1, O::NLDLY),
Flag::new_grouped("nl1", o!(libc::NL1), o!(libc::NLDLY)),
#[cfg(any(
target_vendor = "apple",
target_os = "android",
target_os = "haiku",
target_os = "linux"
))]
Flag::new_grouped("cr0", O::CR0, O::CRDLY).sane(),
Flag::new_grouped("cr0", o!(libc::CR0), o!(libc::CRDLY)).sane(),
#[cfg(any(
target_vendor = "apple",
target_os = "android",
target_os = "haiku",
target_os = "linux"
))]
Flag::new_grouped("cr1", O::CR1, O::CRDLY),
Flag::new_grouped("cr1", o!(libc::CR1), o!(libc::CRDLY)),
#[cfg(any(
target_vendor = "apple",
target_os = "android",
target_os = "haiku",
target_os = "linux"
))]
Flag::new_grouped("cr2", O::CR2, O::CRDLY),
Flag::new_grouped("cr2", o!(libc::CR2), o!(libc::CRDLY)),
#[cfg(any(
target_vendor = "apple",
target_os = "android",
target_os = "haiku",
target_os = "linux"
))]
Flag::new_grouped("cr3", O::CR3, O::CRDLY),
Flag::new_grouped("cr3", o!(libc::CR3), o!(libc::CRDLY)),
#[cfg(any(
target_vendor = "apple",
target_os = "android",
Expand All @@ -159,63 +163,63 @@ pub const OUTPUT_FLAGS: &[Flag<O>] = &[
target_os = "haiku",
target_os = "linux"
))]
Flag::new_grouped("tab1", O::TAB1, O::TABDLY),
Flag::new_grouped("tab1", o!(libc::TAB1), O::TABDLY),
#[cfg(any(
target_vendor = "apple",
target_os = "android",
target_os = "haiku",
target_os = "linux"
))]
Flag::new_grouped("tab2", O::TAB2, O::TABDLY),
Flag::new_grouped("tab2", o!(libc::TAB2), O::TABDLY),
#[cfg(any(
target_vendor = "apple",
target_os = "android",
target_os = "haiku",
target_os = "linux"
))]
Flag::new_grouped("tab3", O::TAB3, O::TABDLY),
Flag::new_grouped("tab3", o!(libc::TAB3), o!(libc::BSDLY)),
#[cfg(any(
target_vendor = "apple",
target_os = "android",
target_os = "haiku",
target_os = "linux"
))]
Flag::new_grouped("bs0", O::BS0, O::BSDLY).sane(),
Flag::new_grouped("bs0", o!(libc::BS0), o!(libc::BSDLY)).sane(),
#[cfg(any(
target_vendor = "apple",
target_os = "android",
target_os = "haiku",
target_os = "linux"
))]
Flag::new_grouped("bs1", O::BS1, O::BSDLY),
Flag::new_grouped("bs1", o!(libc::BS1), o!(libc::BSDLY)),
#[cfg(any(
target_vendor = "apple",
target_os = "android",
target_os = "haiku",
target_os = "linux"
))]
Flag::new_grouped("vt0", O::VT0, O::VTDLY).sane(),
Flag::new_grouped("vt0", o!(libc::VT0), o!(libc::VTDLY)).sane(),
#[cfg(any(
target_vendor = "apple",
target_os = "android",
target_os = "haiku",
target_os = "linux"
))]
Flag::new_grouped("vt1", O::VT1, O::VTDLY),
Flag::new_grouped("vt1", o!(libc::VT1), o!(libc::VTDLY)),
#[cfg(any(
target_vendor = "apple",
target_os = "android",
target_os = "haiku",
target_os = "linux"
))]
Flag::new_grouped("ff0", O::FF0, O::FFDLY).sane(),
Flag::new_grouped("ff0", o!(libc::FF0), o!(libc::FFDLY)).sane(),
#[cfg(any(
target_vendor = "apple",
target_os = "android",
target_os = "haiku",
target_os = "linux"
))]
Flag::new_grouped("ff1", O::FF1, O::FFDLY),
Flag::new_grouped("ff1", o!(libc::FF1), o!(libc::FFDLY)),
];

pub const LOCAL_FLAGS: &[Flag<L>] = &[
Expand Down Expand Up @@ -249,77 +253,6 @@ pub const LOCAL_FLAGS: &[Flag<L>] = &[
Flag::new("extproc", L::EXTPROC),
];

// BSD's use u32 as baud rate, so using the enum is unnecessary.
#[cfg(not(bsd))]
pub const BAUD_RATES: &[(&str, BaudRate)] = &[
("0", BaudRate::B0),
("50", BaudRate::B50),
("75", BaudRate::B75),
("110", BaudRate::B110),
("134", BaudRate::B134),
("150", BaudRate::B150),
("200", BaudRate::B200),
("300", BaudRate::B300),
("600", BaudRate::B600),
("1200", BaudRate::B1200),
("1800", BaudRate::B1800),
("2400", BaudRate::B2400),
("4800", BaudRate::B4800),
("9600", BaudRate::B9600),
("19200", BaudRate::B19200),
("38400", BaudRate::B38400),
("57600", BaudRate::B57600),
("115200", BaudRate::B115200),
("230400", BaudRate::B230400),
// TODO: https://github.com/nix-rust/nix/pull/2815
#[cfg(not(any(
target_os = "cygwin",
target_os = "fuchsia",
target_os = "hurd",
target_os = "redox"
)))]
("460800", BaudRate::B460800),
#[cfg(any(target_os = "android", target_os = "linux"))]
("500000", BaudRate::B500000),
#[cfg(any(target_os = "android", target_os = "linux"))]
("576000", BaudRate::B576000),
// TODO: https://github.com/nix-rust/nix/pull/2815
#[cfg(not(any(
target_os = "cygwin",
target_os = "fuchsia",
target_os = "hurd",
target_os = "redox"
)))]
("921600", BaudRate::B921600),
#[cfg(any(target_os = "android", target_os = "linux"))]
("1000000", BaudRate::B1000000),
#[cfg(any(target_os = "android", target_os = "linux"))]
("1152000", BaudRate::B1152000),
#[cfg(any(target_os = "android", target_os = "linux"))]
("1500000", BaudRate::B1500000),
#[cfg(any(target_os = "android", target_os = "linux"))]
("2000000", BaudRate::B2000000),
#[cfg(any(
target_os = "android",
all(target_os = "linux", not(target_arch = "sparc64"))
))]
("2500000", BaudRate::B2500000),
#[cfg(any(
target_os = "android",
all(target_os = "linux", not(target_arch = "sparc64"))
))]
("3000000", BaudRate::B3000000),
#[cfg(any(
target_os = "android",
all(target_os = "linux", not(target_arch = "sparc64"))
))]
("3500000", BaudRate::B3500000),
#[cfg(any(
target_os = "android",
all(target_os = "linux", not(target_arch = "sparc64"))
))]
("4000000", BaudRate::B4000000),
];
/// Control characters for the stty command.
///
/// This constant provides a mapping between the names of control characters
Expand Down Expand Up @@ -378,3 +311,58 @@ pub const COMBINATION_SETTINGS: &[(&str, bool)] = &[
("sane", false),
("tabs", true),
];

// rustix::termios::SpecialCodeIndex, but ordered as same as C header
#[cfg(bsd)] // different order with Linux
pub const SPECIAL_INDICES: &[S] = &[
S::VEOF,
S::VEOL,
S::VEOL2,
S::VERASE,
S::VWERASE,
S::VKILL,
S::VREPRINT,
S::VINTR,
S::VQUIT,
S::VSUSP,
S::VDSUSP,
S::VSTART,
S::VSTOP,
S::VLNEXT,
S::VDISCARD,
S::VMIN,
S::VTIME,
S::VSTATUS,
];

#[cfg(not(bsd))]
pub const SPECIAL_INDICES: &[S] = &[
S::VINTR,
S::VQUIT,
S::VERASE,
S::VKILL,
S::VEOF,
S::VTIME,
S::VMIN,
#[cfg(not(any(target_os = "haiku", target_os = "hurd")))]
S::VSWTC,
S::VSTART,
S::VSTOP,
S::VSUSP,
S::VEOL,
#[cfg(not(target_os = "haiku"))]
S::VREPRINT,
#[cfg(not(target_os = "haiku"))]
S::VDISCARD,
#[cfg(not(target_os = "haiku"))]
S::VWERASE,
#[cfg(not(target_os = "haiku"))]
S::VLNEXT,
S::VEOL2,
#[cfg(target_os = "haiku")]
S::VSWTCH,
#[cfg(target_os = "hurd")]
S::VDSUSP,
#[cfg(any(target_os = "hurd", target_os = "illumos"))]
S::VSTATUS,
];
Loading
Loading