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/>.
30 #define PROGNAME "rrace"
31 static const char *progname = PROGNAME;
32 static const struct option lopts[] = { LOPTS_INITIALIZER, {0} };
34 static char * const default_resources[] = {
35 PROGNAME "*game.height: 371", // 365 + 2*shadowThickness
36 PROGNAME "*game.width: 498",
38 PROGNAME "*game.XmFrame.shadowThickness: 3",
39 PROGNAME "*game.XmFrame.shadowType: shadow_in",
40 PROGNAME "*goalArea.leftOffset: 1",
45 static void print_version(void)
47 printf("%s %s\n", PROGNAME, PACKAGE_VERSION);
48 printf("Copyright (C) 2022 Nick Bowler\n");
49 puts("License GPLv3+: GNU GPL version 3 or any later version");
50 puts("This is free software: you are free to change and redistribute it.");
51 puts("There is NO WARRANTY, to the extent permitted by law.");
54 static void print_usage(FILE *f)
56 fprintf(f, "Usage: %s [options]\n", progname);
58 fprintf(f, "Try %s --help for more information.\n", progname);
61 static void print_help(void)
63 const struct option *opt;
69 for (opt = lopts; opt->name; opt++) {
70 struct lopt_help help;
73 if (!lopt_get_help(opt, &help))
75 help_print_option(opt, help.arg, help.desc, 20);
79 printf("Report bugs to <%s>.\n", PACKAGE_BUGREPORT);
82 static Widget early_setup(XtAppContext *app, int argc, char **argv)
87 /* Check for --help/--version early (before X connection) */
89 while ((opt = getopt_long_only(argc, argv, "", lopts, NULL)) != -1) {
100 shell = XtOpenApplication(app, PROGNAME, NULL, 0,
101 &argc, argv, (String *)default_resources,
102 sessionShellWidgetClass, NULL, 0);
105 while ((opt = getopt_long_only(argc, argv, "", lopts, NULL)) != -1) {
114 fprintf(stderr, "%s: excess command-line arguments.\n",
123 static XtAppContext app_initialize(int argc, char **argv)
131 shell = early_setup(&app, argc, argv);
132 ui_initialize(shell);
133 XtRealizeWidget(shell);
138 int main(int argc, char **argv)
140 XtAppMainLoop(app_initialize(argc, argv));