From b579e346cef958bd5ef42a3c22b15232542db5f9 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Tue, 3 Jan 2023 23:01:44 -0500 Subject: [PATCH] motif: Optimize widget string table a bit. With a little tweaking of how the tables are generated, we can include a few of the traversal strings into the same table as the widget names, which compacts things a little bit. --- Makefile.am | 12 +++++------- common | 2 +- src/mkstrtab.awk | 24 ++++++++++++++++++++++++ src/motif_ui.c | 14 ++++++++------ src/motifgui.dat | 7 +++++++ 5 files changed, 45 insertions(+), 14 deletions(-) create mode 100755 src/mkstrtab.awk diff --git a/Makefile.am b/Makefile.am index f64bb6d..c0d0c27 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -# Copyright © 2022 Nick Bowler +# Copyright © 2022-2023 Nick Bowler # # License WTFPL2: Do What The Fuck You Want To Public License, version 2. # This is free software: you are free to do what the fuck you want to. @@ -78,14 +78,12 @@ TREEFILES = src/cursmenu.dat src/motifgui.dat .dat.h: $(AM_V_GEN) :; { \ $(AWK) -f $(DX_BASEDIR)/scripts/gen-tree.awk $< && \ - printf '%s\n' \ - 'sub(/^#&/, "\\&") == 0 { next }' \ - '{ has_strtab=1 } END { if (!has_strtab) { exit(0); } print "" }' \ - | $(AWK) -f - -f $(DX_BASEDIR)/scripts/gen-strtab.awk $<; \ + $(AWK) -f $(srcdir)/src/mkstrtab.awk \ + -f $(DX_BASEDIR)/scripts/gen-strtab.awk $<; \ } >$@-t $(AM_V_at) mv -f $@-t $@ -$(TREEFILES:.dat=.h): $(DX_BASEDIR)/scripts/gen-strtab.awk -EXTRA_DIST += $(DX_BASEDIR)/scripts/gen-strtab.awk +$(TREEFILES:.dat=.h): src/mkstrtab.awk $(DX_BASEDIR)/scripts/gen-strtab.awk +EXTRA_DIST += src/mkstrtab.awk $(DX_BASEDIR)/scripts/gen-strtab.awk $(TREEFILES:.dat=.h): $(DX_BASEDIR)/scripts/gen-tree.awk EXTRA_DIST += $(DX_BASEDIR)/scripts/gen-tree.awk DISTCLEANFILES += $(TREEFILES:.dat=.h) diff --git a/common b/common index 8cda0a6..203a69f 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 8cda0a6cc9cc31edf0fe94c470038f12c8dcc905 +Subproject commit 203a69fab1ff61e958dfb88599fd5d7f24648abf diff --git a/src/mkstrtab.awk b/src/mkstrtab.awk new file mode 100755 index 0000000..aa21937 --- /dev/null +++ b/src/mkstrtab.awk @@ -0,0 +1,24 @@ +#!/bin/awk -f +# +# Copyright © 2023 Nick Bowler +# +# Helper script used by the RRace makefile to combine gen-tree.awk and +# gen-strtab.awk inputs into a single source file and build rule. +# +# Usage: awk -f mkstrtab.awk -f gen-strtab.awk input.dat +# +# License WTFPL2: Do What The Fuck You Want To Public License, version 2. +# This is free software: you are free to do what the fuck you want to. +# There is NO WARRANTY, to the extent permitted by law. + +{ + if (sub(/^#&/, "\\&")) { + # Lines beginning with #& are taken verbatim (with the # removed) + explicit[$1] = 1; + } else if (sub(/,$/, "", $1) && !("&"$1 in explicit)) { + # Put tree node ids into the strtab, unless explicitly defined earlier. + $0 = "&&" $1 " " $1; + } else { + next; + } +} diff --git a/src/motif_ui.c b/src/motif_ui.c index c650031..e1b523a 100644 --- a/src/motif_ui.c +++ b/src/motif_ui.c @@ -1,6 +1,6 @@ /* * X11 GUI for slide puzzle game - * Copyright © 2022 Nick Bowler + * Copyright © 2022-2023 Nick Bowler * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,6 +26,8 @@ #include "xcounter.h" #include "version.h" +#define tree_strtab strtab + /* XXX generate this list? */ enum { widgetMainWindow, @@ -267,13 +269,13 @@ void ui_initialize(struct app_state *state, Widget shell) construct_widgets(mainwin, shell, 0); - menubar = XtNameToWidget(shell, "*menuBar"); + menubar = XtNameToWidget(shell, &strtab[glob_menuBar]); construct_menu(mainmenu, menubar, 0); - help = XtNameToWidget(menubar, "helpMenu"); + help = XtNameToWidget(menubar, tree_strtab+helpMenu); XtVaSetValues(menubar, XmNmenuHelpWidget, help, (char *)NULL); - configure_mainwin(state, XtNameToWidget(shell, "*game")); + configure_mainwin(state, XtNameToWidget(shell, &strtab[glob_game])); XtAddCallback(state->game, XmNresizeCallback, resize, state); XtAddCallback(state->game, XmNexposeCallback, expose, state); @@ -304,7 +306,7 @@ void ui_show_about(struct app_state *state, Widget shell) construct_widgets(dialog, shell, 0); - w = XtNameToWidget(shell, "*aboutDialog"); + w = XtNameToWidget(shell, &strtab[glob_aboutDialog]); XtUnmanageChild(XmMessageBoxGetChild(w, XmDIALOG_CANCEL_BUTTON)); XtAddCallback(w, XmNunmapCallback, dialog_close, NULL); @@ -322,7 +324,7 @@ void ui_show_about(struct app_state *state, Widget shell) (char *)NULL); free(msg); - l = XtNameToWidget(w, "*licenseBlurb"); + l = XtNameToWidget(w, &strtab[glob_licenseBlurb]); XmTextSetString(l, "This program is free software: you can redistribute it and/or modify\n" "it under the terms of the GNU General Public License as published by\n" diff --git a/src/motifgui.dat b/src/motifgui.dat index a562e06..8ab82c4 100644 --- a/src/motifgui.dat +++ b/src/motifgui.dat @@ -1,3 +1,5 @@ +@nostrtab + MAINWIN main, main_OFFSET, widgetMainWindow menuBar, 0, widgetMenuBar @@ -24,3 +26,8 @@ MAINMENU gameExit, 0, widgetPushButton, gameExitLabel helpMenu, helpMenu_OFFSET, widgetCascadeButton, helpMenuLabel helpAbout, 0, widgetPushButton, helpAboutLabel + +#&&glob_licenseBlurb *licenseBlurb +#&&glob_aboutDialog *aboutDialog +#&&glob_menuBar *menuBar +#&&glob_game *game -- 2.43.2