4-space indentation

This commit is contained in:
Connor Olding 2014-03-15 08:37:34 -07:00
parent 097e116c19
commit 027a8db2e1
3 changed files with 50 additions and 50 deletions

32
run
View File

@ -5,33 +5,33 @@ SRCDIR="$(readlink -f "$(dirname "$0")" )"
declare -a actions
while getopts 'aph' opt; do
case $opt in
a) actions+=(addtorrent);;
p) actions+=(prettify);;
?) echo -E "usage: $0 [-ap]" 1>&2;;
esac
case $opt in
a) actions+=(addtorrent);;
p) actions+=(prettify);;
?) echo -E "usage: $0 [-ap]" 1>&2;;
esac
done
prettify() {
echo -E "$1"$'\n'"dl:"$'\t'"$2"$'\n'"at:"$'\t'"$(date -d @"$3")"
echo -E "$1"$'\n'"dl:"$'\t'"$2"$'\n'"at:"$'\t'"$(date -d @"$3")"
}
declare -a torrents
addtorrent() {
torrents+=("$2")
torrents+=("$2")
}
runactions() {
[ ${#actions} = 0 ] && {
cat
return
}
while IFS=$SEP read -r title torrent time; do
for a in "${actions[@]}"; do
"$a" "$title" "$torrent" "$time"
[ ${#actions} = 0 ] && {
cat
return
}
while IFS=$SEP read -r title torrent time; do
for a in "${actions[@]}"; do
"$a" "$title" "$torrent" "$time"
done
done
done
for t in "${torrents[@]}"; do transmission-remote -a "$t"; done
for t in "${torrents[@]}"; do transmission-remote -a "$t"; done
}
. "$SRCDIR/meow.sh"

View File

@ -1,39 +1,39 @@
function opentag(str, tag) {
topen="<"tag">"
tclose="</"tag">"
len=length(tag)
begin=index(str, topen)
end=index(str, tclose)
return (begin && end) ? substr(str, begin+len+2, end-begin-len-2) : ""
topen="<"tag">"
tclose="</"tag">"
len=length(tag)
begin=index(str, topen)
end=index(str, tclose)
return (begin && end) ? substr(str, begin+len+2, end-begin-len-2) : ""
}
function unescape(str) {
while (match(str, /&#([0-9]+);/, b))
str=substr(str, 1, RSTART-1) sprintf("%c",b[1]) substr(str, RSTART+RLENGTH)
return str
while (match(str, /&#([0-9]+);/, b))
str=substr(str, 1, RSTART-1) sprintf("%c",b[1]) substr(str, RSTART+RLENGTH)
return str
}
function hotdate(str) {
split(str, d, "[ :]")
return mktime(d[4]" "months[d[3]]" "d[2]" "d[5]" "d[6]" "d[7])
split(str, d, "[ :]")
return mktime(d[4]" "months[d[3]]" "d[2]" "d[5]" "d[6]" "d[7])
}
BEGIN{
# http://stackoverflow.com/a/2123002
m=split("Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec",d,"|")
for(o=1;o<=m;o++) months[d[o]]=sprintf("%02d",o)
glen=length(g)
# http://stackoverflow.com/a/2123002
m=split("Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec",d,"|")
for(o=1;o<=m;o++) months[d[o]]=sprintf("%02d",o)
glen=length(g)
}
function run(str) {
title=unescape(opentag(str, "title"))
if (substr(title,1,glen+2) != "["g"]") return
pub=unescape(opentag($0, "pubDate"))
# "date -d \""pub "\" +%s" | getline pubunix
pubunix=hotdate(pub)
if (pubunix <= ts) return
torrent=unescape(opentag(str, "link"))
print title sep torrent sep pubunix
title=unescape(opentag(str, "title"))
if (substr(title,1,glen+2) != "["g"]") return
pub=unescape(opentag($0, "pubDate"))
# "date -d \""pub "\" +%s" | getline pubunix
pubunix=hotdate(pub)
if (pubunix <= ts) return
torrent=unescape(opentag(str, "link"))
print title sep torrent sep pubunix
}
{run($0)}

View File

@ -1,13 +1,13 @@
{
str=$0
topen="<"tag">"
tclose="</"tag">"
len=length(tag)
for (;;) {
begin=index(str, topen)
end=index(str,tclose)
if (!(begin || end)) break
print substr(str, begin+len+2, end-begin-len-2)
str=substr(str, end+len+3)
}
str=$0
topen="<"tag">"
tclose="</"tag">"
len=length(tag)
for (;;) {
begin=index(str, topen)
end=index(str,tclose)
if (!(begin || end)) break
print substr(str, begin+len+2, end-begin-len-2)
str=substr(str, end+len+3)
}
}