summaryrefslogtreecommitdiff
path: root/src/lib/libreblacklist
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libreblacklist')
-rwxr-xr-xsrc/lib/libreblacklist46
1 files changed, 25 insertions, 21 deletions
diff --git a/src/lib/libreblacklist b/src/lib/libreblacklist
index fb8b43a..bbba1ce 100755
--- a/src/lib/libreblacklist
+++ b/src/lib/libreblacklist
@@ -16,18 +16,17 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# make sure XDG_CACHE_HOME is set
-. $(librelib conf.sh)
+. $(librelib conf)
# Usage: blacklist-normalize <$file
-# Normalizes the syntax of the blacklist on stdin
+# Normalizes the syntax of the blacklist on stdin.
blacklist-normalize() {
sed -e 's/^[^:]*$/&::/' -e 's/^[^:]*:[^:]*$/&:/'
}
# Usage: blacklist-cat
# Prints the blacklist.
-# Uses the chache, but downloads it if it doesn't exist. Also normalizes the
-# blacklist for easier parsing.
+# Uses the cache, but downloads it if it doesn't exist. Also normalizes the blacklist for easier parsing.
blacklist-cat() {
local file="$XDG_CACHE_HOME/libretools/blacklist.txt"
if ! [[ -e $file ]]; then
@@ -38,7 +37,7 @@ blacklist-cat() {
}
# Usage: blacklist-update
-# Updates (or creates) the cached copy of the blacklist
+# Updates (or creates) the cached copy of the blacklist.
blacklist-update() (
. libremessages
load_files libretools || return 1
@@ -95,33 +94,38 @@ blacklist-get-reason() {
if [[ "${0##*/}" == libreblacklist ]]; then
usage-outside() {
- sed -n '/^# Usage:/,/()/p' $0 |
+ sed -n '/^# Usage:/,/()/p' "$0" |
tr '\n' '\r' | sed 's/\s*()\s*[{(]/\n/g'
}
+ # The output format of this is:
+ # - The first line is "Usage:"
+ # - The second line is a brief description
+ # - The last line is the command name (prefixed with "blacklist-")
+ # - The in-between lines are the extended description.
usage-inside() {
- sed 's/\r/\n/g'<<<"$1"|sed '/^$/d'
+ sed 's/\r/\n/g'<<<"$1"|sed -e '/^$/d' -e 's/^# //'
}
usage() {
+ . $(librelib messages)
if [[ $# -eq 0 ]]; then
- printf "Usage: %s [-h] COMMAND [ARGUMENTS]\n" "${0##*/}"
- echo "Tool for working with the nonfree software blacklist"
+ print "Usage: %s [-h] COMMAND [ARGUMENTS]" "${0##*/}"
+ print "Tool for working with the nonfree software blacklist"
echo
- echo "Commands:"
+ print "Commands:"
usage-outside | while read -r sec; do sec="$(usage-inside "$sec")"
- <<<"$sec" sed -n \
- -e 's/blacklist-//g' \
- -e 's/^# //' \
- -e '2p;$p' |
- tac|tr '\n' '\t'
- echo
- done|column -t -s"$(printf '\t')"|sed 's/^/ /'
+ cmd=$(<<<"$sec" sed -n '$s/^blacklist-//p')
+ desc="$(_ "$(sed -n 2p <<<"$sec")")"
+ flag "$cmd" "${desc//blacklist-/${0##*/} }"
+ done
else
usage-outside | while read -r sec; do sec="$(usage-inside "$sec")"
- cmd=$(<<<"$sec" sed -n 's/.*blacklist[ -]//;$p')
+ cmd=$(<<<"$sec" sed -n '$s/^blacklist-//p')
if [[ "$cmd" == "$1" ]]; then
- <<<"$sec" sed -n \
- -e "s/blacklist-/${0##*/} /g" \
- -e 's/^# //p'
+ <<<"$sec" sed '$d' |
+ while read -r line; do _ "$line"; done |
+ sed "s/blacklist-/${0##*/} /g" |
+ fmt -us
+ return 0
fi
done
fi