-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathconfigcheck.pl
116 lines (96 loc) · 3.07 KB
/
configcheck.pl
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/perl
# $Id: configcheck.pl,v 1.2 2024/05/01 14:31:56 cvsuser Exp $
# -*- tabs: 8; indent-width: 4; -*-
# Check config.hin against acdefines.h
#
#
# Copyright (c) 1920 - 2024, Adam Young.
# All rights reserved.
#
# This file is part of the GRIEF Editor.
#
# The GRIEF Editor is free software: you can redistribute it
# and/or modify it under the terms of the GRIEF Editor License.
#
# Redistributions of source code must retain the above copyright
# notice, and must be distributed with the license document above.
#
# Redistributions in binary form must reproduce the above copyright
# notice, and must include the license document above in
# the documentation and/or other materials provided with the
# distribution.
#
# The GRIEF Editor is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# License for more details.
# ==end==
#
use strict;
use warnings;
BEGIN {
my $var = $ENV{"PERLINC"};
if (defined($var) && -d $var) { # import PERLINC
my ($quoted_var) = quotemeta($var);
push (@INC, $var)
if (! grep /^$quoted_var$/, @INC);
}
}
my $root = './';
my $include = './include';
sub check()
{
#################################################################################
my %CONFIG_H = ();
if (! open(ACDEFINES, "${root}/acdefines.h")) {
open(ACDEFINES, "${root}/acdefines.h") or
die "cannot open ${root}/acdefines.h : $!";
}
while (<ACDEFINES>) {
$_ =~ s/\s*(\n|$)//; # kill trailing whitespace & nl
if (/^#define ([A-Z0-9_]+) /) {
$CONFIG_H{$1} = 1;
}
}
close ACDEFINES;
#################################################################################
my $text = '';
if (! open(CONFIG, "${include}/config.hin")) {
open(CONFIG, "${include}/config.hin") or
die "cannot open ${include}/config.hin : $!";
}
while (<CONFIG>) {
$_ =~ s/\s*(\n|$)//; # kill trailing whitespace & nl
$text .= "$_\n";
}
close CONFIG;
#################################################################################
my @MISSING = ();
my @MULTIPLE = ();
foreach my $config (sort keys %CONFIG_H) {
my $value = $CONFIG_H{$config};
if ($text =~ /^([ \t]*#[ \t]*undef[ \t]+${config})([ \t]*|[ \t]+.+)$/m) {
my $count = 0;
while ($text =~ s/^([ \t]*#[ \t]*undef[ \t]+${config})([ \t]*|[ \t]+.+)$/#define ${config} ${value}/m) {
++$count;
}
push @MULTIPLE, $config
if ($count > 1);
} else {
push @MISSING, $config;
}
}
$text =~ s/(#undef[^*\n]+)\n/\/* $1 *\/\n/g;
if (scalar @MISSING) {
foreach my $config (@MISSING) {
print "missing: $config\n";
}
}
if (scalar @MULTIPLE) {
foreach my $config (@MULTIPLE) {
print "multiple: $config\n";
}
}
}
check();
1;