xref: /curl/tests/test1477.pl (revision eefcc1bd)
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# Check that libcurl-errors.3 and the public header files have the same set of
27# error codes.
28
29use strict;
30use warnings;
31
32# we may get the dir roots pointed out
33my $root=$ARGV[0] || ".";
34my $buildroot=$ARGV[1] || ".";
35my $manpge = "$buildroot/docs/libcurl/libcurl-errors.3";
36my $curlh = "$root/include/curl";
37my $errors=0;
38
39my @hnames;
40my %wherefrom;
41my @mnames;
42my %manfrom;
43
44sub scanheader {
45    my ($file)=@_;
46    open H, "<$file";
47    my $line = 0;
48    while(<H>) {
49        $line++;
50        if($_ =~ /^  (CURL(E|UE|SHE|HE|M)_[A-Z0-9_]*)/) {
51            my ($name)=($1);
52            if(($name !~ /OBSOLETE/) && ($name !~ /_LAST\z/)) {
53                push @hnames, $name;
54                if($wherefrom{$name}) {
55                    print STDERR "double: $name\n";
56                }
57                $wherefrom{$name}="$file:$line";
58            }
59        }
60    }
61    close(H);
62}
63
64sub scanmanpage {
65    my ($file)=@_;
66    open H, "<$file";
67    my $line = 0;
68    while(<H>) {
69        $line++;
70        if($_ =~ /^\.IP \"(CURL(E|UE|SHE|HE|M)_[A-Z0-9_]*)/) {
71            my ($name)=($1);
72            push @mnames, $name;
73            $manfrom{$name}="$file:$line";
74        }
75    }
76    close(H);
77}
78
79
80opendir(my $dh, $curlh) || die "Can't opendir $curlh: $!";
81my @hfiles = grep { /\.h$/ } readdir($dh);
82closedir $dh;
83
84for(sort @hfiles) {
85    scanheader("$curlh/$_");
86}
87scanmanpage($manpge);
88
89print "Result\n";
90for my $h (sort @hnames) {
91    if(!$manfrom{$h}) {
92        printf "$h from %s, not in man page\n", $wherefrom{$h};
93    }
94}
95
96for my $m (sort @mnames) {
97    if(!$wherefrom{$m}) {
98        printf "$m from %s, not in any header\n", $manfrom{$m};
99    }
100}
101