From 291a80c6640ce9e9f03153d2b47f45188ee10b17 Mon Sep 17 00:00:00 2001
From: cladmi <gaetan.harter@fu-berlin.de>
Date: Mon, 15 Oct 2018 16:45:17 +0200
Subject: [PATCH] openocd.sh: refactor splitting banks in a separate function

Prepare for other refactoring.
---
 dist/tools/openocd/openocd.sh | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/dist/tools/openocd/openocd.sh b/dist/tools/openocd/openocd.sh
index a4c72dd386..ba50e5b1cd 100755
--- a/dist/tools/openocd/openocd.sh
+++ b/dist/tools/openocd/openocd.sh
@@ -159,6 +159,20 @@ _is_binfile() {
         [[ -z "${firmware_type}" ]] && _has_bin_extension "${firmware}"; }
 }
 
+# Split bank info on different lines without the '{}'
+_split_banks() {
+    # Input:
+    #   ...
+    #   {name nrf51 base 0 size 0 bus_width 1 chip_width 1} {name nrf51 base 268439552 size 0 bus_width 1 chip_width 1}
+    #   ...
+    #
+    # Output:
+    #   name nrf51 base 0 size 0 bus_width 1 chip_width 1
+    #   name nrf51 base 268439552 size 0 bus_width 1 chip_width 1
+
+    sed -n '/^{.*}$/ {s/\} /\}\n/g;s/[{}]//g;p}'
+}
+
 # Outputs bank info on different lines without the '{}'
 _flash_list() {
     # Openocd output for 'flash list' is
@@ -169,7 +183,7 @@ _flash_list() {
             ${OPENOCD_ADAPTER_INIT} \
             -f '${OPENOCD_CONFIG}' \
             -c 'flash list' \
-            -c 'shutdown'" 2>&1 | sed -n '/^{.*}$/ {s/\} /\}\n/g;s/[{}]//g;p}'
+            -c 'shutdown'" 2>&1 | _split_banks
 }
 
 # Print flash address for 'bank_num' num defaults to 1
-- 
GitLab