-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacSystemReportToHtml
executable file
·158 lines (139 loc) · 3.51 KB
/
macSystemReportToHtml
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env perl -w
#
# By Steven J. DeRose; ~~2011??
#
# To do:
#
#
use strict;
use sjdUtils;
use alogging;
my @labels = (
'Version', 'Last Modified', 'Kind', '64-Bit (Intel)',
'App Store', 'Get Info String', 'Location'
);
my $thead = qq@
<thead>
<tr>
<th>App Name</th>
@;
for my $k (@labels) {
$thead .= "<th>$k</th>\n";
}
$thead .= "</tr></thead>";
##############################################################################
##############################################################################
# Main
#
if (scalar(@ARGV)<=1) {
die "No file specified.\n";
}
warn "Starting macSystemReportToHtml for file '$ARGV[1]'.\n";
my $machine = <>;
my $date = <>;
print qq@
<html>
<head>
<title>Macintosh System Report for '$machine'</title>
<style type="text/css">
td.Classic { bgcolor:red; }
td.PowerPW { bgcolor:red; }
td.Intel { bgcolor:green; }
td.Universal { bgcolor:green; }
</style>
</head>
<body>
@;
#$/ = "\r";
#binmode(STDIN, ":utf8");
my $indiv = 0;
my $recnum = 0;
my $nh1 = 0;
my $curSection = "";
my $nErrors = 0;
while (my $rec = <>) {
$recnum++;
(index($rec, "\r")>=0) && die "CR.\n";
chomp $rec;
if ($rec =~ m/^([A-Z][-\/() \w]*):$/) {
if ($curSection eq "Applications") {
print "</tr>\n</table>\n";
}
$curSection = $1;
$nh1++;
if ($indiv) { print "</div>\n\n"; $indiv = 1; }
warn "Line $recnum: Section $nh1: '$curSection'\n";
print "\n<div>\n<h1>Section $nh1: $rec</h1>\n";
if ($curSection eq "Applications") {
print "\n<table border>\n$thead\n";
}
else {
print "<pre>\n";
}
}
elsif ($curSection eq "Applications") {
if ($rec =~ m/^ (\w[-\w ()]+): (.*)/i) { # Field: value
my $label = $1;
moveTo($label);
if ($label eq "Location") {
print "<td class='$label'><a href='local://$2'>$2</a></td>\n";
}
elsif ($label eq "Kind") {
print "<td class='$2'>$2</td>\n";
}
else {
print "<td class='$label'>$2</td>\n";
}
}
elsif ($rec =~ m/^ (.*):$/) { # Next App
print "</tr>\n";
print "\n<tr><td class='app'>App$1</td>\n";
resetLabel();
}
elsif ($rec =~ m/^\s*$/) { # Blank line
}
elsif ($rec =~ # Crt line
m/^\s*(\xc2\xa0)*(Portions )?(\xA9|\xc2\xa9|\(c\)|All Rights|Copyright)/i) {
#print "<span class='copyright'>$rec</span>\n";
}
else {
$nErrors++;
warn "Error #$nErrors at $recnum: $rec\n";
print "<span type='error'>$rec</span>\n";
}
} # Apps
else {
print "$rec\n";
}
}
print qq@
</table>
</body>
</html>
@;
warn "$recnum records, $nh1 major sections, $nErrors errors.\n";
exit;
# Supply any missing fields (like empty version).
#
BEGIN {
my $nextLabelNum = 0;
sub resetLabel {
$nextLabelNum = 0;
}
sub moveTo {
my ($label) = @_;
my $foundAtNum = -1;
for (my $i=$nextLabelNum; $i<scalar(@labels); $i++) {
if ($labels[$i] eq $label) {
$foundAtNum = $i;
last;
}
}
if ($foundAtNum < 0) { warn "Bad Label"; }
else {
while ($nextLabelNum < $foundAtNum) {
print "<td class='" . $labels[$nextLabelNum++] . "'> </td>\n";
}
}
}
} # END