Menuconfig Implementation and auto-qemu refactoring (#44)
[lunaix-os.git] / lunaix-os / hal / term / lcntls / lcntl.h
1 #ifndef __LUNAIX_LCNTL_H
2 #define __LUNAIX_LCNTL_H
3
4 #include <hal/term.h>
5
6 #define LCNTLF_SPECIAL_CHAR      0b000001
7 #define LCNTLF_CLEAR_INBUF       0b000010
8 #define LCNTLF_CLEAR_OUTBUF      0b000100
9 #define LCNTLF_STOP              0b001000
10
11 enum lcntl_dir {
12     INBOUND,
13     OUTBOUND
14 };
15
16 struct lcntl_state {
17     struct term* tdev;
18     tcflag_t _if;   // iflags
19     tcflag_t _of;   // oflags
20     tcflag_t _lf;   // local flags
21     tcflag_t _cf;   // control flags
22     tcflag_t _sf;   // state flags
23     enum lcntl_dir direction;
24
25     struct linebuffer* active_line;
26     struct rbuffer* inbuf;
27     struct rbuffer* outbuf;
28     struct rbuffer* echobuf;
29 };
30
31 int  
32 lcntl_put_char(struct lcntl_state* state, char c);
33
34 static inline void
35 lcntl_set_flag(struct lcntl_state* state, int flags)
36 {
37     state->_sf |= flags;
38 }
39
40 static inline void
41 lcntl_raise_line_event(struct lcntl_state* state, int event)
42 {
43     state->active_line->sflags |= event;
44 }
45
46 static inline void
47 lcntl_unset_flag(struct lcntl_state* state, int flags)
48 {
49     state->_sf &= ~flags;
50 }
51
52 static inline bool
53 lcntl_test_flag(struct lcntl_state* state, int flags)
54 {
55     return !!(state->_sf & flags);
56 }
57
58 static inline bool
59 lcntl_outbound(struct lcntl_state* state)
60 {
61     return (state->direction == OUTBOUND);
62 }
63
64 static inline bool
65 lcntl_inbound(struct lcntl_state* state)
66 {
67     return (state->direction == INBOUND);
68 }
69
70 static inline bool
71 lcntl_check_echo(struct lcntl_state* state, int echo_type)
72 {
73     return lcntl_inbound(state) && (state->_lf & echo_type);
74 }
75
76
77 #endif /* __LUNAIX_LCNTL_H */