ptgdp: Define function for line validation

This commit is contained in:
Salt 2019-08-14 04:34:32 -05:00
parent afcb98e06b
commit 082d48f61d

21
ptgdp
View File

@ -133,6 +133,14 @@ validatedeps() {
done
return 0
}
validateline() {
# $1: A line to check for comments or whitespace
local linenows=${1//[[:space:]]}
if ! [ "${1#\#}" = "$1" ] || [ -z "$linenows" ]; then
return 1
fi
return 0
}
sanitize() {
[ -z "$1" ] && return 1 # String to strip special chars from
_return="${1//[^ a-zA-Z0-9\[\]|()_-]/}"
@ -230,22 +238,13 @@ playlist() {
while read line; do
# Strictly speaking, this removes all whitespace from the line
# While not *exactly* what I'm looking for, it's sufficient for trimming whitespace lines
local linenows=${line//[[:space:]]}
if ! [ "${line#\#}" = "$line" ] || [ -z "$linenows" ]; then
continue
fi
unset linenows
validateline "$line" || continue
maxlines+=1
done < "$1"
log "Enqueued playlist with $maxlines lines"
while read line; do
[ -z "$line" ] && continue
# Ignore comments and blank lines
local linenows=${line//[[:space:]]}
if ! [ "${line#\#}" = "$line" ] || [ -z "$linenows" ]; then
continue
fi
unset linenows
validateline "$line" || continue
rm "$_tmpfile"* > /dev/null 2>&1
# Do the do
cachesong "$line"