Updated copyright text/header in most source files.
[geda-gaf/peter-b.git] / gnetlist / scripts / annotate.sh.in
blob7cbed5d7d51dac68d432e629b1fc0ef633d807c7
1 #!/bin/sh
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 #------------------------------------------------------------------
18 #--------------------------------JM Routoure-----------------------
19 #---------------------------------28/02/2000-----------------------
20 #------------------------------------------------------------------
22 if [ -z "$1" ]; then
23 echo "No sch file indicated"
24 echo "usage:"
25 echo "annotate file"
26 echo " file is generated by gschem"
27 exit 1
28 fi
30 # create a secure temp directory
31 tmpd=${TMP:-/tmp}/annotate.$$
32 mkdir -m 0700 ${tmpd}
33 rc=$?
34 if test $rc -ne 0 ; then
35 cat << EOF
37 $0: ERROR -- failed to securily create ${tmpd}
38 Check to make sure that the directory does not already
39 exist and that you have sufficient permissions to create it.
41 mkdir returned $rc.
43 EOF
44 exit 1
47 # Determine the different refdes=?
49 list=`@AWK@ '/^refdes=[A-Z]+\?/ {
50 A=$1; gsub(/refdes=/,"",A)
51 gsub(/\?/,"",A)
52 print A}' $1 | sort | @AWK@ 'BEGIN {if (NR==1) {A=$1} }{if (A !=$1) print ; A=$1}' - `
55 if [ -z "$list" ]; then
56 echo "No new devices found!"
57 exit 0
58 fi
60 # make a copy of the current schematics
62 cp $1 $1.sauv
64 # Replace the ? by a number
65 sc=${tmpd}/sc.awk
67 for f in $list; do
68 # creation du script gawk 1
69 echo "BEGIN {R=0}" >${sc}
70 echo "/^refdes=$f[0-9]+/ {B=\$1" >>${sc}
71 echo "gsub(/refdes=[A-Z]+/,\"\",B)" >>${sc}
72 echo "if (B>R) {R=B}" >>${sc}
73 echo "}" >>${sc}
74 echo "END {printf(\"%d\",R)}" >>${sc}
75 # execution des scripts
77 IMAX=`@AWK@ -f ${sc} $1`
78 echo "Numbering of $f will start at $IMAX"
80 # creation du script gawk 2
82 echo "BEGIN {R=MAX} ">${sc}
83 echo "{if (match(\$1,/^refdes=$f\?/)!=0) {" >>${sc}
84 echo "R=R+1" >>${sc}
85 echo "sub(/\?/,R,\$1)" >>${sc}
86 echo "print \$1 } " >>${sc}
87 echo "else {print \$0}}">>${sc}
89 #echo "OK=1" >>${sc}
90 #echo "LL=NR}" >>${sc}
91 #echo "{" >>${sc}
92 #echo "if ((OK==1)&&(NR==LL+1)) {print \$1\" \"\$2\" \"\$3\" \"\$4\" \"\$5\" \"1\" \"\$7\" \"\$8 }" >>${sc}
93 #echo "if (NR==LL+2) {OK=0} " >>${sc}
94 #echo "if (OK==0) {print \$0} " >>${sc}
95 #echo "}" >>${sc}
97 #execute the second script
99 cat $1 | @AWK@ -v MAX=$IMAX -f ${sc} - > $1.tmp
100 mv $1.tmp $1
102 done
104 # clean !
106 rm -fr ${tmpd}