Performance improvement
[iomenu.git] / main.h
blobe749203ee72d6ee259bf18da1bd260c4d592af00
1 #define LINE_SIZE 1024
2 #define OFFSET 5
3 #define CONTINUE 2
5 #define LENGTH(x) (sizeof(x) / sizeof(*x))
6 #define CONTROL(char) (char ^ 0x40)
7 #define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
8 #define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
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 print_number;
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 *current; /* selected line, highlighted */
54 Line *first; /* boundaries of the linked list */
55 Line *last;
56 } Buffer;
59 /* main */
61 void usage(void);
64 /* buffer */
66 Buffer * fill_buffer(char *);
67 void free_buffer(Buffer *);
68 void free_line(Line *);
69 Line * add_line(Buffer *, int, char *, char *, Line *);
70 Line * parse_line(char *, char *);
71 Line * matching_next(Line *);
72 Line * matching_prev(Line *);
73 int match_line(Line *, char *[], int);
74 void filter_lines(Buffer *, int);
77 /* draw */
79 void draw_screen(Buffer *, int, Opt *);
80 void draw_clear(int);
81 void draw_line(Line *, int, int, Opt *);
82 void draw_lines(Buffer *, int, int, Opt *);
83 void draw_prompt(Buffer *, int, Opt *);
86 /* input */
88 int input_get(Buffer *, int, Opt *);
89 int input_key(FILE *, Buffer *, Opt *);
90 void action_jump(Buffer *, int);
91 void action_print_selection(Buffer *,int, int);
92 void action_remove_word_input(Buffer *);
93 void action_add_character(Buffer *, char);
96 /* util */
98 void die(const char *);
99 struct termios set_terminal(int);
100 char * expand_tabs(char *);