Added a man page and a usage function
[iomenu.git] / main.h
bloba05f2d00ec95fb838fb204c62b2d0130479372ae
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_number;
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 /* main */
62 void usage(void);
65 /* buffer */
67 Buffer * fill_buffer(char *);
68 void free_buffer(Buffer *);
69 void free_line(Line *);
70 Line * add_line(Buffer *, int, char *, char *, Line *);
71 Line * parse_line(char *, char *);
72 Line * matching_next(Line *);
73 Line * matching_prev(Line *);
74 int line_match_input(Line *, char *, Opt *);
75 void filter_lines(Buffer *, Opt *);
78 /* draw */
80 void draw_screen(Buffer *, int, Opt *);
81 void draw_clear(int);
82 void draw_line(Line *, int, int, Opt *);
83 void draw_lines(Buffer *, int, int, Opt *);
84 void draw_prompt(Buffer *, int, Opt *);
87 /* input */
89 void input_get(Buffer *, int, Opt *);
90 int input_key(char, Buffer *, Opt *);
91 void action_jump(Buffer *, int);
92 void action_print_selection(Buffer *, Opt *);
93 void action_remove_word_input(Buffer *);
94 void action_add_character(Buffer *, char, Opt *);
97 /* util */
99 void die(const char *);
100 struct termios set_terminal(int);
101 char * expand_tabs(char *);