summaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-11-13 23:23:56 -0300
committerGenerated from internal repo <nobody@neo900.org>2016-11-13 23:23:56 -0300
commit6a180c2999d2e96cb24d52a3a4b01eb54d26a7fe (patch)
tree202de41db959d9db315f17ff29c84395d4364b6b /hw
parent541b86a36cefa6c7c8b4007816500b23d36a9c3f (diff)
downloadee-6a180c2999d2e96cb24d52a3a4b01eb54d26a7fe.tar.gz
ee-6a180c2999d2e96cb24d52a3a4b01eb54d26a7fe.tar.bz2
ee-6a180c2999d2e96cb24d52a3a4b01eb54d26a7fe.zip
hw/sortsheets.pl: new options -xy and -yx to sort by sheet symbol position
Diffstat (limited to 'hw')
-rwxr-xr-xhw/sortsheets.pl51
1 files changed, 49 insertions, 2 deletions
diff --git a/hw/sortsheets.pl b/hw/sortsheets.pl
index efa8f2e..e16f05f 100755
--- a/hw/sortsheets.pl
+++ b/hw/sortsheets.pl
@@ -1,8 +1,23 @@
#!/usr/bin/perl
$MAGIC = "Xsheetnumber";
-if ($ARGV[0] eq "-q") {
- $query = 1;
+sub usage
+{
+ print STDERR "usage: $0 [-q] [-xy|-yx] [top-sheet.sch]\n";
+ exit(1);
+}
+
+
+while ($ARGV[0] =~ /^-/) {
+ if ($ARGV[0] eq "-q") {
+ $query = 1;
+ } elsif ($ARGV[0] eq "-xy") {
+ $xy = 1;
+ } elsif ($ARGV[0] eq "-yx") {
+ $yx = 1;
+ } else {
+ &usage;
+ }
shift @ARGV;
}
@@ -27,6 +42,13 @@ while (<>) {
$where = "outside";
$tmp .= $_;
+ if ($xy || $yx) {
+ push(@x, $x);
+ push(@y, $y);
+ push(@unsorted, $tmp);
+ next;
+ }
+
die "file name not found" unless $tmp =~ /^F1\s+"([^"]+)"/ms;
$file = $1;
open(FILE, $file) || die "$file: $!";
@@ -51,9 +73,34 @@ while (<>) {
$was[$explicit] = $sheet;
next;
}
+ if (/^S\s+(\d+)\s+(\d+)/) {
+ $x = $1;
+ $y = $2;
+ }
$tmp .= $_;
}
+
+sub map
+{
+ local ($a, $b) = @_;
+
+ return $x[$a] == $x[$b] ? $y[$a] <=> $y[$b] : $x[$a] <=> $x[$b]
+ if $xy;
+ return $y[$a] == $y[$b] ? $x[$a] <=> $x[$b] : $y[$a] <=> $y[$b];
+}
+
+
+if ($xy || $yx) {
+ my @i = sort({ &map($a, $b) } ( 0 .. $#unsorted ));
+
+ for (0..$#i) {
+#print STDERR "$_ <- $i[$_] $x[$i[$_]] $y[$i[$_]]\n";
+ $sorted[$_ + 2] = $unsorted[$i[$_]];
+ $was[$_ + 2] = $i[$_] + 2;
+ }
+}
+
print $head || die "write: $!" unless $query;
for ($i = 2; $i <= $#sorted; $i++) {
if (!defined $sorted[$i]) {