feat: nearly complete POSIX.1-2008 compliant terminal interface implementation
[lunaix-os.git] / lunaix-os / includes / hal / term.h
index 79f8f67ad1b18fe9831b46bc5667c0551220c0e3..00fe32b04a074ebd40a236a11ee26367b3fcd913 100644 (file)
@@ -2,21 +2,34 @@
 #define __LUNAIX_TERM_H
 
 #include <lunaix/device.h>
 #define __LUNAIX_TERM_H
 
 #include <lunaix/device.h>
+#include <lunaix/ds/rbuffer.h>
+#include <lunaix/signal_defs.h>
+
+#include <usr/lunaix/term.h>
 
 struct term;
 
 
 struct term;
 
-struct term_lcntl
+struct linebuffer
 {
 {
-    struct llist_header lcntls;
-    size_t (*apply)(struct term* termdev, char* line, size_t len);
+    struct rbuffer *next;
+    struct rbuffer *current;
+    short sflags;
+    short sz_hlf;
 };
 };
+#define LSTATE_EOL (1)
+#define LSTATE_EOF (1 << 1)
+#define LSTATE_SIGRAISE (1 << 2)
 
 
-struct linebuffer
+typedef struct rbuffer** lbuf_ref_t;
+#define ref_current(lbuf) (&(lbuf)->current)
+#define ref_next(lbuf) (&(lbuf)->next)
+#define deref(bref) (*(bref))
+
+struct term_lcntl
 {
 {
-    char* current;
-    char* next;
-    size_t sz_hlf;
-    off_t ptr;
+    struct llist_header lcntls;
+    struct term* term;
+    size_t (*process_and_put)(struct term*, struct linebuffer*, char);
 };
 
 struct term
 };
 
 struct term
@@ -24,12 +37,25 @@ struct term
     struct device* dev;
     struct device* chdev;
     struct llist_header lcntl_stack;
     struct device* dev;
     struct device* chdev;
     struct llist_header lcntl_stack;
-    struct linebuffer line;
+    struct linebuffer line_out;
+    struct linebuffer line_in;
     pid_t fggrp;
     pid_t fggrp;
+
+    struct
+    {
+        int (*set_speed)(struct device*, speed_t);
+    } chdev_ops;
+
+    /* -- POSIX.1-2008 compliant fields -- */
+    tcflag_t iflags;
+    tcflag_t oflags;
+    tcflag_t lflags;
+    cc_t cc[_NCCS];
+    speed_t iospeed;
 };
 
 struct term*
 };
 
 struct term*
-term_create();
+term_create(struct device* chardev, char* suffix);
 
 int
 term_bind(struct term* tdev, struct device* chdev);
 
 int
 term_bind(struct term* tdev, struct device* chdev);
@@ -43,8 +69,12 @@ term_pop_lcntl(struct term* tdev);
 struct term_lcntl*
 term_get_lcntl(u32_t lcntl_index);
 
 struct term_lcntl*
 term_get_lcntl(u32_t lcntl_index);
 
-void
-line_flip(struct linebuffer* lbf);
+static inline void
+line_flip(struct linebuffer* lbf) {
+    struct rbuffer* tmp = lbf->current;
+    lbf->current = lbf->next;
+    lbf->next = tmp;
+}
 
 void
 line_alloc(struct linebuffer* lbf, size_t sz_hlf);
 
 void
 line_alloc(struct linebuffer* lbf, size_t sz_hlf);
@@ -52,23 +82,19 @@ line_alloc(struct linebuffer* lbf, size_t sz_hlf);
 void
 line_free(struct linebuffer* lbf, size_t sz_hlf);
 
 void
 line_free(struct linebuffer* lbf, size_t sz_hlf);
 
-static inline int
-line_put_next(struct linebuffer* lbf, char val, int delta)
-{
-    size_t dptr = (size_t)(lbf->ptr + delta);
-    if (dptr >= lbf->sz_hlf) {
-        return 0;
-    }
-
-    lbf->next[dptr] = val;
-    lbf->ptr++;
-    return 1;
-}
+void
+term_sendsig(struct term* tdev, int signal);
+
+int
+term_flush(struct term* tdev);
+
+int
+term_read(struct term* tdev);
 
 int
 
 int
-term_sendline(struct term* tdev, size_t len);
+lcntl_transform_inseq(struct term* tdev);
 
 int
 
 int
-term_readline(struct term* tdev, size_t len);
+lcntl_transform_outseq(struct term* tdev);
 
 #endif /* __LUNAIX_TERM_H */
 
 #endif /* __LUNAIX_TERM_H */