File: preprocess

package info (click to toggle)
kernel-wedge 2.74%2Bsqueeze4
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 680 kB
  • ctags: 10
  • sloc: perl: 319; sh: 269; makefile: 21
file content (55 lines) | stat: -rwxr-xr-x 952 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/perl
use strict;
use warnings;
my $sysdir="/usr/share/kernel-wedge/modules/";

my %modules;
my %loaded;

sub loadlist {
	my $list=shift;
	
	if ($loaded{$list}) {
		die "include loop detected loading $list\n";
	}
	$loaded{$list}=1;
	
	my $fh;
	open ($fh, $list) || die "cannot read $list\n";
	while (<$fh>) {
		chomp;
		if (/^\s*#include\s+<(.*)>\s*$/) {
			my $basename=$1;
			loadlist($sysdir.$basename);
		}
		elsif (/^\s*#include\s+"(.*)"\s*$/) {
			my $include=$1;
			my ($dirname)=$list=~m!(.*/).*!;
			loadlist($dirname.$include);
		}
		elsif (/^\s*$/) {
			next;
		}
		elsif (/^\s*#/) {
			next;
		}
		elsif (/(.*) -$/) {
			delete $modules{$1};
			# may also appear in other forms:
			delete $modules{"$1 ?"};
			delete $modules{"-$1"};
		}
		else {
			s/^\s*//;
			s/\s*$//;
			$modules{$_}=1;
		}
	}
	close $fh;
}

my $file=shift || die "no input file given";
loadlist($file);
foreach my $m (sort keys %modules) {
	print "$m\n";
}