3
# $Id: refdes_renum,v 1.1 2003/02/21 03:21:12 ahvezda Exp $
5
# Copyright (C) 2003 Dan McMahill
7
# This program is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 2 of the License, or
10
# (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
# This script is used to renumber devices in a gschem (part of gEDA)
23
# schematic. This program works on single as well as multi-sheet
27
# renum.pl file1.sch [file2.sch [file3.sch ...]]
30
# for parsing input options
36
# don't allow -he to be interpreted as --help
37
$Getopt::Long::autoabbrev=0;
39
&GetOptions(("help" => \&usage,
41
"pgskip" => \$pkgskip,
42
"verbose" => \$verbose,
43
"version" => \&version
46
usage() if $Getopt::Long::error;
49
# make sure the input schematic exists and we can read it
52
$fname[$i]=shift(@ARGV);
53
die "Schematic file $fname[$i] does not exist or can not be read"
60
for($i=0; $i < $filecnt; $i++) {
61
print "Processing input file #",$i+1,": $fname[$i]\n";
62
open(NETLIST,"$fname[$i]") or die "Can't open $fname[$i]: $!\n";
65
$outfname="$fname[$i].renum";
66
open(OUTNET,">$outfname") or die "Can't open $outfname: $!\n";
68
while($line = <NETLIST>) {
69
unless( $line =~ /^refdes/) {
76
# for lines like "refdes=CR37" pick out the "CR" part.
77
# There's probably a more concise way, but the perl book
78
# is at work right now.
81
$pre =~ s/[0-9\?]*$//;
82
print "Refdes line \"$line\" has pre=\"$pre\"\n" if($verbose);
84
# if we're skipping numbers, then start at 100 for page 1
85
# and we'll jump to 200 for page 2, etc.
86
if( ! $devcnt{$pre} ) { $devcnt{$pre} = $pkgskip ? ($i+1)*100 : 0; }
88
print "Renumbering $line to $pre$devcnt{$pre}\n" if($verbose);
89
print OUTNET "refdes=$pre$devcnt{$pre}\n";
94
# round each element up to the next 100 to help identify what
95
# schematic page a component is on by the refdes.
97
foreach $dev (keys %devcnt) {
98
$devcnt{$dev} = 100*POSIX::ceil($devcnt{$dev}/100);
99
print "Incremented \"$dev\" counter to $devcnt{$dev}\n" if($verbose);
103
# make this an option to not overwrite the original
105
print "Leaving page #",$i+1," output in $outfname\n";
108
system("mv $outfname $fname[$i]");
115
#######################################################################
119
#######################################################################
121
#---------------------------------
124
# prints program usage
125
#---------------------------------
132
print "\t$pname [--nocopy] [--pgskip] file1 [file2 [file3 ... ] ]\n";
133
print "\t$pname --help\n";
134
print "\t$pname --version\n";
136
print "$pname reads a gschem schematic file or files and renumbers all reference\n";
137
print "designators. The reference designators are numbered starting with 1 and the\n";
138
print "old schematic file is replaced by the modified schematic file.\n";
140
print "$pname accepts the following options:\n";
142
print " --help Displays this help message.\n";
144
print " --nocopy If given, this flag leaves the modified files in new files\n";
145
print " whose names are generated by appending a \".renum\" to the\n";
146
print " original file names. The default is to overwrite the original.\n";
148
print " --pgskip When this flag is used, components on the first schematic sheet\n";
149
print " are numbered starting with 101. On the second sheet, they start\n";
150
print " with 201, etc. \n";
152
print " --verbose Enables verbose output.\n";
154
print " --version Shows the version of this program.\n";
156
print "$pname was written by Dan McMahill <dmcmahill\@netbsd.org>\n";
161
#---------------------------------
164
# prints program version
165
#---------------------------------
168
open(PROG,"$0") or die "Could not open \"$0\" to find version\n\n";
172
while($line = <PROG>) {
173
if( $line =~ /^#\s*\$Id.*\$/) {
174
@words = split ' ',,$line;
175
$version = $words[3];
177
print "$pname ($0): Version $version, $date\n";
181
print "Could not determine version of \"$0\"\n\n";
185
# ----------------------------------------------
189
# $Log: refdes_renum,v $
190
# Revision 1.1 2003/02/21 03:21:12 ahvezda
191
# Added scripts/refdes_renum written by Dan McMahill