Re: select patch

Johannes Altmanninger <[email protected]> Thu, 19 Jun 2014 19:52:14 +0200
Newsgroups gmane.comp.window-managers.ratpoison.devel
Message-ID <[email protected]>
Thanks for your feedback, I fixed most things, below is the current version

On 06/19/2014 07:25 PM, Jeff Abrahamson wrote:
>
> Can you use a function pointer for your compare function so that you 
> don't need to have the pre-processing block?
This sounds scary :-|
Well, let's see if i'll manage

#define MATCH                    0x0000
#define MATCH_PREFIX             0x0001
#define MATCH_IGNORECASE         0x0002

//not yet implemented
#define MATCH_BACKWARDS          0x0004

#define MATCH_PREFER_NOTSELECTED 0x0008

#define MAX_WINDOW_NAME_LENGTH   0x0fff

#include <ctype.h>

rp_window *
find_window_name_ (char *name, int match_type)
{
   int compare_length, i;
   if (MATCH_PREFIX & match_type)
     {
       compare_length = strlen(name);
     }
   else
     {
     compare_length = 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 = NULL;
   int current_win_number = 0;
   rp_window *w = current_window();
   if (w)
     current_win_number = w->number;

   int may_return = 1;
   if (MATCH_PREFER_NOTSELECTED & match_type)
       may_return = 0;

   rp_window *first_match = NULL;

   list_for_each_entry (cur, &rp_current_group->mapped_windows, node)
     {
       strcpy(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, compare_length))
         {
           if (may_return)
             {
               return cur->win;
             }
           else
             {
               if(cur->win->number == current_win_number)
                 may_return = 1;
               if(!first_match)
                 first_match = cur->win;
             }
         }
     }
   /* didn't find it */
   return NULL;
}