Debian Codegraph @

tools/update-require

raw symbols SCIP
1 #!/bin/sh
2
3 # This script fully qualifies all the 'Require' statements of the given
4 # targets (or the current directory if none).
5 #
6 # It assumes that all the prerequisites are already installed. The
7 # install location is found using the ROCQLIB, COQC, COQBIN variables if
8 # set, 'coqc' otherwise.
9 #
10 # Option --exclude can be used to ignore a given user contribution. In
11 # particular, it can be used to ignore the current set of files if it
12 # happens to be already installed.
13 #
14 # Option --stdlib can be used to also qualify the files from the standard
15 # library.
16
17 if test ! "$ROCQLIB"; then
18 if test ${COQBIN##*/}; then COQBIN=$COQBIN/; fi
19 if test ! "$COQC"; then COQC=`which ${COQBIN}coqc`; fi
20 ROCQLIB=`"$COQC" -where`
21 fi
22
23 stdlib=no
24 exclude=""
25
26 scan_dir () {
27 (cd $1 ; find $3 -name '*.vo' |
28 sed -e "s,^./,$2,;s,\([^./]*\)/,\1.,g;s,\([^.]*\).vo,\1,")
29 }
30
31 scan_all_dir () {
32 if test $stdlib = yes; then
33 scan_dir "$ROCQLIB/theories" "Coq."
34 scan_dir "$ROCQLIB/plugins" "Coq."
35 fi
36 scan_dir "$ROCQLIB/user-contrib" "" "$exclude"
37 }
38
39 create_script () {
40 echo "BEGIN {"
41 scan_all_dir |
42 while read file ; do
43 echo $file | sed -e "s,\(.*\)[.]\([^.]*\), t[\"\2\"] = \"\1.\2\","
44 done
45 cat <<EOF
46 }
47
48 \$1 ~ "Require" {
49 for (i = 2; i <= NF; ++i) {
50 if (\$i ~ /[.]\$/) {
51 s = substr(\$i,1,length(\$i)-1)
52 if (t[s]) \$i = t[s] "."
53 break
54 } else if (t[\$i]) \$i = t[\$i]
55 }
56 print
57 next
58 }
59
60 { print }
61 EOF
62 }
63
64 usage () {
65 cat <<EOF
66 Usage: $0 [OPTION...] [TARGET...]
67 The default TARGET is the current directory.
68 Available options:
69 --exclude CONTRIB Do not qualify path to the given CONTRIB
70 --stdlib Qualify files from the standard library
71 --help Display this message
72 EOF
73 }
74
75 dir=""
76 while : ; do
77 case "$1" in
78 "")
79 break;;
80 -h|--help)
81 usage
82 exit 0;;
83 --exclude)
84 exclude="$exclude -path ./$2 -prune -type f -o"
85 shift;;
86 --stdlib)
87 stdlib=yes;;
88 -*)
89 echo "Unknown option $1" 1>&2
90 exit 1;;
91 *)
92 dir="$dir $1";;
93 esac
94 shift
95 done
96
97 script=`tempfile`
98 create_script > $script
99 find $dir -name '*.v' |
100 while read file; do
101 mv $file $file.bak
102 awk -f $script $file.bak > $file
103 done