forked from qpdf/qpdf
-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_assert
executable file
·62 lines (59 loc) · 1.41 KB
/
check_assert
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env perl
require 5.008;
use warnings;
use strict;
use File::Basename;
my $whoami = basename($0);
chdir(dirname($0)) or die;
my $errors = 0;
foreach my $file (glob('*/*.c'), glob('*/*.cc'),
glob('*/*/*.h'), glob('*/*/*.hh'))
{
my $assert_test = 0;
if ($file =~ m,^libqpdf/qpdf/assert_,)
{
next;
}
open(F, "<$file") or die;
my $first_include = undef;
while (<F>)
{
if (m,^\s*#\s*include <qpdf/assert_(.*?).h>,)
{
if ($1 eq 'test')
{
$assert_test = 1;
}
if (defined $first_include)
{
error("$file:$.: qpdf/assert header must be first");
}
}
if (m,^\s*#\s*include <(.*?)>,)
{
my $header = $1;
if (($header eq 'cassert') || ($header eq 'assert.h'))
{
error("$file:$.: assert.h and cassert are not allowed --" .
" use one of the qpdf/assert_ files instead");
}
$first_include = 1;
}
if ((! $assert_test) && (m/assert\(/))
{
error("$file:$.: call qpdf_assert_debug instead of assert");
}
}
close(F);
}
if ($errors)
{
die "$whoami: errors detected\n";
}
print "$whoami: no incorrect use of assert found\n";
sub error
{
my $msg = shift;
warn $msg, "\n";
$errors = 1;
}