Skip to content

Commit 6e8038d

Browse files
committed
AWK scripts
* Moved complex awk scripts to libexec/awk * Simplified update index awk script (only awk!) * Simplified help message extractor awk script * Added tgts command for extracting targets from Makefiles
1 parent d5d6ece commit 6e8038d

7 files changed

Lines changed: 55 additions & 9 deletions

File tree

libexec/awk/help.awk

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
!/^#/ { stop = 1 }
2+
3+
/^# .+/ && !stop {
4+
printf $2
5+
for (i = 3; i <= NF; i++)
6+
printf " " $i
7+
printf "\n"
8+
}

libexec/awk/html.awk

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/<\/TR>/ { row += 1; }
2+
3+
/<TD CLASS="name">/ {
4+
gsub(/<[^>]+>/, "")
5+
data[row]["name"] = $0
6+
}
7+
8+
/<TD CLASS="sum">/ {
9+
gsub(/<BR>/, FS)
10+
gsub(/<[^>]+>/, "")
11+
data[row]["md5"] = $2
12+
data[row]["sha1"] = $4
13+
}
14+
15+
END {
16+
for(row in data)
17+
print(data[row]["name"], data[row]["sha1"], data[row]["md5"])
18+
}

libexec/comp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# Summary: Prints completion options for a command
44
#
5-
# Usage: luav comp <command> [<args>]
5+
# Usage: luav comp <command> [<args...>]
66
#
77

88
if [[ $# -ge 1 ]]
@@ -19,7 +19,7 @@ then
1919
get )
2020
libexec/all
2121
;;
22-
set | unset | make | rm )
22+
set | unset | make | rm | tgts )
2323
libexec/list
2424
;;
2525
help | comp )
@@ -32,7 +32,7 @@ then
3232
make )
3333
if libexec/list | grep -q "^$1$"
3434
then
35-
awk -F ':' '/^[a-z-]+:/ { print $1 }' versions/$1/Makefile versions/$1/src/Makefile
35+
libexec/tgts "$1"
3636
fi
3737
;;
3838
esac

libexec/help

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ then
1616
exit 1
1717
fi
1818

19-
sed -ne 's/^# \(Usage: .*\)$/\1/ p ; s/^# \(Hint: .*\)$/\1/ p' "libexec/$command"
19+
awk -f libexec/awk/help.awk "libexec/$command"
2020
else
2121
echo "Usage: luav <command> [<args>]"
2222
echo " luav help <command>"

libexec/make

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# Summary: Run make for a specific version of Lua
44
#
5-
# Usage: luav make <version> [<targets-and-flags>]
5+
# Usage: luav make <version> [<options...>]
66
#
77
# Hint: You can customize your compilation by setting the CFLAGS environment variable
88
#

libexec/tgts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Summary: Lists all main targets of a specific version of Lua
4+
#
5+
# Usage: luav tgts <version>
6+
#
7+
8+
if [[ $# -ge 1 ]]
9+
then
10+
version=$1
11+
shift
12+
else
13+
usage
14+
fi
15+
16+
if [[ ! -d versions/$version ]]
17+
then
18+
echo "Version '$version' not found" 2>&1
19+
echo "Hint: luav get $version" 2>&1
20+
exit 1
21+
fi
22+
23+
find "versions/$version" -name Makefile -type f | xargs awk -F: '/^[a-z-]+:/ { print $1 }'

libexec/update

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,4 @@
66
#
77

88
mkdir -p versions
9-
curl -s https://www.lua.org/ftp/ | \
10-
awk '/<\/TR>/ { row += 1; } /<\/TD>/ { print row, $0 }' | \
11-
sed 's/<\/TD>//g; s/<TD CLASS="\([^\"]*\)">/\1 /g; s/<A HREF="\([^\"]*\)">.*/\1/g; s/\(^[0-9]*\) [^ ]* md5: \([^<]*\)<BR>sha1: \(.*\)/\1 md5sum \2\n\1 sha1sum \3/g' | \
12-
awk '{ data[$1][$2] = $3 } END { for (i in data) print(data[i]["name"], data[i]["sha1sum"], data[i]["md5sum"], data[i]["date"], data[i]["size"]) }' > versions/.index
9+
curl -s https://www.lua.org/ftp/ | awk -f libexec/awk/html.awk > versions/.index

0 commit comments

Comments
 (0)