Re: select patch
Johannes Altmanninger <[email protected]> Thu, 19 Jun 2014 19:07:12 +0200
| Newsgroups | gmane.comp.window-managers.ratpoison.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi Jeff, Bernhard,
I rewrote find_window_name() trying to incorporate your suggestions:
The second argument to find_window_name() is a bitmask that defines the
match_type
By setting the cmplen beforehand I can fit everything in a single loop
Here is what I came up with (It compiled without warnings but I did not
test it)
What do you think, is something like this feasible?
(the case conversion looks a bit awkwark)
// MATCH means exact match
#define MATCH 0x0000
#define MATCH_PREFIX 0x0001
#define MATCH_IGNORECASE 0x0002
#define MATCH_PREFIX_IGNORECASE 0x0004
#define MAX_WINDOW_NAME_LENGTH 42
#include <ctype.h>
rp_window *
find_window_name (char *name, int match_type)
{
int cmplen, i;
if (MATCH_PREFIX & match_type)
cmplen = strnlen(name, MAX_WINDOW_NAME_LENGTH);
else
cmplen = MAX_WINDOW_NAME_LENGTH;
if(MATCH_IGNORECASE & match_type)
for(i=0; i<strlen(name); i++)
name[i] = toupper (name[i]);
rp_window_elem *cur;
char *curname;
list_for_each_entry (cur, &rp_current_group->mapped_windows, node)
{
curname = window_name(cur->win);
if(MATCH_IGNORECASE & match_type)
for(i=0; i<strlen(curname); i++)
curname[i] = toupper (curname[i]);
if (!strncmp (name, curname, cmplen))
{
return cur->win;
}
}
/* didn't find it */
return NULL;
}