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