]> git.draconx.ca Git - rrace.git/commitdiff
motif: Optimize widget string table a bit.
authorNick Bowler <nbowler@draconx.ca>
Wed, 4 Jan 2023 04:01:44 +0000 (23:01 -0500)
committerNick Bowler <nbowler@draconx.ca>
Sat, 7 Jan 2023 16:43:13 +0000 (11:43 -0500)
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
common
src/mkstrtab.awk [new file with mode: 0755]
src/motif_ui.c
src/motifgui.dat

index f64bb6d3eea227134a92c8fa684f488af68966ba..c0d0c273a1cc4eb4e5547a5cfc4dab1732df9ba4 100644 (file)
@@ -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 8cda0a6cc9cc31edf0fe94c470038f12c8dcc905..203a69fab1ff61e958dfb88599fd5d7f24648abf 160000 (submodule)
--- 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 (executable)
index 0000000..aa21937
--- /dev/null
@@ -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;
+  }
+}
index c6500311a8264017fd638490e44bd84cffd02cd1..e1b523a0088cae77603c4e204c9318fc1d0b1764 100644 (file)
@@ -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"
index a562e06f257bae46f59be5d57a569a8bda072e70..8ab82c4f00c9b9fd302c1a2d15c25d0f9194c95d 100644 (file)
@@ -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