[arch-projects] [netctl] [PATCH] Simplify init_profiles() implementation

Emil Velikov emil.l.velikov at gmail.com
Tue Jun 26 10:25:21 UTC 2018


From: Emil Velikov <emil.velikov at collabora.com>

Currently each profile is handles in two stages:
 - a unique value is returned for a set of patterns matches
 - depending on the value the profile/essid is added to global lists

A shorter and simpler solution is to omit the unnecessary value
passing/processing all together.

Cc: Jouke Witteveen <j.witteveen at gmail.com>
Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
---
Jouke, let me know if you'd like this rebased on top of your patch.
Pardon if you're getting this twice. The initial submission was rejected
by the ML :-\
---
 src/wifi-menu | 40 ++++++++++++++--------------------------
 1 file changed, 14 insertions(+), 26 deletions(-)

diff --git a/src/wifi-menu b/src/wifi-menu
index 42c4c53..928cf5e 100755
--- a/src/wifi-menu
+++ b/src/wifi-menu
@@ -29,34 +29,22 @@ quote_safe() {
     fi
 }
 
-# Fill PROFILES and ESSIDS with the profile names and essids of the profiles
-# for interface $1
+# Fill GENERATED, PROFILES and ESSIDS with the profile names and essids of the
+# profiles for interface $1
 init_profiles() {
-    local i=0 essid profile
+    local i=0 profile
     while IFS= read -r profile; do
-        essid=$(
-            unset Interface ESSID
-            source "$PROFILE_DIR/$profile" > /dev/null
-            if [[ "$Interface" = "$1" && -n "$ESSID" ]]; then
-                printf "%s" "$ESSID"
-                if [[ "$Description" =~ "Automatically generated" ]]; then
-                    return 2
-                else
-                    return 1
-                fi
-            fi
-            return 0
-        )
-        case $? in
-            2)
-                GENERATED+=("$profile")
-                ;&
-            1)
-                PROFILES[i]=$profile
-                ESSIDS[i]=$essid
-                (( ++i ))
-                ;;
-        esac
+        unset Interface ESSID
+        source "$PROFILE_DIR/$profile" > /dev/null
+        if [[ "$Interface" != "$1" || -z "$ESSID" ]]; then
+            continue;
+        fi
+        if [[ "$Description" =~ "Automatically generated" ]]; then
+            GENERATED+=("$profile")
+        fi
+        PROFILES[i]=$profile
+        ESSIDS[i]=$ESSID
+        (( ++i ))
     done < <(list_profiles)
 }
 
-- 
2.18.0


More information about the arch-projects mailing list