Added a -H to also return header
[iomenu.git] / main.h
blob42c04dc355b246ef9fc4a90cb495505ca712a135
1 #define LINE_SIZE 1024
2 #define OFFSET 5
3 #define CONTINUE 2 /* as opposed to EXIT_SUCCESS and EXIT_FAILURE */
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))
12 * Options from the command line, to pass to each function that need some
14 typedef struct Opt {
15 int line_numbers;
16 int print_number;
17 int print_header;
18 char validate_key;
19 char *separator;
20 int lines;
21 char *prompt;
22 } Opt;
26 * Line coming from stdin, wrapped in a header.
28 typedef struct Line {
29 char *content; /* sent as output and matched by input */
30 char *comment; /* displayed at the right of the content */
32 int number; /* set here as order will not change */
33 int matches; /* whether it matches buffer's input */
34 int header; /* whether the line is a header */
36 struct Line *prev; /* doubly linked list structure */
37 struct Line *next;
38 } Line;
42 * Buffer containing a doubly linked list of headers
44 typedef struct Buffer {
45 int total; /* total number of line in buffer */
46 int matching; /* number lines matching the input */
48 char input[LINE_SIZE]; /* string from user's keyboard */
50 Line *current; /* selected line, highlighted */
51 Line *first; /* boundaries of the linked list */
52 Line *last;
53 } Buffer;
56 /* main */
58 void usage(void);
61 /* buffer */
63 Buffer * fill_buffer(char *);
64 void free_buffer(Buffer *);
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 match_line(Line *, char **, size_t);
70 void filter_lines(Buffer *, int);
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 int input_get(Buffer *, int, Opt *);
85 int input_key(FILE *, Buffer *, Opt *);
86 void action_jump(Buffer *, int);
87 void action_print_selection(Buffer *,int, Opt *);
88 void action_remove_word_input(Buffer *);
89 void action_add_character(Buffer *, char);
92 /* util */
94 void die(const char *);
95 struct termios set_terminal(int);
96 char * expand_tabs(char *);