From 36e70e902d91bcdb9a09f3e86e4170695022f92a Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Fri, 8 Feb 2002 23:53:58 +0000 Subject: [PATCH] Added --force argument; added support for slurping the $Id$ string out of the target file and stuffing it back into the newly generated file so that the generated file doesn't inherit the $Id$ string of the declaration file which would generally not be what we want. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@971 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- bin/gendobj | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/bin/gendobj b/bin/gendobj index 509642c88..0fa31c289 100755 --- a/bin/gendobj +++ b/bin/gendobj @@ -1,6 +1,6 @@ #!/usr/bin/perl -w # -# $Id: gendobj,v 1.3 2002/02/08 23:32:16 mdb Exp $ +# $Id: gendobj,v 1.4 2002/02/08 23:53:58 mdb Exp $ # # gendobj is used to generate DObject source file definitons basded on # abbreviated declarations. Because DObject fields all have standard @@ -11,11 +11,13 @@ use strict; use Getopt::Long; -my $usage = "Usage: $0 \n"; +my $usage = "Usage: $0 [--verbose] [--force] \n"; # get our options my $verbose; -GetOptions("verbose" => \$verbose); +my $force; +GetOptions("verbose" => \$verbose, + "force" => \$force); die $usage unless (@ARGV); @@ -23,16 +25,28 @@ my $source; while ($source = shift) { # massage the source file name into the destination file name my $dest = $source; - $dest =~ s/.dobj$/.java/g; + $dest =~ s/.dobj$/.java/; if ($dest !~ /.java$/) { warn "Unable to infer target file name from original: $source\n"; next; } + # if the destination file already exists, slurp the existing CVS $Id: gendobj,v 1.4 2002/02/08 23:53:58 mdb Exp $ + # information out of it so that we can slip that into the new one + my $idstr; + if (-f $dest && open(IN, "$dest")) { + while () { + if (/(\$Id: gendobj,v 1.4 2002/02/08 23:53:58 mdb Exp $)/) { + $idstr = $1; + } + } + close(IN); + } + # if the destination file is newer than the source file, do nothing my $dmtime = (stat($dest))[9]; my $smtime = (stat($source))[9]; - if ((defined $dmtime) && ($dmtime > $smtime)) { + if (!$force && (defined $dmtime) && ($dmtime > $smtime)) { warn "Skipping $source as source is newer.\n" if ($verbose); next; } @@ -51,6 +65,9 @@ while ($source = shift) { my $mode = "preamble"; while () { + # swap in the parsed $Id: gendobj,v 1.4 2002/02/08 23:53:58 mdb Exp $ str if we have one + $_ =~ s/(\$Id: gendobj,v 1.4 2002/02/08 23:53:58 mdb Exp $)/$idstr/ if (defined $idstr); + if ($mode eq "preamble") { # look to see if we're transitioning from the preamble to the # class declaration