From patchwork Tue Jun 26 10:25:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Velikov via arch-projects X-Patchwork-Id: 656 Return-Path: Delivered-To: patchwork@archlinux.org Received: from apollo.archlinux.org (localhost [127.0.0.1]) by apollo.archlinux.org (Postfix) with ESMTP id 6ECBC51399AD for ; Tue, 26 Jun 2018 10:27:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on apollo X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED=0.1, DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3,T_DKIMWL_WL_HIGH=-0.01 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-BL-Results: [127.0.9.2] Received: from orion.archlinux.org (orion.archlinux.org [88.198.91.70]) by apollo.archlinux.org (Postfix) with ESMTPS for ; Tue, 26 Jun 2018 10:27:33 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id 1910BB65A2487; Tue, 26 Jun 2018 10:27:29 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [IPv6:2a01:4f8:160:3033::2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by orion.archlinux.org (Postfix) with ESMTPS; Tue, 26 Jun 2018 10:27:29 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id D66182C6FC; Tue, 26 Jun 2018 10:27:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=luna2; t=1530008848; bh=/PXGOXcWvD/r1vGMpKznhbmPIyalWgGl9pHcG+Iyqec=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc; b=FLlOFTlux8MWBVvAxYLhcW+11g776YdtjoWJdPWpYW01oGHbceGOsarmddKYlvX4S +0vJdxhhMOyVyOnLB6Gm6qXSYoFMUJDisHQ5s9uM7L6nFY6ysnhxixRv8mLXeamHFo tQZmdlGSDiJyg0S6Ik7Gq0VaYVw6MC76HnukdgUJhxZx/Qqhn5NUsIwcwRI5N+NJHd 3Zkevaqsr6zEyNFDb1NxrE+dCOBL0chHvE6l48ywe+gaYQQc3Jq0OJH6pcDoBViIm4 Et/kU1Jt4qAPbmFq8FmbyxFFygQo01qMwFlm5USkAlWZrUZoq00BBdbQjKceZkrPV9 nrWP04K27kWIPuHsrulSCZ/cOnbKNCDdMyX0zxDTjSsQD/3J0Clf6cHyW4ZhnyfAnA PrRwKEtcA7huLe8EdQzGasgMtvmw2DO/VUJ/QgGBN74DsLudYeuMcYJzmK+75m2KoF 3oai7zNIJNvxm/NMs0kiPf7QSRwgBbuVi5AKgUUboTFvEovvKoGm42vO7CYfT2Lh3I MwzBUrRXVu/ryL5bKM7y4xS+ogVRURVq4wjEKsTe7PN37pyFvbOsQP7UT3aGerW2yf d/VEW8Z3eahcYq3arceHVdfyJmGv06w4VCLKxCn59HgHW4/fivhcVUBPe4m1NGpwSt 5TbZJxBLK2n0ZX8WyO+iOxho= Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id DDD962C6FC for ; Tue, 26 Jun 2018 10:27:26 +0000 (UTC) Received: from orion.archlinux.org (orion.archlinux.org [88.198.91.70]) by luna.archlinux.org (Postfix) with ESMTPS for ; Tue, 26 Jun 2018 10:27:26 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id E9C4FB65A2482 for ; Tue, 26 Jun 2018 10:27:22 +0000 (UTC) Received: from mail-wm0-x244.google.com (mail-wm0-x244.google.com [IPv6:2a00:1450:400c:c09::244]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by orion.archlinux.org (Postfix) with ESMTPS for ; Tue, 26 Jun 2018 10:27:22 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id v16-v6so1275418wmv.5 for ; Tue, 26 Jun 2018 03:27:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=c0p+j9NiJ8MEfUvCjqL4YGN4EYbO9JWMN3vR2B6FE20=; b=amKQiydPLlzGmBVn91sv/edHuldhor2H/J4XAbKF5smC6z+vf/066SGi1jHNQqNvZj rtC+Z5JQWA5r3iH0Zum7NMwZP4sxaSaj38mjKKPH3UOnMBDxNnLTdTYOcN+3zMRj6YCS 8d97BaaSp//zEy1TRMnIcRN515oplYs2vw+Sb0003rRbPmeZ4+EbnAFOk25nE7VNLivS Kznd3EW06/tiPpxNqspcrBjp2Tm0eFTjw5a1ed5ybZQJmQbjp7OGmJe0H3kMkVPbnXjf A3CZ1GCAx5dN/NwlRdxGiCraVH6TymBmHyta7+9TUd05Obkw0vOauLiflu7i2N71KxXQ idEQ== X-Gm-Message-State: APt69E05t1YTiMGOrYmGeGS3bsPaU1O6XhuoYIWlL+o7fCz5e72iyz7B 5uWgRJVQjjMp2tWE1tfp+wbb3w== X-Google-Smtp-Source: AAOMgpfNfkeegjDkxE0kx2K6X10GSL2Zy43woRPzeCGPGH5eKVtiMa1/zW2FhWBd3rBwltteLUtPnw== X-Received: by 2002:a1c:a845:: with SMTP id r66-v6mr1194268wme.2.1530008842376; Tue, 26 Jun 2018 03:27:22 -0700 (PDT) Received: from arch-x1c3.cbg.collabora.co.uk ([2a00:5f00:102:0:9665:9cff:feee:aa4d]) by smtp.gmail.com with ESMTPSA id s191-v6sm2692020wmd.27.2018.06.26.03.27.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 03:27:21 -0700 (PDT) To: arch-projects@archlinux.org Date: Tue, 26 Jun 2018 11:25:21 +0100 Message-Id: <20180626102521.28129-1-emil.l.velikov@gmail.com> X-Mailer: git-send-email 2.18.0 Subject: [arch-projects] [netctl] [PATCH] Simplify init_profiles() implementation X-BeenThere: arch-projects@archlinux.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Arch Linux projects development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Emil Velikov via arch-projects Reply-To: Arch Linux projects development discussion Cc: Emil Velikov Errors-To: arch-projects-bounces@archlinux.org Sender: "arch-projects" From: Emil Velikov 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 Signed-off-by: Emil Velikov --- 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) }