Commit | Line | Data |
---|---|---|
959f3c4c JH |
1 | ?RCS: $Id: Options.U,v 3.0.1.7 1997/02/28 15:08:15 ram Exp $ |
2 | ?RCS: | |
3 | ?RCS: Copyright (c) 1991-1993, Raphael Manfredi | |
4 | ?RCS: | |
5 | ?RCS: You may redistribute only under the terms of the Artistic Licence, | |
6 | ?RCS: as specified in the README file that comes with the distribution. | |
7 | ?RCS: You may reuse parts of this distribution only within the terms of | |
8 | ?RCS: that same Artistic Licence; a copy of which may be found at the root | |
9 | ?RCS: of the source tree for dist 3.0. | |
10 | ?RCS: | |
11 | ?RCS: $Log: Options.U,v $ | |
12 | ?RCS: Revision 3.0.1.7 1997/02/28 15:08:15 ram | |
13 | ?RCS: patch61: optdef.sh now starts with a "startsh" | |
14 | ?RCS: patch61: moved some code from Head.U | |
15 | ?RCS: | |
16 | ?RCS: Revision 3.0.1.6 1995/09/25 09:14:46 ram | |
17 | ?RCS: patch59: protected option parsing code against 'echo -*' option failure | |
18 | ?RCS: | |
19 | ?RCS: Revision 3.0.1.5 1995/05/12 12:04:52 ram | |
20 | ?RCS: patch54: added -K option for experts | |
21 | ?RCS: | |
22 | ?RCS: Revision 3.0.1.4 1995/01/30 14:27:52 ram | |
23 | ?RCS: patch49: this unit now exports file optdef.sh, not a variable | |
24 | ?RCS: | |
25 | ?RCS: Revision 3.0.1.3 1995/01/11 15:19:00 ram | |
26 | ?RCS: patch45: new -O option allowing -D and -U to override config.sh setttings | |
27 | ?RCS: patch45: file optdef.sh is no longer removed after sourcing | |
28 | ?RCS: | |
29 | ?RCS: Revision 3.0.1.2 1994/10/29 15:58:06 ram | |
30 | ?RCS: patch36: ensure option definition file is removed before appending | |
31 | ?RCS: patch36: protect variable definitions with spaces in them | |
32 | ?RCS: | |
33 | ?RCS: Revision 3.0.1.1 1994/06/20 06:55:44 ram | |
34 | ?RCS: patch30: now uses new me symbol to tag error messages | |
35 | ?RCS: patch30: new -D and -U options to define/undef symbols (JHI) | |
36 | ?RCS: | |
37 | ?RCS: Revision 3.0 1993/08/18 12:05:14 ram | |
38 | ?RCS: Baseline for dist 3.0 netwide release. | |
39 | ?RCS: | |
40 | ?X: | |
41 | ?X: Command line parsing. It is really important that the variables used here | |
42 | ?X: be not listed in the MAKE line, or they will be saved in config.sh and | |
43 | ?X: loading this file to fetch default answers would clobber the values set | |
44 | ?X: herein. | |
45 | ?X: | |
46 | ?MAKE:Options: startsh | |
47 | ?MAKE: -pick wipe $@ %< | |
48 | ?V:reuseval alldone error realsilent silent extractsh fastread \ | |
49 | override knowitall: config_sh | |
50 | ?T:arg symbol | |
51 | ?F:./optdef.sh | |
52 | : produce awk script to parse command line options | |
53 | cat >options.awk <<'EOF' | |
54 | BEGIN { | |
55 | optstr = "dD:eEf:hKOrsSU:V"; # getopt-style specification | |
56 | ||
57 | len = length(optstr); | |
58 | for (i = 1; i <= len; i++) { | |
59 | c = substr(optstr, i, 1); | |
60 | ?X: some older awk's do not have the C ?: construct | |
61 | if (i < len) a = substr(optstr, i + 1, 1); else a = ""; | |
62 | if (a == ":") { | |
63 | arg[c] = 1; | |
64 | i++; | |
65 | } | |
66 | opt[c] = 1; | |
67 | } | |
68 | } | |
69 | { | |
70 | expect = 0; | |
71 | str = $0; | |
72 | if (substr(str, 1, 1) != "-") { | |
73 | printf("'%s'\n", str); | |
74 | next; | |
75 | } | |
76 | len = length($0); | |
77 | for (i = 2; i <= len; i++) { | |
78 | c = substr(str, i, 1); | |
79 | if (!opt[c]) { | |
80 | printf("-%s\n", substr(str, i)); | |
81 | next; | |
82 | } | |
83 | printf("-%s\n", c); | |
84 | if (arg[c]) { | |
85 | if (i < len) | |
86 | printf("'%s'\n", substr(str, i + 1)); | |
87 | else | |
88 | expect = 1; | |
89 | next; | |
90 | } | |
91 | } | |
92 | } | |
93 | END { | |
94 | if (expect) | |
95 | print "?"; | |
96 | } | |
97 | EOF | |
98 | ||
99 | : process the command line options | |
100 | ?X: Use "$@" to keep arguments with spaces in them from being split apart. | |
101 | ?X: For the same reason, awk will output quoted arguments and the final eval | |
102 | ?X: removes them and sets a proper $* array. An 'X' is prependend to each | |
103 | ?X: argument before being fed to echo to guard against 'echo -x', where -x | |
104 | ?X: would be understood as an echo option! It is removed before feeding awk. | |
105 | set X `for arg in "$@"; do echo "X$arg"; done | | |
106 | sed -e s/X// | awk -f options.awk` | |
107 | eval "set $*" | |
108 | shift | |
109 | rm -f options.awk | |
110 | ||
111 | : set up default values | |
112 | fastread='' | |
113 | reuseval=false | |
114 | config_sh='' | |
115 | alldone='' | |
116 | error='' | |
117 | silent='' | |
118 | extractsh='' | |
119 | override='' | |
120 | knowitall='' | |
121 | rm -f optdef.sh | |
122 | cat >optdef.sh <<EOS | |
123 | $startsh | |
124 | EOS | |
125 | ||
126 | ?X: | |
127 | ?X: Given that we now have the possibility to execute Configure remotely | |
128 | ?X: thanks to the new src.U support, we have to face the possibility | |
129 | ?X: of having to ask where the source lie, which means we need the Myread.U | |
130 | ?X: stuff and possibly other things that might echo something on the | |
131 | ?X: screen... | |
132 | ?X: | |
133 | ?X: That's not pretty, and might be confusing in 99% of the time. So... | |
134 | ?X: We introduce a new realsilent variable which is set when -s is given, | |
135 | ?X: and we force silent=true if -S is supplied. The Extractall.U unit | |
136 | ?X: will then undo the >&4 redirection based on the value of the | |
137 | ?X: realsilent variable... -- RAM, 18/93/96 | |
138 | ?X: | |
139 | ||
140 | : option parsing | |
141 | while test $# -gt 0; do | |
142 | case "$1" in | |
143 | -d) shift; fastread=yes;; | |
144 | -e) shift; alldone=cont;; | |
145 | -f) | |
146 | shift | |
147 | cd .. | |
148 | if test -r "$1"; then | |
149 | config_sh="$1" | |
150 | else | |
151 | echo "$me: cannot read config file $1." >&2 | |
152 | error=true | |
153 | fi | |
154 | cd UU | |
155 | shift;; | |
156 | -h) shift; error=true;; | |
157 | -r) shift; reuseval=true;; | |
158 | -s) shift; silent=true; realsilent=true;; | |
159 | -E) shift; alldone=exit;; | |
160 | -K) shift; knowitall=true;; | |
161 | -O) shift; override=true;; | |
162 | -S) shift; silent=true; extractsh=true;; | |
163 | -D) | |
164 | shift | |
165 | case "$1" in | |
166 | *=) | |
167 | echo "$me: use '-U symbol=', not '-D symbol='." >&2 | |
168 | echo "$me: ignoring -D $1" >&2 | |
169 | ;; | |
170 | *=*) echo "$1" | \ | |
171 | sed -e "s/'/'\"'\"'/g" -e "s/=\(.*\)/='\1'/" >> optdef.sh;; | |
172 | *) echo "$1='define'" >> optdef.sh;; | |
173 | esac | |
174 | shift | |
175 | ;; | |
176 | -U) | |
177 | shift | |
178 | case "$1" in | |
179 | *=) echo "$1" >> optdef.sh;; | |
180 | *=*) | |
181 | echo "$me: use '-D symbol=val', not '-U symbol=val'." >&2 | |
182 | echo "$me: ignoring -U $1" >&2 | |
183 | ;; | |
184 | *) echo "$1='undef'" >> optdef.sh;; | |
185 | esac | |
186 | shift | |
187 | ;; | |
188 | -V) echo "$me generated by metaconfig <VERSION> PL<PATCHLEVEL>." >&2 | |
189 | exit 0;; | |
190 | --) break;; | |
191 | -*) echo "$me: unknown option $1" >&2; shift; error=true;; | |
192 | *) break;; | |
193 | esac | |
194 | done | |
195 | ||
196 | case "$error" in | |
197 | true) | |
198 | cat >&2 <<EOM | |
199 | Usage: $me [-dehrsEKOSV] [-f config.sh] [-D symbol] [-D symbol=value] | |
200 | [-U symbol] [-U symbol=] | |
201 | -d : use defaults for all answers. | |
202 | -e : go on without questioning past the production of config.sh. | |
203 | -f : specify an alternate default configuration file. | |
204 | -h : print this help message and exit (with an error status). | |
205 | -r : reuse C symbols value if possible (skips costly nm extraction). | |
206 | -s : silent mode, only echoes questions and essential information. | |
207 | -D : define symbol to have some value: | |
208 | -D symbol symbol gets the value 'define' | |
209 | -D symbol=value symbol gets the value 'value' | |
210 | -E : stop at the end of questions, after having produced config.sh. | |
211 | -K : do not use unless you know what you are doing. | |
212 | -O : let -D and -U override definitions from loaded configuration file. | |
213 | -S : perform variable substitutions on all .SH files (can mix with -f) | |
214 | -U : undefine symbol: | |
215 | -U symbol symbol gets the value 'undef' | |
216 | -U symbol= symbol gets completely empty | |
217 | -V : print version number and exit (with a zero status). | |
218 | EOM | |
219 | exit 1 | |
220 | ;; | |
221 | esac | |
222 | ||
223 | ?X: | |
224 | ?X: Unless they specified both -d and -e/E, make sure we're running | |
225 | ?X: interactively, i.e. attached to a terminal. Moved from Head.U to be able | |
226 | ?X: to handle batch configurations... | |
227 | ?X: | |
228 | ?X: We have to hardwire the Configure name and cannot use $me, since if they | |
229 | ?X: said 'sh <Configure', then $me is 'sh'... | |
230 | ?X: | |
231 | : Sanity checks | |
232 | case "$fastread$alldone" in | |
233 | yescont|yesexit) ;; | |
234 | *) | |
235 | if test ! -t 0; then | |
236 | echo "Say 'sh Configure', not 'sh <Configure'" | |
237 | exit 1 | |
238 | fi | |
239 | ;; | |
240 | esac | |
241 | ||
242 | ?X: In silent mode, the standard output is closed. Questions are asked by | |
243 | ?X: outputing on file descriptor #4, which is the original stdout descriptor. | |
244 | ?X: This filters out all the "junk", since all the needed information is written | |
245 | ?X: on #4. Note that ksh will not let us redirect output if the file descriptor | |
246 | ?X: has not be defined yet, unlike sh, hence the following line...--RAM. | |
247 | exec 4>&1 | |
248 | case "$silent" in | |
249 | true) exec 1>/dev/null;; | |
250 | esac | |
251 | ||
252 | : run the defines and the undefines, if any, but leave the file out there... | |
253 | touch optdef.sh | |
254 | . ./optdef.sh | |
255 |