aboutsummaryrefslogtreecommitdiff
path: root/unused.jai
diff options
context:
space:
mode:
authordam <dam@gudinoff>2024-04-30 12:54:13 +0100
committerdam <dam@gudinoff>2024-04-30 12:54:13 +0100
commit2037cba123cb98f367024346d2d882a505fd961e (patch)
tree0bccd323e5f07cbe3c490101398844ae71e69191 /unused.jai
parentc7a4f1c0c98a1df1e683b3de0454b3d981519e9e (diff)
downloadtask-time-tracker-2037cba123cb98f367024346d2d882a505fd961e.tar.zst
task-time-tracker-2037cba123cb98f367024346d2d882a505fd961e.zip
Fixed TUI\unix from c_octal-to-jai mis-conversion.
Diffstat (limited to 'unused.jai')
-rw-r--r--unused.jai145
1 files changed, 145 insertions, 0 deletions
diff --git a/unused.jai b/unused.jai
index 9e05904..0425f8d 100644
--- a/unused.jai
+++ b/unused.jai
@@ -37,6 +37,151 @@ print_database :: (db: Database) {
);
}
}
+
+// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- //
+
+// Implementation of tcsetattr, tcgetattr, and tcflush using only 'ioctl' which is provided by jai.
+
+#if USE_LIBC {
+
+ libc :: #system_library "libc";
+
+ // https://codebrowser.dev/glibc/glibc/sysdeps/unix/sysv/linux/tcsetattr.c.html
+ tcsetattr :: (fd: s32, optional_actions: s32, termios_p : *Terminal_IO_Mode) -> s32 #foreign libc;
+
+ // https://codebrowser.dev/glibc/glibc/sysdeps/unix/sysv/linux/tcgetattr.c.html
+ tcgetattr :: (fd: s32, termios_p: *Terminal_IO_Mode) -> s32 #foreign libc;
+
+ // https://codebrowser.dev/glibc/glibc/sysdeps/unix/sysv/linux/tcflush.c.html
+ tcflush :: (fd: s32, queue_selector: s32) -> s32 #foreign libc;
+}
+else {
+
+ // https://codebrowser.dev/glibc/glibc/sysdeps/unix/sysv/linux/tcsetattr.c.html
+ tcsetattr :: (fd: s32, optional_actions: s32, termios_p : *Terminal_IO_Mode) -> s32 {
+
+ #if OS == .LINUX {
+ TCSETS :: 0x5402;
+ TCSETSW :: 0x5403;
+ TCSETSF :: 0x5404;
+ tcflag_t :: u32;
+ cc_t :: u8;
+ __KERNEL_NCCS :: 19;
+ __kernel_termios :: struct {
+ c_iflag : tcflag_t; // input mode flags
+ c_oflag : tcflag_t; // output mode flags
+ c_cflag : tcflag_t; // control mode flags
+ c_lflag : tcflag_t; // local mode flags
+ c_line : cc_t; // line discipline
+ c_cc : [__KERNEL_NCCS]cc_t; // control characters
+ };
+
+ k_termios: __kernel_termios;
+ cmd: u64;
+ if optional_actions == {
+ case xx Optional_Actions.TCSANOW;
+ cmd = TCSETS;
+
+ case xx Optional_Actions.TCSADRAIN;
+ cmd = TCSETSW;
+
+ case xx Optional_Actions.TCSAFLUSH;
+ cmd = TCSETSF;
+
+ case;
+ return EINVAL;
+ }
+ // k_termios.c_iflag = termios_p.c_iflag & ~IBAUD0;
+ k_termios.c_iflag = xx termios_p.c_iflag;
+ k_termios.c_oflag = xx termios_p.c_oflag;
+ k_termios.c_cflag = xx termios_p.c_cflag;
+ k_termios.c_lflag = xx termios_p.c_lflag;
+ k_termios.c_line = xx termios_p.c_line;
+ // #if _HAVE_C_ISPEED && _HAVE_STRUCT_TERMIOS_C_ISPEED
+ // k_termios.c_ispeed = termios_p->c_ispeed;
+ // #endif
+ // #if _HAVE_C_OSPEED && _HAVE_STRUCT_TERMIOS_C_OSPEED
+ // k_termios.c_ospeed = termios_p->c_ospeed;
+ // #endif
+ memcpy(*k_termios.c_cc[0], *termios_p.c_cc[0], __KERNEL_NCCS * 1);//size_of(cc_t));
+ return ioctl(fd, cmd, *k_termios);
+ }
+ #if OS == .MACOS {
+ // return __ioctl (fd, TIOCSETAF, termios_p);
+ #assert(false, "NOT IMPLEMENTED");
+ }
+ return 0;
+ }
+
+ // https://codebrowser.dev/glibc/glibc/sysdeps/unix/sysv/linux/tcgetattr.c.html
+ tcgetattr :: (fd: s32, termios_p: *Terminal_IO_Mode) -> s32 {
+ TCSETS :: 0x5402;
+ TCSETSW :: 0x5403;
+ TCSETSF :: 0x5404;
+ tcflag_t :: u32;
+ cc_t :: u8;
+ __KERNEL_NCCS :: 19;
+ __kernel_termios :: struct {
+ c_iflag : tcflag_t; // input mode flags
+ c_oflag : tcflag_t; // output mode flags
+ c_cflag : tcflag_t; // control mode flags
+ c_lflag : tcflag_t; // local mode flags
+ c_line : cc_t; // line discipline
+ c_cc : [__KERNEL_NCCS]cc_t; // control characters
+ };
+
+
+ // int
+ // __tcgetattr (int fd, struct termios *termios_p)
+ // {
+ // struct __kernel_termios k_termios;
+ k_termios: __kernel_termios;
+ retval: int;
+ retval = ioctl(fd, TCGETS, *k_termios);
+ if retval == 0 {
+ termios_p.c_iflag = xx k_termios.c_iflag;
+ termios_p.c_oflag = xx k_termios.c_oflag;
+ termios_p.c_cflag = xx k_termios.c_cflag;
+ termios_p.c_lflag = xx k_termios.c_lflag;
+ termios_p.c_line = xx k_termios.c_line;
+ // #if _HAVE_STRUCT_TERMIOS_C_ISPEED
+ // # if _HAVE_C_ISPEED
+ // termios_p->c_ispeed = k_termios.c_ispeed;
+ // # else
+ // termios_p->c_ispeed = k_termios.c_cflag & (CBAUD | CBAUDEX);
+ // # endif
+ // #endif
+ // #if _HAVE_STRUCT_TERMIOS_C_OSPEED
+ // # if _HAVE_C_OSPEED
+ // termios_p->c_ospeed = k_termios.c_ospeed;
+ // # else
+ // termios_p->c_ospeed = k_termios.c_cflag & (CBAUD | CBAUDEX);
+ // # endif
+ // #endif
+ size_of_cc_t := __KERNEL_NCCS * 1;
+ memcpy(*termios_p.c_cc[0], *k_termios.c_cc[0], size_of_cc_t);
+ // memset(*termios_p.c_cc[0] + size_of_cc_t + 1, _POSIX_VDISABLE, (NCCS - __KERNEL_NCCS) * 1);
+ //
+ // if (sizeof (cc_t) == 1 || _POSIX_VDISABLE == 0 || (unsigned char) _POSIX_VDISABLE == (unsigned char) -1) {
+ // memset (__mempcpy (&termios_p->c_cc[0], &k_termios.c_cc[0], __KERNEL_NCCS * sizeof (cc_t)), _POSIX_VDISABLE, (NCCS - __KERNEL_NCCS) * sizeof (cc_t));
+ // }
+ // else
+ // {
+ // memcpy (&termios_p->c_cc[0], &k_termios.c_cc[0], __KERNEL_NCCS * sizeof (cc_t));
+ // for (size_t cnt = __KERNEL_NCCS; cnt < NCCS; ++cnt) {
+ // termios_p->c_cc[cnt] = _POSIX_VDISABLE;
+ // }
+ // }
+ }
+ return xx retval;
+ }
+
+ // https://codebrowser.dev/glibc/glibc/sysdeps/unix/sysv/linux/tcflush.c.html
+ tcflush :: inline (fd: s32, queue_selector: s32) -> s32 {
+ TCFLSH :: 0x540B;
+ return ioctl(fd, TCFLSH, queue_selector);
+ }
+}
// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- //