aboutsummaryrefslogtreecommitdiff
path: root/scripts/pd-diff
blob: 26db0a18b2b49db03a9adfd97dd4b437f884704a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/sh

DATE=$(date '+%Y-%m-%d_%H.%M.%S')
TMPDIR=/tmp/pd-diff

#------------------------------------------------------------------------------
# FUNCTIONS	 
generate_tmp_filename () {
	 echo ${TMPDIR}/$(echo $1 | sed -e 's|/|_|g')-${DATE}
}

prep_for_diff () {
	 TMPFILE=$(generate_tmp_filename "$1")

   # everything but the first line
   # no "connect" lines
   # remove position information

	 cat "$1" | \
		  sed '2,$!d' | \
		  grep -v '#X connect ' | \
		  sed 's/\(#[XN] [a-z]+\) [0-9]+ [0-9]+/\1/' \
		  > ${TMPFILE}
}

#------------------------------------------------------------------------------
# THE PROGRAM

if [ $# -ne 2 ]; then
	 echo "ERROR: Invalid number of arguments ($#)"
	 echo "Usage: $0 FILE1 FILE2"
else
	 if [ ! -d ${TMPDIR} ]; then
		  mkdir ${TMPDIR}
	 fi
	 
	 
	 TMP1=$(generate_tmp_filename "$1")
	 TMP2=$(generate_tmp_filename "$2")
	 
	 prep_for_diff "$1" 
	 prep_for_diff "$2" 

# diff of everything except "#X connect"'s
	 diff -uw "${TMP1}" "${TMP2}"

	file1count=$(grep -v '#X connect ' "$1" | wc -l)
	file2count=$(grep -v '#X connect ' "$2" | wc -l)
	if [ $file1count -ne $file2count ]; then 
		 echo "---------------------------------------------------------"
		 echo Connections differ: ${file1count} vs. ${file2count}
	fi
fi