Simplified, hopefully cleaner
[iomenu.git] / main.h
blob3bf12b42d324b1cb92293196111654505735c562
1 #define LINE_SIZE 1024
3 #define LENGTH(x) (sizeof(x) / sizeof(*x))
4 #define CONTROL(char) (char ^ 0x40)
5 #define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
6 #define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
9 enum { FALSE = 0, TRUE = 1, EXIT = 2 };
10 enum { NEXT = 0, PREV = 1, BOTH = 2 };
14 * Options from the command line, to pass to each function that need some
16 typedef struct Opt {
17 int line_numbers;
18 int complete;
19 int print_numbers;
20 char validate_key;
21 char *separator;
22 int lines;
23 char *prompt;
24 } Opt;
28 * Line coming from stdin, wrapped in a header.
30 typedef struct Line {
31 char *content; /* sent as output and matched by input */
32 char *comment; /* displayed at the right of the content */
34 int number; /* set here as order will not change */
35 int matches; /* whether it matches buffer's input */
36 int header; /* whether the line is a header */
38 struct Line *prev; /* doubly linked list structure */
39 struct Line *next;
40 } Line;
44 * Buffer containing a doubly linked list of headers
46 typedef struct Buffer {
47 int total; /* total number of line in buffer */
48 int matching; /* number lines matching the input */
50 char input[LINE_SIZE]; /* string from user's keyboard */
51 char *prompt; /* specified from the command line */
53 Line *empty; /* empty line, for when needed */
54 Line *current; /* selected line, highlighted */
55 Line *first; /* boundaries of the linked list */
56 Line *last;
57 } Buffer;
60 /* buffer */
62 Buffer * fill_buffer(char *);
63 void free_buffer(Buffer *);
64 void free_line(Line *);
65 Line * add_line(Buffer *, int, char *, char *, Line *);
66 Line * parse_line(char *, char *);
67 Line * matching_next(Line *);
68 Line * matching_prev(Line *);
69 int line_match_input(Line *, char *, Opt *);
70 void filter_lines(Buffer *, Opt *);
73 /* draw */
75 void draw_screen(Buffer *, int, int, Opt *);
76 void draw_clear(int);
77 void draw_line(Line *, int, int, Opt *);
78 void draw_lines(Buffer *, int, int, int, Opt *);
79 void draw_prompt(Buffer *, int, Opt *);
82 /* input */
84 void input_get(Buffer *, int, int, Opt *);
85 int input_key(char, Buffer *, Opt *);
86 void action_jump(Buffer *, int, Opt *);
87 void action_print_selection(Buffer *, Opt *);
88 void action_remove_word_input(Buffer *);
89 void action_add_character(Buffer *, char, Opt *);
92 /* util */
94 void die(const char *);
95 struct termios set_terminal(int);
96 char * expand_tabs(char *);