Fixed io-ii
[iomenu.git] / main.h
blob686ccf81075e0174fc58053241c017a96231f7c1
1 #define LINE_SIZE 1024
2 #define OFFSET 5
3 #define CONTINUE 2 /* as opposed to EXIT_SUCCESS and EXIT_FAILURE */
5 #define CONTROL(char) (char ^ 0x40)
6 #define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
7 #define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
11 * Options from the command line, to pass to each function that need some
13 typedef struct Opt {
14 int line_numbers;
15 int print_number;
16 int print_header;
17 char validate_key;
18 char *separator;
19 int lines;
20 char *prompt;
21 } Opt;
25 * Line coming from stdin, wrapped in a header.
27 typedef struct Line {
28 char *content; /* sent as output and matched by input */
29 char *comment; /* displayed at the right of the content */
31 int number; /* set here as order will not change */
32 int matches; /* whether it matches buffer's input */
33 int header; /* whether the line is a header */
35 struct Line *prev; /* doubly linked list structure */
36 struct Line *next;
37 } Line;
41 * Buffer containing a doubly linked list of headers
43 typedef struct Buffer {
44 int total; /* total number of line in buffer */
45 int matching; /* number lines matching the input */
47 char input[LINE_SIZE]; /* string from user's keyboard */
49 Line *current; /* selected line, highlighted */
50 Line *first; /* boundaries of the linked list */
51 Line *last;
52 } Buffer;
55 /* main */
57 void usage(void);
60 /* buffer */
62 Buffer * fill_buffer(char *);
63 void free_buffer(Buffer *);
64 Line * add_line(Buffer *, int, char *, char *, Line *);
65 Line * new_line(char *, char *);
66 Line * matching_next(Line *);
67 Line * matching_prev(Line *);
68 int match_line(Line *, char **, size_t);
69 void filter_lines(Buffer *, int);
72 /* draw */
74 void draw_screen(Buffer *, int, Opt *);
75 void draw_clear(int);
76 void draw_line(Line *, int, int, Opt *);
77 void draw_lines(Buffer *, int, int, Opt *);
78 void draw_prompt(Buffer *, int, Opt *);
81 /* input */
83 int input_get(Buffer *, int, Opt *);
84 int input_key(FILE *, Buffer *, Opt *);
85 void action_jump(Buffer *, int);
86 void action_print_selection(Buffer *,int, Opt *);
87 void action_remove_word_input(Buffer *);
88 void action_add_character(Buffer *, char);
91 /* util */
93 void die(const char *);
94 struct termios set_terminal(int);
95 char * expand_tabs(char *);