blob: 785f7dec1279cb3f13c2d80d1e676ada7168f384 [file] [log] [blame]
# Common utility functions for js/src/doc scripts.
# `relative BASE ABSOLUTE` prints the URL relative to BASE that is
# equivalent to ABSOLUTE. BASE must end with a '/'. This function will
# introduce at most one level of '..'.
relative() {
local parent=$(dirname "$1")
case "$2" in
"$1"*)
# ABSOLUTE is within BASE; just remove BASE.
echo "$2" | sed -e "s|^$1||"
;;
"$parent/"*)
# ABSOLUTE is within BASE/..
echo "$2" | sed -e "s|^$parent/|../|"
;;
*)
# ABSOLUTE is unrelated to BASE.
echo "$2"
;;
esac
}