ptgdp: Implement barebones preprocessor commands

Now to put them to use
This commit is contained in:
Salt 2019-09-13 21:25:18 -05:00
parent ae55cb3ce3
commit 06712e971b

42
ptgdp
View File

@ -50,6 +50,12 @@ notify() {
"$1" \
"$2" > /dev/null 2>&1
}
execpreprocessor() {
# Execute a preprocessor line
# $1: The line, either stripped or not of the leading #:
line="${1#\#:}"
log "pp: $line"
}
checkforsong() {
# $1: A song name to validate
[ -z "$1" ] && return 1
@ -209,6 +215,11 @@ validateline() {
# 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=${1//[[:space:]]}
# Preprocessor commands
if ! [ "${1#\#:}" = "$1" ]; then
return 100
fi
# Comments and whitespace-only lines
if ! [ "${1#\#}" = "$1" ] || [ -z "$linenows" ]; then
return 1
fi
@ -355,22 +366,31 @@ playlist() {
done < "$1"
log "Parsed playlist \"$1\" with $maxlines songs"
while read line; do
[ -z "$line" ] && continue
validateline "$line" || continue
rm "$_tmpfile"* > /dev/null 2>&1
# Do the do
queuesong "$line"
# What did we do?
local errorcode=$?
case $errorcode in
validateline "$line"
case $? in
0)
dlsuccess+=1
rm "$_tmpfile"* > /dev/null 2>&1
# Do the do
queuesong "$line"
# What did we do?
local errorcode=$?
case $errorcode in
0)
dlsuccess+=1
;;
100)
dlexist+=1
;;
*)
dlfailure+=1
;;
esac
;;
100)
dlexist+=1
execpreprocessor "$line"
;;
*)
dlfailure+=1
continue
;;
esac
done < <(if [ -n "$_optshuffle" ]; then shuf "$1"; else cat "$1"; fi)