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