[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 15/34: [sboxes]: Leap through flaming DRY hoop.
From: |
G. Branden Robinson |
Subject: |
[groff] 15/34: [sboxes]: Leap through flaming DRY hoop. |
Date: |
Sat, 16 Oct 2021 23:07:23 -0400 (EDT) |
gbranden pushed a commit to branch master
in repository groff.
commit 67b2e3c8acd2053f0b617de8a2ea4cee779b8b83
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Sun Oct 17 13:52:13 2021 +1100
[sboxes]: Leap through flaming DRY hoop.
Make msboxes.ms quote its own source through a self-interpolation
process (with help from sed and the build system), avoiding the need to
manually keep the source document and its quoted form in sync.
* msboxes.ms: Rename to...
* msboxes.ms.in: ...this.
* notquine.sed: New file; this sed script performs quotation of roff
syntax characters (and hyphens), inserts the quoted form of the
document's source into itself, and reproduces Deri's Schrödinger's
footnote trick.
* sboxes.am: Introduce new variables `sboxes_builddir` and
`sboxesnotquine` for convenience. Update value of
$(SBOXES_EXAMPLEFILES) to point to the new .in source file. Add the
generated ms document to $(SBOXES_PROCESSEDEXAMPLEFILES) and
$(MOSTLYCLEANFILES). Add the `notquine` sed script to the
distribution archive via $(EXTRA_DIST).
($(sboxes_builddir)/msboxes.ms): New rule produces the ms
document from msboxes.ms.in, constructing it with sed.
($(sboxes_builddir)/msboxes.pdf): Update rule to add dependency
on source document, use new `sboxes_builddir` variable, and look
for source document in the build tree instead of the source.
---
contrib/sboxes/ChangeLog | 25 ++++++++++++++++++++++
contrib/sboxes/{msboxes.ms => msboxes.ms.in} | 0
contrib/sboxes/notquine.sed | 17 +++++++++++++++
contrib/sboxes/sboxes.am | 31 +++++++++++++++++++++-------
4 files changed, 65 insertions(+), 8 deletions(-)
diff --git a/contrib/sboxes/ChangeLog b/contrib/sboxes/ChangeLog
index 9f0ee9a..4e7428e 100644
--- a/contrib/sboxes/ChangeLog
+++ b/contrib/sboxes/ChangeLog
@@ -1,5 +1,30 @@
2021-10-17 G. Branden Robinson <g.branden.robinson@gmail.com>
+ Make msboxes.ms quote its own source through a
+ self-interpolation process (with help from sed and the build
+ system), avoiding the need to manually keep the source document
+ and its quoted form in sync.
+
+ * msboxes.ms: Rename to...
+ * msboxes.ms.in: ...this.
+ * notquine.sed: New file; this sed script performs quotation of
+ roff syntax characters (and hyphens), inserts the quoted form of
+ the document's source into itself, and reproduces Deri's
+ Schrödinger's footnote trick.
+ * sboxes.am: Introduce new variables `sboxes_builddir` and
+ `sboxesnotquine` for convenience. Update value of
+ $(SBOXES_EXAMPLEFILES) to point to the new .in source file. Add
+ the generated ms document to $(SBOXES_PROCESSEDEXAMPLEFILES) and
+ $(MOSTLYCLEANFILES). Add the `notquine` sed script to the
+ distribution archive via $(EXTRA_DIST).
+ ($(sboxes_builddir)/msboxes.ms): New rule produces the ms
+ document from msboxes.ms.in, constructing it with sed.
+ ($(sboxes_builddir)/msboxes.pdf): Update rule to add dependency
+ on source document, use new `sboxes_builddir` variable, and look
+ for source document in the build tree instead of the source.
+
+2021-10-17 G. Branden Robinson <g.branden.robinson@gmail.com>
+
* sboxes.am: Add this ChangeLog to `EXTRA_DIST`.
2021-10-11 G. Branden Robinson <g.branden.robinson@gmail.com>
diff --git a/contrib/sboxes/msboxes.ms b/contrib/sboxes/msboxes.ms.in
similarity index 100%
rename from contrib/sboxes/msboxes.ms
rename to contrib/sboxes/msboxes.ms.in
diff --git a/contrib/sboxes/notquine.sed b/contrib/sboxes/notquine.sed
new file mode 100644
index 0000000..248d50a
--- /dev/null
+++ b/contrib/sboxes/notquine.sed
@@ -0,0 +1,17 @@
+s/\\" FOOTNOTE/@FOOTNOTE@/
+s/.*\\##.*/&\n&/
+/\\##/{
+ s/\\##//
+ b}
+s/\\/\\[rs]/g
+s/-/\\&/g
+s/'/\\[aq]/g
+s/^\./\\\&&/
+/@FOOTNOTE@/a\
+.FS\
+This is just a long footnote. Its purpose is only to check that the\
+bottom of the box on this page has been adjusted because of the size\
+of the footnote.\
+.FE
+s/@FOOTNOTE@/\\m[red]\\**\\m[]/
+s/REPLACEME/(replaced by source of this document)/
diff --git a/contrib/sboxes/sboxes.am b/contrib/sboxes/sboxes.am
index 4be77a7..091865c 100644
--- a/contrib/sboxes/sboxes.am
+++ b/contrib/sboxes/sboxes.am
@@ -18,6 +18,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
sboxes_srcdir = $(top_srcdir)/contrib/sboxes
+sboxes_builddir = $(top_builddir)/contrib/sboxes
+sboxesnotquine = $(sboxes_srcdir)/notquine.sed
SBOXES_FLAGS = -M$(sboxes_srcdir) -ms -msboxes -Tpdf
# Files installed in $(tmacdir).
SBOXES_NORMAL_FILES = contrib/sboxes/sboxes.tmac
@@ -25,32 +27,45 @@ sboxestmacdir = $(tmacdir)
dist_sboxestmac_DATA = $(SBOXES_NORMAL_FILES)
EXTRA_DIST += \
- contrib/sboxes/ChangeLog
+ contrib/sboxes/ChangeLog \
+ contrib/sboxes/notquine.sed
# Files installed in $(examplesdir)/sboxes. SBOXES_EXAMPLEFILES are
# located in the source tree, while SBOXESPROCESSEDEXAMPLEFILES are
# generated in the build tree.
-SBOXES_EXAMPLEFILES= contrib/sboxes/msboxes.ms
+SBOXES_EXAMPLEFILES = $(sboxes_srcdir)/msboxes.ms.in
if BUILD_EXAMPLES
sboxesexampledir = $(exampledir)/sboxes
dist_sboxesexample_DATA = $(SBOXES_EXAMPLEFILES)
-SBOXES_PROCESSEDEXAMPLEFILES = contrib/sboxes/msboxes.pdf
+SBOXES_PROCESSEDEXAMPLEFILES = contrib/sboxes/msboxes.ms \
+ contrib/sboxes/msboxes.pdf
sboxesprocessedexampledir = $(exampledir)/sboxes
nodist_sboxesprocessedexample_DATA = $(SBOXES_PROCESSEDEXAMPLEFILES)
else
EXTRA_DIST += \
- $(SBOXES_EXAMPLEFILES)
+ contrib/sboxes/msboxes.ms.in
endif
-MOSTLYCLEANFILES += $(SBOXES_PROCESSEDEXAMPLEFILES)
+MOSTLYCLEANFILES += msboxes.ms \
+ $(SBOXES_PROCESSEDEXAMPLEFILES)
$(SBOXES_PROCESSEDEXAMPLEFILES): $(SBOXES_NORMAL_FILES) \
groff troff gropdf font/devpdf/build_font_files
-contrib/sboxes/msboxes.pdf:
- mkdir -p $(top_builddir)/contrib/sboxes/
+# The ordering of the sed -e expressions is important.
+$(sboxes_builddir)/msboxes.ms: $(SBOXES_EXAMPLEFILES) $(sboxesnotquine)
+ mkdir -p $(sboxes_builddir)
+ $(SED) -n -e '1,/REPLACEME/p' \
+ $(SBOXES_EXAMPLEFILES) > $@.tmp
+ $(SED) -f $(sboxesnotquine) \
+ $(SBOXES_EXAMPLEFILES) >> $@.tmp
+ $(SED) -n -e '/REPLACEME/,$$p' \
+ $(SBOXES_EXAMPLEFILES) >> $@.tmp
+ mv $@.tmp $@
+
+$(sboxes_builddir)/msboxes.pdf: $(sboxes_builddir)/msboxes.ms
$(top_builddir)/test-groff $(SBOXES_FLAGS) \
- $(sboxes_srcdir)/msboxes.ms > $@
+ $(sboxes_builddir)/msboxes.ms > $@
uninstall_groffdirs: uninstall_sboxes
uninstall_sboxes:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 15/34: [sboxes]: Leap through flaming DRY hoop.,
G. Branden Robinson <=