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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
#
# TLSRC.pm
# module for using tlsrc files
# Copyright 2007 Norbert Preining
#
# This file is licensed under the GNU General Public Licence version 2
# or any later version
package TLSRC;
sub new {
my $class = shift;
my %params = @_;
my $self = {
name => $params{'name'},
shortdesc => $params{'shortdesc'},
longdesc => $params{'longdesc'},
catalogue => $params{'catalogue'},
runpatterns => $params{'runpatterns'},
srcpatterns => $params{'srcpatterns'},
docpatterns => $params{'docpatterns'},
binpatterns => $params{'binpatterns'},
executes => $params{'executes'},
depends => $params{'depends'},
};
bless $self, $class;
return $self;
}
sub from_file {
my $self = shift;
if (@_ != 1) {
die("Need a filename for initialization!");
}
open(TMP,"<$_[0]") || die("Cannot open tlsrc file: $_[0]");
my @lines = <TMP>;
close(TMP);
my $name = "";
my $shortdesc = "";
my $longdesc= "";
my $catalogue = "";
my (@executes, @depends);
my (@runpatterns, @docpatterns, @binpatterns, @srcpatterns);
my $started = 0;
my $finished = 0;
my $lastcmd = "";
foreach my $line (@lines) {
$line =~ /^\s*#/ && next; # skip comment lines
if ($line =~ /^\s*$/) {
if (!$started) { next; }
if ($finished) { next; }
die("No empty line allowed in tlsrc files!");
}
if ($line =~ /^ /) {
if ( ($lastcmd eq "longdesc") ||
($lastcmd eq "runpattern") ||
($lastcmd eq "binpattern") ||
($lastcmd eq "docpattern") ||
($lastcmd eq "srcpattern") ||
($lastcmd eq "execute") ||
($lastcmd eq "depend") ) {
$line =~ s/^ /$lastcmd /;
} else {
die("Continuation of $lastcmd not allowed, please fix tlsrc!\n");
}
}
if ($line =~ /^name\s*([\w-]+)$/) {
$name = "$1";
$lastcmd = "name";
$started && die("Cannot have two name directives!");
$started = 1;
} else {
$started || die("First directive needs to be 'name'");
if ($line =~ /^shortdesc\s*(.*)$/) {
$shortdesc .= "$1 ";
$lastcmd = "shortdesc";
next;
} elsif ($line =~ /^longdesc\s*(.*)$/) {
$longdesc .= "$1 ";
$lastcmd = "longdesc";
next;
} elsif ($line =~ /^catalogue\s*(.*)$/) {
$catalogue .= "$1 ";
$lastcmd = "catalogue";
next;
} elsif ($line =~ /^runpattern\s*(.*)$/) {
push @runpatterns, "$1";
$lastcmd = "runpattern";
next;
} elsif ($line =~ /^srcpattern\s*(.*)$/) {
push @srcpatterns, "$1";
$lastcmd = "srcpattern";
next;
} elsif ($line =~ /^docpattern\s*(.*)$/) {
push @docpatterns, "$1";
$lastcmd = "docpattern";
next;
} elsif ($line =~ /^binpattern\s*(.*)$/) {
push @binpatterns, "$1";
$lastcmd = "binpattern";
next;
} elsif ($line =~ /^execute\s*(.*)$/) {
push @executes, "$1";
$lastcmd = "execute";
next;
} elsif ($line =~ /^depend\s*(.*)$/) {
push @depends, "$1";
$lastcmd = "depend";
next;
} else {
die("Unknown directive ...$line... in $tlsrc, please fix it!");
}
}
}
$self->name("$name");
$self->catalogue($catalogue ne "" ? "$catalogue" : "$name");
$self->shortdesc("$shortdesc") if ($shortdesc ne "");
$self->longdesc("$longdesc") if ($longdesc ne "");
$self->srcpatterns(@srcpatterns) if ($#srcpatterns >= 0);
$self->runpatterns(@runpatterns) if ($#runpatterns >= 0);
$self->binpatterns(@binpatterns) if ($#binpatterns >= 0);
$self->docpatterns(@docpatterns) if ($#docpatterns >= 0);
$self->executes(@executes) if ($#executes >= 0);
$self->depends(@depends) if ($#depends >= 0);
}
sub writeout {
my $self = shift;
my $fd = (@_ ? $_[0] : STDOUT);
print $fd "name ", $self->name, "\n";
print $fd "catalogue $self->{'catalogue'}\n";
defined($self->{'shortdesc'}) && print $fd "shortdesc $self->{'shortdesc'}\n";
defined($self->{'longdesc'}) && print $fd "longdesc $self->{'longdesc'}\n";
if (defined($self->{'depends'})) {
foreach (@{$self->{'depends'}}) {
print $fd "depend $_\n";
}
}
if (defined($self->{'executes'})) {
foreach (@{$self->{'executes'}}) {
print $fd "execute $_\n";
}
}
if (defined($self->{'srcpatterns'})) {
foreach (@{$self->{'srcpatterns'}}) {
print $fd "srcpattern $_\n";
}
}
if (defined($self->{'runpatterns'})) {
foreach (@{$self->{'runpatterns'}}) {
print $fd "runpattern $_\n";
}
}
if (defined($self->{'docpatterns'})) {
foreach (@{$self->{'docpatterns'}}) {
print $fd "docpattern $_\n";
}
}
if (defined($self->{'binpatterns'})) {
foreach (@{$self->{'binpatterns'}}) {
print $fd "binpattern $_\n";
}
}
# print final empty line
print $fd "\n";
}
#
# member access functions
#
sub name {
my $self = shift;
if (@_) { $self->{'name'} = shift }
return $self->{'name'};
}
sub shortdesc {
my $self = shift;
if (@_) { $self->{'shortdesc'} = shift }
return $self->{'shortdesc'};
}
sub longdesc {
my $self = shift;
if (@_) { $self->{'longdesc'} = shift }
return $self->{'longdesc'};
}
sub catalogue {
my $self = shift;
if (@_) { $self->{'catalogue'} = shift }
return $self->{'catalogue'};
}
sub srcpatterns {
my $self = shift;
if (@_) { @{ $self->{'srcpatterns'} } = @_ }
return @{ $self->{'srcpatterns'} };
}
sub docpatterns {
my $self = shift;
if (@_) { @{ $self->{'docpatterns'} } = @_ }
return @{ $self->{'docpatterns'} };
}
sub binpatterns {
my $self = shift;
if (@_) { @{ $self->{'binpatterns'} } = @_ }
return @{ $self->{'binpatterns'} };
}
sub depends {
my $self = shift;
if (@_) { @{ $self->{'depends'} } = @_ }
return @{ $self->{'depends'} };
}
sub runpatterns {
my $self = shift;
if (@_) { @{ $self->{'runpatterns'} } = @_ }
return @{ $self->{'runpatterns'} };
}
sub executes {
my $self = shift;
if (@_) { @{ $self->{'executes'} } = @_ }
return @{ $self->{'executes'} };
}
1;
### Local Variables:
### perl-indent-level: 4
### tab-width: 4
### indent-tabs-mode: t
### End:
# vim:set tabstop=4: #
|