From 7f1517275d22a7ce6bc8cece7ae87fb187b439ea Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sat, 6 Oct 2012 20:05:06 -0400 Subject: function: add a map() utility function map() runs the first argument (a function) with each of the remaining arguments as $1. The return value of map() is only 0 if all the calls succeeded. Signed-off-by: Dave Reisner --- functions | 39 +++++++++++++++------------------------ mkinitcpio | 4 +--- 2 files changed, 16 insertions(+), 27 deletions(-) diff --git a/functions b/functions index cc4509a..a10221f 100644 --- a/functions +++ b/functions @@ -172,6 +172,14 @@ die() { cleanup 1 } +map() { + local r=0 + for _ in "${@:2}"; do + "$1" "$_" || r=1 + done + return $r +} + in_array() { # Search for an element in an array. # $1: needle @@ -258,10 +266,7 @@ add_all_modules() { local mod mods mapfile -t mods < <(all_modules "$@") - - for mod in "${mods[@]}"; do - add_module "$mod" - done + map add_module "${mods[@]}" return $(( !${#mods[*]} )) } @@ -279,9 +284,7 @@ add_checked_modules() { mapfile -t mods < <(all_modules "$@") fi - for mod in "${mods[@]}"; do - add_module "$mod" - done + map add_module "${mods[@]}" return $(( !${#mods[*]} )) } @@ -306,7 +309,7 @@ add_module() { # discovered and added. # $1: module name - local module= path= dep= deps= field= value= + local module= path= deps= field= value= local ign_errors=0 if [[ $1 = *\? ]]; then @@ -326,9 +329,7 @@ add_module() { ;; depends) IFS=',' read -r -a deps <<< "$value" - for dep in "${deps[@]}"; do - add_module "$dep" - done + map add_module "${deps[@]}" ;; firmware) if [[ -e /usr/lib/firmware/$value ]]; then @@ -559,19 +560,9 @@ parse_hook() { # prior to the start of hook processing, and after each hook's build # function is run. - local item= - - for item in $MODULES; do - add_module "$item" - done - - for item in $BINARIES; do - add_binary "$item" - done - - for item in $FILES; do - add_file "$item" - done + map add_module $MODULES + map add_binary $BINARIES + map add_file $FILES if [[ $SCRIPT ]]; then add_runscript "$SCRIPT" diff --git a/mkinitcpio b/mkinitcpio index 4bd9376..8e5f9a8 100755 --- a/mkinitcpio +++ b/mkinitcpio @@ -415,9 +415,7 @@ if [[ -r $_d_kmoduledir/modules.builtin ]]; then unset modname path fi -for hook in "${_hooks[@]}"; do - run_build_hook "$hook" || (( ++_builderrors )) -done +map run_build_hook "${_hooks[@]}" || (( ++_builderrors )) # process config file parse_hook -- cgit v1.2.3-24-g4f1b