Skip to content

Instantly share code, notes, and snippets.

@snaga
Created September 5, 2012 06:13
Show Gist options
  • Save snaga/3631442 to your computer and use it in GitHub Desktop.
Save snaga/3631442 to your computer and use it in GitHub Desktop.
A script to summarize PostgreSQL documentation changes in SGML files between two PostgreSQL versions
#!/usr/bin/perl
# -------------------------------------------------------------
# doc_sgml_cmp.pl
#
# A script to summarize PostgreSQL documentation changes
# in SGML files between two PostgreSQL versions.
#
# Written by Satoshi Nagayasu <snaga@snaga.org>
# -------------------------------------------------------------
use strict vars;
my $TARGET1=shift;
my $TARGET2=shift;
sub usage {
print "Usage: $0 [path1] [path2]\n";
print "\n";
print "Both path1 and path2 must point a SGML source directory.\n";
print "\n";
}
# those directories exist?
if ( ! -f "$TARGET1/postgres.sgml" || ! -f "$TARGET2/postgres.sgml" )
{
&usage;
exit;
}
open(FILE, "find $TARGET2 -type f -name '*.sgml' | sort |" ) || die($!);
print "file name,status,total lines,modified lines\n";
while(<FILE>)
{
chomp;
my $file = $_;
$file =~ s,^./,,;
my $basename = $file;
$basename =~ s,.*sgml/,,;
my $lc = `wc -l $_ | sed 's/ .*//'`;
chomp($lc);
if ( ! -f "$TARGET1/$file" )
{
print "$basename,added,$lc,\n";
}
else
{
my $mode = 0;
my $change = 0;
open(DIFF, "diff -rc $TARGET1/$file $file |") || die($!);
while(<DIFF>)
{
if ( /^\*\*\* \d+,\d+ \*\*\*\*/ )
{
$mode = 0;
}
if ( /^--- \d+,\d+ ----/ )
{
$mode = 1;
}
if ( $mode == 1 && /^\!/ )
{
$change++;
}
if ( $mode == 1 && /^\+/ )
{
$change++;
}
# print;
}
close(DIFF);
if ( $change == 0 )
{
print "$basename,not changed,$lc,$change\n";
}
else
{
print "$basename,changed,$lc,$change\n";
}
}
}
close(FILE);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment