summaryrefslogtreecommitdiffstats
path: root/bin/xmldiff.pl
blob: faeab63205794182b95be684c238e4d409ce0bed (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/perl
#
#  Copyright (c) 2002, DecisionSoft Limited All rights reserved.
#  Please see:
#  http://software.decisionsoft.com/licence.html
#  for more information.
#
# Modified for the Fedora Docs Project by Tommy.Reynolds@MegaCoder.com
#

#
# xmldiff: xmldiff program - uses xmlpp, which must be on the ${PATH}
#

#Change this if xmlpp is not in your current path
#for example: $XMLFORMAT = "./xmlpp";
# $XMLFORMAT = "xmlpp";

use Getopt::Std;

getopts('scupChi');

if ($opt_h || @ARGV != 2) {
	usage();
}

my $diffOpts;

my $outputFmt = $opt_u + $opt_c + $opt_s + $opt_p + $opt_C;
if( $outputFmt == 0 )	{
	$outputFmt = $opt_p = 1;
}
if( $outputFmt > 1 )	{
  print STDERR "Error: Only one mode may be specified\n";
  usage();
}

if( $opt_s )	{
	# Standard diff, no playing around
} elsif( $opt_c )	{
	# Plain context diff
	$diffOpts .= "-c ";
} elsif( $opt_u )	{
	# Plain unified diff
	$diffOpts .= "-u ";
} elsif( $opt_p )	{
	# Colorized unified diff
	# $diffOpts .= "-u ";
	$diffOpts .= "--new-line-format='+ %l\n' ";
	$diffOpts .= "--old-line-format='- %l\n' ";
	$diffOpts .= "--unchanged-line-format='  %l\n' ";
} elsif( $opt_C )	{
  $diffOpts .= "--changed-group-format='\n<<<<<<<<<<<<<<\n%<==============\n%>>>>>>>>>>>>>>>\n\n' ";
  $diffOpts .= "--new-line-format='+ %l\n' ";
  $diffOpts .= "--old-line-format='- %l\n' ";
  $diffOpts .= "--unchanged-line-format='  %l\n' ";
}

$XMLFORMAT = "xmlformat";

$file1 = "xmlppTEMP1.$$";
$file2 = "xmlppTEMP2.$$";

my $results = 0;
$results += system("$XMLFORMAT '$ARGV[0]' > $file1");
$results += system("$XMLFORMAT '$ARGV[1]' > $file2");

$results += system("/usr/bin/diff -bB $diffOpts $file1 $file2");


unlink($file1,$file2);

exit( $results );

sub usage {
  print STDERR <<EOF;
usage: $0 [ mode ] [ options ] oldfile.xml newfile.xml

mode must be one of:
  -p  coloured unified diff [default]
  -c  context diff
  -u  unified diff
  -s  standard diff output
  -C  vaguely CVS like unified diff

options:
  -t  split attributes - good for spotting changes in attributes
  -i  ignore element and attribute contents

EOF
  exit 1;
}