Implemented DeviceIoControl VWIN32_DIOC_DOS_DRIVEINFO, needed by
[wine] / tools / genpatch
1 #!/usr/bin/perl
2
3 # genpatch - A utility that generates patches for submission to
4 # wine-patches@winehq.com
5 #
6 # By Steven Elliott <elliotsl@mindspring.com>
7 #
8 # This program is subject to the same license as Wine (www.winehq.com).
9
10 =head1 NAME
11
12 genpatch - A utility that generates patches for submission to
13 wine-patches@winehq.com
14
15 =head1 SYNOPSIS
16
17 genpatch [B<-v>] [B<-n> patch_name] [B<-f> patch_file]
18          [B<-c> change_log] [B<-m> modified_files]
19          [B<-a> added_files]
20
21 =head1 DESCRIPTION
22
23 The genpatch utility generated patches for submission to
24 wine-patches@winehq by acting as a wrapper to "cvs diff".  The "B<-v>"
25 switch specifies that verbose output should be generated.  The "B<-n>"
26 switch overrides the patch name ("Name" field) which defaults to a
27 numeric UTC date.  The "B<-f>" switch overrides the filename of the patch
28 which defaults to "patches/<patch_name>.diff".  The "B<-c>" switch
29 specifies the CVS change log entry ("ChangeLog" field) which can be
30 seen when "cvs log" is invoked.  The "B<-m>" ("ModifiedFiles" field) and
31 "B<-a>" ("AddedFiles" field) switches override the set of files that
32 would normally be included by the "cvs diff".  Normally "cvs diff"
33 includes all files modified relative to the deltas indicated by the
34 "CVS/Entries" file and ignores all newly added files.  The "B<-m>" switch
35 specifies a whitespace separated list of files that were modified.
36 The "B<-a>" switch specifies a whitespace separated list of files that
37 were added.
38
39 =head1 EXAMPLE
40
41 genpatch B<-n> NLSFix B<-c> "various fixes for NLS support" \
42     B<-m> ole/ole2nls.c B<-a> ole/ole3nls.c
43
44 The above generates a patch named "NLSFix" in "patches/NLSFix.diff"
45 that includes a modification to "ole/ole2nls.c" and a newly added
46 "ole/ole3nls.c".
47
48 =cut
49
50 use strict;
51
52 use Getopt::Std;
53 use File::Basename;
54 use POSIX qw(strftime);
55
56 my $gen_date;       # date the patch was generated
57 my %options;        # command line options
58 my @modified_files; # optional list of files that were modified
59 my @added_files;    # added files as an array
60 my $added_file;     # added file being considered
61 my $patches_dir;    # location of the patch file
62 my $cvs_line;       # line of output from CVS
63 my $mod_files_str;  # string that describes the modified files
64
65 # Default the patch name to the UTC time.  Use a more descriptive date for the
66 # patch generation date.
67 $options{n} = strftime "%Y%m%d%H%M", gmtime;
68 $gen_date = strftime "%Y/%m/%d %H:%M:%S UTC", gmtime;
69
70 unless(getopts("vn:f:c:m:a:", \%options))
71 {
72     print STDERR "Usage: $0 [-v] [-n patch_name] [-f patch_file] " .
73         "[-c change_log] [-m modified_files] [-a added_files]\n";
74     exit 1;
75 }
76
77 $options{f} = "patches/$options{n}.diff" unless(exists $options{f});
78 $patches_dir = dirname $options{f};
79 @added_files = split ' ', $options{a};
80 @modified_files = split ' ', $options{m};
81
82 if(-d $patches_dir)
83 {
84     if(-e $options{f})
85     {
86         print STDERR "$options{f} already exists.  Aborting.\n";
87         exit 1;
88     }
89 }
90 else
91 {
92     mkdir $patches_dir, (0777 & ~umask) or
93         die "Unable to mkdir $patches_dir: $!";
94 }
95
96 $mod_files_str = exists($options{m}) ? $options{m} : "<see cvs diff>";
97 print "Generating $options{f}.\n" if($options{v});
98 open OPT_F, ">$options{f}" or die "Unable to open $options{f} for write: $!";
99 print OPT_F <<EOF;
100 Name: $options{n}
101 ChangeLog: $options{c}
102 GenDate: $gen_date
103 ModifiedFiles: $mod_files_str
104 AddedFiles: $options{a}
105 EOF
106
107 print "Invoking cvs diff.\n" if($options{v});
108 open CVS_IN, "cvs diff -u @modified_files|" or die "Unable to invoke cvs: $!";
109 while($cvs_line = <CVS_IN>)
110 {
111     chomp $cvs_line;
112     if($cvs_line =~ /^\? (.*)/)
113     {
114         push @added_files, $1 unless(exists $options{a});
115     }
116     else
117     {
118         print OPT_F <CVS_IN>;
119     }
120 }
121 close CVS_IN;
122
123 foreach $added_file (@added_files)
124 {
125     print "Adding $added_file as a new file.\n" if($options{v});
126     open DIFF_IN, "diff -u /dev/null $added_file|" or die "Unable to " .
127         "invoke diff: $!";
128     print OPT_F <DIFF_IN>;
129     close DIFF_IN;
130 }
131
132 close OPT_F;