Re: FVWM: Bind functions to pan window frame

From: Dominik Vogt <dominik.vogt_at_gmx.de>
Date: Mon, 1 Apr 2002 23:52:29 +0200

On Mon, Apr 01, 2002 at 08:51:40PM +0200, Uwe Pross wrote:
> On Sun, Mar 31, 2002 at 02:35:40PM +0200, Dominik Vogt wrote:
> >
> > Rewrite the code that calls HandlePaging() in events.c. One could
> > write another command "EdgeCommand" that defines the command to
> > execute when the pointer hits the screen edge. Normally, this
> > would be something like
> >
> > EdgeCommand left Scroll -10 0
> > EdgeCommand right Scroll +10 0
> > EdgeCommand top Scroll 0 -10
> > EdgeCommand bottom Scroll 0 +10
> >
>
> I am going to implement such a command. My fvwm does already
> understand the EdgeCommand ;-)
>
> I have still a question. How is the parsing of fvwm commands usally
> done? My function void CMD_EdgeCommand(F_CMD_ARGS) gots a variable
> char * action which contains the arguments of the EdgeCommand call. I
> looked at some CMD_* functions. Some use functions like
> GetIntegerArguments(..) other do thier own parsing of the action
> string. I need just function which extracts/cuts the first token of
> the action string and converts it to lower cases:
>
> getFirstToken( action , border ) ;
> if ( !strcmp( "left" , border ) )
> strcpy( edgeCommandLeft , action ) ;
> ....
>
> Are there any suggestion how the parsing should be done? Maybe the
> function I need is already imlemented. I could write a short parsing
> function but if this would be done for every CMD_* it would be quite
> an overhead.

<Theory>
There is a whole .c file with such functions: libs/Parse.c. The
generic way is to use the GetNextToken function. This takes the
whole action as its first argument and returns the next unquoted
token and the rest of the string:

  rest_of_string = GetNextToken(input_string, &ret_token);

The token must be freed after use. Also, if not NULL is returned,
the token is guaranteed to contain at least one character.

The PeekToken funtion does roughly the same, but is faster and
does not allocate memory:

  token = PeekToken(input_string, &rest_of_string);

Only one token can be peeked at a time since it's located in a
static memory area in the library function.
</Theory>

Finally, there is the function ParseDirectionArgument() in
libs/gravity.c. It takes string as input, compares the first
token with the eight directions and returns one of the DIR_...
constants (see code for details). In this case, the code should
look somewhat like that:

------------------------------ snip --------------------------
  static char *edge_commands[4] = {NULL, NULL, NULL, NULL};
  direction_type dir;
  int i;

  dir = ParseDirectionArgument(action, &action, DIR_NONE);
  /* Note: although the integer value of the constants is the same
   * as the value 'i' is set to, don't rely on this. Might change
   * one day. */
  switch (dir)
  {
  case DIR_N:
          i = 0;
          break;
  case DIR_E:
          i = 1;
          break;
  case DIR_S:
          i = 2;
          break;
  case DIR_N:
          i = 3;
          break;
  default:
          /* missing or illegal direction ... */
          /* error message and exit */
          return;
  }
  if (edge_commands[i] != NULL)
  {
          free(edge_commands[i]);
  }
  edge_commands[i] = safestrdup(action);
------------------------------ snip --------------------------

BTW, if you send a patch ("diff -u" or "diff -c" preferred), don't
forget to provide entries for the ChangeLog (press ctrl-x 4 a in
(x)emacs to generate one), NEWS and AUTHORS files. A patch for
the man page would be nice too (otherwise I have to write one).

Bye

Dominik ^_^ ^_^

 --
Dominik Vogt, dominik.vogt_at_gmx.de
Reply-To: dominik.vogt_at_gmx.de
--
Visit the official FVWM web page at <URL: http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
message to majordomo_at_fvwm.org.
To report problems, send mail to fvwm-owner_at_fvwm.org.
Received on Mon Apr 01 2002 - 15:49:59 BST

This archive was generated by hypermail 2.3.0 : Mon Aug 29 2016 - 19:37:52 BST