123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355 |
- use strict;
- use warnings;
- use Tie::File;
- my $curlver = $ARGV[0];
- my $curldate = $ARGV[1];
- my @dirlist = ("docs/", "docs/libcurl/", "docs/libcurl/opts/", "tests/");
- my @extlist = (".1", ".3");
- my @excludelist = ("mk-ca-bundle.1", "template.3");
- sub printargs{
-
- print "usage: updatemanpages.pl <version> <date>\n";
- exit;
- }
- sub getthline{
-
- my $filename = shift;
- my $file_handle;
- my $file_line;
-
- open($file_handle, $filename);
-
-
- tie(my @file_data, 'Tie::File', $filename);
- foreach my $file_data_line(@file_data) {
- if($file_data_line =~ /^.TH/) {
- $file_line = $file_data_line;
- last;
- }
- }
-
- close($file_handle);
- return $file_line;
- }
- sub extractth{
-
- my $input = shift;
-
- my @tharray;
- my $inputsize = length($input);
- my $inputcurrent = "";
- my $quotemode = 0;
- for(my $inputseek = 0; $inputseek < $inputsize; $inputseek++) {
- if(substr($input, $inputseek, 1) eq " " && $quotemode eq 0) {
- push(@tharray, $inputcurrent);
- $inputcurrent = "";
- next;
- }
- $inputcurrent = $inputcurrent . substr($input, $inputseek, 1);
- if(substr($input, $inputseek, 1) eq "\"") {
- if($quotemode eq 0) {
- $quotemode = 1;
- }
- else {
- $quotemode = 0;
- }
- }
- }
- if($inputcurrent ne "") {
- push(@tharray, $inputcurrent);
- }
- return @tharray;
- }
- sub getdate{
-
- my $filename = shift;
- my $thline;
- my @tharray;
- my $date = "";
- $thline = getthline($filename);
-
- if(!$thline || $thline eq "") {
- return "";
- }
- @tharray = extractth($thline);
-
- $date = substr($tharray[3], 1, -1);
- return $date;
- }
- sub processth{
-
- my $input = shift;
- my $date = shift;
-
- my @tharray = extractth($input);
-
- my $itemdate = "\"";
- $itemdate .= $date;
- $itemdate .= "\"";
- $tharray[3] = $itemdate;
-
- my $itemver = $tharray[4];
- my $itemname = "";
- for(my $itemnameseek = 1;
- $itemnameseek < length($itemver);
- $itemnameseek++) {
- if(substr($itemver, $itemnameseek, 1) eq " " ||
- substr($itemver, $itemnameseek, 1) eq "\"") {
- last;
- }
- $itemname .= substr($itemver, $itemnameseek, 1);
- }
- $itemver = "\"";
- $itemver .= $itemname;
- $itemver .= " ";
- $itemver .= $curlver;
- $itemver .= "\"";
- $tharray[4] = $itemver;
- my $thoutput = "";
- foreach my $thvalue (@tharray) {
- $thoutput .= $thvalue;
- $thoutput .= " ";
- }
- $thoutput =~ s/\s+$//;
- $thoutput .= "\n";
-
- return $thoutput;
- }
- sub processfile{
-
- my $filename = shift;
- my $date = shift;
- my $file_handle;
- my $file_dist_handle;
- my $filename_dist;
-
-
- $filename_dist = $filename . ".dist";
- open($file_handle, $filename);
- open($file_dist_handle, ">" . $filename_dist);
-
-
- tie(my @file_data, 'Tie::File', $filename);
- foreach my $file_data_line (@file_data) {
- if($file_data_line =~ /^.TH/) {
- my $file_dist_line = processth($file_data_line, $date);
- print $file_dist_handle $file_dist_line . "\n";
- }
- else {
- print $file_dist_handle $file_data_line . "\n";
- }
- }
-
- close($file_handle);
- close($file_dist_handle);
- }
- if(!$curlver) {
- printargs();
- }
- my $gitcheck = `git log -1 --date="format:%B %d, %Y" $dirlist[0] 2>/dev/null`;
- if(length($gitcheck) < 1) {
- print "git version too old or $dirlist[0] is a bad argument\n";
- exit;
- }
- my $dir_handle;
- foreach my $dirname (@dirlist) {
- foreach my $extname (@extlist) {
-
-
- opendir($dir_handle, $dirname);
- my @filelist = grep(/.$extname$/i, readdir($dir_handle));
- foreach my $file (@filelist) {
-
- if(grep(/^$file$/, @excludelist)) {
- next;
- }
-
- my $filedate;
-
-
- if(-e ($dirname . $file . ".dist")) {
- $filedate = getdate(($dirname . $file . ".dist"));
- }
- else {
- $filedate = getdate(($dirname . $file));
- }
-
- if(!$filedate || $filedate eq "") {
- next;
- }
-
- my $repodata = `LC_TIME=C git log -1 --date="format:%B %d, %Y" \\
- --since="$filedate" $dirname$file | grep ^Date:`;
-
-
-
- if($repodata) {
- my $thisdate;
- if(!$curldate) {
- if($repodata =~ /^Date: +(.*)/) {
- $thisdate = $1;
- }
- else {
- print STDERR "Warning: " . ($dirname . $file) . ": found no " .
- "date\n";
- }
- }
- else {
- $thisdate = $curldate;
- }
- processfile(($dirname . $file), $thisdate);
- print $dirname . $file . " page updated to $thisdate\n";
- }
- }
- closedir($dir_handle);
- }
- }
- __END__
|