Skip to content

Commit 6c939ed

Browse files
authored
Merge pull request #72 from matejak/newlines
Added the newline substitution functionality to the second help desc.
2 parents 48b8a7d + 04c8695 commit 6c939ed

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/stuff.m4

+3-2
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ m4_define([_MAKE_HELP], [MAKE_FUNCTION(
343343
[and it makes sense to remind the user how the script is supposed to be called.]],
344344
[print_help], [m4_do(
345345
[m4_ifnblank(m4_expand([_HELP_MSG]),
346-
m4_dquote(_INDENT_()[printf] '%s\n' "_SUBSTITUTE_LF_FOR_NEWLINE_WITH_DISPLAY_INDENT_AND_ESCAPE_DOUBLEQUOTES(_HELP_MSG)"_ENDL_()))],
346+
m4_dquote(_INDENT_()[printf] '%s\n' "SUBSTITUTE_LF_FOR_NEWLINE_WITH_INDENT_AND_ESCAPE_DOUBLEQUOTES(_HELP_MSG, [])"_ENDL_()))],
347347
[_INDENT_()[]printf 'Usage: %s],
348348
[dnl If we have optionals, display them like [--opt1 arg] [--(no-)opt2] ... according to their type. @<:@ becomes square bracket at the end of processing
349349
],
@@ -359,7 +359,8 @@ m4_define([_MAKE_HELP], [MAKE_FUNCTION(
359359
],
360360
[m4_list_ifempty([ENV_NAMES], ,[_MAKE_HELP_FUNCTION_ENVVARS_PART()_ENDL_()])],
361361
[_MAKE_ARGS_STACKING_HELP_PRINT_IF_NEEDED],
362-
[m4_ifnblank(m4_quote(_HELP_MSG_EX), m4_dquote(_INDENT_()[printf '\n%s\n' "]_HELP_MSG_EX"_ENDL_()))],
362+
[m4_ifnblank(m4_quote(_HELP_MSG_EX),
363+
m4_dquote(_INDENT_()[printf] '\n%s\n' "SUBSTITUTE_LF_FOR_NEWLINE_WITH_INDENT_AND_ESCAPE_DOUBLEQUOTES(_HELP_MSG_EX, [])"_ENDL_()))],
363364
)],
364365
)])
365366

src/utilities.m4

+9-1
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,16 @@ dnl $1: The text to substitute
121121
dnl Regexp: Find beginning of backslashes, match for pairs, and if \\n is left, then substitute it for literal newline.
122122
dnl The indentation is a display indentation - not source code one.
123123
m4_define([_SUBSTITUTE_LF_FOR_NEWLINE_WITH_DISPLAY_INDENT_AND_ESCAPE_DOUBLEQUOTES],
124+
[SUBSTITUTE_LF_FOR_NEWLINE_WITH_INDENT_AND_ESCAPE_DOUBLEQUOTES([$1], [ ])])
125+
126+
dnl
127+
dnl $1: The text to substitute
128+
dnl $2: The indent for the new line.
129+
dnl Regexp: Find beginning of backslashes, match for pairs, and if \\n is left, then substitute it for literal newline.
130+
dnl The indentation is a display indentation - not source code one.
131+
m4_define([SUBSTITUTE_LF_FOR_NEWLINE_WITH_INDENT_AND_ESCAPE_DOUBLEQUOTES],
124132
[m4_bpatsubsts([[$1]],
125-
[\([^\\]\)\(\\\\\)*\\n], m4_expand([[\1\2]_ENDL_() ]),
133+
[\([^\\]\)\(\\\\\)*\\n], m4_expand([[\1\2]_ENDL_()$2]),
126134
[\([^\]\)"], [\1\\"])])
127135
128136

tests/unittests/check-utils.m4

+3
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ assert_equals(UNDERLINE(,=,=), [
120120
assert_equals(UNDERLINE([a], [-]), [a
121121
-])
122122

123+
assert_equals(SUBSTITUTE_LF_FOR_NEWLINE_WITH_INDENT_AND_ESCAPE_DOUBLEQUOTES([The Castle\n"Totenhammer"], [-]), [The Castle
124+
-\"Totenhammer\"])
125+
123126

124127
assert_equals(UNDERLINE([Abc], [+], [=]), [===
125128
Abc

0 commit comments

Comments
 (0)