From d3e8e1963741c5f0596db9a571969f169b88e427 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 27 Jul 2022 09:57:18 +0200 Subject: names.sh: improve readability MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- names.sh | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/names.sh b/names.sh index a4d1eed..75bf885 100755 --- a/names.sh +++ b/names.sh @@ -3,14 +3,35 @@ format="$1" shift 1 -prefix="$(printf '%s\\|' "$@" | sed 's/..$//')" +prefix="$( + printf '%s\\|' "$@" | + sed 's/..$//' +)" -definitions_with_max="$(sed -n 's/^\s*#\s*define\s\+\(\('"$prefix"'\)_[A-Za-z0-9_]*\)\s\+\(0[xX][0-9A-Fa-f]\+\|[0-9]\+\)\(.*\)$/\3 \1/p')" +definitions_with_max="$( + sed -n 's/^\s*#\s*define\s\+\(\('"$prefix"'\)_[A-Za-z0-9_]*\)\s\+\(0[xX][0-9A-Fa-f]\+\|[0-9]\+\)\(.*\)$/\3 \1/p' +)" -definitions="$(printf '%s\n' "$definitions_with_max" | sed '/ \('"$prefix"'\)_MAX$/d')" -max=$(printf '%u\n' $(printf '%s\n' "$definitions_with_max" | sed -n 's/^\(.*\) \('"$prefix"'\)_MAX$/\1/p')) +definitions="$( + printf '%s\n' "$definitions_with_max" | + sed '/ \('"$prefix"'\)_MAX$/d' +)" -nonunique="$(printf '%s\n' "$definitions" | while read num name; do printf '0x%08X\n' $num; done | sort | uniq -d)" +max=$( + printf '%u\n' $( + printf '%s\n' "$definitions_with_max" | + sed -n 's/^\(.*\) \('"$prefix"'\)_MAX$/\1/p' + ) +) + +nonunique="$( + printf '%s\n' "$definitions" | + while read num name; do + printf '0x%08X\n' $num + done | + sort | + uniq -d +)" printf '%s\n' "$definitions" | while read line; do -- cgit v1.2.3-70-g09d2