2 * X11 GUI for slide puzzle game
3 * Copyright © 2022 Nick Bowler
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
31 #define PROGNAME "rrace"
32 static const char *progname = PROGNAME;
33 static const struct option lopts[] = { LOPTS_INITIALIZER, {0} };
35 static char * const default_resources[] = {
36 PROGNAME "*game.height: 371", // 365 + 2*shadowThickness
37 PROGNAME "*game.width: 498",
39 PROGNAME "*game.XmFrame.shadowThickness: 3",
40 PROGNAME "*game.XmFrame.shadowType: shadow_in",
41 PROGNAME "*goalArea.leftOffset: 1",
42 PROGNAME "*gameCanvas.background: #404040",
47 static void print_version(void)
49 printf("%s %s\n", PROGNAME, PACKAGE_VERSION);
50 printf("Copyright (C) 2022 Nick Bowler\n");
51 puts("License GPLv3+: GNU GPL version 3 or any later version");
52 puts("This is free software: you are free to change and redistribute it.");
53 puts("There is NO WARRANTY, to the extent permitted by law.");
56 static void print_usage(FILE *f)
58 fprintf(f, "Usage: %s [options]\n", progname);
60 fprintf(f, "Try %s --help for more information.\n", progname);
63 static void print_help(void)
65 const struct option *opt;
71 for (opt = lopts; opt->name; opt++) {
72 struct lopt_help help;
75 if (!lopt_get_help(opt, &help))
77 help_print_option(opt, help.arg, help.desc, 20);
81 printf("Report bugs to <%s>.\n", PACKAGE_BUGREPORT);
84 static Widget early_setup(XtAppContext *app, int argc, char **argv)
89 /* Check for --help/--version early (before X connection) */
91 while ((opt = getopt_long_only(argc, argv, "", lopts, NULL)) != -1) {
102 shell = XtOpenApplication(app, PROGNAME, NULL, 0,
103 &argc, argv, (String *)default_resources,
104 sessionShellWidgetClass, NULL, 0);
107 while ((opt = getopt_long_only(argc, argv, "", lopts, NULL)) != -1) {
116 fprintf(stderr, "%s: excess command-line arguments.\n",
125 static XtAppContext app_initialize(int argc, char **argv)
127 static struct app_state state;
134 shell = early_setup(&app, argc, argv);
135 ui_initialize(&state, shell);
136 x11_initialize(&state, XtScreen(shell));
137 game_reset(&state.board);
138 XtRealizeWidget(shell);
143 int main(int argc, char **argv)
145 XtAppMainLoop(app_initialize(argc, argv));