2
0

version-check.pl 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. # This script accepts a source file as input on the command line.
  26. #
  27. # It first loads the 'symbols-in-versions' document and stores a lookup
  28. # table for all known symbols for which version they were introduced.
  29. #
  30. # It then scans the given source file to dig up all symbols starting with CURL.
  31. # Finally, it sorts the internal list of found symbols (using the version
  32. # number as sort key) and then it outputs the most recent version number and
  33. # the symbols from that version that are used.
  34. #
  35. # Usage:
  36. #
  37. # version-check.pl [source file]
  38. #
  39. open(S, "<../libcurl/symbols-in-versions") || die;
  40. my %doc;
  41. my %rem;
  42. while(<S>) {
  43. if(/(^CURL[^ \n]*) *(.*)/) {
  44. my ($sym, $rest)=($1, $2);
  45. my @a=split(/ +/, $rest);
  46. $doc{$sym}=$a[0]; # when it was introduced
  47. if($a[2]) {
  48. # this symbol is documented to have been present the last time
  49. # in this release
  50. $rem{$sym}=$a[2];
  51. }
  52. }
  53. }
  54. close(S);
  55. sub age {
  56. my ($ver)=@_;
  57. my @s=split(/\./, $ver);
  58. return $s[0]*10000+$s[1]*100+$s[2];
  59. }
  60. my %used;
  61. open(C, "<$ARGV[0]") || die;
  62. while(<C>) {
  63. if(/\W(CURL[_A-Z0-9v]+)\W/) {
  64. #print "$1\n";
  65. $used{$1}++;
  66. }
  67. }
  68. close(C);
  69. sub sortversions {
  70. my $r = age($doc{$a}) <=> age($doc{$b});
  71. if(!$r) {
  72. $r = $a cmp $b;
  73. }
  74. return $r;
  75. }
  76. my @recent = reverse sort sortversions keys %used;
  77. # the most recent symbol
  78. my $newsym = $recent[0];
  79. # the most recent version
  80. my $newver = $doc{$newsym};
  81. print "The scanned source uses these symbols introduced in $newver:\n";
  82. for my $w (@recent) {
  83. if($doc{$w} eq $newver) {
  84. printf " $w\n";
  85. next;
  86. }
  87. last;
  88. }