2 #***************************************************************************
4 # Project ___| | | | _ \| |
6 # | (__| |_| | _ <| |___
7 # \___|\___/|_| \_\_____|
9 # Copyright (C) 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.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 # SPDX-License-Identifier: curl
24 ###########################################################################
32 # Data from the command line.
34 my $curlver = $ARGV[0];
35 my $curldate = $ARGV[1];
37 # Directories and extensions.
39 my @dirlist = ("docs/", "docs/libcurl/", "docs/libcurl/opts/", "tests/");
40 my @extlist = (".1", ".3");
41 my @excludelist = ("mk-ca-bundle.1", "template.3");
46 # Print arguments and exit.
48 print "usage: updatemanpages.pl <version> <date>\n";
53 # Process file looking for .TH section.
61 open($file_handle, $filename);
63 # Look for the .TH section, process it into an array,
64 # modify it and write to file.
66 tie(my @file_data, 'Tie::File', $filename);
67 foreach my $file_data_line(@file_data) {
68 if($file_data_line =~ /^.TH/) {
69 $file_line = $file_data_line;
81 # Extract .TH section as an array.
85 # Split the line into an array.
88 my $inputsize = length($input);
89 my $inputcurrent = "";
92 for(my $inputseek = 0; $inputseek < $inputsize; $inputseek++) {
94 if(substr($input, $inputseek, 1) eq " " && $quotemode eq 0) {
95 push(@tharray, $inputcurrent);
100 $inputcurrent = $inputcurrent . substr($input, $inputseek, 1);
102 if(substr($input, $inputseek, 1) eq "\"") {
103 if($quotemode eq 0) {
112 if($inputcurrent ne "") {
113 push(@tharray, $inputcurrent);
120 # Get the date from the .TH section.
122 my $filename = shift;
127 $thline = getthline($filename);
129 # Return nothing if there is no .TH section found.
131 if(!$thline || $thline eq "") {
135 @tharray = extractth($thline);
137 # Remove the quotes at the start and end.
139 $date = substr($tharray[3], 1, -1);
144 # Process .TH section.
149 # Split the line into an array.
151 my @tharray = extractth($input);
158 $tharray[3] = $itemdate;
160 # Alter the item version.
162 my $itemver = $tharray[4];
165 for(my $itemnameseek = 1;
166 $itemnameseek < length($itemver);
168 if(substr($itemver, $itemnameseek, 1) eq " " ||
169 substr($itemver, $itemnameseek, 1) eq "\"") {
172 $itemname .= substr($itemver, $itemnameseek, 1);
176 $itemver .= $itemname;
178 $itemver .= $curlver;
181 $tharray[4] = $itemver;
185 foreach my $thvalue (@tharray) {
186 $thoutput .= $thvalue;
189 $thoutput =~ s/\s+$//;
192 # Return updated string.
198 # Process file looking for .TH section.
200 my $filename = shift;
203 my $file_dist_handle;
206 # Open a handle for the original file and a second file handle
209 $filename_dist = $filename . ".dist";
211 open($file_handle, $filename);
212 open($file_dist_handle, ">" . $filename_dist);
214 # Look for the .TH section, process it into an array,
215 # modify it and write to file.
217 tie(my @file_data, 'Tie::File', $filename);
218 foreach my $file_data_line (@file_data) {
219 if($file_data_line =~ /^.TH/) {
220 my $file_dist_line = processth($file_data_line, $date);
221 print $file_dist_handle $file_dist_line . "\n";
224 print $file_dist_handle $file_data_line . "\n";
231 close($file_dist_handle);
234 # Check that $curlver is set, otherwise print arguments and exit.
240 # check to see that the git command works, it requires git 2.6 something
241 my $gitcheck = `git log -1 --date="format:%B %d, %Y" $dirlist[0] 2>/dev/null`;
242 if(length($gitcheck) < 1) {
243 print "git version too old or $dirlist[0] is a bad argument\n";
247 # Look in each directory.
251 foreach my $dirname (@dirlist) {
252 foreach my $extname (@extlist) {
253 # Go through the directory looking for files ending with
254 # the current extension.
256 opendir($dir_handle, $dirname);
257 my @filelist = grep(/.$extname$/i, readdir($dir_handle));
259 foreach my $file (@filelist) {
260 # Skip if file is in exclude list.
262 if(grep(/^$file$/, @excludelist)) {
266 # Load the file and get the date.
270 # Check if dist version exists and load date from that
273 if(-e ($dirname . $file . ".dist")) {
274 $filedate = getdate(($dirname . $file . ".dist"));
277 $filedate = getdate(($dirname . $file));
280 # Skip if value is empty.
282 if(!$filedate || $filedate eq "") {
286 # Check the man page in the git repository.
288 my $repodata = `LC_TIME=C git log -1 --date="format:%B %d, %Y" \\
289 --since="$filedate" $dirname$file | grep ^Date:`;
291 # If there is output then update the man page
292 # with the new date/version.
294 # Process the file if there is output.
299 if($repodata =~ /^Date: +(.*)/) {
303 print STDERR "Warning: " . ($dirname . $file) . ": found no " .
308 $thisdate = $curldate;
310 processfile(($dirname . $file), $thisdate);
311 print $dirname . $file . " page updated to $thisdate\n";
314 closedir($dir_handle);
322 =head1 updatemanpages.pl
324 Updates the man pages with the version number and optional date. If the date
325 isn't provided, the last modified date from git is used.
329 updatemanpages.pl version [date]
333 Specifies version (required)
337 Specifies date (optional)
343 Specifies the list of directories to look for files in.
347 Specifies the list of files with extensions to process.
351 Specifies the list of files to not process.
355 This script is used during maketgz.