aboutsummaryrefslogtreecommitdiff
path: root/lang/sml-nj-devel/scripts
diff options
context:
space:
mode:
authorJoseph Koshy <jkoshy@FreeBSD.org>1998-11-20 08:14:12 +0000
committerJoseph Koshy <jkoshy@FreeBSD.org>1998-11-20 08:14:12 +0000
commit190c2427ea2fe89ca2a3b6aaa4ea17dc9a0b8d81 (patch)
treea8964850342d50945e9a72ed3a1533ae94df21d6 /lang/sml-nj-devel/scripts
parent09ae5a3b638b58661adba5e90d8196c2f1ce0764 (diff)
Notes
Diffstat (limited to 'lang/sml-nj-devel/scripts')
-rw-r--r--lang/sml-nj-devel/scripts/get-cm81
1 files changed, 81 insertions, 0 deletions
diff --git a/lang/sml-nj-devel/scripts/get-cm b/lang/sml-nj-devel/scripts/get-cm
new file mode 100644
index 000000000000..88992a05219f
--- /dev/null
+++ b/lang/sml-nj-devel/scripts/get-cm
@@ -0,0 +1,81 @@
+#!/bin/sh
+#
+# usage: get-cm work_dir
+#
+# Find all .cm Group and Library descriptions that are referenced
+# from the top level alias files in $SML_BASE/lib/
+
+# temp file
+tmpfile="${TMP:-/tmp}/chomp$$"
+
+# attempt to change directory to work dir
+cd $1 || exit 1
+work_dir=`pwd` # get the canonical name for the current directory
+
+trap "rm -f $tmpfile" 0 1 2 3 15
+
+# hack to remove SML comments '(* ... *)'
+
+strip_comments()
+{
+ # caveat: the following assumes gcc is present ...
+ gcc -x c -E -P -ansi -DOPSYS_UNIX $1 | awk '{
+ line = $0
+ if (match(line, "\\(\\*")) {
+ while (match($0, "\\(\\*")) {
+ if (RSTART > 1) {
+ print substr($0, 0, RSTART-1);
+ }
+ sub("^.*\\(\\*", "");
+ while (!match($0, "\\*\\)")) {
+ getline
+ }
+ $0 = substr($0, RSTART+RLENGTH);
+ }
+ }
+ print
+ }'
+}
+
+# return canonical name for a path with embedded ..'s
+
+canonical()
+{
+ echo $(cd `dirname $1` && pwd)/`basename $1`
+}
+
+# initial list of CM description files
+global_cm_list="$(cat ./lib/*.cm | awk '{ print $2 }')"
+
+set -- $global_cm_list
+
+touch $tmpfile
+
+# process the global list
+while [ $# -ge 1 ]; do
+
+ cm_file="$1"; shift
+ global_cm_list="$*"
+
+ echo $cm_file >> $tmpfile
+
+ cm_dir=`dirname $cm_file`
+ cm_new=$(strip_comments $cm_file | grep '\.cm' | \
+ awk '{ print $1 }')
+
+ # append new CM files to current global list
+ for i in $cm_new; do
+ new_cm_file=$(canonical $cm_dir/$i)
+ if [ -r $new_cm_file ]; then
+ if ! grep "^$new_cm_file" $tmpfile > /dev/null; then
+ global_cm_list="$new_cm_file $global_cm_list"
+ echo $new_cm_file >> $tmpfile
+ fi
+ fi
+ done
+
+ set -- $global_cm_list
+done
+
+# output to stdout
+sort -u < $tmpfile | sed -e "s,^$work_dir/,,"