source: LMDZ5/trunk/tools/diffdef.sh @ 2154

Last change on this file since 2154 was 2101, checked in by lguez, 10 years ago

Exclude "out.def" of the comparison of ".def" files with
diffdef. "out.def" is neither an input file neither a file written by
IOIPSL like the files "used_*.def". So "out.def" contains some
duplicate lines with "used_guide.def", and the script diffdef would
signal that as an error.

  • Property svn:executable set to *
File size: 2.2 KB
Line 
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. The script uses GNU versions of the
6# utilities cut, sort and uniq.
7
8# See guide:
9# http://lmdz.lmd.jussieu.fr/utilisateurs/outils/utilisation-de-lmdz#section-5
10
11USAGE="usage: `basename $0` directory_1 directory_2"
12
13if (($# != 2))
14    then
15    echo "$USAGE" >&2
16    exit 1
17fi
18
19##set -x
20set -e
21
22script_dir=`dirname $0`
23
24# Let us make sure we know what the sort order is:
25export LC_ALL=C
26
27# Enable extended pattern matching features:
28shopt -s extglob
29
30for my_directory in $*
31  do
32  cd $my_directory
33  rm -f all.def
34  echo "def files in $my_directory:"
35  ls !(traceur|out).def
36
37  # Concatenate and format the def files:
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
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
58done
59
60
61sort $1/all.def $2/all.def | uniq --repeated >common_lines
62
63for my_directory in $*
64  do
65  sort $my_directory/all.def common_lines | uniq --unique \
66      >$my_directory/uniq_lines
67done
68
69sort --field-separator="=" --key=1,1 --unique $2/uniq_lines $1/uniq_lines \
70    | sort - $2/uniq_lines | uniq --unique >$1/uniq_var
71sort --field-separator="=" --key=1,1 --unique $1/uniq_lines $2/uniq_lines \
72    | sort - $1/uniq_lines | uniq --unique >$2/uniq_var
73
74for 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
81done
82
83$script_dir/compare_real.py $*
84sort common_lines --output=common_lines # was modified by the Python script
85echo "Created files \"./common_lines\" and \"./uniq_val\"."
86
87# Clean up:
88for my_directory in $*
89  do
90    rm $my_directory/common_var $my_directory/all.def
91done
Note: See TracBrowser for help on using the repository browser.