<commit_before>#!/usr/bin/perl -w
#
# Copyright (c) 2003-2010 <NAME> <<EMAIL>>.
# All rights reserved. Use of the code is allowed under the
# Artistic License 2.0 terms, as specified in the LICENSE file
# distributed with this code, or available from
# http://www.opensource.org/licenses/artistic-license-2.0.php
#
# A simple utility to generate a version.h file from a template,
# with keyword substitution.
# The named file is replaced iff the newley generated one's
# different, to avoid spurious recompilations.
#
# Usage: $0 template outfile
# (typically: $0 version.in version.h)
#

use strict;
use warnings;

sub usage {
    print "Usage: $0 template outfile\n";
    exit 1;
}

my $SVNVERSION = "/usr/bin/svnversion";
die "Couldn't find $SVNVERSION" unless (-x $SVNVERSION);

my $ROOT = "../../.."; # should really be passed as arg
&usage unless ($#ARGV == 1);
my $TEMPLATE = $ARGV[0];
my $OUTFILE = $ARGV[1];

my $SVNVERSTRING = `$SVNVERSION -n $ROOT`;

#Now that we're done with the formalities, let's get to work:
my $TMPFILE = "/tmp/v$$";

open(TH, "<$TEMPLATE") || die "Couldn't read $TEMPLATE\n";
open(VH, ">$TMPFILE") || die "Couldn't open $TMPFILE for writing\n";

while (<TH>) {
    if (!m/SVN_VERSION/) {
        print VH;
    } else {
        print VH "#define SVN_VERSION \"$SVNVERSTRING\"\n";
    }
}

close(TH);
close(VH);

# Replace $OUTFILE with $TMPFILE iff:
# 1. Former doesn't exist
# OR
# 2. The two differ

if (!-e $OUTFILE) {
    rename($TMPFILE, $OUTFILE) || die "Couldn't rename $TMPFILE to $OUTFILE\n";
} else {
    `/usr/bin/diff -q $TMPFILE $OUTFILE > /dev/null`;
    if ($? != 0) {
        unlink $OUTFILE || die "Couldn't remove old $OUTFILE\n";
        rename($TMPFILE, $OUTFILE) || die "Couldn't rename $TMPFILE to $OUTFILE\n";
    } else { # no changes, cleanup
        unlink $TMPFILE;
    }
}
exit 0;
<commit_msg>perl's rename doesn't seem to work across fielsystem boundaries, use File::Copy instead<commit_after>#!/usr/bin/perl -w
#
# Copyright (c) 2003-2010 <NAME> <<EMAIL>>.
# All rights reserved. Use of the code is allowed under the
# Artistic License 2.0 terms, as specified in the LICENSE file
# distributed with this code, or available from
# http://www.opensource.org/licenses/artistic-license-2.0.php
#
# A simple utility to generate a version.h file from a template,
# with keyword substitution.
# The named file is replaced iff the newley generated one's
# different, to avoid spurious recompilations.
#
# Usage: $0 template outfile
# (typically: $0 version.in version.h)
#

use strict;
use warnings;
use File::Copy;

sub usage {
    print "Usage: $0 template outfile\n";
    exit 1;
}

my $SVNVERSION = "/usr/bin/svnversion";
die "Couldn't find $SVNVERSION" unless (-x $SVNVERSION);

my $ROOT = "../../.."; # should really be passed as arg
&usage unless ($#ARGV == 1);
my $TEMPLATE = $ARGV[0];
my $OUTFILE = $ARGV[1];

my $SVNVERSTRING = `$SVNVERSION -n $ROOT`;

#Now that we're done with the formalities, let's get to work:
my $TMPFILE = "/tmp/v$$";

open(TH, "<$TEMPLATE") || die "Couldn't read $TEMPLATE\n";
open(VH, ">$TMPFILE") || die "Couldn't open $TMPFILE for writing\n";

while (<TH>) {
    if (!m/SVN_VERSION/) {
        print VH;
    } else {
        print VH "#define SVN_VERSION \"$SVNVERSTRING\"\n";
    }
}

close(TH);
close(VH);

# Replace $OUTFILE with $TMPFILE iff:
# 1. Former doesn't exist
# OR
# 2. The two differ

if (!-e $OUTFILE) {
    move($TMPFILE, $OUTFILE) || die "Couldn't move $TMPFILE to $OUTFILE: $!\n";
} else {
    `/usr/bin/diff -q $TMPFILE $OUTFILE > /dev/null`;
    if ($? != 0) {
        unlink $OUTFILE || die "Couldn't remove old $OUTFILE\n";
        move($TMPFILE, $OUTFILE) || die "Couldn't move $TMPFILE to $OUTFILE: $!\n";
    } else { # no changes, cleanup
        unlink $TMPFILE;
    }
}
exit 0;

{'fraction_non_alphanumeric': 0.15745129015271195, 'fraction_numerical': 0.012111637704054766, 'mean_word_length': 3.4484777517564402, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7103135', 'n_tokens_mistral': 1417, 'n_tokens_neox': 1362, 'n_words': 449}