From: Lionel Sambuc Date: Fri, 9 Oct 2015 12:36:26 +0000 (+0200) Subject: Upgrade releasetools/sort_set X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zpipe.c?a=commitdiff_plain;h=refs%2Fchanges%2F15%2F3215%2F4;p=minix.git Upgrade releasetools/sort_set - retire the old shell script - import perl script The perl scripts has the following advantages: - The sorting should be more stable, even accross different OSes. - The sorted output is automatically formatted into columns - It is much faster, even on large inputs. Change-Id: I1068b21fda981b4cf9eeea4af83165ec2968280b --- diff --git a/releasetools/sort_set.pl b/releasetools/sort_set.pl new file mode 100755 index 000000000..81ac4ea02 --- /dev/null +++ b/releasetools/sort_set.pl @@ -0,0 +1,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 < out +# mv out mi +# +HEADER + +while() { + # 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); +} diff --git a/releasetools/sort_set.sh b/releasetools/sort_set.sh deleted file mode 100755 index 6da42403a..000000000 --- a/releasetools/sort_set.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh -# -# kinda natural sorting for sets -# prepend every line with a modified path where -# slashes are replaced by "1" and "0" is added -# at the end of the string. -# -# entry -# ./bin/cat minix-sys -# becomes -#.1bin1cat0 ./bin/cat minix-sys -# -# This entry gets sorted after wich the key is removed using -# cut -# -# Additionally all lines starting with "#" are put on -# top in the order they where put in the file. this is done -# by creating a "key" with the value COUNTER -# -COUNTER=10000 -while read i -do - A=$(echo $i | cut -f 1 -d ' ' | sed "s,^#,00$COUNTER,g" | sed 's,/,1,g' ) - echo "${A}0 $i" - COUNTER=$(($COUNTER +1)) -done | sort | cut -d ' ' -f 2-