1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-25 20:57:12 +02:00

swapcmp/: swap (rename) components in a layout

This commit is contained in:
Werner Almesberger 2011-09-29 00:50:52 -03:00
parent eff2e8e3b9
commit 886de1554a
2 changed files with 67 additions and 0 deletions

2
README
View File

@ -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 - schhist: a system to walk a KiCad project's git revision history and
generating Web-browseable graphical differences of the schematics. 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 Each utility can have its own licensing terms. They're specified in the
respective directory or in the file itself. respective directory or in the file itself.

65
swpcmp/swpcmp Executable file
View File

@ -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);
}