line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package LW4::Reader; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
27841
|
use 5.008001; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
51
|
|
5
|
|
|
|
|
|
|
#use strict; |
6
|
|
|
|
|
|
|
#use warnings; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require Exporter; |
9
|
1
|
|
|
1
|
|
1151
|
use AutoLoader qw(AUTOLOAD); |
|
1
|
|
|
|
|
6277
|
|
|
1
|
|
|
|
|
8
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw( read_header read_item_info build_category_phrases ); |
13
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub read_header { |
16
|
|
|
|
|
|
|
# Read the show info information of the file. |
17
|
|
|
|
|
|
|
# |
18
|
|
|
|
|
|
|
# Passed: The file handle of the Lightwright file to read from. |
19
|
|
|
|
|
|
|
# Returns: Hashref of header info. |
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
1
|
59
|
my $lw4_file_fh = shift; |
22
|
1
|
|
|
|
|
3
|
my $header_ref = { }; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Get file header info. This includes: * The file identifier * The |
25
|
|
|
|
|
|
|
# date/time last saved, and the user saved by. * The show info |
26
|
|
|
|
|
|
|
# (title of the document). This data should always predictably be |
27
|
|
|
|
|
|
|
# found at the top of the file so there isn't a need to go seeking |
28
|
|
|
|
|
|
|
# for it. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# There are some things in this format that I haven't |
31
|
|
|
|
|
|
|
# figured out yet. For now read them in to a discardable |
32
|
|
|
|
|
|
|
# variable and carry on. We'll come back and fill in the |
33
|
|
|
|
|
|
|
# blanks when I have a better understanding of some of |
34
|
|
|
|
|
|
|
# these specifics. |
35
|
|
|
|
|
|
|
|
36
|
1
|
|
|
|
|
57
|
my $junk = <$lw4_file_fh>; |
37
|
1
|
|
|
|
|
3
|
$junk = <$lw4_file_fh>; |
38
|
1
|
|
|
|
|
3
|
$junk = <$lw4_file_fh>; |
39
|
1
|
|
|
|
|
4
|
$header_ref->{file_ident} = <$lw4_file_fh>; |
40
|
1
|
|
|
|
|
2
|
$junk = <$lw4_file_fh>; |
41
|
1
|
|
|
|
|
1
|
$junk = <$lw4_file_fh>; |
42
|
1
|
|
|
|
|
3
|
$junk = <$lw4_file_fh>; |
43
|
1
|
|
|
|
|
2
|
$header_ref->{show_name} = <$lw4_file_fh>; |
44
|
1
|
|
|
|
|
3
|
$header_ref->{sub_head_1} = <$lw4_file_fh>; |
45
|
1
|
|
|
|
|
3
|
$header_ref->{sub_head_2} = <$lw4_file_fh>; |
46
|
1
|
|
|
|
|
2
|
$header_ref->{sub_head_3} = <$lw4_file_fh>; |
47
|
1
|
|
|
|
|
3
|
$header_ref->{sub_head_4} = <$lw4_file_fh>; |
48
|
1
|
|
|
|
|
3
|
$header_ref->{sub_head_5} = <$lw4_file_fh>; |
49
|
1
|
|
|
|
|
2
|
$header_ref->{sub_head_6} = <$lw4_file_fh>; |
50
|
1
|
|
|
|
|
2
|
$junk = <$lw4_file_fh>; |
51
|
1
|
|
|
|
|
2
|
$junk = <$lw4_file_fh>; |
52
|
1
|
|
|
|
|
2
|
$junk = <$lw4_file_fh>; |
53
|
1
|
|
|
|
|
2
|
$junk = <$lw4_file_fh>; |
54
|
1
|
|
|
|
|
3
|
$junk = <$lw4_file_fh>; |
55
|
1
|
|
|
|
|
2
|
$header_ref->{num_fixtures} = <$lw4_file_fh>; |
56
|
1
|
|
|
|
|
2
|
$header_ref->{save_date} = <$lw4_file_fh>; |
57
|
1
|
|
|
|
|
3
|
$junk = <$lw4_file_fh>; |
58
|
1
|
|
|
|
|
1
|
$header_ref->{save_time} = <$lw4_file_fh>; |
59
|
1
|
|
|
|
|
2
|
$junk = <$lw4_file_fh>; |
60
|
1
|
|
|
|
|
1
|
$header_ref->{max_num_fixtures} = <$lw4_file_fh>; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Some entries have preceding white space that we'll want to |
63
|
|
|
|
|
|
|
# strip. |
64
|
|
|
|
|
|
|
|
65
|
1
|
|
|
|
|
7
|
foreach my $key (keys %$header_ref) { |
66
|
12
|
|
|
|
|
30
|
$header_ref->{$key} =~ s/^\s+//gxms; |
67
|
12
|
|
|
|
|
57
|
$header_ref->{$key} =~ s/\s+$//gxms; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
1
|
|
|
|
|
5
|
return $header_ref; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub read_item_info { |
74
|
|
|
|
|
|
|
# Read the data portions of the file. |
75
|
|
|
|
|
|
|
# |
76
|
|
|
|
|
|
|
# Passed: the file handle of the LW4 file. |
77
|
|
|
|
|
|
|
# Returns: Array of hashes of item information extracted from |
78
|
|
|
|
|
|
|
# the file. |
79
|
|
|
|
|
|
|
|
80
|
1
|
|
|
1
|
1
|
3886
|
my $lw4_file_fh = shift; |
81
|
1
|
|
|
|
|
3
|
my @lw4_item_info_AoH; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# * Build the "vocabulary" the file uses to describe |
84
|
|
|
|
|
|
|
# it's data. |
85
|
1
|
|
|
|
|
4
|
my $phrase_table_AoA = build_category_phrases($lw4_file_fh); |
86
|
|
|
|
|
|
|
|
87
|
1
|
|
|
|
|
4
|
my $current_count = 0; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# ** Seek to the line that contains '** Item Info:' |
90
|
1
|
|
|
|
|
5
|
LINE: while (<$lw4_file_fh>) { |
91
|
2071
|
|
|
|
|
2066
|
my $lw4_file_line = $_; |
92
|
2071
|
|
|
|
|
1720
|
chomp $lw4_file_line; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# Read lines from the file until we find Item info, then create |
95
|
|
|
|
|
|
|
# an AoH of each item, substituting the references in the file |
96
|
|
|
|
|
|
|
# for the names we have compiled in the phrase table. |
97
|
|
|
|
|
|
|
|
98
|
2071
|
100
|
|
|
|
4991
|
if ($lw4_file_line =~ m/^\*\* Item Info:/) { |
99
|
|
|
|
|
|
|
# There are two things at the top of the Item Info section, |
100
|
|
|
|
|
|
|
# and I don't know what they are yet. We'll probably be able |
101
|
|
|
|
|
|
|
# to use them for something once I figure out what they are, |
102
|
|
|
|
|
|
|
# but for now just store them. |
103
|
1
|
|
|
|
|
4
|
my $final_rec = 0; |
104
|
1
|
|
|
|
|
52
|
my $item_count = <$lw4_file_fh>; |
105
|
1
|
|
|
|
|
3
|
chomp $item_count; |
106
|
1
|
|
|
|
|
4
|
$item_count =~ s/^\s//; |
107
|
1
|
|
|
|
|
5
|
$item_count =~ s/\s+$//g; |
108
|
|
|
|
|
|
|
|
109
|
1
|
|
|
|
|
2
|
my $mystery_item_head_two = <$lw4_file_fh>; |
110
|
1
|
|
|
|
|
1
|
my $head_seperator = <$lw4_file_fh>; |
111
|
|
|
|
|
|
|
|
112
|
1
|
|
|
|
|
535
|
ITEM: while ($current_count <= $item_count) { |
113
|
23
|
|
|
|
|
34
|
$lw4_file_line = <$lw4_file_fh>; |
114
|
23
|
|
|
|
|
24
|
chomp $lw4_file_line; |
115
|
|
|
|
|
|
|
|
116
|
23
|
|
|
|
|
20
|
my %lw4_item; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# Build the item hash table, one lines at a time. There are |
119
|
|
|
|
|
|
|
# still a lot of uknowns in this file, but we should be able |
120
|
|
|
|
|
|
|
# to figure them out at some point in the future. |
121
|
|
|
|
|
|
|
# |
122
|
|
|
|
|
|
|
# Rather than doing phrase table substitutions in place, |
123
|
|
|
|
|
|
|
# we'll batch clean out the newlines and leading whitespace |
124
|
|
|
|
|
|
|
# after the fact, and then make the substitutions for the |
125
|
|
|
|
|
|
|
# appropriate records. |
126
|
|
|
|
|
|
|
|
127
|
23
|
|
|
|
|
43
|
$lw4_item{unknown1} = $lw4_file_line; |
128
|
23
|
|
|
|
|
42
|
$lw4_item{channel} = <$lw4_file_fh>; |
129
|
23
|
|
|
|
|
33
|
$lw4_item{dimmer} = <$lw4_file_fh>; |
130
|
23
|
|
|
|
|
31
|
$lw4_item{unit} = <$lw4_file_fh>; |
131
|
23
|
|
|
|
|
26
|
$lw4_item{watts} = <$lw4_file_fh>; |
132
|
23
|
|
|
|
|
41
|
$lw4_item{circuit} = <$lw4_file_fh>; |
133
|
23
|
|
|
|
|
27
|
$lw4_item{unknown2} = <$lw4_file_fh>; |
134
|
23
|
|
|
|
|
42
|
$lw4_item{unknown3} = <$lw4_file_fh>; |
135
|
23
|
|
|
|
|
31
|
$lw4_item{unknown4} = <$lw4_file_fh>; |
136
|
23
|
|
|
|
|
26
|
$lw4_item{unknown5} = <$lw4_file_fh>; |
137
|
23
|
|
|
|
|
26
|
$lw4_item{unknown6} = <$lw4_file_fh>; |
138
|
23
|
|
|
|
|
32
|
$lw4_item{unknown7} = <$lw4_file_fh>; |
139
|
23
|
|
|
|
|
27
|
$lw4_item{unknown8} = <$lw4_file_fh>; |
140
|
23
|
|
|
|
|
27
|
$lw4_item{purpose} = <$lw4_file_fh>; # lookup needed |
141
|
23
|
|
|
|
|
25
|
$lw4_item{position} = <$lw4_file_fh>; # lookup needed |
142
|
23
|
|
|
|
|
40
|
$lw4_item{color} = <$lw4_file_fh>; # lookup needed |
143
|
23
|
|
|
|
|
70
|
$lw4_item{accessory} = <$lw4_file_fh>; # lookup needed |
144
|
23
|
|
|
|
|
26
|
$lw4_item{type} = <$lw4_file_fh>; # lookup needed |
145
|
23
|
|
|
|
|
27
|
$lw4_item{pattern} = <$lw4_file_fh>; # lookup needed |
146
|
23
|
|
|
|
|
33
|
$lw4_item{unknown10} = <$lw4_file_fh>; |
147
|
23
|
|
|
|
|
24
|
$lw4_item{unknown11} = <$lw4_file_fh>; |
148
|
23
|
|
|
|
|
29
|
$lw4_item{unknown12} = <$lw4_file_fh>; |
149
|
23
|
|
|
|
|
28
|
$lw4_item{unknown13} = <$lw4_file_fh>; |
150
|
23
|
|
|
|
|
40
|
$lw4_item{unknown14} = <$lw4_file_fh>; |
151
|
23
|
|
|
|
|
29
|
$lw4_item{unknown15} = <$lw4_file_fh>; |
152
|
23
|
|
|
|
|
25
|
$lw4_item{unknown16} = <$lw4_file_fh>; |
153
|
23
|
|
|
|
|
26
|
$lw4_item{unknown17} = <$lw4_file_fh>; |
154
|
23
|
|
|
|
|
25
|
$lw4_item{unknown18} = <$lw4_file_fh>; |
155
|
23
|
|
|
|
|
27
|
$lw4_item{unknown19} = <$lw4_file_fh>; |
156
|
23
|
|
|
|
|
25
|
$lw4_item{unknown20} = <$lw4_file_fh>; |
157
|
23
|
|
|
|
|
27
|
$lw4_item{unknown21} = <$lw4_file_fh>; |
158
|
23
|
|
|
|
|
54
|
$lw4_item{unknown22} = <$lw4_file_fh>; |
159
|
23
|
|
|
|
|
29
|
$lw4_item{unknown23} = <$lw4_file_fh>; |
160
|
23
|
|
|
|
|
34
|
$lw4_item{unknown24} = <$lw4_file_fh>; |
161
|
23
|
|
|
|
|
32
|
$lw4_item{unknown25} = <$lw4_file_fh>; |
162
|
23
|
|
|
|
|
25
|
$lw4_item{unknown26} = <$lw4_file_fh>; |
163
|
23
|
|
|
|
|
28
|
$lw4_item{unknown27} = <$lw4_file_fh>; |
164
|
23
|
|
|
|
|
30
|
$lw4_item{unknown28} = <$lw4_file_fh>; |
165
|
23
|
|
|
|
|
26
|
$lw4_item{item_key} = <$lw4_file_fh>; |
166
|
23
|
|
|
|
|
26
|
$lw4_item{unknown30} = <$lw4_file_fh>; |
167
|
23
|
|
|
|
|
26
|
$lw4_item{unknown31} = <$lw4_file_fh>; |
168
|
23
|
|
|
|
|
32
|
$lw4_item{unknown32} = <$lw4_file_fh>; |
169
|
23
|
|
|
|
|
30
|
$lw4_item{unknown33} = <$lw4_file_fh>; |
170
|
23
|
|
|
|
|
29
|
$lw4_item{unknown34} = <$lw4_file_fh>; |
171
|
23
|
|
|
|
|
27
|
$lw4_item{unknown35} = <$lw4_file_fh>; |
172
|
23
|
|
|
|
|
25
|
$lw4_item{unknown36} = <$lw4_file_fh>; |
173
|
23
|
|
|
|
|
23
|
my $seperator = <$lw4_file_fh>; |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
# This should be the end of the item record. |
176
|
|
|
|
|
|
|
# Eliminate leading whitespace and newlines. |
177
|
|
|
|
|
|
|
|
178
|
23
|
|
|
|
|
179
|
foreach my $key (keys %lw4_item) { |
179
|
1058
|
|
|
|
|
1110
|
chomp $lw4_item{$key}; |
180
|
1058
|
|
|
|
|
1722
|
$lw4_item{$key} =~ s/^\s//; |
181
|
1058
|
|
|
|
|
2119
|
$lw4_item{$key} =~ s/\s+$//g; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
# Now perform the substitutions for the items in |
185
|
|
|
|
|
|
|
# the phrase table. |
186
|
|
|
|
|
|
|
|
187
|
23
|
|
|
|
|
74
|
my $temp_buff = $lw4_item{purpose}; |
188
|
23
|
|
|
|
|
44
|
$lw4_item{purpose} = $phrase_table_AoA->[1]->[$temp_buff]; |
189
|
|
|
|
|
|
|
|
190
|
23
|
|
|
|
|
23
|
$temp_buff = $lw4_item{position}; |
191
|
23
|
|
|
|
|
32
|
$lw4_item{position} = $phrase_table_AoA->[2]->[$temp_buff]; |
192
|
|
|
|
|
|
|
|
193
|
23
|
|
|
|
|
24
|
$temp_buff = $lw4_item{type}; |
194
|
23
|
|
|
|
|
35
|
$lw4_item{type} = $phrase_table_AoA->[3]->[$temp_buff]; |
195
|
|
|
|
|
|
|
|
196
|
23
|
|
|
|
|
24
|
$temp_buff = $lw4_item{accessory}; |
197
|
23
|
|
|
|
|
24
|
$lw4_item{accessory} = $phrase_table_AoA->[4]->[$temp_buff]; |
198
|
|
|
|
|
|
|
|
199
|
23
|
|
|
|
|
25
|
$temp_buff = $lw4_item{color}; |
200
|
23
|
|
|
|
|
26
|
$lw4_item{color} = $phrase_table_AoA->[5]->[$temp_buff]; |
201
|
|
|
|
|
|
|
|
202
|
23
|
|
|
|
|
23
|
$temp_buff = $lw4_item{pattern}; |
203
|
23
|
|
|
|
|
31
|
$lw4_item{pattern} = $phrase_table_AoA->[6]->[$temp_buff]; |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
# Now that substitutions are completed, add a ref to the hash |
206
|
|
|
|
|
|
|
# to the AoH. |
207
|
|
|
|
|
|
|
|
208
|
23
|
|
|
|
|
51
|
push @lw4_item_info_AoH, \%lw4_item; |
209
|
|
|
|
|
|
|
|
210
|
23
|
|
|
|
|
57
|
$current_count++; |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
} # end ITEM: while (<$lw4_file_fh>) { |
213
|
|
|
|
|
|
|
} # end if ($lw4_file_line =~ m/^\*\* Item Info:/) { |
214
|
|
|
|
|
|
|
} # end LINE: while (<$lw4_file_fh>) { |
215
|
|
|
|
|
|
|
|
216
|
1
|
|
|
|
|
21
|
return \@lw4_item_info_AoH; |
217
|
|
|
|
|
|
|
} # end sub read_item_info { |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
sub build_category_phrases { |
220
|
|
|
|
|
|
|
# Passed: The file handle of the LW4 file. |
221
|
|
|
|
|
|
|
# Returns: Array of Arrays of category phrases |
222
|
|
|
|
|
|
|
|
223
|
2
|
|
|
2
|
0
|
3928
|
my $lw4_file_fh = shift; |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
# This method of creating the ref to @category_phrases is a little |
226
|
|
|
|
|
|
|
# bit wordy, but safe for use strict. |
227
|
|
|
|
|
|
|
|
228
|
2
|
|
|
|
|
5
|
my @category_phrases = ( ); |
229
|
2
|
|
|
|
|
3
|
my $category_phrases = \@category_phrases; |
230
|
2
|
|
|
|
|
4
|
my $category_index = 0; |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
# * Seek to '** Category Phrases:' |
233
|
|
|
|
|
|
|
|
234
|
2
|
|
|
|
|
27
|
LINE: while (<$lw4_file_fh>) { |
235
|
657
|
|
|
|
|
683
|
my $lw4_file_line = $_; |
236
|
657
|
|
|
|
|
566
|
chomp $lw4_file_line; |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
##print "$lw4_file_line\n"; |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
# Read the Category Phrases out of the LW4 file. Everything is |
241
|
|
|
|
|
|
|
# sequential, so an AoA seems to make the most sense. If we |
242
|
|
|
|
|
|
|
# make sure that we're incrimenting the index on the newline that |
243
|
|
|
|
|
|
|
# seperates the records BEFORE reading the first record, everything |
244
|
|
|
|
|
|
|
# will start at index 1, so we won't need to read the Category |
245
|
|
|
|
|
|
|
# Index table later. |
246
|
657
|
100
|
|
|
|
1544
|
if ($lw4_file_line =~ m/^\*\* Category Phrases:/) { |
247
|
2
|
|
|
|
|
8
|
PHRASE: while (<$lw4_file_fh>) { |
248
|
136
|
|
|
|
|
140
|
my $lw4_file_line = $_; |
249
|
136
|
|
|
|
|
121
|
chomp $lw4_file_line; |
250
|
136
|
100
|
|
|
|
316
|
if ($lw4_file_line =~ m/^\W+$/) |
251
|
|
|
|
|
|
|
{ |
252
|
36
|
|
|
|
|
38
|
$category_index++; |
253
|
|
|
|
|
|
|
} |
254
|
136
|
100
|
|
|
|
192
|
last LINE if $lw4_file_line =~ m/^\*\* Category Order Pointers:/; |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
# Apparently there is some trailing white space at the |
257
|
|
|
|
|
|
|
# end of each record. |
258
|
134
|
|
|
|
|
369
|
$lw4_file_line =~ s/\s+$//g; |
259
|
134
|
|
|
|
|
119
|
push @{ $category_phrases->[$category_index] }, $lw4_file_line; |
|
134
|
|
|
|
|
415
|
|
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
} |
262
|
|
|
|
|
|
|
} |
263
|
|
|
|
|
|
|
} |
264
|
|
|
|
|
|
|
|
265
|
2
|
|
|
|
|
6
|
return $category_phrases; |
266
|
|
|
|
|
|
|
} |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
1; |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
# Autoload methods go after =cut, and are processed by the autosplit program. |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
__END__ |