Skip to content

Commit 077b141

Browse files
committed
Makefile.am, docs/Makefile.am: add recipe for spellcheck-report-dict-usage to prepare a $(NUT_SPELL_DICT).usage-report [networkupstools#2402]
Facilitate maintenance of nut-website's spell checking dictionary with words unique to the site sources. Signed-off-by: Jim Klimov <[email protected]>
1 parent 6356ff6 commit 077b141

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Makefile.in
5050
/test-driver
5151
*-spellchecked
5252
*-prepped
53+
*.usage-report
5354
*.adoc-parsed
5455
*.adoc*.tmp
5556
*.txt*.tmp

Makefile.am

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ spellcheck spellcheck-interactive:
175175
# such as PDF generators, so it should only be called at developer's
176176
# discretion, choice and risk. The "check-man" targets covers source
177177
# texts, man pages and HTML rendering of man pages, as enabled by tools.
178-
doc spellcheck-sortdict \
178+
doc spellcheck-sortdict spellcheck-report-dict-usage \
179179
all-docs check-docs \
180180
man all-man man-man check-man man-html all-html:
181181
+cd $(abs_top_builddir)/docs && $(MAKE) $(AM_MAKEFLAGS) -s $(abs_top_builddir)/docs/.prep-src-docs

docs/Makefile.am

+46
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ ALL_TXT_SRC = nut-names.txt daisychain.txt \
8888
release-notes.txt ChangeLog.txt solaris-usb.txt
8989

9090
ASPELL_FILTER_PATH = @ASPELL_FILTER_PATH@
91+
# NOTE: This can be set by caller such as nut-website builder:
9192
NUT_SPELL_DICT = nut.dict
9293
EXTRA_DIST += $(ALL_TXT_SRC) $(SHARED_DEPS) $(IMAGE_FILES) \
9394
$(IMAGE_LOGO_FILES) $(IMAGE_LOGO_FILES_JENKINS_NUT) $(CABLES_IMAGES) $(NUT_SPELL_DICT) \
@@ -145,6 +146,16 @@ all-docs: docs
145146

146147
check-docs: check-pdf check-html-single check-html-chunked check-man
147148

149+
# Not called by default, but handy for maintainers to check which words
150+
# in the custom dictionary are used or not by the current NUT codebase.
151+
# Note that historically many words were added to facilitate rendition
152+
# of the nut-website (long ago splintered from main nut repository),
153+
# but since recently it has a way to track its own additions to the
154+
# dictionary file. This code should help populate it as well, and keep
155+
# only relevant entries in the appropriate corner of the sources.
156+
# Note this can take 5-10 minutes!
157+
spellcheck-report-dict-usage: $(NUT_SPELL_DICT).usage-report
158+
148159
pdf: $(ASCIIDOC_PDF)
149160
# also build the HTML manpages with these targets
150161
html-single: $(ASCIIDOC_HTML_SINGLE)
@@ -611,6 +622,41 @@ spellcheck-interactive:
611622
@echo "Documentation spell check not available since 'aspell' was not found (or missing its English dictionary)."
612623
endif !HAVE_ASPELL
613624

625+
# Note that NUT_SPELL_DICT may be an include snippet without the header line.
626+
# To exclude files like `docs/nut.dict` or `nut-website.dict(.addons)` from
627+
# the usage lookups, we assume that a `*.dict*` pattern fits any used names.
628+
# Entries prefixed with '+++' mean something used in NUT sources in context
629+
# that aspell is likely to treat as a word (standalone or surrounded by certain
630+
# chars); otherwise in entries prefixed with '---' we print hit counts and
631+
# contents (if any, ending with '^^^') for the character pattern across the
632+
# whole Git-tracked codebase (case-insensitively for good measure).
633+
# Note this can take 5-10 minutes!
634+
# TOTHINK: Constrain to (caller-specified or default) SPELLCHECK_SRC?
635+
$(NUT_SPELL_DICT).usage-report: $(NUT_SPELL_DICT)
636+
@echo "Preparing $@"; \
637+
LANG=C; LC_ALL=C; export LANG; export LC_ALL; \
638+
grep -v -E '^personal_ws' < $? \
639+
| while read W ; do ( \
640+
cd "$(abs_top_srcdir)" || exit ; \
641+
git grep -q "$$W" -- ':!*.dict*' || git grep -qE "[0-9_,./\ -]$$W[0-9_,./\ -]" -- ':!*.dict*' ) \
642+
&& echo "+++ $$W" \
643+
|| ( \
644+
HITS_CS="`git grep "$$W" -- ':!*.dict*'`" || true; \
645+
HITS_CI="`git grep -i "$$W" -- ':!*.dict*'`" || true; \
646+
if [ -n "$$HITS_CS" ] ; then HITC_CS="`echo "$$HITS_CS" | wc -l`" ; else HITC_CS=0; fi; \
647+
if [ -n "$$HITS_CI" ] ; then HITC_CI="`echo "$$HITS_CI" | wc -l`" ; else HITC_CI=0; fi; \
648+
printf '%s (%d case-sensitive/%d case-insensitive)\n' "--- $$W" "$$HITC_CS" "$$HITC_CI"; \
649+
if [ "$$HITC_CS" != 0 ] ; then echo "$$HITS_CS" ; echo "^^^"; else \
650+
if [ "$$HITC_CI" != 0 ] ; then echo "$$HITS_CI" ; echo "^^^"; fi; \
651+
fi; \
652+
); \
653+
done > "$@.tmp"
654+
test -f "$@.tmp" && mv -f "$@.tmp" "$@"
655+
@echo "Reporting words from $? possibly not used in current inspected code base revision under $(abs_top_srcdir)" >&2 ; \
656+
grep -E '^--- ' < "$@" | grep '(0)' || echo "SUCCESS: None found"
657+
658+
CLEANFILES += $(NUT_SPELL_DICT).usage-report.tmp
659+
MAINTAINERCLEANFILES += $(NUT_SPELL_DICT).usage-report
614660

615661
# When building out-of-tree, be sure to have all asciidoc resources
616662
# under the same dir structure (tool limitation)

0 commit comments

Comments
 (0)