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