etc/services - sync with NetBSD-8
[minix.git] / releasetools / sort_set.pl
blob81ac4ea02a80f1bf07fbbc0810c21fbe09602f65
1 #!/usr/bin/perl -T -t -w -W
3 # Sort each line of the input, ignoring any line beginning with a #.
4 # Also format the output so that it is properly aligned, with exceptions
5 # for values which are too long for their respective field.
7 print <<HEADER;
9 # Sorted using sort_set.pl in releasetools.
10 # to add an entry simply add it at the end of the
11 # file and run
12 # ../../../../releasetools/sort_set.pl < mi > out
13 # mv out mi
15 HEADER
17 while(<STDIN>) {
18 # Ignore any line starting with a '#'
19 if ($_ =~ m/#.*/) {
20 next;
23 # Entry with a condition field, one or more whitespace characters
24 # separate each column. Example:
25 # ./etc/X11 minix-base xorg
26 if ($_ =~ m/(\S+)\s+(\S+)\s+(\S+)/) {
27 my ($f, $s, $c) = ($1, $2, $3);
28 $k = "$f.$c";
29 $files{$k} = $f;
30 $sets{$k} = $s;
31 $conditions{$k} = $c;
32 next;
35 # Entry without a condition field. Example:
36 # ./bin minix-base
37 if ($_ =~ m/(\S+)\s+(\S+)/) {
38 my ($f, $s) = ($1, $2);
39 $k = "$f.";
40 $files{$k} = $f;
41 $sets{$k} = $s;
45 # Sort by file/directory name.
46 foreach $key (sort keys %sets) {
47 $file = $files{$key};
48 $set = $sets{$key};
50 if (length($file) < 56) {
51 printf("%-55s ", $file);
52 } else {
53 printf("%s ", $file);
56 $last = $set;
57 if (exists($conditions{$key})) {
58 # A condition is present, so make sure it is printed with
59 # the required alignment, by adding the necessary padding
60 # after the set column. Otherwise do not add trailing
61 # spaces.
62 $last = $conditions{$key};
63 if (length($set) < 16) {
64 printf("%-15s ", $set);
65 } else {
66 printf("%s ", $set);
70 printf("%s\n", $last);