Simplifying and cleaning
[iomenu.git] / main.h
blob28fe4647cdb3d380a88d744b3c68e88b7377c137
1 #define LINE_SIZE 1024
2 #define OFFSET 5
4 #define LENGTH(x) (sizeof(x) / sizeof(*x))
5 #define CONTROL(char) (char ^ 0x40)
6 #define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
7 #define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
10 enum { FALSE = 0, TRUE, EXIT };
11 enum { PREV = 0, NEXT, ANY };
15 * Options from the command line, to pass to each function that need some
17 typedef struct Opt {
18 int line_numbers;
19 int complete;
20 int print_numbers;
21 char validate_key;
22 char *separator;
23 int lines;
24 char *prompt;
25 } Opt;
29 * Line coming from stdin, wrapped in a header.
31 typedef struct Line {
32 char *content; /* sent as output and matched by input */
33 char *comment; /* displayed at the right of the content */
35 int number; /* set here as order will not change */
36 int matches; /* whether it matches buffer's input */
37 int header; /* whether the line is a header */
39 struct Line *prev; /* doubly linked list structure */
40 struct Line *next;
41 } Line;
45 * Buffer containing a doubly linked list of headers
47 typedef struct Buffer {
48 int total; /* total number of line in buffer */
49 int matching; /* number lines matching the input */
51 char input[LINE_SIZE]; /* string from user's keyboard */
52 char *prompt; /* specified from the command line */
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, Opt *);
76 void draw_clear(int);
77 void draw_line(Line *, int, int, Opt *);
78 void draw_lines(Buffer *, int, int, Opt *);
79 void draw_prompt(Buffer *, int, Opt *);
82 /* input */
84 void input_get(Buffer *, 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 *);