Simplifying and cleaning
[iomenu.git] / main.c
blob1c72c893153d9b2b045fd8c2ece6f2c272d5e60f
1 #include <ctype.h>
2 #include <fcntl.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <sys/ioctl.h>
7 #include <termios.h>
8 #include <unistd.h>
10 #include "main.h"
13 int
14 main(int argc, char *argv[])
16 int i;
17 Buffer *buffer = NULL;
18 int tty_fd = open("/dev/tty", O_RDWR);
19 Opt *opt = malloc(sizeof(Opt));
21 opt->line_numbers = FALSE;
22 opt->complete = FALSE;
23 opt->print_numbers = FALSE;
24 opt->validate_key = CONTROL('M');
25 opt->separator = NULL;
26 opt->lines = 30;
27 opt->prompt = "";
29 /* command line arguments */
30 for (i = 0; i < argc; i++) {
31 if (argv[i][0] == '-') {
32 switch (argv[i][1]) {
33 case 'n':
34 opt->line_numbers = TRUE;
35 break;
36 case 'c':
37 opt->complete = TRUE;
38 break;
39 case 'N':
40 opt->print_numbers = TRUE;
41 opt->line_numbers = TRUE;
42 break;
43 case 'k':
44 opt->validate_key = (argv[i++][0] == '^') ?
45 CONTROL(argv[i][1]):
46 argv[i][0];
47 break;
48 case 's':
49 opt->separator = argv[++i];
50 break;
51 case 'l':
52 if (sscanf(argv[++i], "%d", &opt->lines) <= 0)
53 die("Wrong number format after -l.");
54 break;
55 case 'p':
56 opt->prompt = argv[++i];
57 break;
62 /* command line arguments */
63 buffer = fill_buffer(opt->separator);
65 /* set the interface */
66 filter_lines(buffer, opt);
67 draw_screen(buffer, tty_fd, opt);
69 /* listen and interact to input */
70 input_get(buffer, tty_fd, opt);
72 draw_clear(opt->lines);
74 /* close files descriptors and pointers, and free memory */
75 close(tty_fd);
76 free(opt);
77 free_buffer(buffer);
79 return 0;