line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package StanzaFile::Grub ; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# Revision History: |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# 21-Dec-2002 Dick Munroe (munroe@csworks.com) |
7
|
|
|
|
|
|
|
# Add documentation detailing the overridden methods. |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# 17-May-2003 Dick Munroe (munroe@csworks.com) |
10
|
|
|
|
|
|
|
# Fix things so that package variables can't leak and clobber |
11
|
|
|
|
|
|
|
# other packages. |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
# 20-May-2003 Dick Munroe (munroe@csworks.com) |
14
|
|
|
|
|
|
|
# Make the test harness happy. |
15
|
|
|
|
|
|
|
# |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
749
|
use strict ; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
45
|
|
18
|
1
|
|
|
1
|
|
8
|
use vars qw($VERSION @ISA) ; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
55
|
|
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
6
|
use StanzaFile ; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
536
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = "1.02" ; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our @ISA = qw(StanzaFile) ; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub addHeader |
27
|
|
|
|
|
|
|
{ |
28
|
0
|
|
|
0
|
1
|
|
my ($theObject, $theLHS, $theRHS) = @_ ; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
$theObject->{'header'}->add($theLHS, $theRHS) ; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
return $theObject ; |
33
|
|
|
|
|
|
|
} ; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub isBeginning |
36
|
|
|
|
|
|
|
{ |
37
|
0
|
0
|
|
0
|
1
|
|
die "Too few arguments passed to StanzaFile::Grub::isBeginning" if (scalar(@_) < 2) ; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
my ($theObject, $theLine) = @_ ; |
40
|
|
|
|
|
|
|
|
41
|
0
|
0
|
|
|
|
|
if ($theLine =~ m/^title\s+(.*)/i) |
42
|
|
|
|
|
|
|
{ |
43
|
0
|
|
|
|
|
|
my $theName = $1 ; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
$theName =~ s/(.*?)\s+$/$1/ ; |
46
|
0
|
|
|
|
|
|
$theName =~ s/\s{2,}/ /g ; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
return $theName ; |
49
|
|
|
|
|
|
|
} ; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
return undef ; |
52
|
|
|
|
|
|
|
} ; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub isValue |
55
|
|
|
|
|
|
|
{ |
56
|
0
|
|
|
0
|
1
|
|
my ($theObject, $theLine) = @_ ; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# |
59
|
|
|
|
|
|
|
# The grub.conf file format consists of two distinct types of data. |
60
|
|
|
|
|
|
|
# The first is global configuration data and appears before the first |
61
|
|
|
|
|
|
|
# stanza (stanzaFlag in the object will be false when this data is |
62
|
|
|
|
|
|
|
# valid and required. After that, there are image sections containing |
63
|
|
|
|
|
|
|
# menu commands and those have a substantially different format. |
64
|
|
|
|
|
|
|
# |
65
|
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
|
if ($theObject->{'stanzaFlag'}) |
67
|
|
|
|
|
|
|
{ |
68
|
|
|
|
|
|
|
# |
69
|
|
|
|
|
|
|
# If we really wanted to be anal, we could check for all the possible |
70
|
|
|
|
|
|
|
# keywords that could be in grub stanzas. I don't really think there |
71
|
|
|
|
|
|
|
# is any reason to do that. |
72
|
|
|
|
|
|
|
# |
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
if ($theLine =~ m/^\s*(\w+)\s+(.*)/) |
75
|
|
|
|
|
|
|
{ |
76
|
0
|
|
|
|
|
|
return ($1, $2) |
77
|
|
|
|
|
|
|
} ; |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
return undef ; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
else |
82
|
|
|
|
|
|
|
{ |
83
|
0
|
|
|
|
|
|
return $theObject->SUPER::isValue($theLine) ; |
84
|
|
|
|
|
|
|
} ; |
85
|
|
|
|
|
|
|
} ; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub headerAsString |
88
|
|
|
|
|
|
|
{ |
89
|
0
|
|
|
0
|
1
|
|
my $theObject = shift ; |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
my $theString = $theObject->SUPER::stanzaAsString($theObject->header()) ; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
$theString =~ s/.*?\n// ; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
return $theString ; |
96
|
|
|
|
|
|
|
} ; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub stanzaAsString |
99
|
|
|
|
|
|
|
{ |
100
|
0
|
|
|
0
|
1
|
|
my ($theObject, $theStanza) = @_ ; |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
my $theString = "title\t" . $theStanza->name() . "\n" ; |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
my $theLength ; |
105
|
|
|
|
|
|
|
|
106
|
0
|
0
|
|
|
|
|
map { $theLength = length($_) if (length($_) > $theLength) ; } $theStanza->order() ; |
|
0
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
$theLength++ ; |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
$theLength = "%-" . $theLength . "s" ; |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
foreach ($theStanza->order()) |
113
|
|
|
|
|
|
|
{ |
114
|
0
|
|
|
|
|
|
$theString = $theString . "\t" . sprintf($theLength,$_) . $theStanza->item($_) . "\n" ; |
115
|
|
|
|
|
|
|
} ; |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
return $theString ; |
118
|
|
|
|
|
|
|
} ; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=pod |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 NAME |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
StanzaFile::Grub - read, parse, and write Grand Unified Bootloader configuration |
127
|
|
|
|
|
|
|
files. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 SYNOPSIS |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
There are no interface changes between this and the parent |
132
|
|
|
|
|
|
|
class, StanzaFile. This is included, partly, as an example |
133
|
|
|
|
|
|
|
of the ease with which additional different stanza file |
134
|
|
|
|
|
|
|
formats can be supported using the StanzaFile class and, |
135
|
|
|
|
|
|
|
mostly, because I used the StanzaFile::Grub class in a kernel |
136
|
|
|
|
|
|
|
build and installation management package I wrote (check it |
137
|
|
|
|
|
|
|
out, kif at sourceforge.net). |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 DESCRIPTION |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
The grub configuration file format differs in a couple of ways |
142
|
|
|
|
|
|
|
from the WINDOWS.INI format. It has a "global" section that |
143
|
|
|
|
|
|
|
appears before any of the stanzas actually start. This global |
144
|
|
|
|
|
|
|
section is stored in a dummy stanza accessable via the header |
145
|
|
|
|
|
|
|
method defined in StanzaFile. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
The format of entries in the global section also differs from |
148
|
|
|
|
|
|
|
entries in the stanzas. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
All this is dealt with by overriding 5 methods. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=over 4 |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=item $theObject->addHeader($leftHandSide, $rightHandSide) |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
addHeader puts a new global header item into the Grub StanzaFile |
157
|
|
|
|
|
|
|
object. The value of the new header item is the value of the |
158
|
|
|
|
|
|
|
$rightHandSide variable and is optional for those header items |
159
|
|
|
|
|
|
|
without values. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=item $theObject->headerAsString() |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Produce a string suitable for printing that represents the contents |
164
|
|
|
|
|
|
|
of the header portion of the Grub stanza file object. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=item $theObject->isBeginning($line) |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
A predicate which tests the line to see if it is the beginning of |
169
|
|
|
|
|
|
|
a new stanza. If it is, the value of the predicate is the name of |
170
|
|
|
|
|
|
|
the new stanza. Otherwise the value of the predicate is undefined. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=item $theObject->isValue($line) |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
A predicate which tests the line to see if it contains a name/value |
175
|
|
|
|
|
|
|
pair and returns that pair as the value of the prediate. Otherwise |
176
|
|
|
|
|
|
|
it returns and undefined. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=item $theObject->stanzaAsString() |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Produce a string suitable for printing that represents a Grub file |
181
|
|
|
|
|
|
|
stanza other than the header. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=back |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 EXAMPLES |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head1 BUGS |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
None known. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 WARNINGS |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
No comments or whitespace are preserved in the configuration file |
194
|
|
|
|
|
|
|
when it is read and/or written. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head1 AUTHOR |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Dick Munroe (munroe@csworks). I'm looking for work. If you hear |
199
|
|
|
|
|
|
|
of anything that might be of interest to a VERY senior engineer/architect |
200
|
|
|
|
|
|
|
drop me a note. See |
201
|
|
|
|
|
|
|
L for details. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head1 SEE ALSO |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
The Kernel Installation Facility uses these classes extensively. For more |
206
|
|
|
|
|
|
|
details see L |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=cut |
209
|
|
|
|
|
|
|
|