home · contact · privacy
Client: Save commands config file path in world struct.
[plomrogue] / src / client / main.c
1 /* main.c */
2
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 "../common/rexit.h" /* set_cleanup_func(), exit_trouble() */
9 #include "cleanup.h" /* cleanup(), set_cleanup_flag() */
10 #include "command_db.h" /* init_command_db() */
11 #include "io.h" /* io_loop(), try_send() */
12 #include "misc.h" /* load_interface_conf(), winch_called() */
13 #include "windows.h" /* struct Win, winch_called() */
14 #include "world.h" /* struct World */
15
16
17
18 struct World world;
19
20
21
22 int main(int argc, char * argv[])
23 {
24     char * f_name = "main()";
25
26     /* Declare hard-coded paths here. */
27     world.path_server_in      = "server/in";
28     world.path_commands       = "confclient/commands";
29     world.path_interface_conf = "confclient/interface_conf";
30
31     /* Parse command line arguments. */
32     obey_argv(argc, argv);
33
34     /* So error exits also go through the client's cleanup() function. */
35     set_cleanup_func(cleanup);
36
37     /* Initialize the whole interface. */
38     world.winDB.t_screen = initscr();
39     set_cleanup_flag(CLEANUP_NCURSES);
40     noecho();
41     curs_set(0);
42     keypad(world.winDB.t_screen, TRUE);
43     init_command_db();      /* The command DB needs to be initialized before  */
44     load_interface_conf();  /* the interface, whose keybindings depend on it. */
45
46     /* Set handler for terminal window resizing. */
47     struct sigaction act;
48     memset(&act, 0, sizeof(act));
49     act.sa_handler = &winch_called;
50     exit_trouble(sigaction(SIGWINCH, &act, NULL), f_name, "sigaction()");
51
52     /* This is where most everything happens. */
53     char * quit_msg = io_loop();
54
55     /* Leave properly. */
56     cleanup();
57     printf("%s\n", quit_msg);
58     exit(EXIT_SUCCESS);
59 }