I'd like to rewrite the style code that handles simple switches. At the moment, we have a big chain of "if () ... else if () ..." statements which is ugly, inefficient and requires a lot of maintenance when things change.
What I'm aiming at is to put all the simple style switches that just toggle a single bit in a big, sorted list. The "Style" command would use bsearch to find the given style in that list and set or delete the corresponding bits. For example, the current code ... else if (StrEquals(token, "Sticky")) { found = True; SFSET_IS_STICKY(*ptmpstyle, 1); SMSET_IS_STICKY(*ptmpstyle, 1); SCSET_IS_STICKY(*ptmpstyle, 1); } else if (StrEquals(token, "Slippery")) { found = True; SFSET_IS_STICKY(*ptmpstyle, 0); SMSET_IS_STICKY(*ptmpstyle, 1); SCSET_IS_STICKY(*ptmpstyle, 1); } ... would become /* type declarations */ typedef struct { size_t byte_offset_from_start; unsigned char bit_mask_in_byte; } bit_address_t typedef struct { char *switch_name; bit_address_t flag_address; unsigned flag_value : 1; } style_switch_entry_t; typedef style_switch_entry_t *style_switch_table_t; /* the style switch table */ static style_switch_table_t style_switch_table[] = { ... { "Slippery", {<address of is_sticky bit in common_flags_type>}, 0 }, ... { "Sticky", {<address of is_sticky bit in common_flags_type>}, 1 }, ... } Only the few more complex styles need the "if...else if..." chain. The problem: given an address of a flags structure: common_flags_type *flags; and the name of a member, e.g. "is_sticky" or "s.is_size_fixed". How do we get the offset of the byte that holds the flag in the structure and the bit number in that byte? A solution that works at compile time is preferred, but it wouldn't be too bad to fill the table at run time. The solution must work on any hardware, regardless of the byte, word or dword order. One idea for a compile time solution: Write a small program that creates a structure "flags" of the given type and zeros it. Then it sets the given flag with flags.<flag_name> = 1; Finally, it searches for the byte that now has a bit set to 1, takes its offset from the start of the structure as byte_offset_from_start and its value as bit_mask_in_byte and generates a table entry in a file that implements the style switch list. But this solution is ugly and complicates the build process. I'm not very fond of files that are generated at build time. Instead, it would be better to have some macros or whatever that do the calculations at preprocessing time without the help of external programs. Ideas, please! Long term goal: Allow *all* style switch names in conditional commands without duplicating the code to parse their names, e.g. next (Style GrabFocus, Style NoBorder) foobar Bye Dominik ^_^ ^_^ -- Dominik Vogt, mail: [EMAIL PROTECTED], phone: 0721/91374-382 Schlund + Partner AG, Erbprinzenstr. 4-12, D-76133 Karlsruhe -- 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]