1 | # This is a script in Bash. |
---|
2 | # Author: Lionel GUEZ |
---|
3 | |
---|
4 | # This script compares files "*.def" other than "traceur.def", |
---|
5 | # "tracer.def", "isotopes_params.def" and "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/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 | set -e |
---|
23 | |
---|
24 | script_dir=`dirname $0` |
---|
25 | |
---|
26 | # Let us make sure we know what the sort order is: |
---|
27 | export LC_ALL=C |
---|
28 | |
---|
29 | # Enable extended pattern matching features: |
---|
30 | shopt -s extglob |
---|
31 | |
---|
32 | for my_directory in $* |
---|
33 | do |
---|
34 | cd $my_directory |
---|
35 | rm -f all.def |
---|
36 | echo "def files in $my_directory:" |
---|
37 | ls !(traceur|tracer|out|isotopes_params).def |
---|
38 | |
---|
39 | # Concatenate and format the def files: |
---|
40 | cat !(traceur|tracer|out|isotopes_params).def | tr -d " \t" \ |
---|
41 | | grep -v -E '(^#|^!|INCLUDEDEF|^$)' \ |
---|
42 | | tr '[:lower:]' '[:upper:]' | sed 's/=[NF]$/=FALSE/' \ |
---|
43 | | sed 's/=[YT]$/=TRUE/' | sort >all.def |
---|
44 | |
---|
45 | # Check that no variable is repeated: |
---|
46 | |
---|
47 | cut --fields=1 --delimiter="=" all.def | uniq --repeated >plouf_$$ |
---|
48 | |
---|
49 | if [[ -s plouf_$$ ]] |
---|
50 | then |
---|
51 | echo |
---|
52 | echo "Error: a variable is repeated in directory \"$my_directory\"." |
---|
53 | echo |
---|
54 | echo "Here is the list of repeated variables in directory " \ |
---|
55 | "\"$my_directory\":" |
---|
56 | echo |
---|
57 | cat plouf_$$ |
---|
58 | rm plouf_$$ |
---|
59 | rm all.def |
---|
60 | exit 1 |
---|
61 | fi |
---|
62 | |
---|
63 | rm plouf_$$ |
---|
64 | cd - >/dev/null |
---|
65 | done |
---|
66 | |
---|
67 | sort $1/all.def $2/all.def | uniq --repeated >common_lines |
---|
68 | |
---|
69 | for my_directory in $* |
---|
70 | do |
---|
71 | sort $my_directory/all.def common_lines | uniq --unique \ |
---|
72 | >$my_directory/uniq_lines |
---|
73 | done |
---|
74 | |
---|
75 | sort --field-separator="=" --key=1,1 --unique $2/uniq_lines $1/uniq_lines \ |
---|
76 | | sort - $2/uniq_lines | uniq --unique >$1/uniq_var |
---|
77 | sort --field-separator="=" --key=1,1 --unique $1/uniq_lines $2/uniq_lines \ |
---|
78 | | sort - $1/uniq_lines | uniq --unique >$2/uniq_var |
---|
79 | |
---|
80 | for my_directory in $* |
---|
81 | do |
---|
82 | cd $my_directory |
---|
83 | echo "Created file \"$my_directory/uniq_var\"." |
---|
84 | sort uniq_lines uniq_var | uniq --unique >common_var |
---|
85 | rm uniq_lines |
---|
86 | cd - >/dev/null |
---|
87 | done |
---|
88 | |
---|
89 | $script_dir/compare_real.py $* |
---|
90 | sort common_lines --output=common_lines # was modified by the Python script |
---|
91 | echo "Created files \"./common_lines\" and \"./uniq_val\"." |
---|
92 | |
---|
93 | # Clean up: |
---|
94 | for my_directory in $* |
---|
95 | do |
---|
96 | rm $my_directory/common_var $my_directory/all.def |
---|
97 | done |
---|