1 | # This is a script in Bash. |
---|
2 | # Author: Lionel GUEZ |
---|
3 | |
---|
4 | # This script compares files "*.def" other than "traceur.def" and |
---|
5 | # "out.def" in two directories. |
---|
6 | |
---|
7 | # This script uses GNU versions of the utilities cut, sort and uniq, |
---|
8 | # and calls a Python script. |
---|
9 | |
---|
10 | # See guide: |
---|
11 | # http://lmdz.lmd.jussieu.fr/utilisateurs/outils/utilisation-de-lmdz#section-5 |
---|
12 | |
---|
13 | USAGE="usage: `basename $0` directory_1 directory_2" |
---|
14 | |
---|
15 | if (($# != 2)) |
---|
16 | then |
---|
17 | echo "$USAGE" >&2 |
---|
18 | exit 1 |
---|
19 | fi |
---|
20 | |
---|
21 | ##set -x |
---|
22 | |
---|
23 | type python3 >/dev/null 2>&1 |
---|
24 | if (($? == 0)) |
---|
25 | then |
---|
26 | my_python=python3 |
---|
27 | else |
---|
28 | my_python=python |
---|
29 | fi |
---|
30 | |
---|
31 | set -e |
---|
32 | |
---|
33 | script_dir=`dirname $0` |
---|
34 | |
---|
35 | # Let us make sure we know what the sort order is: |
---|
36 | export LC_ALL=C |
---|
37 | |
---|
38 | # Enable extended pattern matching features: |
---|
39 | shopt -s extglob |
---|
40 | |
---|
41 | for my_directory in $* |
---|
42 | do |
---|
43 | cd $my_directory |
---|
44 | rm -f all.def |
---|
45 | echo "def files in $my_directory:" |
---|
46 | ls !(traceur|out).def |
---|
47 | |
---|
48 | # Concatenate and format the def files: |
---|
49 | cat !(traceur|out).def | tr -d " " | grep -v -E '(^#|^!|INCLUDEDEF|^$)' \ |
---|
50 | | tr '[:lower:]' '[:upper:]' | sed 's/=[NF]$/=FALSE/' \ |
---|
51 | | sed 's/=[YT]$/=TRUE/' | sort >all.def |
---|
52 | |
---|
53 | # Check that no variable is repeated: |
---|
54 | cut --fields=1 --delimiter="=" all.def | uniq --repeated >plouf_$$ |
---|
55 | if [[ -s plouf_$$ ]] |
---|
56 | then |
---|
57 | echo |
---|
58 | echo "Error: a variable is repeated in directory \"$my_directory\"." |
---|
59 | echo |
---|
60 | echo "Here is the list of repeated variables in directory \"$my_directory\":" |
---|
61 | echo |
---|
62 | cat plouf_$$ |
---|
63 | rm plouf_$$ |
---|
64 | rm all.def |
---|
65 | exit 1 |
---|
66 | fi |
---|
67 | rm plouf_$$ |
---|
68 | |
---|
69 | cd - >/dev/null |
---|
70 | done |
---|
71 | |
---|
72 | |
---|
73 | sort $1/all.def $2/all.def | uniq --repeated >common_lines |
---|
74 | |
---|
75 | for my_directory in $* |
---|
76 | do |
---|
77 | sort $my_directory/all.def common_lines | uniq --unique \ |
---|
78 | >$my_directory/uniq_lines |
---|
79 | done |
---|
80 | |
---|
81 | sort --field-separator="=" --key=1,1 --unique $2/uniq_lines $1/uniq_lines \ |
---|
82 | | sort - $2/uniq_lines | uniq --unique >$1/uniq_var |
---|
83 | sort --field-separator="=" --key=1,1 --unique $1/uniq_lines $2/uniq_lines \ |
---|
84 | | sort - $1/uniq_lines | uniq --unique >$2/uniq_var |
---|
85 | |
---|
86 | for my_directory in $* |
---|
87 | do |
---|
88 | cd $my_directory |
---|
89 | echo "Created file \"$my_directory/uniq_var\"." |
---|
90 | sort uniq_lines uniq_var | uniq --unique >common_var |
---|
91 | rm uniq_lines |
---|
92 | cd - >/dev/null |
---|
93 | done |
---|
94 | |
---|
95 | $my_python $script_dir/compare_real.py $* |
---|
96 | sort common_lines --output=common_lines # was modified by the Python script |
---|
97 | echo "Created files \"./common_lines\" and \"./uniq_val\"." |
---|
98 | |
---|
99 | # Clean up: |
---|
100 | for my_directory in $* |
---|
101 | do |
---|
102 | rm $my_directory/common_var $my_directory/all.def |
---|
103 | done |
---|