Changeset 2f01162
- Timestamp:
- Mar 29, 2009, 3:08:14 PM (15 years ago)
- Branches:
- owl
- Children:
- a0bde15
- Parents:
- 2ace81e
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
functions.c
r01dcae5 r2f01162 2488 2488 * name of the filter, which the caller must free. 2489 2489 */ 2490 char *owl_function_classinstfilt(char *c lass, char *instance)2490 char *owl_function_classinstfilt(char *c, char *i) 2491 2491 { 2492 2492 owl_list *fl; … … 2494 2494 char *argbuff, *filtname; 2495 2495 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 } 2497 2502 2498 2503 fl=owl_global_get_filterlist(&g); 2499 2504 2500 2505 /* name for the filter */ 2501 len=strlen(class)+30;2502 if (instance) len+=strlen(instance);2503 filtname=owl_malloc(len);2504 2506 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); 2508 2510 } 2509 2511 /* 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 } 2511 2519 /* turn spaces, single quotes, and double quotes into dots */ 2512 2520 owl_text_tr(filtname, ' ', '.'); … … 2520 2528 2521 2529 /* create the new filter */ 2522 argbuff=owl_malloc(len+20);2523 2530 tmpclass=owl_text_quote(class, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); 2524 2531 owl_text_tr(tmpclass, ' ', '.'); … … 2531 2538 owl_text_tr(tmpinstance, '"', '.'); 2532 2539 } 2533 sprintf(argbuff, "( class ^%s$ )", tmpclass); 2540 2541 argbuff = owl_sprintf("class ^(un)*%s(\\.d)*$", tmpclass); 2534 2542 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); 2536 2546 } 2537 2547 owl_free(tmpclass); … … 2545 2555 2546 2556 owl_free(argbuff); 2557 owl_free(class); 2558 if (instance) { 2559 owl_free(instance); 2560 } 2547 2561 return(filtname); 2548 2562 } -
util.c
rfa00c5c r2f01162 765 765 } 766 766 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 */ 771 char * 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 767 790 /**************************************************************************/ 768 791 /************************* REGRESSION TESTS *******************************/
Note: See TracChangeset
for help on using the changeset viewer.