forked from MLton/mlton
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmlbdeps
executable file
·57 lines (50 loc) · 1.26 KB
/
mlbdeps
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env bash
set -e
SED=${SED:-sed}
name=$(basename "$0")
function normalize_path () {
local path="$1"
local opath=""
while [ "$opath" != "$path" ]; do
opath="$path"
path="$(echo "$path" | ${SED} -e 's;^\./;;')"
done
local opath=""
while [ "$opath" != "$path" ]; do
opath="$path"
path="$(echo "$path" | ${SED} -e 's;/\./;/;')"
done
opath=""
while [ "$opath" != "$path" ]; do
opath="$path"
path="$(echo "$path" | ${SED} -e 's;[^/][^/]*/\.\./;;')"
done
path="$(echo "$path" | ${SED} -e 's;^\./;;')"
echo "$path"
}
declare -a seen
function doit() {
local mlb="$1"
for s in "${seen[@]}"; do
if [ "$mlb" == "$s" ]; then
return 0
fi
done
seen+=("$mlb");
echo "$mlb"
if [ -e "$mlb" ]; then
local dir="$(dirname $mlb)"
for f in $(cat "$mlb" | ${SED} -n -e 's/^[ ]*\([^ ]*\.\(sml\|sig\|fun\|mlb\)\).*/\1/p'); do
case "$f" in
/*) ;;
\$\(*\)*) ;;
*) f="$(normalize_path "$dir"/"$f")" ;;
esac
case "$f" in
*.mlb) doit "$f";;
*) echo "$f";;
esac
done
fi
}
doit "$(normalize_path "$1")"