From a8cba5fb49f78ae73e8002f3f2a45aaf3fb8cb71 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Sun, 8 Jan 2023 00:41:32 -0500 Subject: [PATCH] Use new packed option format from gen-options.awk. This new format uses a compact, fully constant array to generate the real struct option array at runtime. This allows the full-sized array to be dropped after command-line processing is finished, and with position-independent executables, reduces the amount of relocation processing needed. --- Makefile.am | 3 ++- common | 2 +- src/curses.c | 8 +++++--- src/motif.c | 8 +++++--- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Makefile.am b/Makefile.am index 88fde3c..d9c0c44 100644 --- a/Makefile.am +++ b/Makefile.am @@ -34,7 +34,8 @@ endif EXTRA_DIST += doc/rrace-motif.1 -noinst_HEADERS = conf_post.h src/version.h src/icon.h src/ewmhicon.h +noinst_HEADERS = conf_post.h src/version.h src/icon.h src/ewmhicon.h \ + common/src/xtra.h rrace_curses_SOURCES = common/src/help.c src/game.c src/version.c rrace_curses_LDADD = $(libcursesmain_a_OBJECTS) $(CURSES_LIBS) $(GNULIB) diff --git a/common b/common index 203a69f..e599119 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 203a69fab1ff61e958dfb88599fd5d7f24648abf +Subproject commit e599119f0492b01f1f21a8cce8d695c314dab3b1 diff --git a/src/curses.c b/src/curses.c index 2d9ef64..46f0d7e 100644 --- a/src/curses.c +++ b/src/curses.c @@ -24,6 +24,7 @@ #include #include "help.h" +#include "xtra.h" #include "version.h" #include "cursesui.h" @@ -34,7 +35,6 @@ enum { }; static const char *progname = "rrace"; -static const struct option lopts[] = { LOPTS_INITIALIZER, {0} }; static struct app_state state; @@ -53,7 +53,7 @@ static void print_usage(FILE *f) fprintf(f, "Try %s --help for more information.\n", progname); } -static void print_help(void) +static void print_help(const struct option *lopts) { struct lopt_help help = {0}; const struct option *opt; @@ -292,6 +292,8 @@ static void app_initialize(int argc, char **argv) int enable_mouse = 1; int opt; + XTRA_PACKED_LOPTS(lopts); + if (argc > 0) progname = argv[0]; @@ -307,7 +309,7 @@ static void app_initialize(int argc, char **argv) print_version(); exit(EXIT_SUCCESS); case LOPT_HELP: - print_help(); + print_help(lopts); exit(EXIT_SUCCESS); default: print_usage(stderr); diff --git a/src/motif.c b/src/motif.c index e3ff6c2..8b0fa41 100644 --- a/src/motif.c +++ b/src/motif.c @@ -25,6 +25,7 @@ #include #include "help.h" +#include "xtra.h" #include "motif.h" #include "ewmhicon.h" #include "motifopt.h" @@ -40,7 +41,6 @@ #define PROGNAME "rrace" static const char *progname = PROGNAME; -static const struct option lopts[] = { LOPTS_INITIALIZER, {0} }; static char * const default_resources[] = { "*title: RRace", @@ -76,7 +76,7 @@ static void print_usage(FILE *f) fprintf(f, "Try %s --help for more information.\n", progname); } -static void print_help(void) +static void print_help(const struct option *lopts) { struct lopt_help help = {0}; const struct option *opt; @@ -100,6 +100,8 @@ static Widget early_setup(XtAppContext *app, int argc, char **argv) Widget shell; int opt; + XTRA_PACKED_LOPTS(lopts); + /* Check for --help/--version early (before X connection) */ opterr = 0; while ((opt = getopt_long_only(argc, argv, "", lopts, NULL)) != -1) { @@ -108,7 +110,7 @@ static Widget early_setup(XtAppContext *app, int argc, char **argv) print_version(); exit(EXIT_SUCCESS); case LOPT_HELP: - print_help(); + print_help(lopts); exit(EXIT_SUCCESS); } } -- 2.43.2