summaryrefslogtreecommitdiff
path: root/releasetools/sort_set.pl
blob: 81ac4ea02a80f1bf07fbbc0810c21fbe09602f65 (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
#!/usr/bin/perl -T -t -w -W

# Sort each line of the input, ignoring any line beginning with a #.
# Also format the output so that it is properly aligned, with exceptions
# for values which are too long for their respective field.

print <<HEADER;
#
# Sorted using sort_set.pl in releasetools.
# to add an entry simply add it at the end of the
# file and run
# ../../../../releasetools/sort_set.pl < mi > out
# mv out mi
#
HEADER

while(<STDIN>) {
	# Ignore any line starting with a '#'
	if ($_ =~ m/#.*/) {
		next;
	}

	# Entry with a condition field, one or more whitespace characters
	# separate each column. Example:
	# ./etc/X11	minix-base	xorg
	if ($_ =~ m/(\S+)\s+(\S+)\s+(\S+)/) {
		my ($f, $s, $c) = ($1, $2, $3);
		$k = "$f.$c";
		$files{$k} = $f;
		$sets{$k} = $s;
		$conditions{$k} = $c;
		next;
	}

	# Entry without a condition field. Example:
	# ./bin		minix-base
	if ($_ =~ m/(\S+)\s+(\S+)/) {
		my ($f, $s) = ($1, $2);
		$k = "$f.";
		$files{$k} = $f;
		$sets{$k} = $s;
	}
}

# Sort by file/directory name.
foreach $key (sort keys %sets) {
	$file = $files{$key};
	$set = $sets{$key};

	if (length($file) < 56) {
		printf("%-55s ", $file);
	} else {
		printf("%s ", $file);
	}

	$last = $set;
	if (exists($conditions{$key})) {
		# A condition is present, so make sure it is printed with
		# the required alignment, by adding the necessary padding
		# after the set column. Otherwise do not add trailing
		# spaces.
		$last = $conditions{$key};
		if (length($set) < 16) {
			printf("%-15s ", $set);
		} else {
			printf("%s ", $set);
		}
	}

	printf("%s\n", $last);
}