Uprage 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
This commit is contained in:
Lionel Sambuc 2015-10-09 14:36:26 +02:00
parent 94a0fb49a5
commit 083cb8ab2e
2 changed files with 50 additions and 26 deletions

50
releasetools/sort_set.pl Executable file
View File

@ -0,0 +1,50 @@
#!/usr/bin/perl -T -t -w -W
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>) {
if ($_ =~ m/#.*/) {
next;
}
if ($_ =~ m/(\S+)\s+(\S+)\s+(\S+)/) {
my ($f, $s, $c) = ($1, $2, $3);
$sets{"$f"} = $s;
$conditions{"$f"} = $c;
}
if ($_ =~ m/(\S+)\s+(\S+)/) {
my ($f, $s) = ($1, $2);
$sets{"$f"} = $s;
}
}
foreach $file (sort keys %sets) {
$set = $sets{$file};
if (length($file) < 56) {
printf("%-55s ", $file);
} else {
printf("%s ", $file);
}
$last = $set;
if (exists($conditions{$file})) {
$last = $conditions{$file};
if (length($set) < 16) {
printf("%-15s ", $set);
} else {
printf("%s ", $set);
}
}
printf("%s\n", $last);
}

View File

@ -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-