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.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
25use strict;
26use warnings;
27
28# the DISABLE options that can be set by configure
29my %disable;
30# the DISABLE options that are used in C files
31my %file;
32# the DISABLE options that are documented
33my %docs;
34
35# we may get the dir root pointed out
36my $root=$ARGV[0] || ".";
37my $DOCS="CURL-DISABLE.md";
38
39sub scan_configure {
40    open S, "<$root/configure.ac";
41    while(<S>) {
42        if(/(CURL_DISABLE_[A-Z_]+)/g) {
43            my ($sym)=($1);
44            $disable{$sym} = 1;
45        }
46    }
47    close S;
48}
49
50sub scan_file {
51    my ($source)=@_;
52    open F, "<$source";
53    while(<F>) {
54        if(/(CURL_DISABLE_[A-Z_]+)/g) {
55            my ($sym)=($1);
56            $file{$sym} = $source;
57        }
58    }
59    close F;
60}
61
62sub scan_dir {
63    my ($dir)=@_;
64    opendir(my $dh, $dir) || die "Can't opendir $dir: $!";
65    my @cfiles = grep { /\.c\z/ && -f "$dir/$_" } readdir($dh);
66    closedir $dh;
67    for my $f (sort @cfiles) {
68        scan_file("$dir/$f");
69    }
70}
71
72sub scan_sources {
73    scan_dir("$root/src");
74    scan_dir("$root/lib");
75    scan_dir("$root/lib/vtls");
76    scan_dir("$root/lib/vauth");
77}
78
79sub scan_docs {
80    open F, "<$root/docs/$DOCS";
81    my $line = 0;
82    while(<F>) {
83        $line++;
84        if(/^## (CURL_DISABLE_[A-Z_]+)/g) {
85            my ($sym)=($1);
86            $docs{$sym} = $line;
87        }
88    }
89    close F;
90}
91
92scan_configure();
93scan_sources();
94scan_docs();
95
96
97my $error = 0;
98# Check the configure symbols for use in code
99for my $s (sort keys %disable) {
100    if(!$file{$s}) {
101        printf "Present in configure.ac, not used by code: %s\n", $s;
102        $error++;
103    }
104    if(!$docs{$s}) {
105        printf "Present in configure.ac, not documented in $DOCS: %s\n", $s;
106        $error++;
107    }
108}
109
110# Check the code symbols for use in configure
111for my $s (sort keys %file) {
112    if(!$disable{$s}) {
113        printf "Not set by configure: %s (%s)\n", $s, $file{$s};
114        $error++;
115    }
116    if(!$docs{$s}) {
117        printf "Used in code, not documented in $DOCS: %s\n", $s;
118        $error++;
119    }
120}
121
122# Check the documented symbols
123for my $s (sort keys %docs) {
124    if(!$disable{$s}) {
125        printf "Documented but not in configure: %s\n", $s;
126        $error++;
127    }
128    if(!$file{$s}) {
129        printf "Documented, but not used by code: %s\n", $s;
130        $error++;
131    }
132}
133
134exit $error;
135