ptgdp: Implement barebones preprocessor commands
Now to put them to use
This commit is contained in:
42
ptgdp
42
ptgdp
@@ -50,6 +50,12 @@ notify() {
|
|||||||
"$1" \
|
"$1" \
|
||||||
"$2" > /dev/null 2>&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() {
|
checkforsong() {
|
||||||
# $1: A song name to validate
|
# $1: A song name to validate
|
||||||
[ -z "$1" ] && return 1
|
[ -z "$1" ] && return 1
|
||||||
@@ -209,6 +215,11 @@ validateline() {
|
|||||||
# Strictly speaking, this removes all whitespace from the line
|
# Strictly speaking, this removes all whitespace from the line
|
||||||
# While not *exactly* what I'm looking for, it's sufficient for trimming whitespace lines
|
# While not *exactly* what I'm looking for, it's sufficient for trimming whitespace lines
|
||||||
local linenows=${1//[[:space:]]}
|
local linenows=${1//[[:space:]]}
|
||||||
|
# Preprocessor commands
|
||||||
|
if ! [ "${1#\#:}" = "$1" ]; then
|
||||||
|
return 100
|
||||||
|
fi
|
||||||
|
# Comments and whitespace-only lines
|
||||||
if ! [ "${1#\#}" = "$1" ] || [ -z "$linenows" ]; then
|
if ! [ "${1#\#}" = "$1" ] || [ -z "$linenows" ]; then
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@@ -355,22 +366,31 @@ playlist() {
|
|||||||
done < "$1"
|
done < "$1"
|
||||||
log "Parsed playlist \"$1\" with $maxlines songs"
|
log "Parsed playlist \"$1\" with $maxlines songs"
|
||||||
while read line; do
|
while read line; do
|
||||||
[ -z "$line" ] && continue
|
validateline "$line"
|
||||||
validateline "$line" || continue
|
case $? in
|
||||||
rm "$_tmpfile"* > /dev/null 2>&1
|
|
||||||
# Do the do
|
|
||||||
queuesong "$line"
|
|
||||||
# What did we do?
|
|
||||||
local errorcode=$?
|
|
||||||
case $errorcode in
|
|
||||||
0)
|
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)
|
100)
|
||||||
dlexist+=1
|
execpreprocessor "$line"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
dlfailure+=1
|
continue
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done < <(if [ -n "$_optshuffle" ]; then shuf "$1"; else cat "$1"; fi)
|
done < <(if [ -n "$_optshuffle" ]; then shuf "$1"; else cat "$1"; fi)
|
||||||
|
Reference in New Issue
Block a user