Root/
| 1 | #!/usr/bin/perl |
| 2 | # |
| 3 | # subschname2file - Translate a subsheet's name to sheet file's name |
| 4 | # |
| 5 | # Written 2010 by Werner Almesberger |
| 6 | # Copyright 2010 Werner Almesberger |
| 7 | # |
| 8 | # This program is free software; you can redistribute it and/or modify |
| 9 | # it under the terms of the GNU General Public License as published by |
| 10 | # the Free Software Foundation; either version 2 of the License, or |
| 11 | # (at your option) any later version. |
| 12 | # |
| 13 | |
| 14 | sub usage |
| 15 | { |
| 16 | print STDERR "usage: $0 toplevel.sch subsheet-name\n"; |
| 17 | exit(1); |
| 18 | } |
| 19 | |
| 20 | |
| 21 | ($top, $name) = @ARGV; |
| 22 | &usage if $#ARGV != 1; |
| 23 | |
| 24 | open(FILE, $top) || die "$top: $!"; |
| 25 | while (<FILE>) { |
| 26 | $sheet = 1 if /^\$Sheet/; |
| 27 | $sheet = 0 if /^\$EndSheet/; |
| 28 | next unless $sheet; |
| 29 | $f0 = $1 if /^F0 "(.*)" /; |
| 30 | next unless /^F1 "(.*)" /; |
| 31 | next unless $f0 eq $name; |
| 32 | print "$1\n"; |
| 33 | exit(0); |
| 34 | } |
| 35 | print STDERR "\"$name\" not found in $top\n"; |
| 36 | exit(1); |
| 37 |
Branches:
master
