]> git.sur5r.net Git - tio/blob - src/main.c
Imported Upstream version 1.18
[tio] / src / main.c
1 /*
2  * tio - a simple TTY terminal I/O application
3  *
4  * Copyright (c) 2014-2016  Martin Lund
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21
22 #include "config.h"
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <unistd.h>
26 #include "tio/options.h"
27 #include "tio/tty.h"
28 #include "tio/log.h"
29 #include "tio/error.h"
30 #include "tio/print.h"
31
32 int main(int argc, char *argv[])
33 {
34     int status;
35
36     /* Install error exit handler */
37     atexit(&error_exit);
38
39     /* Parse options */
40     parse_options(argc, argv);
41
42     /* Configure tty device */
43     tty_configure();
44
45     /* Configure output terminal */
46     stdout_configure();
47
48     /* Install log exit handler */
49     atexit(&log_exit);
50
51     /* Create log file */
52     if (option.log)
53         log_open(option.log_filename);
54
55     /* Connect to tty device */
56     if (option.no_autoconnect)
57         status = tty_connect();
58     else
59     {
60         /* Enter connect loop */
61         while (true)
62         {
63             tty_wait_for_device();
64             status = tty_connect();
65         }
66     }
67
68     return status;
69 }