Skip to content

Commit

Permalink
Commit 40
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
madmurphy committed Feb 7, 2022
1 parent 8cb7e05 commit 17e4031
Show file tree
Hide file tree
Showing 12 changed files with 1,090 additions and 172 deletions.
35 changes: 35 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,41 @@ Change Log
==========


2.4.0
-----

Changes:

* 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


2.3.0
-----

Expand Down
45 changes: 45 additions & 0 deletions collection-utils/create_test_directory.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash
#
# create_test_directory.sh
#

M4SUGAR_DIR='/usr/share/autoconf/m4sugar'

if [[ ! -d "${M4SUGAR_DIR}" ]]; then
echo 'You don'\''t have GNU Autoconf installed. Abort.'
exit 1
fi

mkdir -p ../tests
cd ../tests
rm -rf m4sugar
ln -s "${M4SUGAR_DIR}" m4sugar

cat << '_NA_HEREDOC_' > 'do_your_tests_here.m4'
dnl **************************************************************************
dnl
dnl Launch
dnl
dnl m4 do_your_tests_here.m4
dnl
dnl to parse this file.
dnl
dnl **************************************************************************
include(m4sugar/m4sugar.m4)
m4_include([m4sugar/m4sh.m4])
m4_init
m4_define([AC_DEFUN], m4_defn([m4_defun]))
m4_define([AC_DEFUN_ONCE], m4_defn([m4_defun]))
m4_define([n4_sincludedir],
[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
dnl
dnl **************************************************************************
dnl PLEASE WRITE YOUR M4 CODE AFTER THIS COMMENT
dnl **************************************************************************
dnl
dnl This is just an example...
n4_repeat([79], [~])
_NA_HEREDOC_

echo 'A directory for experimenting on the Not Autotools project has been created in'
echo "$(pwd)."
14 changes: 10 additions & 4 deletions collection-utils/macro-index-generator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@
#
# macro-index-generator.sh
#
# Run this script to generate the complete macro list
# Run this script from its directory to generate the complete macro list
#

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

echo 'File ../macro-index.md has been updated.'
3 changes: 2 additions & 1 deletion collection-utils/strip-all-comments.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ find 'undocumented-m4' -type f -name '*.m4' \
-exec sed -i '/^dnl\(\W\|\s*$\)/d' '{}' ';' \
-exec sed -i -z 's/^\n*//;s/\n\n\+/\n\n\n/g' '{}' ';'


echo 'An undocumented version of this library has been created in'
echo "$(pwd)/undocumented-m4."
150 changes: 133 additions & 17 deletions m4/not-autoshell.m4
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: shell code
dnl Requires: nothing
dnl Version: 1.0.0
dnl Version: 1.0.1
dnl Author: madmurphy
dnl
dnl **************************************************************************
AC_DEFUN([NS_SETVARS],
[AS_VAR_SET([$1], [$2]); m4_if(m4_eval([$# > 2]), [1],
[NS_SETVARS(m4_shift2($@))])])
[m4_if([$#], [0], [],
[AS_VAR_SET([$1], [$2])[]m4_if([$#], [1], [], [$#], [2], [],
[m4_newline()NS_SETVARS(m4_shift2($@))])])])


dnl NS_GETVAR(var)
Expand All @@ -57,11 +58,12 @@ dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: shell code
dnl Requires: nothing
dnl Version: 1.0.0
dnl Version: 1.1.0
dnl Author: madmurphy
dnl
dnl **************************************************************************
AC_DEFUN([NS_GETVAR], [@S|@{$1}])
AC_DEFUN([NS_GETVAR],
[AS_LITERAL_WORD_IF([$1], [${$1}], [$(eval echo "\${$1}")])])


dnl NS_GETOUT(command)
Expand All @@ -73,7 +75,7 @@ dnl Same as `$(command)`. This macro works exactly like `m4_esyscmd()`, but
dnl instead of executing a command during the `autoreconf` process, it
dnl executes it during the `configure` process, when all M4 macros have been
dnl already expanded. The returned value cannot therefore be stored in another
dnl macro, but must be stored in a shell variable instead.
dnl macro, but must be stored in a shell variable.
dnl
dnl Example:
dnl
Expand All @@ -94,7 +96,7 @@ AC_DEFUN([NS_GETOUT], [@S|@@{:@$1@:}@])
dnl NS_UNSET(var1[, var2[, var3[, ... varN]]])
dnl **************************************************************************
dnl
dnl Like `AS_UNSET()`, but it allows to unset many variables altogether
dnl Like `AS_UNSET()`, but allows to unset many variables altogether
dnl
dnl For example:
dnl
Expand All @@ -108,12 +110,14 @@ dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: shell code
dnl Requires: nothing
dnl Version: 1.0.0
dnl Version: 1.0.1
dnl Author: madmurphy
dnl
dnl **************************************************************************
AC_DEFUN([NS_UNSET],
[m4_ifnblank([$1], [AS_UNSET(m4_quote(m4_normalize([$1])));])m4_if([$#], [1], [], [NS_UNSET(m4_shift($@))])])
[m4_if([$#], [0], [],
[AS_UNSET(m4_normalize([$1]))])[]m4_if([$#], [1], [],
[m4_newline()[]NS_UNSET(m4_shift($@))])])


dnl NS_MOVEVAR(destination, source)
Expand All @@ -126,12 +130,12 @@ dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: shell code
dnl Requires: nothing
dnl Version: 1.0.0
dnl Version: 1.0.1
dnl Author: madmurphy
dnl
dnl **************************************************************************
AC_DEFUN([NS_MOVEVAR],
[{ AS_VAR_COPY([$1], [$2]); AS_UNSET([$2]); }])
[AS_VAR_COPY([$1], [$2])[]m4_newline()[]AS_UNSET([$2])])


dnl NS_REPLACEVAR(destination, source)
Expand All @@ -145,12 +149,14 @@ dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl Expansion type: shell code
dnl Requires: nothing
dnl Version: 1.0.0
dnl Version: 1.1.0
dnl Author: madmurphy
dnl
dnl **************************************************************************
AC_DEFUN([NS_REPLACEVAR],
[{ @S|@{$2+:} false && { AS_VAR_COPY([$1], [$2]); AS_UNSET([$2]); } || AS_UNSET([$1]) }])
[AS_VAR_SET_IF([$2],
[AS_VAR_COPY([$1], [$2])[]m4_newline()[]AS_UNSET([$2])],
[AS_UNSET([$1])])])


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



dnl NS_CATCH(shell-code[, stdout-var-name[, stderr-var-name]])
dnl **************************************************************************
dnl
dnl Execute custom shell code and save `stdout` and `stderr` into shell
dnl variables
dnl
dnl Both `stdout-var-name` and `stderr-var-name` can be left empty, and in
dnl that case the respective file descriptor will be normally flushed.
dnl Alternatively, they can be set to a hyphen (`-`), and in that case the
dnl respective file descriptor will be redirected to `/dev/null`.
dnl
dnl A few examples:
dnl
dnl # Save both `stdout` and `stderr` into two variables
dnl NS_CATCH([
dnl echo 'This is stderr' 1>&2
dnl echo 'This is stdout'
dnl ], [MY_STDOUT], [MY_STDERR])
dnl
dnl # Save `stdout` into a variable and silence `stderr`
dnl NS_CATCH([
dnl echo 'This is stderr' 1>&2
dnl echo 'This is stdout'
dnl ], [MY_STDOUT], [-])
dnl
dnl # Save `stdout` into a variable and print `stderr` normally
dnl NS_CATCH([
dnl echo 'This is stderr' 1>&2
dnl echo 'This is stdout'
dnl ], [MY_STDOUT])
dnl
dnl # Save `stderr` into a variable and silence `stdout`
dnl NS_CATCH([
dnl echo 'This is stderr' 1>&2
dnl echo 'This is stdout'
dnl ], [-], [MY_STDERR])
dnl
dnl # Save `stderr` into a variable and print `stdout` normally
dnl NS_CATCH([
dnl echo 'This is stderr' 1>&2
dnl echo 'This is stdout'
dnl ], [], [MY_STDERR])
dnl
dnl # Silence both `stdout` and `stderr`
dnl NS_CATCH([
dnl echo 'This is stderr' 1>&2
dnl echo 'This is stdout'
dnl ], [-], [-])
dnl
dnl # Silence `stderr`, print only `stdout`
dnl NS_CATCH([
dnl echo 'This is stderr' 1>&2
dnl echo 'This is stdout'
dnl ], [], [-])
dnl
dnl # Silence `stdout`, print only `stderr`
dnl NS_CATCH([
dnl echo 'This is stderr' 1>&2
dnl echo 'This is stdout'
dnl ], [-])
dnl
dnl # Print both `stdout` and `stderr` normally
dnl NS_CATCH([
dnl echo 'This is stderr' 1>&2
dnl echo 'This is stdout'
dnl ])
dnl
dnl This macro may be invoked before `AC_INIT()`.
dnl
dnl NOTE: `NS_CATCH()` incorporates an answer of mine on stackoverflow
dnl (https://stackoverflow.com/a/59592881, "10. The POSIX-compliant
dnl version #2").
dnl
dnl Expansion type: shell code
dnl Requires: nothing
dnl Version: 1.0.0
dnl Author: madmurphy
dnl
dnl **************************************************************************
dnl NOTE: The `NS_` prefix (which stands for "Not autoShell") is used with the
dnl purpose of avoiding collisions with the default Autotools prefixes
dnl `AC_`, `AM_`, `AS_`, `AX_`, `LT_`.
AC_DEFUN([NS_CATCH],
[m4_if([$2$3], [],
[{m4_newline()[]$1[]m4_newline()}],
[$2$3], [--],
[{m4_newline(){m4_newline()[]$1[]m4_newline()} 1> /dev/null 2>&1[]m4_newline()}],
[$2], [],
[m4_if([$3], [-],
[{m4_newline(){m4_newline()[]$1[]m4_newline()} 2> /dev/null[]m4_newline()}],
[{m4_newline()[]AS_VAR_SET([$3], ["$({]m4_newline()[$1]m4_newline()[} 3>&2 2>&1 1>&3 3>&-)"])[]m4_newline()} 2>&1])],
[$2], [-],
[m4_if([$3], [],
[{m4_newline(){m4_newline()[]$1[]m4_newline()} 1> /dev/null[]m4_newline()}],
[{m4_newline()[]AS_VAR_SET([$3], ["$({]m4_newline()[$1]m4_newline()[} 3>&2 2>&1 1>&3 3>&-)"])[]m4_newline()} 2> /dev/null])],
[$3], [],
[AS_VAR_SET([$2], ["$({]m4_newline()[$1]m4_newline()[})"])],
[$3], [-],
[AS_VAR_SET([$2], ["$({]m4_newline()[$1]m4_newline()[} 2> /dev/null)"])],
[# See https://stackoverflow.com/a/59592881
__sep__=$'\cZ'
{
IFS=$'\n'"${__sep__}" read -r -d "${__sep__}" "$2";
IFS=$'\n'"${__sep__}" read -r -d "${__sep__}" "$3";
(IFS=$'\n'"${__sep__}" read -r -d "${__sep__}" __errno__; exit ${__errno__});
} <<__NA_EOF__
$((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)
__NA_EOF__
AS_UNSET([__sep__])
])])



dnl **************************************************************************
dnl NOTE: The `NS_` prefix (which stands for "Not autoShell") is used with
dnl the purpose of avoiding collisions with the default Autotools
dnl prefixes `AC_`, `AM_`, `AS_`, `AX_`, `LT_`.
dnl **************************************************************************


Expand Down
Loading

0 comments on commit 17e4031

Please sign in to comment.