version-check.pl 2.6 KB

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