missing NULL terminator in set_config_x
[geda-gaf.git] / gnetlist-legacy / scripts / annotate.sh.in
blob0d58cd91583f9281a4fcfcc0703eac9f82906bf5
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., 51 Franklin Street, Fifth Floor, Boston,
16 # MA 02111-1301, USA
18 #------------------------------------------------------------------
19 #--------------------------------JM Routoure-----------------------
20 #---------------------------------28/02/2000-----------------------
21 #------------------------------------------------------------------
23 if [ -z "$1" ]; then
24 echo "No sch file indicated"
25 echo "usage:"
26 echo "annotate file"
27 echo " file is generated by gschem"
28 exit 1
31 # create a secure temp directory
32 tmpd=${TMP:-/tmp}/annotate.$$
33 mkdir -m 0700 ${tmpd}
34 rc=$?
35 if test $rc -ne 0 ; then
36 cat << EOF
38 $0: ERROR -- failed to securily create ${tmpd}
39 Check to make sure that the directory does not already
40 exist and that you have sufficient permissions to create it.
42 mkdir returned $rc.
44 EOF
45 exit 1
48 # Determine the different refdes=?
50 list=`@AWK@ '/^refdes=[A-Z]+\?/ {
51 A=$1; gsub(/refdes=/,"",A)
52 gsub(/\?/,"",A)
53 print A}' $1 | sort | @AWK@ 'BEGIN {if (NR==1) {A=$1} }{if (A !=$1) print ; A=$1}' - `
56 if [ -z "$list" ]; then
57 echo "No new devices found!"
58 exit 0
61 # make a copy of the current schematics
63 cp $1 $1.sauv
65 # Replace the ? by a number
66 sc=${tmpd}/sc.awk
68 for f in $list; do
69 # creation du script gawk 1
70 echo "BEGIN {R=0}" >${sc}
71 echo "/^refdes=$f[0-9]+/ {B=\$1" >>${sc}
72 echo "gsub(/refdes=[A-Z]+/,\"\",B)" >>${sc}
73 echo "if (B>R) {R=B}" >>${sc}
74 echo "}" >>${sc}
75 echo "END {printf(\"%d\",R)}" >>${sc}
76 # execution des scripts
78 IMAX=`@AWK@ -f ${sc} $1`
79 echo "Numbering of $f will start at $IMAX"
81 # creation du script gawk 2
83 echo "BEGIN {R=MAX} ">${sc}
84 echo "{if (match(\$1,/^refdes=$f\?/)!=0) {" >>${sc}
85 echo "R=R+1" >>${sc}
86 echo "sub(/\?/,R,\$1)" >>${sc}
87 echo "print \$1 } " >>${sc}
88 echo "else {print \$0}}">>${sc}
90 #echo "OK=1" >>${sc}
91 #echo "LL=NR}" >>${sc}
92 #echo "{" >>${sc}
93 #echo "if ((OK==1)&&(NR==LL+1)) {print \$1\" \"\$2\" \"\$3\" \"\$4\" \"\$5\" \"1\" \"\$7\" \"\$8 }" >>${sc}
94 #echo "if (NR==LL+2) {OK=0} " >>${sc}
95 #echo "if (OK==0) {print \$0} " >>${sc}
96 #echo "}" >>${sc}
98 #execute the second script
100 cat $1 | @AWK@ -v MAX=$IMAX -f ${sc} - > $1.tmp
101 mv $1.tmp $1
103 done
105 # clean !
107 rm -fr ${tmpd}