]> git.ipfire.org Git - thirdparty/openssl.git/blame - util/ck_errf.pl
Copyright consolidation: perl files
[thirdparty/openssl.git] / util / ck_errf.pl
CommitLineData
e0a65194
RS
1#! /usr/bin/env perl
2# Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
d02b48c6 3#
e0a65194
RS
4# Licensed under the OpenSSL license (the "License"). You may not use
5# this file except in compliance with the License. You can obtain a copy
6# in the file LICENSE in the source distribution or at
7# https://www.openssl.org/source/license.html
8
d02b48c6
RE
9# This is just a quick script to scan for cases where the 'error'
10# function name in a XXXerr() macro is wrong.
11#
12# Run in the top level by going
13# perl util/ck_errf.pl */*.c */*/*.c
14#
15
3ed3603b
DSH
16my $err_strict = 0;
17my $bad = 0;
18
d02b48c6
RE
19foreach $file (@ARGV)
20 {
3ed3603b
DSH
21 if ($file eq "-strict")
22 {
23 $err_strict = 1;
24 next;
25 }
d02b48c6
RE
26 open(IN,"<$file") || die "unable to open $file\n";
27 $func="";
28 while (<IN>)
29 {
0223ca09 30 if (!/;$/ && /^\**([a-zA-Z_].*[\s*])?([A-Za-z_0-9]+)\(.*([),]|$)/)
d02b48c6 31 {
8afca8d9
BM
32 /^([^()]*(\([^()]*\)[^()]*)*)\(/;
33 $1 =~ /([A-Za-z_0-9]*)$/;
34 $func = $1;
d02b48c6
RE
35 $func =~ tr/A-Z/a-z/;
36 }
5c95c2ac 37 if (/([A-Z0-9]+)err\(([^,]+)/ && ! /ckerr_ignore/)
d02b48c6 38 {
d02b48c6
RE
39 $errlib=$1;
40 $n=$2;
8afca8d9
BM
41
42 if ($func eq "")
3ed3603b 43 { print "$file:$.:???:$n\n"; $bad = 1; next; }
8afca8d9 44
d02b48c6
RE
45 if ($n !~ /([^_]+)_F_(.+)$/)
46 {
47 # print "check -$file:$.:$func:$n\n";
48 next;
49 }
50 $lib=$1;
51 $n=$2;
52
53 if ($lib ne $errlib)
3ed3603b 54 { print "$file:$.:$func:$n [${errlib}err]\n"; $bad = 1; next; }
d02b48c6
RE
55
56 $n =~ tr/A-Z/a-z/;
57 if (($n ne $func) && ($errlib ne "SYS"))
3ed3603b 58 { print "$file:$.:$func:$n\n"; $bad = 1; next; }
d02b48c6
RE
59 # print "$func:$1\n";
60 }
61 }
dfeab068 62 close(IN);
d02b48c6
RE
63 }
64
3ed3603b
DSH
65if ($bad && $err_strict)
66 {
67 print STDERR "FATAL: error discrepancy\n";
68 exit 1;
69 }
70