options-scan.pl 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 sure that the version in $opts matches the version in the file in
  30. # $cmddir
  31. #
  32. my $opts = $ARGV[0];
  33. my $cmddir = $ARGV[1];
  34. sub cmdfiles {
  35. my ($dir)=@_;
  36. opendir(my $dh, $dir) || die "Can't opendir $dir: $!";
  37. my @opts = grep { /\.d$/ && -f "$dir/$_" } readdir($dh);
  38. closedir $dh;
  39. for(@opts) {
  40. $_ =~ s/\.d$//;
  41. $file{$_}=1;
  42. }
  43. return @opts;
  44. }
  45. sub mentions {
  46. my ($f) = @_;
  47. my @options;
  48. open(my $fh, "<", "$f");
  49. while(<$fh>) {
  50. chomp;
  51. if(/(.*) +([0-9.]+)/) {
  52. my ($flag, $version)=($1, $2);
  53. # store the name without the leading dashes
  54. $flag =~ s/^--//;
  55. # cut out short option (if present)
  56. $flag =~ s/ \(-.\)//;
  57. # store the name without trailing space
  58. $flag =~ s/ +$//;
  59. push @options, $flag;
  60. # options-in-versions says...
  61. $oiv{$flag} = $version;
  62. }
  63. }
  64. close($fh);
  65. return @options;
  66. }
  67. sub versioncheck {
  68. my ($f, $v)=@_;
  69. open(my $fh, "<", "$cmddir/$f.d");
  70. while(<$fh>) {
  71. chomp;
  72. if(/^Added: ([0-9.]+)/) {
  73. if($1 ne $v) {
  74. print STDERR "$f lists $v in doc but $1 in file\n";
  75. $error++;
  76. }
  77. last;
  78. }
  79. }
  80. close($fh);
  81. }
  82. # get all the files
  83. my @cmdopts = cmdfiles($cmddir);
  84. # get all the options mentioned in $o
  85. my @veropts = mentions($opts);
  86. # check if all files are in the doc
  87. for my $c (sort @cmdopts) {
  88. if($oiv{$c}) {
  89. # present, but at same version?
  90. versioncheck($c, $oiv{$c});
  91. }
  92. else {
  93. print STDERR "--$c is in the option directory but not in $opts!\n";
  94. $error++;
  95. }
  96. }
  97. # check if the all options in the doc have files
  98. for my $v (sort @veropts) {
  99. if($file{$v}) {
  100. # present
  101. }
  102. else {
  103. print STDERR "$v is in the doc but NOT as a file!\n";
  104. $error++;
  105. }
  106. }
  107. print STDERR "ok\n" if(!$error);
  108. exit $error;