From 94683b40016c6011809ce9b88eb35f180aada647 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 2 Jul 2023 00:37:38 +0200 Subject: Fix icon listing and make Makefile portable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- check-icons-listing | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100755 check-icons-listing (limited to 'check-icons-listing') diff --git a/check-icons-listing b/check-icons-listing new file mode 100755 index 0000000..404e089 --- /dev/null +++ b/check-icons-listing @@ -0,0 +1,89 @@ +#!/bin/sh +set -e + +rel () { + to="$1" + from="$2" + while test $(printf '%s\n' "$to" "$from" | grep / | wc -l) = 2; do + todir="$(printf '%s\n' "$to" | cut -d / -f 1)" + fromdir="$(printf '%s\n' "$from" | cut -d / -f 1)" + if test ! "$todir" = "$fromdir"; then + break + fi + to="$(printf '%s\n' "$to" | cut -d / -f 2-)" + from="$(printf '%s\n' "$frm" | cut -d / -f 2-)" + done + while test -n "$(printf '%s\n' "$from" | grep /)"; do + from="$(printf '%s\n' "$from" | cut -d / -f 2-)" + to="../$to" + done + printf '%s\n' "$to" +} + +lines=$(sed 's/\\$//' < icons.mk | sed '/^\s*\(#.*\|\)$/d' | sed 1d | wc -l) +test ! $lines = 0 + +test $(sed 's/\\$//' < icons.mk | sed '/^\s*\(#.*\|\)$/d' | sed 1d | sed 's/\t/ /g' | grep '^ ' | wc -l) = $lines + +test $(sed 's/\\$//' < icons.mk | sed '/^\s*\(#.*\|\)$/d' | sed '1s/^.*$//' | grep -n ' ' | wc -l) = 0 + +stack="" +i=0 +sed 's/\\$//' < icons.mk | sed '/^\s*\(#.*\|\)$/d' | sed 1d | sed 's/^\t/x/' | while read L; do + i=$(( i + 1 )) + printf 'Checking %i of %i\n\033[A' $i $lines >&2 + tabs=0 + while test ! $(printf '%s\n' "$L" | sed -n '/^x\t/p' | wc -l) = 0; do + L="$(printf '%s\n' "$L" | sed 's/^x\t/x/')" + tabs=$(( tabs + 1 )) + done + L="$(printf '%s\n' "$L" | sed 's/^x//')" + f="scalable/$L.svg" + if test ! $(printf '%s\n' $f | wc -l) = 1; then + printf '\033[K%s contains whitespace\n' "$L" >&2 + exit 1 + fi + tabsplus1=$(( tabs + 1 )) + if test -z "$(printf '%s\n' $stack x | sed -n ${tabsplus1}p)"; then + printf '\033[K%s is overtabulated\n' "$L" >&2 + exit 1 + else + stack="$(printf '%s\n' $stack | head -n $tabs; printf '%s\n' "$L")" + fi + if test ! -e "$f"; then + if test -L "$f"; then + printf '\033[K%s is a dangling symlink\n' "$L" >&2 + else + printf '\033[K%s is listed but does not exist\n' "$L" >&2 + fi + exit 1 + fi + if test $tabs = 0; then + if test -L "$f"; then + printf '\033[K%s is a symlink but not indented\n' "$L" >&2 + exit 1 + fi + else + goal_="$(printf '%s\n' $stack | sed -n "${tabs}p")" + if test ! -L "$f"; then + printf '\033[K%s is not a symlink but listed as linking to %s\n' "$L" "$goal" >&2 + exit 1 + fi + target="$(realpath -- "$f")" + goal="$(realpath -- "scalable/${goal_}.svg")" + if test "$target" = "$goal"; then + diff="same real file" + else + diff="different real file" + fi + target="$(readlink -- "$f")" + goal="$(rel "${goal_}.svg" "$L.svg")" + if test "$target" = "./$goal"; then + ln -sf -- "$target" "$f" + elif test ! "$target" = "$goal"; then + printf '\033[K%s links to %s but should link to %s (%s)\n' "$L" "$target" "$goal" "$diff" >&2 + exit 1 + fi + fi +done +printf '\033[K' >&2 -- cgit v1.2.3-70-g09d2