1#!/usr/bin/perl -T -t -w -W 2 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. 6 7print <<HEADER; 8# 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 14# 15HEADER 16 17while(<STDIN>) { 18 # Ignore any line starting with a '#' 19 if ($_ =~ m/#.*/) { 20 next; 21 } 22 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; 33 } 34 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; 42 } 43} 44 45# Sort by file/directory name. 46foreach $key (sort keys %sets) { 47 $file = $files{$key}; 48 $set = $sets{$key}; 49 50 if (length($file) < 56) { 51 printf("%-55s ", $file); 52 } else { 53 printf("%s ", $file); 54 } 55 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); 67 } 68 } 69 70 printf("%s\n", $last); 71} 72