forked from cgustave/fgtconfig
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtmlizer.pl
More file actions
executable file
·135 lines (87 loc) · 2.07 KB
/
htmlizer.pl
File metadata and controls
executable file
·135 lines (87 loc) · 2.07 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#! /usr/bin/perl -w
# Author Cedric GUSTAVE
use strict ;
use Getopt::Long ;
use FileHandle ;
use Data::Dumper ;
use vars qw ($debug $file) ;
$| = 1 ; # no buffer
my $fh_in = new FileHandle ;
my $input = 'STDIN' ; # STDIN is the default input
my $line = undef ;
my $line_count = 0 ;
# Control command line options
GetOptions(
"debug" => \$debug,
"file=s" => \$file,
) ;
# Initialisations
$debug = 0 if not(defined($debug)) ;
if (defined($file)) {
$input = 'fh_in' ;
open(fh_in, '<', $file) or die "Cannot open file " . $file . " for reading\n" ;
}
# Main loop
html_head() ;
LINE: while (<$input>) {
$line_count++ ;
$line = $_ ;
print "[" . $line_count . "]" . $line . "\n" if $debug ;
color_features(\$line) ;
color_warnings(\$line) ;
color_vdom(\$line) ;
print $line ;
} # end while loop
html_foot();
close(fh_in) ;
# ---
sub color_features {
my $aref_line = shift ;
# 'no' in green
$$aref_line =~ s/=no/=<span style=\"color:#11AF26\">no<\/span>/g;
# 'YES' in bold red
$$aref_line =~ s/=YES/=<span style=\"color:#FF0000\"><b>YES<\/b><\/span>/g;
}
# ---
sub color_warnings {
my $aref_line = shift ;
my $color_flag = 0 ;
($$aref_line =~ s/warn:([^\|]*)/warn:<span style=\"color:#F2C600\"><b>$1<\/b><\/span>/ ) ;
}
# ---
sub color_vdom {
my $aref_line = shift ;
if ($$aref_line =~ /^\|\svdom:\s\[\s/) {
# This is a root vdom (with [ ]), color in red
$$aref_line =~ s/vdom: \[ (\S*) \]/vdom: <span style=\"color:#FF0000"><b>\[ $1 \]<\/b><\/span>/
}
else {
$$aref_line =~ s/vdom: (\S*)/vdom: <span style=\"color:#0000FF"><b>$1<\/b><\/span>/ ;
}
}
# ---
sub html_head {
print <<EOT;
<html>
<head>
<title>Configuration summary</title>
<style type="text/css">
<!--
body {
display: inline;
font-size: 12px;
font-family: Terminal, "Courier New", Courier, monospace;
white-space: pre;
}
-->
</style></head>
<body>
EOT
}
# ---
sub html_foot {
print <<EOT;
</body>
</html>
EOT
}