summaryrefslogtreecommitdiff
path: root/new-infra/use_tldb.pl
blob: d9342a0267bb8d157ef911aade91eaae6f88d0a5 (plain)
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
232
233
234
235
236
237
238
239
240
241
#!/usr/bin/perl -w
#
# use_tldb.pl
# use the tldb file which is nothing else then a concatenation of
# single tlp files
# (c) 2007 Norbert Preining
#
# This file is licensed under the GNU General Public Licence version 2
# (not later)

use strict;

my %tldb;
my $opt_debug = 0;

my $tlpline;

&main(@ARGV);

1;




sub main {
	my ($tldb) = @_;
	read_tldb_file($tldb);
	foreach my $f (keys %tldb) {
		write_tlp_file($f);
	}
}

sub read_tldb_file {
	my ($tldb) = @_;
	open(TMP,"<$tldb") || die("Cannot open $tldb: $!");
	my @lines = <TMP>;
	close(TMP);
	my $name = "";
	my $shortdesc = "";
	my $longdesc= "";
	my $catalogue = "";
	my (@executes, @depends);
	my (@runfiles, @docfiles, @binfiles, @srcfiles);
	my $started = 0;
	my $lastcmd = 

	logit("Working on $tldb\n");
	foreach my $line (@lines) {
		logit("line=>>>$line<<<\n");
		$line =~ /^\s*#/ && next;          # skip comment lines
		if ($line =~ /^\s*$/) {
			if ($started) {
				# one entry is finished, we have to fill the hash and
				# clean the tmp variables
				# clear the tmp variables
				@runfiles = @docfiles = @srcfiles = @binfiles = ();
				@executes = @depends = ();
				$shortdesc = $longdesc = $catalogue = "";
				$started = 0;
				next;
			} else {
				# ignore empty lines between tlps
				next;
			}
		}
		if ($line =~ /^ /) {
			if ( ($lastcmd eq "longdesc") ||
			     ($lastcmd eq "runfiles")  ||
			     ($lastcmd eq "binfiles")  ||
			     ($lastcmd eq "docfiles")  ||
			     ($lastcmd eq "srcfiles")  ||
			     ($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+)$/) {
			logit("found name: $1\n");
			$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*(.*)$/) {
				logit("found shortdesc: $1\n");
				$tldb{$name}{'shortdesc'} .= "$1 ";
				$lastcmd = "shortdesc";
				next;
			} elsif ($line =~ /^longdesc\s*(.*)$/) {
				logit("found longdesc: $1\n");
				$tldb{$name}{'longdesc'} .= "$1 ";
				$lastcmd = "longdesc";
				next;
			} elsif ($line =~ /^catalogue\s*(.*)$/) {
				logit("found catalogue: $1\n");
				$tldb{$name}{'catalogue'} = "$1";
				$lastcmd = "catalogue";
				next;
			} elsif ($line =~ /^runfiles\s*(.*)$/) {
				logit("found runfiles: $1\n");
				push @{$tldb{$name}{'runfiles'}}, "$1" unless "$1" eq "";
				$lastcmd = "runfiles";
				next;
			} elsif ($line =~ /^srcfiles\s*(.*)$/) {
				logit("found srcfiles: $1\n");
				push @{$tldb{$name}{'srcfiles'}}, "$1" unless "$1" eq "";
				$lastcmd = "srcfiles";
				next;
			} elsif ($line =~ /^docfiles\s*(.*)$/) {
				logit("found docfiles: $1\n");
				push @{$tldb{$name}{'docfiles'}}, "$1" unless "$1" eq "";
				$lastcmd = "docfiles";
				next;
			} elsif ($line =~ /^binfiles\s*(.*)$/) {
				logit("found binfiles: $1\n");
				push @{$tldb{$name}{'binfiles'}}, "$1" unless "$1" eq "";
				$lastcmd = "binfiles";
				next;
			} elsif ($line =~ /^execute\s*(.*)$/) {
				logit("found execute: $1\n");
				push @{$tldb{$name}{'executes'}}, "$1" unless "$1" eq "";
				$lastcmd = "execute";
				next;
			} elsif ($line =~ /^depend\s*(.*)$/) {
				logit("found depend: $1\n");
				push @{$tldb{$name}{'depends'}}, "$1" unless "$1" eq "";
				$lastcmd = "depend";
				next;
			} else {
				die("Unknown directive ...$line... in $tldb, please fix it!");
			}
		}
	}
	logit("Done reading the tldb file, filling the data structure!\n");
	if ($catalogue ne "") {
		$tldb{$name}{'catalogue'} = "$catalogue";
	} else {
		$tldb{$name}{'catalogue'} = "$name";
	}
	if ($shortdesc ne "") {
		$tldb{$name}{'shortdesc'} = "$shortdesc";
	}
	if ($longdesc ne "") {
		$tldb{$name}{'longdesc'} = "$longdesc";
	}
	if ($#srcfiles >= 0) {
		$tldb{$name}{'srcfiles'} = [ @srcfiles ];
	}
	if ($#runfiles >= 0) {
		$tldb{$name}{'runfiles'} = [ @runfiles ];
	}
	if ($#binfiles >= 0) {
		$tldb{$name}{'binfiles'} = [ @binfiles ];
	}
	if ($#docfiles >= 0) {
		$tldb{$name}{'docfiles'} = [ @docfiles ];
	}
	if ($#executes >= 0) {
		$tldb{$name}{'executes'} = [ @executes ];
	}
	if ($#depends>= 0) {
		$tldb{$name}{'depends'} = [ @depends ];
	}
}

sub write_tlp_file {
	my ($tlp) = @_;
	open(TLP,">tlp/$tlp.tlp") || die("Cannot open tlp/$tlp.tlp for writing: $!");
	print TLP "name $tlp\n";
	if (defined($tldb{$tlp}{'shortdesc'})) {
		$tlpline = "shortdesc $tldb{$tlp}{'shortdesc'}";
		write TLP;
	}
	if (defined($tldb{$tlp}{'longdesc'})) {
		$tlpline = "longdesc $tldb{$tlp}{'longdesc'}";
		write TLP;
	}
	if (defined($tldb{$tlp}{'catalogue'})) {
		print TLP "catalogue $tldb{$tlp}{'catalogue'}\n";
	}
	my @tmp;
	if (defined($tldb{$tlp}{'executes'})) {
		foreach (@{$tldb{$tlp}{'executes'}}) {
			print TLP "execute $_\n";
		}
	}
	if (defined($tldb{$tlp}{'depends'})) {
		foreach (@{$tldb{$tlp}{'depends'}}) {
			print TLP "depend $_\n";
		}
	}
	if (defined($tldb{$tlp}{'docfiles'})) {
		print TLP "docfiles\n";
		foreach (@{$tldb{$tlp}{'docfiles'}}) {
			print TLP " $_\n";
		}
	}
	if (defined($tldb{$tlp}{'srcfiles'})) {
		print TLP "srcfiles\n";
		foreach (@{$tldb{$tlp}{'srcfiles'}}) {
			print TLP " $_\n";
		}
	}
	if (defined($tldb{$tlp}{'binfiles'})) {
		print TLP "binfiles\n";
		foreach (@{$tldb{$tlp}{'binfiles'}}) {
			print TLP " $_\n";
		}
	}
	if (defined($tldb{$tlp}{'runfiles'})) {
		print TLP "runfiles\n";
		foreach (@{$tldb{$tlp}{'runfiles'}}) {
			print TLP " $_\n";
		}
	}
	close(TLP);
}

sub logit {
	$opt_debug && print STDERR @_;
}


###### Formats
format TLP =
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$tlpline
 ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~
$tlpline
.


### Local Variables:
### perl-indent-level: 4
### tab-width: 4
### indent-tabs-mode: t
### End:
# vim:set tabstop=4: #