From 553514cc67247fe1be4cf286bc949158d54045f0 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Wed, 22 Sep 2010 06:42:06 -0300 Subject: [PATCH] schhist/subschname2file: search a subsheet name in the top-level sheet and print the name of the subsheet file --- schhist/subschname2file | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 schhist/subschname2file diff --git a/schhist/subschname2file b/schhist/subschname2file new file mode 100755 index 0000000..a908b83 --- /dev/null +++ b/schhist/subschname2file @@ -0,0 +1,36 @@ +#!/usr/bin/perl +# +# subschname2file - Translate a subsheet's name to sheet file's name +# +# Written 2010 by Werner Almesberger +# Copyright 2010 Werner Almesberger +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# + +sub usage +{ + print STDERR "usage: $0 toplevel.sch subsheet-name\n"; + exit(1); +} + + +($top, $name) = @ARGV; +&usage if $#ARGV != 1; + +open(FILE, $top) || die "$top: $!"; +while () { + $sheet = 1 if /^\$Sheet/; + $sheet = 0 if /^\$EndSheet/; + next unless $sheet; + $f0 = $1 if /^F0 "(.*)" /; + next unless /^F1 "(.*)" /; + next unless $f0 eq $name; + print "$1\n"; + exit(0); +} +print STDERR "\"$name\" not found in $top\n"; +exit(1);