3 #include <ncurses.h> /* keypad() */
4 #include <signal.h> /* struct sigaction, sigaction() */
5 #include <stddef.h> /* NULL */
6 #include <stdlib.h> /* exit() */
7 #include <string.h> /* memset() */
8 #include <unistd.h> /* access() */
9 #include "../common/err_try_fgets.h" /* set_err_try_fgets_delim() */
10 #include "../common/rexit.h" /* set_cleanup_func(), exit_trouble(),exit_err() */
11 #include "cleanup.h" /* cleanup(), set_cleanup_flag() */
12 #include "command_db.h" /* init_command_db() */
13 #include "io.h" /* io_loop(), try_send() */
14 #include "misc.h" /* load_interface_conf(), winch_called() */
15 #include "windows.h" /* winch_called() */
16 #include "world.h" /* struct World */
24 int main(int argc, char * argv[])
26 char * f_name = "main()";
28 /* Declare hard-coded paths and values here. */
29 world.path_server_in = "server/in";
30 world.path_commands = "confclient/commands";
31 world.path_interface = "confclient/interface_conf";
32 world.winDB.legal_ids = "012ciklm";
34 set_err_try_fgets_delim(world.delim);
36 /* Parse command line arguments. */
37 obey_argv(argc, argv);
39 /* So error exits also go through the client's cleanup() function. */
40 set_cleanup_func(cleanup);
42 /* Check existence of config files. */
43 exit_err(access(world.path_commands, F_OK), "No commands config file.");
44 exit_err(access(world.path_interface, F_OK), "No interface config file.");
46 /* Initialize the whole interface. */
47 world.winDB.t_screen = initscr();
48 set_cleanup_flag(CLEANUP_NCURSES);
51 keypad(world.winDB.t_screen, TRUE);
52 init_command_db(); /* The command DB needs to be initialized before */
53 load_interface_conf(); /* the interface, whose keybindings depend on it. */
55 /* Set handler for terminal window resizing. */
57 memset(&act, 0, sizeof(act));
58 act.sa_handler = &winch_called;
59 exit_trouble(sigaction(SIGWINCH, &act, NULL), f_name, "sigaction()");
61 /* This is where most everything happens. */
62 char * quit_msg = io_loop();
66 printf("%s\n", quit_msg);