• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env perl
2#***************************************************************************
3#                                  _   _ ____  _
4#  Project                     ___| | | |  _ \| |
5#                             / __| | | | |_) | |
6#                            | (__| |_| |  _ <| |___
7#                             \___|\___/|_| \_\_____|
8#
9# Copyright (C) 2010 - 2020, 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#
25# - Get all options mentioned in the $cmddir.
26# - Make sure they're all mentioned in the $opts document
27# - Make usre that the version in $opts matches the version in the file in
28#   $cmddir
29#
30
31my $opts = $ARGV[0];
32my $cmddir = $ARGV[1];
33
34sub cmdfiles {
35    my ($dir)=@_;
36
37    opendir(my $dh, $dir) || die "Can't opendir $dir: $!";
38    my @opts = grep { /\.d$/ && -f "$dir/$_" } readdir($dh);
39    closedir $dh;
40
41    for(@opts) {
42        $_ =~ s/\.d$//;
43        $file{$_}=1;
44    }
45    return @opts;
46}
47
48sub mentions {
49    my ($f) = @_;
50    my @options;
51    open(F, "<$f");
52    while(<F>) {
53        chomp;
54        if(/(.*) +([0-9.]+)/) {
55            my ($flag, $version)=($1, $2);
56
57            # store the name without the leading dashes
58            $flag =~ s/^--//;
59
60            # cut out short option (if present)
61            $flag =~ s/ \(-.\)//;
62
63            # store the name without trailing space
64            $flag =~ s/ +$//;
65
66            push @options, $flag;
67
68            # options-in-versions says...
69            $oiv{$flag} = $version;
70        }
71    }
72    return @options;
73}
74
75sub versioncheck {
76    my ($f, $v)=@_;
77    open(F, "<$cmddir/$f.d");
78    while(<F>) {
79        chomp;
80        if(/^Added: ([0-9.]+)/) {
81            if($1 ne $v) {
82                print STDERR "$f lists $v in doc but $1 in file\n";
83                $error++;
84            }
85            last;
86        }
87    }
88    close(F);
89}
90
91# get all the files
92my @cmdopts = cmdfiles($cmddir);
93
94# get all the options mentioned in $o
95my @veropts = mentions($opts);
96
97# check if all files are in the doc
98for my $c (sort @cmdopts) {
99    if($oiv{$c}) {
100        # present, but at same version?
101        versioncheck($c, $oiv{$c});
102    }
103    else {
104        print STDERR "--$c is in the option directory but not in $opts!\n";
105        $error++;
106    }
107}
108
109# check if the all options in the doc have files
110for my $v (sort @veropts) {
111    if($file{$v}) {
112        # present
113    }
114    else {
115        print STDERR "$v is in the doc but NOT as a file!\n";
116        $error++;
117    }
118}
119
120print STDERR "ok\n" if(!$error);
121
122exit $error;
123