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 '\r' '\n' | tr -d " " \ |
---|
50 | | grep -v -E '(^#|^!|INCLUDEDEF|^$)' \ |
---|
51 | | tr '[:lower:]' '[:upper:]' | sed 's/=[NF]$/=FALSE/' \ |
---|
52 | | sed 's/=[YT]$/=TRUE/' | sort >all.def |
---|
53 | |
---|
54 | # Check that no variable is repeated: |
---|
55 | cut --fields=1 --delimiter="=" all.def | uniq --repeated >plouf_$$ |
---|
56 | if [[ -s plouf_$$ ]] |
---|
57 | then |
---|
58 | echo |
---|
59 | echo "Error: a variable is repeated in directory \"$my_directory\"." |
---|
60 | echo |
---|
61 | echo "Here is the list of repeated variables in directory \"$my_directory\":" |
---|
62 | echo |
---|
63 | cat plouf_$$ |
---|
64 | rm plouf_$$ |
---|
65 | rm all.def |
---|
66 | exit 1 |
---|
67 | fi |
---|
68 | rm plouf_$$ |
---|
69 | |
---|
70 | cd - >/dev/null |
---|
71 | done |
---|
72 | |
---|
73 | |
---|
74 | sort $1/all.def $2/all.def | uniq --repeated >common_lines |
---|
75 | |
---|
76 | for my_directory in $* |
---|
77 | do |
---|
78 | sort $my_directory/all.def common_lines | uniq --unique \ |
---|
79 | >$my_directory/uniq_lines |
---|
80 | done |
---|
81 | |
---|
82 | sort --field-separator="=" --key=1,1 --unique $2/uniq_lines $1/uniq_lines \ |
---|
83 | | sort - $2/uniq_lines | uniq --unique >$1/uniq_var |
---|
84 | sort --field-separator="=" --key=1,1 --unique $1/uniq_lines $2/uniq_lines \ |
---|
85 | | sort - $1/uniq_lines | uniq --unique >$2/uniq_var |
---|
86 | |
---|
87 | for my_directory in $* |
---|
88 | do |
---|
89 | cd $my_directory |
---|
90 | echo "Created file \"$my_directory/uniq_var\"." |
---|
91 | sort uniq_lines uniq_var | uniq --unique >common_var |
---|
92 | rm uniq_lines |
---|
93 | cd - >/dev/null |
---|
94 | done |
---|
95 | |
---|
96 | $my_python $script_dir/compare_real.py $* |
---|
97 | sort common_lines --output=common_lines # was modified by the Python script |
---|
98 | echo "Created files \"./common_lines\" and \"./uniq_val\"." |
---|
99 | |
---|
100 | # Clean up: |
---|
101 | for my_directory in $* |
---|
102 | do |
---|
103 | rm $my_directory/common_var $my_directory/all.def |
---|
104 | done |
---|