2
0

options-scan.pl 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #!/usr/bin/env perl
  2. #***************************************************************************
  3. # _ _ ____ _
  4. # Project ___| | | | _ \| |
  5. # / __| | | | |_) | |
  6. # | (__| |_| | _ <| |___
  7. # \___|\___/|_| \_\_____|
  8. #
  9. # Copyright (C) 2010 - 2022, 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. 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(F, "<$f");
  49. while(<F>) {
  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. return @options;
  65. }
  66. sub versioncheck {
  67. my ($f, $v)=@_;
  68. open(F, "<$cmddir/$f.d");
  69. while(<F>) {
  70. chomp;
  71. if(/^Added: ([0-9.]+)/) {
  72. if($1 ne $v) {
  73. print STDERR "$f lists $v in doc but $1 in file\n";
  74. $error++;
  75. }
  76. last;
  77. }
  78. }
  79. close(F);
  80. }
  81. # get all the files
  82. my @cmdopts = cmdfiles($cmddir);
  83. # get all the options mentioned in $o
  84. my @veropts = mentions($opts);
  85. # check if all files are in the doc
  86. for my $c (sort @cmdopts) {
  87. if($oiv{$c}) {
  88. # present, but at same version?
  89. versioncheck($c, $oiv{$c});
  90. }
  91. else {
  92. print STDERR "--$c is in the option directory but not in $opts!\n";
  93. $error++;
  94. }
  95. }
  96. # check if the all options in the doc have files
  97. for my $v (sort @veropts) {
  98. if($file{$v}) {
  99. # present
  100. }
  101. else {
  102. print STDERR "$v is in the doc but NOT as a file!\n";
  103. $error++;
  104. }
  105. }
  106. print STDERR "ok\n" if(!$error);
  107. exit $error;