3 # Copyright (C) 2003, 2006, 2010 Dan McMahill
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 # This script is used to process annotation files from the PCB
21 # program (http://pcb.gpleda.org) to backannotate
22 # changes to gEDA schematics.
24 # It is heavily based on the pads_backannotate program which is also
27 # for parsing input options
33 # don't allow -he to be interpreted as --help
34 $Getopt::Long
::autoabbrev
=0;
36 # make the options be case sensitive
37 $Getopt::Long
::ignorecase
=0;
39 &GetOptions
( ('h|help' => \
&usage
,
40 'n|nocopy' => \
$nocopy,
41 'v|verbose' => \
$verbose,
42 'V|version' => \
&version
45 usage
() if $Getopt::Long
::error
;
48 # Annotation file name
49 $eco = shift( @ARGV );
51 # if no schematic names follow, exit
54 # make sure the input netlist exists and we can open it
57 $fname[$i] = shift( @ARGV );
58 die "Schematic file $fname[$i] does not exist or can not be read"
66 if( $verbose ){ print "Loading PCB annotation file file: $eco\n"; }
67 my $eco_state="DEFAULT";
68 open( ECO
, "$eco" ) or die "Can't open PCB annotation file $eco !\n";
71 while( $line = <ECO
> ) {
72 if( $line =~ /^\*FILEVERSION\* / ) {
74 $ver =~ s/^\*FILEVERSION\*\s*//;
76 } elsif( $line =~ /^\*VERSION\* 20060814/ ) {
83 print "ERROR: Unable to determine annotation file version.\n";
87 print "Annotation file version is $ver\n" if $verbose ;
88 if( $ver != 20061031 && $ver != 20060814 ) {
89 print "ERROR: This version of the program is unable to process\n";
90 print " PCB annotation files of version $ver.\n";
95 # reopen and parse the file this time
96 open( ECO
, "$eco" ) or die "Can't open PCB annotation file $eco !\n";
97 while( $line = <ECO
> ) {
98 # if( $verbose ){ print "$line\n"; }
99 if( $line =~ /^\*COMMENT\*/ ) {
100 print "Skipping comment line: $line\n";
102 } elsif( $line =~ /^\*VERSION\* 20060814/ || $line =~ /^\*FILEVERSION\* [0-9]*/) {
103 # the version line. Note that the very first version of the annotation
104 # file used *VERSION* but it was quickly changed to FILEVERSION to avoid
105 # confusing it with the program version.
107 } elsif( $line =~ /^\*RENAME\*/ ) {
108 # rename refdes in design (forward/backward annotation)
109 #$eco_state="RENAME";
110 print " *RENAME* (Refdes Renumber)\n" if $verbose;
111 $line =~ s/^\*RENAME\*\s*//;
114 } elsif( $line =~ /^\*WARN\*/ ) {
115 # A warning generated by PCB
116 print "Found the following warning in the annotation file:\n";
119 } elsif( $line =~ /^\*/ ) {
120 print "WARNING: Unknown command line:\n";
122 $eco_state="DEFAULT";
125 # this must be a data line
126 #if( $verbose ){ print "Processing data line: $line"; }
132 for($i=0; $i < $filecnt; $i++) {
133 print "Processing schematic file #", $i+1, ": $fname[$i]\n";
134 open(NETLIST
,"$fname[$i]") or
135 die "Can't open schematic $fname[$i]: $!\n";
137 # open output netlist
138 $outfname="$fname[$i].new";
139 open(OUTSCH
,">$outfname") or die "Can't open $outfname: $!\n";
141 while($line = <NETLIST
>) {
142 $line = executeRENAME
($line);
143 print OUTSCH
"$line";
149 print "Leaving page #",$i+1," output in $outfname\n";
152 system("mv $outfname $fname[$i]");
157 print "\n---- Gate Swapping ----\n";
159 print "\n---- Pin Swapping ----\n";
161 print "\nBackannotation finished ", scalar localtime, "\n";
166 #######################################################################
170 #######################################################################
172 #---------------------------------
173 # executeRENAME(line)
174 #---------------------------------
177 my $line = shift(@_);
179 return $line unless defined %cmd_rename;
180 return $line unless $line =~ /^refdes=/;
182 # pick out the reference designator
184 $refdes =~ s/^refdes=//;
185 $refdes =~ s/[\r\n]*$//;
187 # see if its listed in our hash of reference designators to be
189 return $line unless exists $cmd_rename{$refdes};
191 print "executeRENAME(): Renaming $refdes to $cmd_rename{$refdes}\n"
193 return "refdes=$cmd_rename{$refdes}\n";
197 #---------------------------------
199 #---------------------------------
201 sub executeSWPGATES
{
204 foreach $key (keys %cmd_swap_gates ) {
205 print "Please manually swap gates $key and $cmd_swap_gates{$key}\n";
209 #---------------------------------
211 #---------------------------------
217 foreach $key (keys %cmd_swap_pins ) {
218 @pins = split '\.',,$cmd_swap_pins{$key};
219 print "Please manually swap pins $pins[0] and $pins[1] on $key\n";
223 #---------------------------------
225 #---------------------------------
228 my $line = shift(@_);
230 @refs = split ' ',,$line;
232 $refs[0] =~ s/"//g; # "
233 $refs[1] =~ s/"//g; # "
235 print "parseRENAME(): Scheduling rename of $refs[0] to $refs[1]\n"
237 $cmd_rename{$refs[0]} = $refs[1];
241 #---------------------------------
242 # parseSWPGATES(line)
243 #---------------------------------
246 my $line = shift(@_);
248 @refs = split ' ',,$line;
250 print "parseSWPGATES(): Scheduling swap of gate $refs[0] with $refs[1]\n"
252 $cmd_swap_gates{$refs[0]} = $refs[1];
256 #---------------------------------
258 #---------------------------------
261 my $line = shift(@_);
262 @refs = split ' ',,$line;
263 @pins = split '\.',,$refs[1];
265 print "parseSWPPINS(): Scheduling swap of pins on $refs[0] : pins ",
266 "$pins[0] and $pins[1]\n" if $verbose;
267 $cmd_swap_pins{$refs[0]} = $refs[1];
271 #---------------------------------
274 # prints program usage
275 #---------------------------------
285 $pname [-n|--nocopy] [-v|--verbose] change.log file1.sch [file2.sch ...]
287 $pname -V|--version\n
289 $pname reads a PCB annotation file and backannotates changes\n
292 $pname accepts the following options:
295 --help Displays this help message.
298 --nocopy If given, this flag leaves the modified files in new files
299 whose names are generated by appending a \".new\" to the
300 original file names. The default is to overwrite the original.
303 --verbose Enables verbose output.
306 --version Shows the version of this program.
309 $pname was written by Dan McMahill <dmcmahill\@netbsd.org>
317 #---------------------------------
320 # prints program version
321 #---------------------------------
324 open(PROG
,"$0") or die "Could not open \"$0\" to find version\n\n";
328 while($line = <PROG
>) {
329 if( $line =~ /^#\s*\$Id.*\$/) {
330 @words = split ' ',,$line;
331 $version = $words[3];
333 print "$pname ($0): Version $version, $date\n";
337 print "Could not determine version of \"$0\"\n\n";