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