"Fossies" - the Fresh Open Source Software Archive 
Member "xombrero-1.6.4/config-checker.pl" (17 Feb 2015, 6821 Bytes) of package /linux/www/old/xombrero-1.6.4.tgz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "config-checker.pl" see the
Fossies "Dox" file reference documentation.
1 #!/usr/bin/perl -P
2
3 # Copyright (c) 2012 Stevan Andjelkovic <stevan.andjelkovic@strath.ac.uk>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
17
18 use constant SETTINGS => "settings.c";
19 use constant CONFIG => "xombrero.conf";
20 use constant MAIN => "xombrero.c";
21
22 # This is a script that checks if the default setting values of xombrero
23 # (found in SETTINGS) are reflected by the CONFIG. It is meant to help
24 # the developers; the end user need not bother with it.
25
26 # The rule of the game: if a setting has a boolean value (i.e. on or
27 # off), then the config value should be the negation of the default
28 # value, otherwise (i.e. the value is non-boolean) the config value
29 # should be the default value.
30
31 sub follows_the_rule {
32 my ($default_value, $config_value) = @_;
33
34 # Boolean setting.
35 if ($default_value =~ /^(0|1)$/) {
36 if ($default_value != $config_value) {
37 return (1);
38 }
39 # Non-boolean setting.
40 } else {
41 if ($default_value eq $config_value) {
42 return (1);
43 }
44 }
45 return (0);
46 }
47
48 # There are plenty of limitations, for example: struct settings are
49 # ignored, some string settings are initialized in special ways (we only
50 # account for strings initialized in main() using g_strdup.), etc.
51
52 # The following are settings which will not be checked by the script,
53 # because either they are exceptions to the rule or it is hard to check
54 # them in a systematic way. Check them manually.
55 my @unsupported = qw(
56 url_regex
57 http_proxy
58 browser_mode
59 default_script
60 search_string
61
62 cmd_font cmd_font_name
63 oops_font oops_font_name
64 tabbar_font tabbar_font_name
65 statusbar_font statusbar_font_name
66
67 runtime_settings
68 cookie_wl
69 js_wl
70 keybinding
71 mime_type
72 alias
73 );
74
75 # The -P flag invokes the C pre-processor.
76 #define DEBUG (0)
77
78 use strict;
79 #if (DEBUG)
80 use warnings;
81 #endif
82
83 my %settings = ();
84 my %config = ();
85
86
87 # ----------------------------------------------------------------------
88 # Main
89
90
91 # Walk through SETTINGS and collect all settings and their default
92 # values. Note that the default string values cannot be initialized in
93 # SETTINGS.
94 with_file(SETTINGS, \&process_settings, \%settings);
95
96 # We need to go through MAIN to get the default string values.
97 with_file(MAIN, \&process_main, \%settings);
98
99 # Then walk through CONFIG and collect all settings and their config
100 # values.
101 with_file(CONFIG, \&process_config, \%config);
102
103 # Finally check if the collected settings follow the rule.
104 summary();
105
106
107 # ----------------------------------------------------------------------
108 # Helper subroutines
109
110
111 # Higher-order subroutine that takes a file, a subroutine and a hash. It
112 # opens the file and applies the subroutine to each line of the file. The
113 # hash is used for debugging output.
114 sub with_file {
115
116 my ($file, $sub, $hash) = @_;
117
118 open(my $fh, "<", $file)
119 or die "Cannot open $file: $!";
120
121 while (<$fh>) {
122 &$sub($_);
123 }
124
125 close($fh)
126 or warn "Cannot close $file: $!";
127
128 if (DEBUG) {
129 print("$file:\n" . "=" x length($file) . "\n");
130 while (my ($key, $value) = each(%{$hash})) {
131 print "$key => $value\n";
132 }
133 }
134 }
135
136 sub process_settings {
137
138 # Save integer settings.
139 if (/^[g]?int\s+(\w+)\s+=\s(\d+);/) {
140 $settings{$1} = $2;
141 }
142
143 # Save float settings.
144 if (/^[g]?float\s+(\w+)\s+=\s(\d+\.\d+);/) {
145 $settings{$1} = $2;
146 }
147
148 # Save boolean settings.
149 if (/^gboolean\s+(\w+)\s+=\s(\w+);/) {
150 if ($2 eq "TRUE") {
151 $settings{$1} = 1;
152 } elsif ($2 eq "FALSE") {
153 $settings{$1} = 0;
154 } else {
155 die "$1 got non-boolean value $2 in "
156 . SETTINGS;
157 }
158 }
159
160 # Save string setting. Note that the default string cannot be
161 # initialized in SETTINGS, that is why we also process MAIN.
162 if (/^[g]?char\s+\*(\w+)\s+=\s+NULL;/ or
163 /^[g]?char\s+(\w+)\[\w+\];/) {
164 $settings{$1} = "NULL";
165 }
166 }
167
168 my $found_main = 0;
169
170 sub process_main {
171
172 # Find main(), as that is where the strings are initialized.
173 unless ($found_main) {
174 if (/^main\(int argc, char \*argv\[\]\)$/) {
175 $found_main = 1;
176 }
177 return;
178 }
179
180 # Once we found main(), get the string settings.
181 for my $setting (keys %settings) {
182 $setting = quotemeta $setting;
183 if (/^\s+$setting\s+=\s+g_strdup\("(.*)"\);/) {
184 $settings{$setting} = $1;
185 }
186 }
187 }
188
189 sub process_config {
190
191 # Save integer and boolean settings.
192 if (/^#\s+(\w+)\s+=\s+(\d+)$/) {
193 $config{$1} = $2;
194 return;
195 }
196
197 # Save float settings.
198 if (/^#\s+(\w+)\s+=\s+(\d+\.\d+)$/) {
199 $config{$1} = $2;
200 return;
201 }
202
203 # Save string settings.
204 if (/^#\s+(\w+)\s+=\s+(.*)$/) {
205 $config{$1} = $2;
206 }
207 }
208
209 my @breaks_the_rule = ();
210 my @missing_in_config = ();
211 my @missing_in_settings = ();
212
213 sub summary {
214
215 print_with_sep("Summary", "=");
216
217 # Collect settings that are in SETTINGS, but missing in CONFIG
218 # as well as settings that break the rule.
219 while (my ($setting, $default_value) = each(%settings)) {
220
221 my $config_value = $config{$setting};
222
223 if (!defined $config_value) {
224 push(@missing_in_config, $setting);
225 next;
226 }
227
228 if (!follows_the_rule($default_value, $config_value)) {
229 push(@breaks_the_rule, $setting);
230 }
231 }
232
233 # Collect settings that are in CONFIG, but not in SETTINGS.
234 for my $setting (keys %config) {
235 if (!defined $settings{$setting}) {
236 push(@missing_in_settings, $setting);
237 }
238 }
239
240 # Report the settings that break the rule.
241 print_with_sep("Settings that break the rule", "-");
242 for my $setting (@breaks_the_rule) {
243 print SETTINGS . ":\t$setting = $settings{$setting}\n"
244 . CONFIG . ":\t$setting = $config{$setting}\n\n"
245 unless $setting ~~ @unsupported;
246 }
247
248 # Report the settings that are in SETTINGS, but not in CONFIG.
249 print_with_sep("Settings in " . SETTINGS . " that are not in " . CONFIG, "-");
250 map { print "$_ = $settings{$_}\n" unless $_ ~~ @unsupported }
251 @missing_in_config;
252
253 # And vice versa.
254 print_with_sep("Settings in " . CONFIG . " that are not in " . SETTINGS, "-");
255 map { print "$_ = $config{$_}\n" unless $_ ~~ @unsupported }
256 @missing_in_settings;
257
258 print_with_sep("Manually check the following", "-");
259 map { print "$_\n" } @unsupported;
260 }
261
262 sub print_with_sep {
263 my ($line, $sep) = @_;
264
265 print "\n$line\n" . $sep x length($line) . "\n";
266 }