From 886de1554a29d5c54913268efbbb4f08bc8c3ecc Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Thu, 29 Sep 2011 00:50:52 -0300 Subject: [PATCH] swapcmp/: swap (rename) components in a layout --- README | 2 ++ swpcmp/swpcmp | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100755 swpcmp/swpcmp diff --git a/README b/README index b09fd61..e1c9282 100644 --- a/README +++ b/README @@ -21,5 +21,7 @@ This is a collection of utilities for Electronic Design Automation: - schhist: a system to walk a KiCad project's git revision history and generating Web-browseable graphical differences of the schematics. +- swpcmp: swap components in a layout + Each utility can have its own licensing terms. They're specified in the respective directory or in the file itself. diff --git a/swpcmp/swpcmp b/swpcmp/swpcmp new file mode 100755 index 0000000..a27f4ad --- /dev/null +++ b/swpcmp/swpcmp @@ -0,0 +1,65 @@ +#!/usr/bin/perl + +sub usage +{ + print STDERR "usage: $0 name=name ... [file ...]\n"; + exit(1); +} + + +&usage if $ARGV[0] =~ /^-/; +&usage if !@ARGV; + +while ($ARGV[0] =~ /=/) { + die "already renaming component $`" if defined $map{$`}; + die "already renaming component $'" if defined $map{$'}; + $map{$`} = $'; + $map{$'} = $`; + shift @ARGV; +} + +undef $mod; +while (<>) { + if (/^\$MODULE\s+(\S+)\s*$/) { + die "\$MODULE within \$MODULE" if $mod; + $mod = 1; + $fp = $1; + undef $name; + } + if (!$mod) { + print; + next; + } + if (/^(T0\s.*")([^"]+)("\s*)$/) { + die "duplicate name \"$name\" vs. \"$2\"" if defined $name; + $name = $2; + if (defined $map{$name}) { + print "$1$map{$name}$3"; + } else { + print; + } + } else { + print; + } + if (/^\$EndMODULE/) { + die "module has no name" unless defined $name; + if (defined $map{$name}) { + if ($mod{$map{$name}}) { + die "footprint mismatch: $name/$fp vs. ". + $map{$name}."/".$fp{$map{$name}} unless + $fp eq $fp{$map{$name}}; + delete $map{$map{$name}}; + delete $map{$name}; + } else { + $mod{$name} = 1; + $fp{$name} = $fp; + } + } + $mod = 0; + } +} + +die "EOF within module" if $mod; +for (keys %map) { + die "not swapped: ".join(", ", sort keys %map); +}