summaryrefslogtreecommitdiffstats
path: root/functions
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2012-10-07 02:05:06 +0200
committerDave Reisner <dreisner@archlinux.org>2012-10-21 21:25:46 +0200
commit7f1517275d22a7ce6bc8cece7ae87fb187b439ea (patch)
tree04b47fa68261dd3f0578df25d37358efdd14585e /functions
parent5c466b4fe50a2b8b5706b0f8774942f9a328c08f (diff)
downloadmkinitcpio-7f1517275d22a7ce6bc8cece7ae87fb187b439ea.tar.gz
mkinitcpio-7f1517275d22a7ce6bc8cece7ae87fb187b439ea.tar.xz
function: add a map() utility function0.11.0
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 <dreisner@archlinux.org>
Diffstat (limited to 'functions')
-rw-r--r--functions39
1 files changed, 15 insertions, 24 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"