Debian Codegraph @

ReleaseTools/permute

raw symbols SCIP
1 #!/usr/bin/env bash
2
3 # Run through all possible configuration combinations
4 # permute [-n] [-s] [-v] [program...]
5 # -n Just display the combinations
6 # -s Just run the singles
7
8 # Needs to be run from the top of a source tree (where x3270, s3270, tcl3270
9 # and c3270 can be seen).
10
11 TD=${TD-/tmp}
12 ver=3.3
13 prog=${0##*/}
14
15 function usage()
16 {
17 echo >&2 "usage $prog [-n] [-s] [-v] [program...]"
18 exit 1
19 }
20
21 while (( $# > 0 ))
22 do case $1 in
23 -n) noop=1
24 shift
25 ;;
26 -s) singles=1
27 shift
28 ;;
29 -v) verbose=1
30 shift
31 ;;
32 -*) usage
33 ;;
34 *) break
35 esac
36 done
37
38 if [ $# -eq 0 ]
39 then progs="x3270 s3270 tcl3270 c3270 pr3287"
40 else progs="$@"
41 fi
42
43 # Run one iteration
44 # $prog program name
45 # $c configure options
46 #
47 # $TD temporary directory
48 # $noop if 1, display rather than run
49 function iterate()
50 {
51 typeset rc=0
52
53 if [ $noop ]
54 then echo $prog: $c
55 else ./configure --without-pr3287 $c >/dev/null 2>&1 || (echo "$prog configure --without-pr3287 $c failed"; exit 1)
56 make clean >/dev/null 2>&1
57 if mk >$TD/mk$$ 2>&1
58 then echo -n "."
59 else echo
60 echo "$prog failed: $c"
61 [ $verbose ] && cat $TD/mk$$
62 rc=1
63 fi
64 if grep 'warning:' $TD/mk$$
65 then echo "Warnings: $c"
66 fi
67 rm $TD/mk$$
68 fi
69 return $rc
70 }
71
72 # Compute the options for the given iteration.
73 # $1 iteration
74 #
75 # $n_opts number of possible options for this program
76 # $masks[] bit mask for each option
77 # $opts[] name of each option
78 # $nixpr --without-pr3287 option, if applicable
79 function config_opts()
80 {
81 typeset -i x=$1
82 typeset c=""
83 typeset -i j=0
84
85 while (( j < n_opts ))
86 do if (( x & ${masks[$j]} ))
87 then c="$c --${opts[$j]}"
88 fi
89 j=j+1
90 done
91 echo $c $nixpr
92 }
93
94 # Count the bits in $1.
95 # $1 integer to evaluate
96 function cob()
97 {
98 typeset -i n=$1 b=1 r=0
99 while (( $b <= $n ))
100 do if (( $n & $b ))
101 then r=r+1
102 fi
103 b=b*2
104 done
105 echo $r
106 }
107
108 for prog in $progs
109 do echo "Trying $prog."
110 rm -rf $TD/$prog-$ver/
111 p=$PWD
112 cd $prog
113 make -f Makefile.aux $prog-src.tgz
114 cd $TD/
115 tar -xzf ~-/$prog-src.tgz
116 cd $prog-$ver/
117 [ -f $p/$prog/.mk ] && cp $p/$prog/.mk .
118
119 typeset -i b=1
120 unset opts[@]
121 if [ $prog = x3270 -o $prog = c3270 ]
122 then nixpr=--without-pr3287
123 else unset nixpr
124 fi
125 typeset -a opts masks
126 typeset -i n_opts=0
127 for opt in disable-ansi disable-apl disable-local-process disable-printer disable-script disable-tn3270e disable-trace disable-menus disable-keypad disable-ft disable-ssl disable-dbcs with-iconv disable-ipv6
128 do unset ok
129 case $opt in
130 disable-dbcs|disable-ssl|with-iconv|disable-ipv6)
131 # apply to all
132 ok=1
133 ;;
134 disable-ansi|disable-apl|disable-local-process|disable-tn3270e|disable-trace|disable-ft)
135 # apply to all except pr3287
136 if [ $prog != pr3287 ]
137 then ok=1
138 fi
139 ;;
140 disable-printer|disable-menus)
141 # only apply to x3270 and c3270
142 if [ $prog = x3270 -o $prog = c3270 ]
143 then ok=1
144 fi
145 ;;
146 disable-script)
147 # required for s3270 and tcl3270
148 if [ $prog != s3270 -a $prog != tcl3270 -a $prog != pr3287 ]
149 then ok=1
150 fi
151 ;;
152 disable-keypad)
153 # apply only to x3270
154 if [ $prog = x3270 ]
155 then ok=1
156 fi
157 ;;
158 esac
159 if [ "$ok" ]
160 then opts[$n_opts]=$opt
161 masks[$n_opts]=$b
162 b=b*2
163 n_opts=n_opts+1
164 fi
165 done
166 echo "$prog: possible options are [${opts[@]}]: $b combinations"
167
168 # Loop through the singles.
169 typeset -i x=0
170 while (( x < b ))
171 do c=$(config_opts $x)
172 iterate || exit 1
173 if (( $x == 0 ))
174 then x=1
175 else x=x*2
176 fi
177 done
178
179 # Loop through everything else.
180 if [ ! "$singles" ]
181 then
182 typeset -i x=0
183 while (( x < b ))
184 do c=$(config_opts $x)
185 typeset nb=$(cob $x)
186 if (( nb > 1 ))
187 then iterate
188 fi
189 x=x+1
190 done
191 fi
192
193 echo
194
195 cd ..
196 rm -rf $prog-$ver/
197 cd $p
198 done