Skip to content

Commit 17e4031

Browse files
committed
Commit 40
- New library file `not-increments.m4` has been created, containing the following new macros: - `n4_pp_amount()` - `n4_ppn_amount()` - `n4_amount_pp()` - `n4_amount_ppn()` - `n4_amount_incr()` - `n4_amount_add()` - `n4_amounts_incr()` - `n4_amounts_add()` - `n4_mm_amount()` - `n4_mmn_amount()` - `n4_amount_mm()` - `n4_amount_mmn()` - `n4_amount_decr()` - `n4_amount_subtract()` - `n4_amounts_decr()` - `n4_amounts_subtract()` - New macro `n4_retrieve()` has been created in `not-m4sugar.m4` - New macro `NS_CATCH()` has been created in `not-autoshell.m4` - New macro `NC_CPP_EXPAND()` has been created in `not-cc.m4` - New macros `NR_RECORD_HISTORY_RC()`, `NR_GET_EVENT_VSTATE_RC()` and `NR_FOR_EACH_EVENT_RC()` have been created in `not-autoversion.m4` - Code review (macro `NC_AUTOVERSION_SUBSTITUTIONS()` in `not-autoversion.m4`; macros `NS_SETVARS()`, `NS_GETVAR()`, `NS_UNSET()`, `NS_MOVEVAR()` and `NS_REPLACEVAR()` in `not-autoshell.m4`) - File `macro-index.md` has been sorted alphabetically - Documentation
1 parent 8cb7e05 commit 17e4031

12 files changed

+1090
-172
lines changed

ChangeLog.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,41 @@ Change Log
22
==========
33

44

5+
2.4.0
6+
-----
7+
8+
Changes:
9+
10+
* New library file `not-increments.m4` has been created, containing the
11+
following new macros:
12+
* `n4_pp_amount()`
13+
* `n4_ppn_amount()`
14+
* `n4_amount_pp()`
15+
* `n4_amount_ppn()`
16+
* `n4_amount_incr()`
17+
* `n4_amount_add()`
18+
* `n4_amounts_incr()`
19+
* `n4_amounts_add()`
20+
* `n4_mm_amount()`
21+
* `n4_mmn_amount()`
22+
* `n4_amount_mm()`
23+
* `n4_amount_mmn()`
24+
* `n4_amount_decr()`
25+
* `n4_amount_subtract()`
26+
* `n4_amounts_decr()`
27+
* `n4_amounts_subtract()`
28+
* New macro `n4_retrieve()` has been created in `not-m4sugar.m4`
29+
* New macro `NS_CATCH()` has been created in `not-autoshell.m4`
30+
* New macro `NC_CPP_EXPAND()` has been created in `not-cc.m4`
31+
* New macros `NR_RECORD_HISTORY_RC()`, `NR_GET_EVENT_VSTATE_RC()` and
32+
`NR_FOR_EACH_EVENT_RC()` have been created in `not-autoversion.m4`
33+
* Code review (macro `NC_AUTOVERSION_SUBSTITUTIONS()` in `not-autoversion.m4`;
34+
macros `NS_SETVARS()`, `NS_GETVAR()`, `NS_UNSET()`, `NS_MOVEVAR()` and
35+
`NS_REPLACEVAR()` in `not-autoshell.m4`)
36+
* File `macro-index.md` has been sorted alphabetically
37+
* Documentation
38+
39+
540
2.3.0
641
-----
742

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
#
3+
# create_test_directory.sh
4+
#
5+
6+
M4SUGAR_DIR='/usr/share/autoconf/m4sugar'
7+
8+
if [[ ! -d "${M4SUGAR_DIR}" ]]; then
9+
echo 'You don'\''t have GNU Autoconf installed. Abort.'
10+
exit 1
11+
fi
12+
13+
mkdir -p ../tests
14+
cd ../tests
15+
rm -rf m4sugar
16+
ln -s "${M4SUGAR_DIR}" m4sugar
17+
18+
cat << '_NA_HEREDOC_' > 'do_your_tests_here.m4'
19+
dnl **************************************************************************
20+
dnl
21+
dnl Launch
22+
dnl
23+
dnl m4 do_your_tests_here.m4
24+
dnl
25+
dnl to parse this file.
26+
dnl
27+
dnl **************************************************************************
28+
include(m4sugar/m4sugar.m4)
29+
m4_include([m4sugar/m4sh.m4])
30+
m4_init
31+
m4_define([AC_DEFUN], m4_defn([m4_defun]))
32+
m4_define([AC_DEFUN_ONCE], m4_defn([m4_defun]))
33+
m4_define([n4_sincludedir],
34+
[m4_pushdef([_files_], m4_dquote(m4_dquote(m4_shift(m4_esyscmd([find '$1' -type f -name '*.m4' -printf ", [[%p]]" 2>/dev/null])))))[]m4_ifnblank(m4_expand(_files_), [m4_foreach([_file_], _files_, [m4_include(_file_)])])[]m4_popdef([_files_])])[]n4_sincludedir([../m4/])[]m4_divert[]dnl
35+
dnl
36+
dnl **************************************************************************
37+
dnl PLEASE WRITE YOUR M4 CODE AFTER THIS COMMENT
38+
dnl **************************************************************************
39+
dnl
40+
dnl This is just an example...
41+
n4_repeat([79], [~])
42+
_NA_HEREDOC_
43+
44+
echo 'A directory for experimenting on the Not Autotools project has been created in'
45+
echo "$(pwd)."

collection-utils/macro-index-generator.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@
22
#
33
# macro-index-generator.sh
44
#
5-
# Run this script to generate the complete macro list
5+
# Run this script from its directory to generate the complete macro list
66
#
77

88
{
99
echo '_Not Autotools_ Macro Index'
1010
echo '==========================='
1111
echo
1212
echo 'This is the complete list of macros released by the **Not Autotools** project.'
13-
(cd .. && find 'm4' -type f -name '*.m4' -printf '\n\n## [`%p`](%p)\n\n' \
14-
-exec grep -oPHn '(?<=^dnl )\w+\(\)?' '{}' ';') | \
15-
sed 's/()$//g;s/($/()/g;s,\([^:]\+\):\([^:]\+\):\([^(]\+\(()\)\?\)$,* [`\3`](\1#L\2),g'
13+
(cd .. && find 'm4' -type f -name '*.m4' -print0) | sort -z | while IFS= read -r -d $'\0' __file__; do
14+
echo
15+
echo
16+
echo "## [\`${__file__}\`](${__file__})"
17+
echo
18+
(cd .. && grep -oPHn '(?<=^dnl )\w+\(\)?' "${__file__}") | \
19+
sed 's/()$//g;s/($/()/g;s,\([^:]\+\):\([^:]\+\):\([^(]\+\(()\)\?\)$,* [`\3`](\1#L\2),g'
20+
done
1621
echo
1722
} > ../macro-index.md
1823

24+
echo 'File ../macro-index.md has been updated.'

collection-utils/strip-all-comments.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ find 'undocumented-m4' -type f -name '*.m4' \
1111
-exec sed -i '/^dnl\(\W\|\s*$\)/d' '{}' ';' \
1212
-exec sed -i -z 's/^\n*//;s/\n\n\+/\n\n\n/g' '{}' ';'
1313

14-
14+
echo 'An undocumented version of this library has been created in'
15+
echo "$(pwd)/undocumented-m4."

m4/not-autoshell.m4

Lines changed: 133 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ dnl This macro may be invoked before `AC_INIT()`.
3232
dnl
3333
dnl Expansion type: shell code
3434
dnl Requires: nothing
35-
dnl Version: 1.0.0
35+
dnl Version: 1.0.1
3636
dnl Author: madmurphy
3737
dnl
3838
dnl **************************************************************************
3939
AC_DEFUN([NS_SETVARS],
40-
[AS_VAR_SET([$1], [$2]); m4_if(m4_eval([$# > 2]), [1],
41-
[NS_SETVARS(m4_shift2($@))])])
40+
[m4_if([$#], [0], [],
41+
[AS_VAR_SET([$1], [$2])[]m4_if([$#], [1], [], [$#], [2], [],
42+
[m4_newline()NS_SETVARS(m4_shift2($@))])])])
4243

4344

4445
dnl NS_GETVAR(var)
@@ -57,11 +58,12 @@ dnl This macro may be invoked before `AC_INIT()`.
5758
dnl
5859
dnl Expansion type: shell code
5960
dnl Requires: nothing
60-
dnl Version: 1.0.0
61+
dnl Version: 1.1.0
6162
dnl Author: madmurphy
6263
dnl
6364
dnl **************************************************************************
64-
AC_DEFUN([NS_GETVAR], [@S|@{$1}])
65+
AC_DEFUN([NS_GETVAR],
66+
[AS_LITERAL_WORD_IF([$1], [${$1}], [$(eval echo "\${$1}")])])
6567

6668

6769
dnl NS_GETOUT(command)
@@ -73,7 +75,7 @@ dnl Same as `$(command)`. This macro works exactly like `m4_esyscmd()`, but
7375
dnl instead of executing a command during the `autoreconf` process, it
7476
dnl executes it during the `configure` process, when all M4 macros have been
7577
dnl already expanded. The returned value cannot therefore be stored in another
76-
dnl macro, but must be stored in a shell variable instead.
78+
dnl macro, but must be stored in a shell variable.
7779
dnl
7880
dnl Example:
7981
dnl
@@ -94,7 +96,7 @@ AC_DEFUN([NS_GETOUT], [@S|@@{:@$1@:}@])
9496
dnl NS_UNSET(var1[, var2[, var3[, ... varN]]])
9597
dnl **************************************************************************
9698
dnl
97-
dnl Like `AS_UNSET()`, but it allows to unset many variables altogether
99+
dnl Like `AS_UNSET()`, but allows to unset many variables altogether
98100
dnl
99101
dnl For example:
100102
dnl
@@ -108,12 +110,14 @@ dnl This macro may be invoked before `AC_INIT()`.
108110
dnl
109111
dnl Expansion type: shell code
110112
dnl Requires: nothing
111-
dnl Version: 1.0.0
113+
dnl Version: 1.0.1
112114
dnl Author: madmurphy
113115
dnl
114116
dnl **************************************************************************
115117
AC_DEFUN([NS_UNSET],
116-
[m4_ifnblank([$1], [AS_UNSET(m4_quote(m4_normalize([$1])));])m4_if([$#], [1], [], [NS_UNSET(m4_shift($@))])])
118+
[m4_if([$#], [0], [],
119+
[AS_UNSET(m4_normalize([$1]))])[]m4_if([$#], [1], [],
120+
[m4_newline()[]NS_UNSET(m4_shift($@))])])
117121

118122

119123
dnl NS_MOVEVAR(destination, source)
@@ -126,12 +130,12 @@ dnl This macro may be invoked before `AC_INIT()`.
126130
dnl
127131
dnl Expansion type: shell code
128132
dnl Requires: nothing
129-
dnl Version: 1.0.0
133+
dnl Version: 1.0.1
130134
dnl Author: madmurphy
131135
dnl
132136
dnl **************************************************************************
133137
AC_DEFUN([NS_MOVEVAR],
134-
[{ AS_VAR_COPY([$1], [$2]); AS_UNSET([$2]); }])
138+
[AS_VAR_COPY([$1], [$2])[]m4_newline()[]AS_UNSET([$2])])
135139

136140

137141
dnl NS_REPLACEVAR(destination, source)
@@ -145,12 +149,14 @@ dnl This macro may be invoked before `AC_INIT()`.
145149
dnl
146150
dnl Expansion type: shell code
147151
dnl Requires: nothing
148-
dnl Version: 1.0.0
152+
dnl Version: 1.1.0
149153
dnl Author: madmurphy
150154
dnl
151155
dnl **************************************************************************
152156
AC_DEFUN([NS_REPLACEVAR],
153-
[{ @S|@{$2+:} false && { AS_VAR_COPY([$1], [$2]); AS_UNSET([$2]); } || AS_UNSET([$1]) }])
157+
[AS_VAR_SET_IF([$2],
158+
[AS_VAR_COPY([$1], [$2])[]m4_newline()[]AS_UNSET([$2])],
159+
[AS_UNSET([$1])])])
154160

155161

156162
dnl NS_IF(test1, run1[, test2, run2[, testN, runN]][, run-if-false])
@@ -828,11 +834,121 @@ AC_DEFUN([NS_HEREDOC],
828834
[{ cat << m4_default_nblank_quoted([$2], [NS_END_HEREDOC])[]m4_newline()$1[]m4_newline()m4_default_nblank_quoted([$2], [NS_END_HEREDOC])[]m4_newline() }])
829835

830836

831-
837+
dnl NS_CATCH(shell-code[, stdout-var-name[, stderr-var-name]])
838+
dnl **************************************************************************
839+
dnl
840+
dnl Execute custom shell code and save `stdout` and `stderr` into shell
841+
dnl variables
842+
dnl
843+
dnl Both `stdout-var-name` and `stderr-var-name` can be left empty, and in
844+
dnl that case the respective file descriptor will be normally flushed.
845+
dnl Alternatively, they can be set to a hyphen (`-`), and in that case the
846+
dnl respective file descriptor will be redirected to `/dev/null`.
847+
dnl
848+
dnl A few examples:
849+
dnl
850+
dnl # Save both `stdout` and `stderr` into two variables
851+
dnl NS_CATCH([
852+
dnl echo 'This is stderr' 1>&2
853+
dnl echo 'This is stdout'
854+
dnl ], [MY_STDOUT], [MY_STDERR])
855+
dnl
856+
dnl # Save `stdout` into a variable and silence `stderr`
857+
dnl NS_CATCH([
858+
dnl echo 'This is stderr' 1>&2
859+
dnl echo 'This is stdout'
860+
dnl ], [MY_STDOUT], [-])
861+
dnl
862+
dnl # Save `stdout` into a variable and print `stderr` normally
863+
dnl NS_CATCH([
864+
dnl echo 'This is stderr' 1>&2
865+
dnl echo 'This is stdout'
866+
dnl ], [MY_STDOUT])
867+
dnl
868+
dnl # Save `stderr` into a variable and silence `stdout`
869+
dnl NS_CATCH([
870+
dnl echo 'This is stderr' 1>&2
871+
dnl echo 'This is stdout'
872+
dnl ], [-], [MY_STDERR])
873+
dnl
874+
dnl # Save `stderr` into a variable and print `stdout` normally
875+
dnl NS_CATCH([
876+
dnl echo 'This is stderr' 1>&2
877+
dnl echo 'This is stdout'
878+
dnl ], [], [MY_STDERR])
879+
dnl
880+
dnl # Silence both `stdout` and `stderr`
881+
dnl NS_CATCH([
882+
dnl echo 'This is stderr' 1>&2
883+
dnl echo 'This is stdout'
884+
dnl ], [-], [-])
885+
dnl
886+
dnl # Silence `stderr`, print only `stdout`
887+
dnl NS_CATCH([
888+
dnl echo 'This is stderr' 1>&2
889+
dnl echo 'This is stdout'
890+
dnl ], [], [-])
891+
dnl
892+
dnl # Silence `stdout`, print only `stderr`
893+
dnl NS_CATCH([
894+
dnl echo 'This is stderr' 1>&2
895+
dnl echo 'This is stdout'
896+
dnl ], [-])
897+
dnl
898+
dnl # Print both `stdout` and `stderr` normally
899+
dnl NS_CATCH([
900+
dnl echo 'This is stderr' 1>&2
901+
dnl echo 'This is stdout'
902+
dnl ])
903+
dnl
904+
dnl This macro may be invoked before `AC_INIT()`.
905+
dnl
906+
dnl NOTE: `NS_CATCH()` incorporates an answer of mine on stackoverflow
907+
dnl (https://stackoverflow.com/a/59592881, "10. The POSIX-compliant
908+
dnl version #2").
909+
dnl
910+
dnl Expansion type: shell code
911+
dnl Requires: nothing
912+
dnl Version: 1.0.0
913+
dnl Author: madmurphy
914+
dnl
832915
dnl **************************************************************************
833-
dnl NOTE: The `NS_` prefix (which stands for "Not autoShell") is used with the
834-
dnl purpose of avoiding collisions with the default Autotools prefixes
835-
dnl `AC_`, `AM_`, `AS_`, `AX_`, `LT_`.
916+
AC_DEFUN([NS_CATCH],
917+
[m4_if([$2$3], [],
918+
[{m4_newline()[]$1[]m4_newline()}],
919+
[$2$3], [--],
920+
[{m4_newline(){m4_newline()[]$1[]m4_newline()} 1> /dev/null 2>&1[]m4_newline()}],
921+
[$2], [],
922+
[m4_if([$3], [-],
923+
[{m4_newline(){m4_newline()[]$1[]m4_newline()} 2> /dev/null[]m4_newline()}],
924+
[{m4_newline()[]AS_VAR_SET([$3], ["$({]m4_newline()[$1]m4_newline()[} 3>&2 2>&1 1>&3 3>&-)"])[]m4_newline()} 2>&1])],
925+
[$2], [-],
926+
[m4_if([$3], [],
927+
[{m4_newline(){m4_newline()[]$1[]m4_newline()} 1> /dev/null[]m4_newline()}],
928+
[{m4_newline()[]AS_VAR_SET([$3], ["$({]m4_newline()[$1]m4_newline()[} 3>&2 2>&1 1>&3 3>&-)"])[]m4_newline()} 2> /dev/null])],
929+
[$3], [],
930+
[AS_VAR_SET([$2], ["$({]m4_newline()[$1]m4_newline()[})"])],
931+
[$3], [-],
932+
[AS_VAR_SET([$2], ["$({]m4_newline()[$1]m4_newline()[} 2> /dev/null)"])],
933+
[# See https://stackoverflow.com/a/59592881
934+
__sep__=$'\cZ'
935+
{
936+
937+
IFS=$'\n'"${__sep__}" read -r -d "${__sep__}" "$2";
938+
IFS=$'\n'"${__sep__}" read -r -d "${__sep__}" "$3";
939+
(IFS=$'\n'"${__sep__}" read -r -d "${__sep__}" __errno__; exit ${__errno__});
940+
} <<__NA_EOF__
941+
$((printf "${__sep__}%s${__sep__}%d${__sep__}" "$(((({ {m4_newline()[]$1[]m4_newline()}m4_newline()[]echo "${?}" 1>&3-; } | cut -z -d"${__sep__}" -f1 | tr -d '\0' 1>&4-) 4>&2- 2>&1- | cut -z -d"${__sep__}" -f1 | tr -d '\0' 1>&4-) 3>&1- | exit "$(cat)") 4>&1-)" "${?}" 1>&2) 2>&1)
942+
__NA_EOF__
943+
AS_UNSET([__sep__])
944+
])])
945+
946+
947+
948+
dnl **************************************************************************
949+
dnl NOTE: The `NS_` prefix (which stands for "Not autoShell") is used with
950+
dnl the purpose of avoiding collisions with the default Autotools
951+
dnl prefixes `AC_`, `AM_`, `AS_`, `AX_`, `LT_`.
836952
dnl **************************************************************************
837953

838954

0 commit comments

Comments
 (0)