Prevent unwanted m4 macro expansion + -g GNU compatibility flag

Most of the included files are meant to be output literally, without any
macro processing. Using `undivert` in place of `include` achieves that.
This is a safety net against unsanitized input generated during the
build. Also, developers editing the shell code stub shouldn't be
constantly alert about triggering accidental macro expansion.

In order that `undivert` mimics GNU behaviour on BSDs, the `-g` flag is
used for the m4 invocation.
This commit is contained in:
Vladimir Zhelezov 2020-12-20 07:56:47 +01:00
parent 2e44fe9e90
commit 419817e656
2 changed files with 6 additions and 6 deletions

View File

@ -63,7 +63,7 @@ $(CMDOPTFILES)
endef
hledger-completion.bash: $(M4DEPS)
m4 hledger-completion.bash.m4 > $@
m4 -g hledger-completion.bash.m4 > $@
commands.txt:
printf "%s\n" $(COMMANDS) > $@

View File

@ -1,19 +1,19 @@
include(`hledger-completion.bash.stub')dnl
undivert(`hledger-completion.bash.stub')dnl
# Include lists of commands and options generated by the Makefile using the
# m4 macro processor.
# Included files must have exactly one newline at EOF to prevent weired errors.
read -r -d "" _hledger_complist_commands <<TEXT
include(`commands.txt')dnl
undivert(`commands.txt')dnl
TEXT
read -r -d "" _hledger_complist_query_filters <<TEXT
include(`query-filters.txt')dnl
undivert(`query-filters.txt')dnl
TEXT
read -r -d "" _hledger_complist_generic_options <<TEXT
include(`generic-options.txt')dnl
undivert(`generic-options.txt')dnl
TEXT
# Dashes are replaced by m4 with underscores to form valid identifiers
@ -22,7 +22,7 @@ dnl
include(`foreach2.m4')dnl
foreach(`cmd', (include(`commands-list.txt')), `
read -r -d "" _hledger_complist_options_`'translit(cmd, -, _) <<TEXT
include(options-cmd.txt)dnl
undivert(options-cmd.txt)dnl
TEXT
')dnl