[Date Index][Thread Index]
[Date Prev][Date Next][Thread Prev][Thread Next]
Re: new flag? wml -U
- From: Denis Barbier <nospam@thanx>
- Date: Mon, 27 Aug 2001 15:45:16 +0200
On Mon, Aug 27, 2001 at 02:36:30PM +0200, Jan Holler wrote:
> Hi Denis
>
> On 27-Aug-01 Denis Barbier wrote:
> > On Thu, Aug 16, 2001 at 04:18:44PM +0200, Jan Holler wrote:
> >>
> >> I suggest to implement a flag -U to undefine previously with
> >> -D defined variables.
>
> >> <if <var-exists BAR>
> >> <set-var newbar=<get-var bar>> # or $(BAR) instead of <get-var bar>
> >> <set-var newbar=$(WML_SRC_BASENAME)>
> >> >
>
> > problem is that wml has then to distinguish between
> > -D foo=bar -U foo
> > and
> > -U foo -D foo=bar
> > which is not trivial.
>
> Regard the order: last flag wins over earlier flags from the
> left to the right (.wmlc -> top down). Would that still be
> complicated to implement in the "command-line"-parsing?
>
> > IMO it is always possible to unset a variable by making it empty,
> > and replace your test by <if <get-var BAR> ...
>
> Thanks. That would work around. But needs some
> extra effort (need to unset it in every file or make
> global changes in some include-file) and is IMHO not
> that flexible as the described '-U'. (speaking of
> global and hierarchical settings).
Agree, but there is indeed a problem, all flags are handled separatly.
This is quite common, I do not know any command-line parser which takes
care of flags' order, and the Perl module Getopt::Long do not derogate
to this rule.
So, we would have to parse command-line and .wmlrc twice, first time
with Getopt::Long, then with a single regex checker to determine -D/-U
order. I would prefer avoiding this solution.
Maybe we could adopt a convention, say -Dfoo=_undef to ask wml to
undefine this value (and also delete all previous declarations) before
passing it to every pass, a patch is attached, you may apply it against
wml_frontend/wml.src or your wml script.
--
Denis Barbier
WML Maintainer
Index: wml.src
===================================================================
RCS file: /home/barbier/Projets/Wml/cvs/wml/wml_frontend/wml.src,v
retrieving revision 1.74
diff -u -u -r1.74 wml.src
--- wml.src 2001/08/26 00:43:41 1.74
+++ wml.src 2001/08/27 13:28:42
@@ -543,6 +543,17 @@
push(@opt_o,$opts);
}
+# 7. Undefine variables when requested
+%new_opt_D = ();
+foreach $d (@opt_D) {
+ ($var, $val) = ($d =~ m|^(.+?)=(.*)$|);
+ if ($val eq '_undef') {
+ delete $new_opt_D{$var};
+ } else {
+ $new_opt_D{$var} = $val;
+ }
+}
+@opt_D = map { $_."=".$new_opt_D{$_} } keys %new_opt_D;
# fix the verbose level
if ($opt_v == 0) {