From owner-svn-src-all@freebsd.org Tue Dec 13 00:03:01 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2D2D4C74D83; Tue, 13 Dec 2016 00:03:01 +0000 (UTC) (envelope-from dteske@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id E2477EE4; Tue, 13 Dec 2016 00:03:00 +0000 (UTC) (envelope-from dteske@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uBD030qP005882; Tue, 13 Dec 2016 00:03:00 GMT (envelope-from dteske@FreeBSD.org) Received: (from dteske@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uBD030oK005881; Tue, 13 Dec 2016 00:03:00 GMT (envelope-from dteske@FreeBSD.org) Message-Id: <201612130003.uBD030oK005881@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dteske set sender to dteske@FreeBSD.org using -f From: Devin Teske Date: Tue, 13 Dec 2016 00:03:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r309959 - head/usr.sbin/bsdinstall/scripts X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Dec 2016 00:03:01 -0000 Author: dteske Date: Tue Dec 13 00:02:59 2016 New Revision: 309959 URL: https://svnweb.freebsd.org/changeset/base/309959 Log: Use the oft-neglected awk syntax "startcondition, stopcondition { ... }" to process the range of country labels which appear as columnar list from the "ifconfig DEV list countries" command. Not only improving maintainability, but also properly encapsulating arguments in single-quotes instead of trying to escape whitespace. It is also completely unnecessary to collapse newlines into whitespace (shell will do this for you automatically upon expansion of the contents where necessary). NB: This also changes the sorting algorithm to sort on the country code, not the country name. The type-ahead feature of dialog is destroyed if the tags are not sorted properly. Modified: head/usr.sbin/bsdinstall/scripts/wlanconfig Modified: head/usr.sbin/bsdinstall/scripts/wlanconfig ============================================================================== --- head/usr.sbin/bsdinstall/scripts/wlanconfig Mon Dec 12 22:57:07 2016 (r309958) +++ head/usr.sbin/bsdinstall/scripts/wlanconfig Tue Dec 13 00:02:59 2016 (r309959) @@ -96,17 +96,19 @@ dialog_country_select() input=$( ifconfig "$WLAN_IFACE" list countries | sed -e 's/DEBUG//gi' ) regdomains=$( echo $input | sed -e 's/.*domains://' | tr ' ' '\n' | sort | tr '\n' ' ' ) - countries=$( echo $input | awk '{ - sub(/Country codes:/, "") - sub(/Regulatory.*/, "") - for (i = 1; i <= NF; i++) { - printf "%s", $i - if ($i ~ /[[:lower:]]/) - printf $(i+1) ~ /[[:lower:]]/ ? "\\\\\\ " : "\n" - else - printf " " + countries=$( echo "$input" | awk ' + sub(/Country codes:/, ""), sub(/Regulatory.*/, "") { + while (match($0, /[[:upper:]][[:upper:][:digit:]] /)) { + country = substr($0, RSTART) + sub(/ [[:upper:]][[:upper:][:digit:]].*/, "", country) + code = substr(country, 1, 2) + desc = substr(country, 4) + sub(/[[:space:]]*$/, "", desc) + printf "'\''%s'\'' '\''%s'\''\n", code, desc + $0 = substr($0, RSTART + RLENGTH) + } } - }' | sort -k 2 | tr '\n' ' ' ) + ' | sort ) f_dialog_title "Regdomain selection" f_dialog_menu_size height width rows "$DIALOG_TITLE" \ @@ -123,16 +125,18 @@ dialog_country_select() ) f_dialog_title "Country selection" - f_dialog_menu_size height width rows "$DIALOG_TITLE" \ - "$DIALOG_BACKTITLE" "Select your country." "" $countries - country=$( sh -c "$DIALOG \ - --title \"$DIALOG_TITLE\" \ - --backtitle \"$DIALOG_BACKTITLE\" \ - --cancel-label \"$msg_skip\" \ + eval f_dialog_menu_size height width rows \ + \"\$DIALOG_TITLE\" \"\$DIALOG_BACKTITLE\" \ + \"Select your country.\" \"\" $countries + country=$( eval $DIALOG \ + --title \"\$DIALOG_TITLE\" \ + --backtitle \"\$DIALOG_BACKTITLE\" \ + --cancel-label \"\$msg_skip\" \ --default-item \"$default_country\" \ - --stdout \ --menu \"Select your country.\" \ - $height $width $rows $countries" + $height $width $rows \ + $countries \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD ) country_set "$regdomain" "$country"