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