Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 83 lines (69 sloc) 2.04 KB
#!/bin/bash
function help {
echo "PointedEars' JavaScript Version Checker 0.3
Copyright (c) 2002 Thomas Lahn <PointedEars@gmx.de>
Detect the version a JavaScript is presumably written in, using version-
specific language elements. Note that not all elements can be checked for,
so this program may detect the wrong version.
Usage: `basename $0` [-v] script1 ... scriptN
-v, --verbose Enable verbose mode.
script1 ... scriptN List of script file names to be checked.
Two or more file names are separated by spaces, so
file names containing spaces must be enclosed in quotes.
"
}
status=0
verbose=0
[ "$1" = "-v" -o "$1" = "--verbose" ] && verbose=1 && shift
[ -z "$1" ] && help && exit 255
ident=('\.toExponential\>' \
'\.toFixed\>' \
'\.toPrecision\>' \
'\+\?' \
'\*\?' \
'\?\?' \
'\}\?' \
'\(\*\?:' \
'\(\?=' \
'\(\?!' \
'\<if[[:space:]]*?\(.+?\)[[:space:]]*?\{.*?function [[:alnum:]]+?\}' \
'=[[:space:]]*?function[[:space:]]*?\{.*?}' \
'\<catch[[:space:]]*?([[:space:]]*?[[:alnum:]]+?[[:space:]]+?if[[:space:]]+?[[:alnum:]]+?[[:space:]]+?instanceof[[:space:]]+?[[:alnum:]]+?)' \
'\<try\>' \
'\<const\>' \
'\.toSource\>' \
'\[[[:space:]]*^[[:digit:]]+[[:space:]]*\]'
)
# checking for getters and setters feature of JavaScript 1.5 not yet supported
for i in "$*"; do
cur=0
[ $verbose -eq 1 ] && echo -n "$i: "
if [ -f "$i" ]; then
for j in $(seq 0 $((${#ident[@]}-1)))
do
ver=1
[ $j -le 15 ] && {
ver=2
} && [ $j -le 15 ] && {
ver=3
} && [ $j -le 14 ] && {
ver=5
}
egrep -q -e "${ident[$j]}" "$i" && [ $cur -lt $ver ] && {
cur=$ver
exp="${ident[$j]} = "
break
}
done
if [ $verbose -eq 1 ]; then
echo "${exp}1.$cur"
else
printf "${exp}1.$cur "
fi
else
[ $verbose -eq 1 ] && echo 'not found'
let status++
fi
done
[ $verbose -ne 1 ] && echo
exit $status