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