3 * This file is part of PlomRogue. PlomRogue is licensed under the GPL version 3
4 * or any later version. For details on its copyright, license, and warranties,
5 * see the file NOTICE in the root directory of the PlomRogue source package.
8 #define _POSIX_C_SOURCE 1 /* sigaction, sigaction() */
9 #define _DARWIN_C_SOURCE 1 /* SIGWINCH on OS X */
10 #include <ncurses.h> /* keypad(), start_color() */
11 #include <signal.h> /* SIGWINCH, sigaction, sigaction() */
12 #include <stddef.h> /* NULL */
13 #include <stdlib.h> /* exit() */
14 #include <string.h> /* memset() */
15 #include <unistd.h> /* access() */
16 #include "../common/readwrite.h" /* try_fopen() */
17 #include "../common/rexit.h" /* set_cleanup_func(), exit_trouble(),exit_err() */
18 #include "cleanup.h" /* cleanup(), set_cleanup_flag() */
19 #include "command_db.h" /* init_command_db() */
20 #include "interface_conf.h" /* load_interface_conf(), obey_argv() */
21 #include "io.h" /* io_loop() */
22 #include "windows.h" /* winch_called() */
23 #include "world.h" /* struct World */
31 int main(int argc, char * argv[])
33 /* Declare hard-coded paths and values here. */
34 world.path_commands = "confclient/commands";
35 world.path_interface = "confclient/interface_conf";
36 world.winDB.legal_ids = "012cilms";
37 char * path_server_in = "server/in";
38 char * path_server_out = "server/out";
40 /* Parse command line arguments. */
41 obey_argv(argc, argv);
43 /* So error exits also go through the client's cleanup() function. */
44 set_cleanup_func(cleanup);
46 /* Check existence of config files. */
47 exit_err(access(world.path_commands, F_OK), "No commands config file.");
48 exit_err(access(world.path_interface, F_OK), "No interface config file.");
50 /* Initialize the whole interface. */
51 world.winDB.t_screen = initscr();
53 set_cleanup_flag(CLEANUP_NCURSES);
56 keypad(world.winDB.t_screen, TRUE);
57 init_command_db(); /* The command DB needs to be initialized before */
58 load_interface_conf(); /* the interface, whose keybindings depend on it. */
61 /* Set handler for terminal window resizing. */
63 memset(&act, 0, sizeof(act));
64 act.sa_handler = &winch_called;
65 exit_trouble(sigaction(SIGWINCH, &act, NULL), __func__, "sigaction");
67 /* Open file streams for communicating with the server. */
68 exit_err(access(path_server_in, F_OK), "No server input file found.");
69 world.file_server_in = try_fopen(path_server_in, "a", __func__);
70 set_cleanup_flag(CLEANUP_SERVER_IN);
71 world.file_server_out = try_fopen(path_server_out, "r", __func__);
72 set_cleanup_flag(CLEANUP_SERVER_OUT);
74 /* This is where most everything happens. */
75 char * quit_msg = io_loop();
79 exit_trouble(printf("%s\n", quit_msg) < 0, __func__, "printf");