summaryrefslogtreecommitdiffstats
path: root/third_party/rust/redox_termios
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/rust/redox_termios
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/redox_termios')
-rw-r--r--third_party/rust/redox_termios/.cargo-checksum.json1
-rw-r--r--third_party/rust/redox_termios/Cargo.toml26
-rw-r--r--third_party/rust/redox_termios/LICENSE21
-rw-r--r--third_party/rust/redox_termios/README.md2
-rw-r--r--third_party/rust/redox_termios/src/lib.rs218
5 files changed, 268 insertions, 0 deletions
diff --git a/third_party/rust/redox_termios/.cargo-checksum.json b/third_party/rust/redox_termios/.cargo-checksum.json
new file mode 100644
index 0000000000..cfb655d32a
--- /dev/null
+++ b/third_party/rust/redox_termios/.cargo-checksum.json
@@ -0,0 +1 @@
+{"files":{"Cargo.toml":"e7d20b4132bf22e2c98a5f846f8c16e7628a9181d485fd131b97127ea8719130","LICENSE":"cb46b697c3fd9d27d7bfe1b1ad48f8a58a284984504c6eb215ae2164538df7cb","README.md":"c62ac3d33174db7977cfc7fc77605885f5445c0c9c7d1310dcbe3564c2854edb","src/lib.rs":"af5bc7c59c695880fef0352f9e0f9e9f8682c262a9b1c0fce725b10553647b4e"},"package":"7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"} \ No newline at end of file
diff --git a/third_party/rust/redox_termios/Cargo.toml b/third_party/rust/redox_termios/Cargo.toml
new file mode 100644
index 0000000000..a89b0e89c5
--- /dev/null
+++ b/third_party/rust/redox_termios/Cargo.toml
@@ -0,0 +1,26 @@
+# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
+#
+# When uploading crates to the registry Cargo will automatically
+# "normalize" Cargo.toml files for maximal compatibility
+# with all versions of Cargo and also rewrite `path` dependencies
+# to registry (e.g. crates.io) dependencies
+#
+# If you believe there's an error in this file please file an
+# issue against the rust-lang/cargo repository. If you're
+# editing this file be aware that the upstream Cargo.toml
+# will likely look very different (and much more reasonable)
+
+[package]
+name = "redox_termios"
+version = "0.1.1"
+authors = ["Jeremy Soller <jackpot51@gmail.com>"]
+description = "A Rust library to access Redox termios functions"
+documentation = "https://docs.rs/redox_termios"
+license = "MIT"
+repository = "https://github.com/redox-os/termios"
+
+[lib]
+name = "redox_termios"
+path = "src/lib.rs"
+[dependencies.redox_syscall]
+version = "0.1"
diff --git a/third_party/rust/redox_termios/LICENSE b/third_party/rust/redox_termios/LICENSE
new file mode 100644
index 0000000000..5deeece4f4
--- /dev/null
+++ b/third_party/rust/redox_termios/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2017 Redox OS
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/third_party/rust/redox_termios/README.md b/third_party/rust/redox_termios/README.md
new file mode 100644
index 0000000000..24156cb955
--- /dev/null
+++ b/third_party/rust/redox_termios/README.md
@@ -0,0 +1,2 @@
+# termios
+Redox Rust termios library
diff --git a/third_party/rust/redox_termios/src/lib.rs b/third_party/rust/redox_termios/src/lib.rs
new file mode 100644
index 0000000000..b1c904502b
--- /dev/null
+++ b/third_party/rust/redox_termios/src/lib.rs
@@ -0,0 +1,218 @@
+#![allow(non_camel_case_types)]
+#![no_std]
+
+extern crate syscall;
+
+use core::{mem, slice};
+use core::ops::{Deref, DerefMut};
+
+pub type tcflag_t = u32;
+pub type cc_t = u8;
+
+/* c_cc { */
+pub const VEOF: usize = 0;
+pub const VEOL: usize = 1;
+pub const VEOL2: usize = 2;
+pub const VERASE: usize = 3;
+pub const VWERASE: usize = 4;
+pub const VKILL: usize = 5;
+pub const VREPRINT: usize = 6;
+pub const VSWTC: usize = 7;
+pub const VINTR: usize = 8;
+pub const VQUIT: usize = 9;
+pub const VSUSP: usize = 10;
+pub const VSTART: usize = 12;
+pub const VSTOP: usize = 13;
+pub const VLNEXT: usize = 14;
+pub const VDISCARD: usize = 15;
+pub const VMIN: usize = 16;
+pub const VTIME: usize = 17;
+pub const NCCS: usize = 32;
+/* } c_cc */
+
+/* c_iflag { */
+pub const IGNBRK: tcflag_t = 0o000001;
+pub const BRKINT: tcflag_t = 0o000002;
+pub const IGNPAR: tcflag_t = 0o000004;
+pub const PARMRK: tcflag_t = 0o000010;
+pub const INPCK: tcflag_t = 0o000020;
+pub const ISTRIP: tcflag_t = 0o000040;
+pub const INLCR: tcflag_t = 0o000100;
+pub const IGNCR: tcflag_t = 0o000200;
+pub const ICRNL: tcflag_t = 0o000400;
+pub const IXON: tcflag_t = 0o001000;
+pub const IXOFF: tcflag_t = 0o002000;
+/* } c_iflag */
+
+/* c_oflag { */
+pub const OPOST: tcflag_t = 0o000001;
+pub const ONLCR: tcflag_t = 0o000002;
+pub const OLCUC: tcflag_t = 0o000004;
+
+pub const OCRNL: tcflag_t = 0o000010;
+pub const ONOCR: tcflag_t = 0o000020;
+pub const ONLRET: tcflag_t = 0o000040;
+
+pub const OFILL: tcflag_t = 0o0000100;
+pub const OFDEL: tcflag_t = 0o0000200;
+/* } c_oflag */
+
+/* c_cflag { */
+pub const B0: tcflag_t = 0o000000;
+pub const B50: tcflag_t = 0o000001;
+pub const B75: tcflag_t = 0o000002;
+pub const B110: tcflag_t = 0o000003;
+pub const B134: tcflag_t = 0o000004;
+pub const B150: tcflag_t = 0o000005;
+pub const B200: tcflag_t = 0o000006;
+pub const B300: tcflag_t = 0o000007;
+pub const B600: tcflag_t = 0o000010;
+pub const B1200: tcflag_t = 0o000011;
+pub const B1800: tcflag_t = 0o000012;
+pub const B2400: tcflag_t = 0o000013;
+pub const B4800: tcflag_t = 0o000014;
+pub const B9600: tcflag_t = 0o000015;
+pub const B19200: tcflag_t = 0o000016;
+pub const B38400: tcflag_t = 0o000017;
+pub const B57600: tcflag_t = 0o0020;
+pub const B115200: tcflag_t = 0o0021;
+pub const B230400: tcflag_t = 0o0022;
+pub const B460800: tcflag_t = 0o0023;
+pub const B500000: tcflag_t = 0o0024;
+pub const B576000: tcflag_t = 0o0025;
+pub const B921600: tcflag_t = 0o0026;
+pub const B1000000: tcflag_t = 0o0027;
+pub const B1152000: tcflag_t = 0o0030;
+pub const B1500000: tcflag_t = 0o0031;
+pub const B2000000: tcflag_t = 0o0032;
+pub const B2500000: tcflag_t = 0o0033;
+pub const B3000000: tcflag_t = 0o0034;
+pub const B3500000: tcflag_t = 0o0035;
+pub const B4000000: tcflag_t = 0o0036;
+
+pub const __MAX_BAUD: tcflag_t = B4000000;
+
+pub const CSIZE: tcflag_t = 0o0001400;
+pub const CS5: tcflag_t = 0o0000000;
+pub const CS6: tcflag_t = 0o0000400;
+pub const CS7: tcflag_t = 0o0001000;
+pub const CS8: tcflag_t = 0o0001400;
+
+pub const CSTOPB: tcflag_t = 0o0002000;
+pub const CREAD: tcflag_t = 0o0004000;
+pub const PARENB: tcflag_t = 0o0010000;
+pub const PARODD: tcflag_t = 0o0020000;
+pub const HUPCL: tcflag_t = 0o0040000;
+
+pub const CLOCAL: tcflag_t = 0o0100000;
+/* } c_clfag */
+
+/* c_lflag { */
+pub const ISIG: tcflag_t = 0x00000080;
+pub const ICANON: tcflag_t = 0x00000100;
+pub const ECHO: tcflag_t = 0x00000008;
+pub const ECHOE: tcflag_t = 0x00000002;
+pub const ECHOK: tcflag_t = 0x00000004;
+pub const ECHONL: tcflag_t = 0x00000010;
+pub const NOFLSH: tcflag_t = 0x80000000;
+pub const TOSTOP: tcflag_t = 0x00400000;
+pub const IEXTEN: tcflag_t = 0x00000400;
+/* } c_lflag */
+
+#[derive(Clone, Copy, Debug)]
+#[repr(C)]
+pub struct Termios {
+ pub c_iflag: tcflag_t,
+ pub c_oflag: tcflag_t,
+ pub c_cflag: tcflag_t,
+ pub c_lflag: tcflag_t,
+ pub c_cc: [cc_t; 32]
+}
+
+impl Default for Termios {
+ fn default() -> Termios {
+ let mut termios = Termios {
+ c_iflag: ICRNL | IXON,
+ c_oflag: OPOST | ONLCR,
+ c_cflag: B38400 | CS8 | CREAD | HUPCL,
+ c_lflag: ISIG | ICANON | ECHO | ECHOE | ECHOK | IEXTEN,
+ c_cc: [0; 32]
+ };
+
+ {
+ let mut cc = |i: usize, b: cc_t| {
+ termios.c_cc[i] = b;
+ };
+
+ cc(VEOF, 0o004); // CTRL-D
+ cc(VEOL, 0o000); // NUL
+ cc(VEOL2, 0o000); // NUL
+ cc(VERASE, 0o177); // DEL
+ cc(VWERASE, 0o027); // CTRL-W
+ cc(VKILL, 0o025); // CTRL-U
+ cc(VREPRINT, 0o022);// CTRL-R
+ cc(VINTR, 0o003); // CTRL-C
+ cc(VQUIT, 0o034); // CTRL-\
+ cc(VSUSP, 0o032); // CTRL-Z
+ cc(VSTART, 0o021); // CTRL-Q
+ cc(VSTOP, 0o023); // CTRL-S
+ cc(VLNEXT, 0o026); // CTRL-V
+ cc(VDISCARD, 0o017);// CTRL-U
+ cc(VMIN, 1);
+ cc(VTIME, 0);
+ }
+
+ termios
+ }
+}
+
+impl Termios {
+ pub fn make_raw(&mut self) {
+ self.c_iflag &= !(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
+ self.c_oflag &= !OPOST;
+ self.c_cflag &= !(CSIZE | PARENB);
+ self.c_cflag |= CS8;
+ self.c_lflag &= !(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
+ }
+}
+
+impl Deref for Termios {
+ type Target = [u8];
+ fn deref(&self) -> &[u8] {
+ unsafe {
+ slice::from_raw_parts(self as *const Termios as *const u8, mem::size_of::<Termios>()) as &[u8]
+ }
+ }
+}
+
+impl DerefMut for Termios {
+ fn deref_mut(&mut self) -> &mut [u8] {
+ unsafe {
+ slice::from_raw_parts_mut(self as *mut Termios as *mut u8, mem::size_of::<Termios>()) as &mut [u8]
+ }
+ }
+}
+
+#[derive(Clone, Copy, Debug, Default)]
+#[repr(C)]
+pub struct Winsize {
+ pub ws_row: u16,
+ pub ws_col: u16
+}
+
+impl Deref for Winsize {
+ type Target = [u8];
+ fn deref(&self) -> &[u8] {
+ unsafe {
+ slice::from_raw_parts(self as *const Winsize as *const u8, mem::size_of::<Winsize>()) as &[u8]
+ }
+ }
+}
+
+impl DerefMut for Winsize {
+ fn deref_mut(&mut self) -> &mut [u8] {
+ unsafe {
+ slice::from_raw_parts_mut(self as *mut Winsize as *mut u8, mem::size_of::<Winsize>()) as &mut [u8]
+ }
+ }
+}