Properly declare handles.
[wine/multimedia.git] / tools / genpatch
blobb241889babb05567855aa9ec34fdcb27327474b0
1 #!/usr/bin/perl -w
3 # genpatch - A utility that generates patches for submission to
4 # wine-patches@winehq.org
6 # Copyright Steven Elliott <elliotsl@mindspring.com>
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License, or (at your option) any later version.
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # Lesser General Public License for more details.
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this library; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 =head1 NAME
25 genpatch - A utility that generates patches for submission to
26 wine-patches@winehq.org
28 =head1 SYNOPSIS
30 genpatch [B<-v>] [B<-n> patch_name] [B<-f> patch_file]
31 [B<-c> change_log] [B<-m> modified_files]
32 [B<-a> added_files]
34 =head1 DESCRIPTION
36 The genpatch utility generated patches for submission to
37 wine-patches@winehq by acting as a wrapper to "cvs diff". The "B<-v>"
38 switch specifies that verbose output should be generated. The "B<-n>"
39 switch overrides the patch name ("Name" field) which defaults to a
40 numeric UTC date. The "B<-f>" switch overrides the filename of the patch
41 which defaults to "patches/<patch_name>.diff". The "B<-c>" switch
42 specifies the CVS change log entry ("ChangeLog" field) which can be
43 seen when "cvs log" is invoked. The "B<-m>" ("ModifiedFiles" field) and
44 "B<-a>" ("AddedFiles" field) switches override the set of files that
45 would normally be included by the "cvs diff". Normally "cvs diff"
46 includes all files modified relative to the deltas indicated by the
47 "CVS/Entries" file and ignores all newly added files. The "B<-m>" switch
48 specifies a whitespace separated list of files that were modified.
49 The "B<-a>" switch specifies a whitespace separated list of files that
50 were added.
52 =head1 EXAMPLE
54 genpatch B<-n> NLSFix B<-c> "various fixes for NLS support" \
55 B<-m> ole/ole2nls.c B<-a> ole/ole3nls.c
57 The above generates a patch named "NLSFix" in "patches/NLSFix.diff"
58 that includes a modification to "ole/ole2nls.c" and a newly added
59 "ole/ole3nls.c".
61 =cut
63 use strict;
65 use Getopt::Std;
66 use File::Basename;
67 use POSIX qw(strftime);
69 # Command line options
70 my %options;
72 # Default the patch name to the UTC time. Use a more descriptive date for the
73 # patch generation date.
74 $options{n} = strftime "%Y%m%d%H%M", gmtime;
75 my $gen_date = strftime "%Y/%m/%d %H:%M:%S UTC", gmtime;
77 unless(getopts("vn:f:c:m:a:p:", \%options))
79 print STDERR "Usage: $0 [-v] [-n patch_name] [-f patch_file] " .
80 "[-c change_log] [-m modified_files] [-a added_files] [-p path_to_patches]\n";
81 exit 1;
84 $options{p} = "patches" if (!defined $options{p});
85 $options{f} = "$options{p}/$options{n}.diff" if (!defined $options{f});
86 $options{p} = dirname $options{f};
87 $options{a} = "" if (!defined $options{a});
88 my @added_files = split ' ', $options{a};
89 $options{m} = "" if (!defined $options{m});
90 $options{c} = "" if (!defined $options{c});
91 $options{c} =~ s/\\n/\n\t/g;
93 if (!-d $options{p})
95 mkdir $options{p}, (0777 & ~umask)
96 or die "Unable to mkdir $options{p}: $!";
98 elsif (-e $options{f})
100 print STDERR "$options{f} already exists. Aborting.\n";
101 exit 1;
104 my $mod_files_str = $options{m} ? $options{m} : "<see cvs diff>";
105 print "Generating $options{f}.\n" if($options{v});
106 open OPT_F, ">$options{f}" or die "Unable to open $options{f} for write: $!";
107 print OPT_F <<EOF;
108 Name: $options{n}
109 ChangeLog: $options{c}
110 GenDate: $gen_date
111 ModifiedFiles: $mod_files_str
112 AddedFiles: $options{a}
115 print "Invoking cvs diff.\n" if($options{v});
116 open CVS_IN, "cvs diff -u $options{m} |"
117 or die "Unable to invoke cvs: $!";
118 while (my $cvs_line = <CVS_IN>)
120 if ($cvs_line !~ /^\? (.*)/)
122 print OPT_F $cvs_line;
124 elsif (!$options{a})
126 push @added_files, chomp $1;
129 close CVS_IN;
131 foreach my $added_file (@added_files)
133 print "Adding $added_file as a new file.\n" if($options{v});
134 open DIFF_IN, "diff -u /dev/null $added_file|"
135 or die "Unable to invoke diff: $!";
136 print OPT_F <DIFF_IN>;
137 close DIFF_IN;
140 close OPT_F;