Changeset 2f01162


Ignore:
Timestamp:
Mar 29, 2009, 3:08:14 PM (12 years ago)
Author:
James M. Kretchmar <kretch@mit.edu>
Branches:
owl
Children:
a0bde15
Parents:
2ace81e
Message:
new classinstfilt that uses ^(un)*%s(\\.d) style matching
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • functions.c

    r01dcae5 r2f01162  
    24882488 * name of the filter, which the caller must free.
    24892489 */
    2490 char *owl_function_classinstfilt(char *class, char *instance)
     2490char *owl_function_classinstfilt(char *c, char *i)
    24912491{
    24922492  owl_list *fl;
     
    24942494  char *argbuff, *filtname;
    24952495  char *tmpclass, *tmpinstance = NULL;
    2496   int len;
     2496  char *class, *instance = NULL;
     2497
     2498  class = owl_util_baseclass(c);
     2499  if(i) {
     2500    instance = owl_util_baseclass(i);
     2501  }
    24972502
    24982503  fl=owl_global_get_filterlist(&g);
    24992504
    25002505  /* name for the filter */
    2501   len=strlen(class)+30;
    2502   if (instance) len+=strlen(instance);
    2503   filtname=owl_malloc(len);
    25042506  if (!instance) {
    2505     sprintf(filtname, "class-%s", class);
    2506   } else {
    2507     sprintf(filtname, "class-%s-instance-%s", class, instance);
     2507    filtname = owl_sprintf("class-%s", class);
     2508  } else {
     2509    filtname = owl_sprintf("class-%s-instance-%s", class, instance);
    25082510  }
    25092511  /* downcase it */
    2510   downstr(filtname);
     2512  {
     2513    char *temp = g_utf8_strdown(filtname, -1);
     2514    if (temp) {
     2515      owl_free(filtname);
     2516      filtname = temp;
     2517    }
     2518  }
    25112519  /* turn spaces, single quotes, and double quotes into dots */
    25122520  owl_text_tr(filtname, ' ', '.');
     
    25202528
    25212529  /* create the new filter */
    2522   argbuff=owl_malloc(len+20);
    25232530  tmpclass=owl_text_quote(class, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
    25242531  owl_text_tr(tmpclass, ' ', '.');
     
    25312538    owl_text_tr(tmpinstance, '"', '.');
    25322539  }
    2533   sprintf(argbuff, "( class ^%s$ )", tmpclass);
     2540
     2541  argbuff = owl_sprintf("class ^(un)*%s(\\.d)*$", tmpclass);
    25342542  if (tmpinstance) {
    2535     sprintf(argbuff, "%s and ( instance ^%s$ )", argbuff, tmpinstance);
     2543    char *tmp = argbuff;
     2544    argbuff = owl_sprintf("%s and ( instance ^(un)*%s(\\.d)*$ )", tmp, tmpinstance);
     2545    owl_free(tmp);
    25362546  }
    25372547  owl_free(tmpclass);
     
    25452555
    25462556  owl_free(argbuff);
     2557  owl_free(class);
     2558  if (instance) {
     2559    owl_free(instance);
     2560  }
    25472561  return(filtname);
    25482562}
  • util.c

    rfa00c5c r2f01162  
    765765}
    766766
     767/* Return the base class or instance from a zephyr class, by removing
     768   leading `un' or trailing `.d'.
     769   The caller is responsible for freeing the allocated string.
     770*/
     771char * owl_util_baseclass(char * class)
     772{
     773  char *start, *end;
     774
     775  start = class;
     776  while(!strncmp(start, "un", 2)) {
     777    start += 2;
     778  }
     779
     780  start = owl_strdup(start);
     781  end = start + strlen(start) - 1;
     782  while(end > start && *end == 'd' && *(end-1) == '.') {
     783    end -= 2;
     784  }
     785  *(end + 1) = 0;
     786
     787  return start;
     788}
     789
    767790/**************************************************************************/
    768791/************************* REGRESSION TESTS *******************************/
Note: See TracChangeset for help on using the changeset viewer.