On 08 Aug 2001 00:27:18 +0700, Dmitry Yu. Bolkhovityanov wrote:
> 
>     I've made a patch which implements a simple "if-else" syntax.
> 
>     A new "Otherwise" command is introduced (wouldn't clash with possible
> future syntax enhancements, right?), which executes supplied command only if
> previous command was unsuccessful.  So the syntax is:
> 
> AddToFunc "Do-this-or-that"
> + "I" Next (SomeProggie) Close
> + "I" Otherwise SomeProggie
> 
> (this implements Dominik's example of "if some window exists, kill it,
> otherwise start it").
> 
>     Each command may return a True/False value, which defaults to "True".
> This logic is implemented in execute_complex_function(), which sets the
> "current return value" to True before calling a command.  There's no change
> in command calling conventions, since "return value of this command" and
> "return value of previous command" are global variables (sic!).  Changed are
> only conditional commands, which set return value to False when
> unsuccessful.  I also investigated if it would be possible to place these
> two vars into exec_func_args_type, but those structs aren't passed between
> *execute*function().
> 
>     Since return values are stored in global vars,
> execute_complex_function() saves previous state and restores it on exit.
> Unfortunately, it contained a number of returns, which had to be replaced
> with "goto END_OF_FUNCTION" (I wish C had Ada/Perl "break from a block"
> feature...).
> 
>     Of course, calling "Otherwise" outside a complex function is senseless.

Grr... :)

Before reading the mail I did my own patch that happens to be almost
equivalent to yours, except for minor things. Say, I used interface
functions instead of global variables (there is only one static variable).
Also in my intention, functions may return more than just "success" or
"failure". We may have in the future such "failure" codes like: "timeout",
"window mismatch", "timeout", "incorrect usage", and the Otherwise command
may have an optional parameter to distinguish between different failures.

In the future all CMD_* functions may return this value, that is "success"
in most of cases. Currently it is not needed to minimize changes.

I called the function Else, because I hoped to have If in the future (for
non-window conditions). But I have no objections to call it Otherwise.

In any way, this solution is more clean and extendible than the Dominik's
one and it does not change any existing syntax. So, if there are no
objections I will apply the merged patch implementing this new command.

And BTW, it has sense (not yet) to call this command outside of functions.

  Read myfile1 quiet
  Otherwise Read myfile2 quiet
  Otherwise Echo Error: No myfile1 or myfile2 found

Also, it should be noted that the return value is of the entire command,
not of the first or last sub-command, so the following always prints "No"
regardless of absence or presence of terminal windows:

  Next ("XTerm") None ("XTerm") Echo Yes
  Otherwise Echo No

The entire first command fails because either Next or None fails.

Regards,
Mikhael.
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [EMAIL PROTECTED]
To report problems, send mail to [EMAIL PROTECTED]

Reply via email to