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/readwrite.h" /* try_fopen() */
11 #include "../common/rexit.h" /* set_cleanup_func(), exit_trouble(),exit_err() */
12 #include "cleanup.h" /* cleanup(), set_cleanup_flag() */
13 #include "command_db.h" /* init_command_db() */
14 #include "io.h" /* io_loop() */
15 #include "misc.h" /* load_interface_conf(), winch_called() */
16 #include "windows.h" /* winch_called() */
17 #include "world.h" /* struct World */
25 int main(int argc, char * argv[])
27 char * f_name = "main()";
29 /* Declare hard-coded paths and values here. */
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);
35 char * path_server_in = "server/in";
36 char * path_server_out = "server/out";
38 /* Parse command line arguments. */
39 obey_argv(argc, argv);
41 /* So error exits also go through the client's cleanup() function. */
42 set_cleanup_func(cleanup);
44 /* Check existence of config files. */
45 exit_err(access(world.path_commands, F_OK), "No commands config file.");
46 exit_err(access(world.path_interface, F_OK), "No interface config file.");
48 /* Initialize the whole interface. */
49 world.winDB.t_screen = initscr();
50 set_cleanup_flag(CLEANUP_NCURSES);
53 keypad(world.winDB.t_screen, TRUE);
54 init_command_db(); /* The command DB needs to be initialized before */
55 load_interface_conf(); /* the interface, whose keybindings depend on it. */
57 /* Set handler for terminal window resizing. */
59 memset(&act, 0, sizeof(act));
60 act.sa_handler = &winch_called;
61 exit_trouble(sigaction(SIGWINCH, &act, NULL), f_name, "sigaction()");
63 /* Open file streams for communicating with the server. */
64 exit_err(access(path_server_in, F_OK), "No server input file found.");
65 world.file_server_in = try_fopen(path_server_in, "a", f_name);
66 set_cleanup_flag(CLEANUP_SERVER_IN);
67 world.file_server_out = try_fopen(path_server_out, "r", f_name);
68 set_cleanup_flag(CLEANUP_SERVER_OUT);
70 /* This is where most everything happens. */
71 char * quit_msg = io_loop();
75 printf("%s\n", quit_msg);