Subject: Style StrEquals/bsearch problem

From: Dave Trollope <[email-masked]>
Date: Wed, 28 Aug 2002 23:07:29 -0500

Hi Domonik

I was returning to the discussion we had at the start of the month where 
you wanted to replace the if/else chain with a bsearch. We had a 
detailed discussion about changing the data structures etc and I see you 
have modified the macros along some of the lines we discussed, but the 
bsearch problem hasn't been implemented yet and I had another perhaps 
simpler idea.

Instead of trying to get the bitfield address of the field(s) to change 
and storing that in a bsearchable array, perhaps a simpler solution 
would be this - and this is flexible to complex styles as well as simple 
styles.

For each style, create a simple static function to set the data 
appropriately, then in the array of names, use a function pointer. E.G.

Instead of:

if(StrEquals(token,"Sticky))
{ S_SET_STICKY(MCF(...),on)
   S_SET_STICKY(MCM...,1)
   S_SET ....
}else if(StrEquals.....

You could do this:

static void f_Set_Sticky(int on) {
   S_SET_STICKY(MCF(...),on)
   S_SET_STICKY(MCM...),1)
   S_SET ....
}

struct setstyle { char *name; void (*func)(int on); } = {
..... { "Sticky", f_Set_Sticky }, ...
}

ss = bsearch(setstyle,token)
if(ss) ss->func(on)
else { /* do other style checking */ }

This retains the whole data model, and avoids the whole bit mask address 
problem while also being flexible to more complex processing for some 
styles. This does create a lot of functions, but if they are static, 
they should be minimum overhead.

What do you think?

Cheers
Dave

-- 
Dave, Diane & Kringle
http://www.geocities.com/SiliconValley/7499

--
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-masked].
To report problems, send mail to [email-masked]