1#!/usr/bin/env perl 2#*************************************************************************** 3# _ _ ____ _ 4# Project ___| | | | _ \| | 5# / __| | | | |_) | | 6# | (__| |_| | _ <| |___ 7# \___|\___/|_| \_\_____| 8# 9# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 10# 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. 14# 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. 18# 19# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 20# KIND, either express or implied. 21# 22# SPDX-License-Identifier: curl 23# 24########################################################################### 25# 26# 27# - Get all options mentioned in the $cmddir. 28# - Make sure they're all mentioned in the $opts document 29# - Make usre that the version in $opts matches the version in the file in 30# $cmddir 31# 32 33my $opts = $ARGV[0]; 34my $cmddir = $ARGV[1]; 35 36sub cmdfiles { 37 my ($dir)=@_; 38 39 opendir(my $dh, $dir) || die "Can't opendir $dir: $!"; 40 my @opts = grep { /\.d$/ && -f "$dir/$_" } readdir($dh); 41 closedir $dh; 42 43 for(@opts) { 44 $_ =~ s/\.d$//; 45 $file{$_}=1; 46 } 47 return @opts; 48} 49 50sub mentions { 51 my ($f) = @_; 52 my @options; 53 open(F, "<$f"); 54 while(<F>) { 55 chomp; 56 if(/(.*) +([0-9.]+)/) { 57 my ($flag, $version)=($1, $2); 58 59 # store the name without the leading dashes 60 $flag =~ s/^--//; 61 62 # cut out short option (if present) 63 $flag =~ s/ \(-.\)//; 64 65 # store the name without trailing space 66 $flag =~ s/ +$//; 67 68 push @options, $flag; 69 70 # options-in-versions says... 71 $oiv{$flag} = $version; 72 } 73 } 74 return @options; 75} 76 77sub versioncheck { 78 my ($f, $v)=@_; 79 open(F, "<$cmddir/$f.d"); 80 while(<F>) { 81 chomp; 82 if(/^Added: ([0-9.]+)/) { 83 if($1 ne $v) { 84 print STDERR "$f lists $v in doc but $1 in file\n"; 85 $error++; 86 } 87 last; 88 } 89 } 90 close(F); 91} 92 93# get all the files 94my @cmdopts = cmdfiles($cmddir); 95 96# get all the options mentioned in $o 97my @veropts = mentions($opts); 98 99# check if all files are in the doc 100for my $c (sort @cmdopts) { 101 if($oiv{$c}) { 102 # present, but at same version? 103 versioncheck($c, $oiv{$c}); 104 } 105 else { 106 print STDERR "--$c is in the option directory but not in $opts!\n"; 107 $error++; 108 } 109} 110 111# check if the all options in the doc have files 112for my $v (sort @veropts) { 113 if($file{$v}) { 114 # present 115 } 116 else { 117 print STDERR "$v is in the doc but NOT as a file!\n"; 118 $error++; 119 } 120} 121 122print STDERR "ok\n" if(!$error); 123 124exit $error; 125