gsch2pcb: Make --m4-file and -m4-pcbdir arguments work again.
[geda-gaf/peter-b.git] / utils / scripts / gsymupdate
blob163835ae64cc8611f6d268098115058a6cdc21a0
1 #!/usr/bin/perl
3 # gEDA - GPL Electronic Design Automation
4 # gsymupdate - gEDA Symbol Update
5 # Copyright (C) 2002 Ales V. Hvezda
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 # This program takes a symbol filename on the command line and outputs an
24 # update symbol to stdout.
26 # This program does the following modifications to a symbol
28 # - Removes all pin#=# attributes, converting them into pinseq= and
29 # pinnumber= attributes
30 # - Removes all slot#=# attributes, converting them into slotdef= attributes
32 # Right now this program should only be run against symbols which are
33 # either version 20020527 or earlier.
36 print "gEDA/gsymupdate version 0.2\n";
37 print "gEDA/gsymupdate comes with ABSOLUTELY NO WARRANTY; see COPYING for more details\n";
38 print "This is free software, and you are welcome to redistribute it under certain\n";
39 print "conditions; please see the COPYING file for more details.\n\n";
41 $numArgs = $#ARGV + 1;
42 if ($numArgs < 1) {
43 print "Usage: gsymupdate filename1 filename2 ... filenameN\n";
44 exit;
47 foreach $filename (@ARGV) {
49 if (-r "$filename.old") {
50 print "Found backup file: $filename.old. Not gsymUpdating $filename\n";
51 next ;
54 if ( -d "$filename") {
55 print "$filename is a directory not a file. Not gsymUpdating $filename\n";
56 next ;
59 if (! -f "$filename") {
60 print "File $filename does not exist. Not gsymUpdating $filename\n";
61 next ;
64 # FIXME -- we should probably do some sanity checking to see that $filename is
65 # actually a symbol file.
67 rename ($filename, "$filename.old");
68 print "gsymUpdating: $filename (backup: $filename.old)\n";
70 open (FILE, "$filename.old") || die "Cannot open input file: $filename.old Exiting.\n";
71 open (NEWFILE, ">$filename") || die "Cannot open output file: $filename Exiting.\n";
73 while (<FILE>) {
75 # handle text objects
76 if (/^T/) {
78 # Somewhere here you need to deal with multi line text
79 # items eventually. TODO
81 $textcmd = $_;
83 $textline = <FILE>;
85 # are we dealing with an attribute?
86 if ($textline =~ /=/) {
88 # Break the attribute up into name=value
89 @attrib = split(/=/,$textline,2);
90 $name=@attrib[0];
91 $value=@attrib[1];
93 if ($name =~ /^slot[0-9]+/) {
95 # It is a slot#=# attribute
96 @slotnum = split(/slot/,$name);
97 print NEWFILE $textcmd;
98 print NEWFILE "slotdef=@slotnum[1]:$value";
100 } elsif ($name =~ /^pin[0-9]+/) {
102 # It is a pin#=# attribute
103 print NEWFILE $textcmd;
104 print NEWFILE "pinnumber=$value";
106 @pinseq = split(/pin/,$name);
107 # need to post process textcmd here to hide text
108 $newtextcmd = $textcmd;
109 chop($newtextcmd);
110 @textsplit = split(" ",$textcmd);
112 # Hide this new attribute by changing the 5th value to 0
113 # Also show both the name and value for the pinseq attrib
114 print NEWFILE "@textsplit[0] @textsplit[1] @textsplit[2] @textsplit[3] @textsplit[4] 0 0 @textsplit[7] @textsplit[8] @textsplit[9]\n";
115 print NEWFILE "pinseq=@pinseq[1]\n";
117 } elsif ($name =~ /^uref/) {
119 # It is a uref= attribute, convert to refdes=
120 print NEWFILE $textcmd;
121 print NEWFILE "refdes=$value";
123 } elsif ($name =~ /^type/) {
125 # It is a type= attribute, convert to pintype==
126 print NEWFILE $textcmd;
127 print NEWFILE "pintype=$value";
129 } elsif ($name =~ /^label/) {
131 # It is a label= attribute, convert to pinlabel=
132 print NEWFILE $textcmd;
133 print NEWFILE "pinlabel=$value";
135 } else {
136 # none of the above, just pass it through
137 print NEWFILE $textcmd;
138 print NEWFILE $textline;
142 } else {
143 # not an attribute
144 print NEWFILE $textcmd;
145 print NEWFILE $textline;
148 } else {
149 # It is not a text, version, or pin object, so pass it through
150 print NEWFILE;
154 close $FILE;
155 close $NEWFILE;
157 # Load and Save the file using gschlas
158 # This updates the file to be absolutely current
159 system("gschlas $filename");
160 @args = ("gschlas", "$filename");
161 system(@args) == 0 || die "system @args failed: $?"