2 #***************************************************************************
4 # Project ___| | | | _ \| |
6 # | (__| |_| | _ <| |___
7 # \___|\___/|_| \_\_____|
9 # Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
11 # This software is licensed as described in the file COPYING, which
12 # you should have received as part of this distribution. The terms
13 # are also available at https://curl.haxx.se/docs/copyright.html.
15 # You may opt to use, copy, modify, merge, publish, distribute and/or sell
16 # copies of the Software, and permit persons to whom the Software is
17 # furnished to do so, under the terms of the COPYING file.
19 # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 # KIND, either express or implied.
22 ###########################################################################
30 # Data from the command line.
32 my $curlver = $ARGV[0];
33 my $curldate = $ARGV[1];
35 # Directories and extensions.
37 my @dirlist = ("docs/", "docs/libcurl/", "docs/libcurl/opts/", "tests/");
38 my @extlist = (".1", ".3");
39 my @excludelist = ("mk-ca-bundle.1", "template.3");
44 # Print arguments and exit.
46 print "usage: updatemanpages.pl <version> <date>\n";
51 # Process file looking for .TH section.
59 open($file_handle, $filename);
61 # Look for the .TH section, process it into an array,
62 # modify it and write to file.
64 tie(my @file_data, 'Tie::File', $filename);
65 foreach my $file_data_line(@file_data) {
66 if($file_data_line =~ /^.TH/) {
67 $file_line = $file_data_line;
79 # Extract .TH section as an array.
83 # Split the line into an array.
86 my $inputsize = length($input);
87 my $inputcurrent = "";
90 for(my $inputseek = 0; $inputseek < $inputsize; $inputseek++) {
92 if(substr($input, $inputseek, 1) eq " " && $quotemode eq 0) {
93 push(@tharray, $inputcurrent);
98 $inputcurrent = $inputcurrent . substr($input, $inputseek, 1);
100 if(substr($input, $inputseek, 1) eq "\"") {
101 if($quotemode eq 0) {
110 if($inputcurrent ne "") {
111 push(@tharray, $inputcurrent);
118 # Get the date from the .TH section.
120 my $filename = shift;
125 $thline = getthline($filename);
127 # Return nothing if there is no .TH section found.
129 if(!$thline || $thline eq "") {
133 @tharray = extractth($thline);
135 # Remove the quotes at the start and end.
137 $date = substr($tharray[3], 1, -1);
142 # Process .TH section.
147 # Split the line into an array.
149 my @tharray = extractth($input);
156 $tharray[3] = $itemdate;
158 # Alter the item version.
160 my $itemver = $tharray[4];
163 for(my $itemnameseek = 1;
164 $itemnameseek < length($itemver);
166 if(substr($itemver, $itemnameseek, 1) eq " " ||
167 substr($itemver, $itemnameseek, 1) eq "\"") {
170 $itemname .= substr($itemver, $itemnameseek, 1);
174 $itemver .= $itemname;
176 $itemver .= $curlver;
179 $tharray[4] = $itemver;
183 foreach my $thvalue (@tharray) {
184 $thoutput .= $thvalue;
187 $thoutput =~ s/\s+$//;
190 # Return updated string.
196 # Process file looking for .TH section.
198 my $filename = shift;
201 my $file_dist_handle;
204 # Open a handle for the original file and a second file handle
207 $filename_dist = $filename . ".dist";
209 open($file_handle, $filename);
210 open($file_dist_handle, ">" . $filename_dist);
212 # Look for the .TH section, process it into an array,
213 # modify it and write to file.
215 tie(my @file_data, 'Tie::File', $filename);
216 foreach my $file_data_line (@file_data) {
217 if($file_data_line =~ /^.TH/) {
218 my $file_dist_line = processth($file_data_line, $date);
219 print $file_dist_handle $file_dist_line . "\n";
222 print $file_dist_handle $file_data_line . "\n";
229 close($file_dist_handle);
232 # Check that $curlver is set, otherwise print arguments and exit.
238 # check to see that the git command works, it requires git 2.6 something
239 my $gitcheck = `git log -1 --date="format:%B %d, %Y" $dirlist[0] 2>/dev/null`;
240 if(length($gitcheck) < 1) {
241 print "git version too old or $dirlist[0] is a bad argument\n";
245 # Look in each directory.
249 foreach my $dirname (@dirlist) {
250 foreach my $extname (@extlist) {
251 # Go through the directory looking for files ending with
252 # the current extension.
254 opendir($dir_handle, $dirname);
255 my @filelist = grep(/.$extname$/i, readdir($dir_handle));
257 foreach my $file (@filelist) {
258 # Skip if file is in exclude list.
260 if(grep(/^$file$/, @excludelist)) {
264 # Load the file and get the date.
268 # Check if dist version exists and load date from that
271 if(-e ($dirname . $file . ".dist")) {
272 $filedate = getdate(($dirname . $file . ".dist"));
275 $filedate = getdate(($dirname . $file));
278 # Skip if value is empty.
280 if(!$filedate || $filedate eq "") {
284 # Check the man page in the git repository.
286 my $repodata = `LC_TIME=C git log -1 --date="format:%B %d, %Y" \\
287 --since="$filedate" $dirname$file | grep ^Date:`;
289 # If there is output then update the man page
290 # with the new date/version.
292 # Process the file if there is output.
297 if($repodata =~ /^Date: +(.*)/) {
301 print STDERR "Warning: " . ($dirname . $file) . ": found no " .
306 $thisdate = $curldate;
308 processfile(($dirname . $file), $thisdate);
309 print $dirname . $file . " page updated to $thisdate\n";
312 closedir($dir_handle);
320 =head1 updatemanpages.pl
322 Updates the man pages with the version number and optional date. If the date
323 isn't provided, the last modified date from git is used.
327 updatemanpages.pl version [date]
331 Specifies version (required)
335 Specifies date (optional)
341 Specifies the list of directories to look for files in.
345 Specifies the list of files with extensions to process.
349 Specifies the list of files to not process.
353 This script is used during maketgz.