options-scan.pl 3.0 KB

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