113498266Sopenharmony_ci#!/usr/bin/env perl
213498266Sopenharmony_ci#***************************************************************************
313498266Sopenharmony_ci#                                  _   _ ____  _
413498266Sopenharmony_ci#  Project                     ___| | | |  _ \| |
513498266Sopenharmony_ci#                             / __| | | | |_) | |
613498266Sopenharmony_ci#                            | (__| |_| |  _ <| |___
713498266Sopenharmony_ci#                             \___|\___/|_| \_\_____|
813498266Sopenharmony_ci#
913498266Sopenharmony_ci# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
1013498266Sopenharmony_ci#
1113498266Sopenharmony_ci# This software is licensed as described in the file COPYING, which
1213498266Sopenharmony_ci# you should have received as part of this distribution. The terms
1313498266Sopenharmony_ci# are also available at https://curl.se/docs/copyright.html.
1413498266Sopenharmony_ci#
1513498266Sopenharmony_ci# You may opt to use, copy, modify, merge, publish, distribute and/or sell
1613498266Sopenharmony_ci# copies of the Software, and permit persons to whom the Software is
1713498266Sopenharmony_ci# furnished to do so, under the terms of the COPYING file.
1813498266Sopenharmony_ci#
1913498266Sopenharmony_ci# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
2013498266Sopenharmony_ci# KIND, either express or implied.
2113498266Sopenharmony_ci#
2213498266Sopenharmony_ci# SPDX-License-Identifier: curl
2313498266Sopenharmony_ci#
2413498266Sopenharmony_ci###########################################################################
2513498266Sopenharmony_ci
2613498266Sopenharmony_ci# This script accepts a source file as input on the command line.
2713498266Sopenharmony_ci#
2813498266Sopenharmony_ci# It first loads the 'symbols-in-versions' document and stores a lookup
2913498266Sopenharmony_ci# table for all known symbols for which version they were introduced.
3013498266Sopenharmony_ci#
3113498266Sopenharmony_ci# It then scans the given source file to dig up all symbols starting with CURL.
3213498266Sopenharmony_ci# Finally, it sorts the internal list of found symbols (using the version
3313498266Sopenharmony_ci# number as sort key) and then it outputs the most recent version number and
3413498266Sopenharmony_ci# the symbols from that version that are used.
3513498266Sopenharmony_ci#
3613498266Sopenharmony_ci# Usage:
3713498266Sopenharmony_ci#
3813498266Sopenharmony_ci#    version-check.pl [source file]
3913498266Sopenharmony_ci#
4013498266Sopenharmony_ci
4113498266Sopenharmony_ciopen(S, "<../libcurl/symbols-in-versions") || die;
4213498266Sopenharmony_ci
4313498266Sopenharmony_cimy %doc;
4413498266Sopenharmony_cimy %rem;
4513498266Sopenharmony_ciwhile(<S>) {
4613498266Sopenharmony_ci    if(/(^CURL[^ \n]*) *(.*)/) {
4713498266Sopenharmony_ci        my ($sym, $rest)=($1, $2);
4813498266Sopenharmony_ci        my @a=split(/ +/, $rest);
4913498266Sopenharmony_ci
5013498266Sopenharmony_ci        $doc{$sym}=$a[0]; # when it was introduced
5113498266Sopenharmony_ci
5213498266Sopenharmony_ci        if($a[2]) {
5313498266Sopenharmony_ci            # this symbol is documented to have been present the last time
5413498266Sopenharmony_ci            # in this release
5513498266Sopenharmony_ci            $rem{$sym}=$a[2];
5613498266Sopenharmony_ci        }
5713498266Sopenharmony_ci    }
5813498266Sopenharmony_ci
5913498266Sopenharmony_ci}
6013498266Sopenharmony_ci
6113498266Sopenharmony_ciclose(S);
6213498266Sopenharmony_ci
6313498266Sopenharmony_cisub age {
6413498266Sopenharmony_ci    my ($ver)=@_;
6513498266Sopenharmony_ci
6613498266Sopenharmony_ci    my @s=split(/\./, $ver);
6713498266Sopenharmony_ci    return $s[0]*10000+$s[1]*100+$s[2];
6813498266Sopenharmony_ci}
6913498266Sopenharmony_ci
7013498266Sopenharmony_cimy %used;
7113498266Sopenharmony_ciopen(C, "<$ARGV[0]") || die;
7213498266Sopenharmony_ci
7313498266Sopenharmony_ciwhile(<C>) {
7413498266Sopenharmony_ci    if(/\W(CURL[_A-Z0-9v]+)\W/) {
7513498266Sopenharmony_ci        #print "$1\n";
7613498266Sopenharmony_ci        $used{$1}++;
7713498266Sopenharmony_ci    }
7813498266Sopenharmony_ci}
7913498266Sopenharmony_ci
8013498266Sopenharmony_ciclose(C);
8113498266Sopenharmony_ci
8213498266Sopenharmony_cisub sortversions {
8313498266Sopenharmony_ci    my $r = age($doc{$a}) <=> age($doc{$b});
8413498266Sopenharmony_ci    if(!$r) {
8513498266Sopenharmony_ci        $r = $a cmp $b;
8613498266Sopenharmony_ci    }
8713498266Sopenharmony_ci    return $r;
8813498266Sopenharmony_ci}
8913498266Sopenharmony_ci
9013498266Sopenharmony_cimy @recent = reverse sort sortversions keys %used;
9113498266Sopenharmony_ci
9213498266Sopenharmony_ci# the most recent symbol
9313498266Sopenharmony_cimy $newsym = $recent[0];
9413498266Sopenharmony_ci# the most recent version
9513498266Sopenharmony_cimy $newver = $doc{$newsym};
9613498266Sopenharmony_ci
9713498266Sopenharmony_ciprint "The scanned source uses these symbols introduced in $newver:\n";
9813498266Sopenharmony_ci
9913498266Sopenharmony_cifor my $w (@recent) {
10013498266Sopenharmony_ci    if($doc{$w} eq $newver) {
10113498266Sopenharmony_ci        printf "  $w\n";
10213498266Sopenharmony_ci        next;
10313498266Sopenharmony_ci    }
10413498266Sopenharmony_ci    last;
10513498266Sopenharmony_ci}
106