Changeset 01dcae5
- Timestamp:
- Mar 29, 2009, 2:43:40 PM (16 years ago)
- Branches:
- owl
- Children:
- 395b32e
- Parents:
- 3674002
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
filter.c
rfa00c5c r01dcae5 476 476 } 477 477 478 void owl_filter_print(owl_filter *f, char *out)478 char *owl_filter_print(owl_filter *f) 479 479 { 480 480 int i, j; 481 481 owl_filterelement *fe; 482 char *tmp; 483 484 strcpy(out, owl_filter_get_name(f)); 485 strcat(out, ": "); 482 GString *out = g_string_new(""); 486 483 487 484 if (f->color!=OWL_COLOR_DEFAULT) { 488 strcat(out, "-c "); 489 strcat(out, owl_util_color_to_string(f->color)); 490 strcat(out, " "); 485 g_string_append(out, "-c "); 486 if (f->color < 8) { 487 g_string_append(out, owl_util_color_to_string(f->color)); 488 } else { 489 g_string_append_printf(out, "%i",f->color); 490 } 491 g_string_append(out, " "); 491 492 } 492 493 … … 494 495 for (i=0; i<j; i++) { 495 496 fe=owl_list_get_element(&(f->fes), i); 496 tmp=owl_filterelement_to_string(fe); 497 strcat(out, tmp); 498 owl_free(tmp); 499 } 500 strcat(out, "\n"); 497 g_string_append(out, owl_filterelement_to_string(fe)); 498 } 499 500 return g_string_free(out, 0); 501 501 } 502 502 … … 504 504 int owl_filter_equiv(owl_filter *a, owl_filter *b) 505 505 { 506 char buff[LINE], buff2[LINE]; 507 508 owl_filter_print(a, buff); 509 owl_filter_print(b, buff2); 510 511 if (!strcmp(buff, buff2)) return(1); 512 return(0); 506 char *buffa, *buffb; 507 int ret; 508 509 buffa = owl_filter_print(a); 510 buffb = owl_filter_print(b); 511 512 ret = !strcmp(buffa, buffb); 513 ret = ret && !strcmp(owl_filter_get_name(a), 514 owl_filter_get_name(b)); 515 516 owl_free(buffa); 517 owl_free(buffb); 518 519 return ret; 513 520 } 514 521 -
functions.c
r73d8a88 r01dcae5 1711 1711 } 1712 1712 1713 #define PABUFLEN 50001714 1713 void owl_function_printallvars() 1715 1714 { 1716 char buff[PABUFLEN], *pos, *name; 1715 char *name; 1716 char var[LINE]; 1717 1717 owl_list varnames; 1718 int i, numvarnames , rem;1719 1720 pos = buff; 1721 pos += sprintf(pos, "%-20s = %s\n", "VARIABLE", "VALUE");1722 pos += sprintf(pos, "%-20s %s\n", "--------", "-----");1718 int i, numvarnames; 1719 GString *str = g_string_new(""); 1720 1721 g_string_append_printf(str, "%-20s = %s\n", "VARIABLE", "VALUE"); 1722 g_string_append_printf(str, "%-20s %s\n", "--------", "-----"); 1723 1723 owl_variable_dict_get_names(owl_global_get_vardict(&g), &varnames); 1724 rem = (buff+PABUFLEN)-pos-1;1725 1724 numvarnames = owl_list_get_size(&varnames); 1726 1725 for (i=0; i<numvarnames; i++) { 1727 1726 name = owl_list_get_element(&varnames, i); 1728 1727 if (name && name[0]!='_') { 1729 rem = (buff+PABUFLEN)-pos-1; 1730 pos += snprintf(pos, rem, "\n%-20s = ", name); 1731 rem = (buff+PABUFLEN)-pos-1; 1732 owl_variable_get_tostring(owl_global_get_vardict(&g), name, pos, rem); 1733 pos = buff+strlen(buff); 1734 } 1735 } 1736 rem = (buff+PABUFLEN)-pos-1; 1737 snprintf(pos, rem, "\n"); 1728 g_string_append_printf(str, "\n%-20s = ", name); 1729 owl_variable_get_tostring(owl_global_get_vardict(&g), name, var, LINE); 1730 g_string_append(str, var); 1731 } 1732 } 1733 g_string_append(str, "\n"); 1738 1734 owl_variable_dict_namelist_free(&varnames); 1739 1740 owl_function_popless_text(buff); 1735 1736 owl_function_popless_text(str->str); 1737 g_string_free(str, TRUE); 1741 1738 } 1742 1739 … … 2445 2442 { 2446 2443 owl_filter *f; 2447 char buff[5000];2444 char *buff, *tmp; 2448 2445 2449 2446 f=owl_global_get_filter(&g, name); … … 2452 2449 return; 2453 2450 } 2454 owl_filter_print(f, buff); 2451 tmp = owl_filter_print(f); 2452 buff = owl_sprintf("%s: %s", owl_filter_get_name(f), tmp); 2455 2453 owl_function_popless_text(buff); 2454 owl_free(buff); 2455 owl_free(tmp); 2456 2456 } 2457 2457 … … 2461 2461 owl_list *fl; 2462 2462 char buff[5000]; 2463 char *tmp; 2463 2464 owl_fmtext fm; 2464 2465 int i, j; … … 2472 2473 for (i=0; i<j; i++) { 2473 2474 f=owl_list_get_element(fl, i); 2474 owl_filter_print(f, buff);2475 snprintf(buff, sizeof(buff), "[% 2d] ", i+1); 2475 2476 owl_fmtext_append_normal(&fm, buff); 2477 tmp = owl_filter_print(f); 2478 owl_fmtext_append_normal(&fm, tmp); 2479 owl_free(tmp); 2480 owl_fmtext_append_normal(&fm, "\n"); 2476 2481 } 2477 2482 owl_function_popless_fmtext(&fm); … … 2894 2899 void owl_function_zpunt(char *class, char *inst, char *recip, int direction) 2895 2900 { 2896 owl_filter *f; 2897 owl_list *fl; 2898 char *buff; 2901 char *puntexpr, *classexpr, *instexpr, *recipexpr; 2899 2902 char *quoted; 2900 int ret, i, j; 2901 2902 fl=owl_global_get_puntlist(&g); 2903 2904 /* first, create the filter */ 2905 f=malloc(sizeof(owl_filter)); 2906 buff=malloc(strlen(class)+strlen(inst)+strlen(recip)+100); 2907 strcpy(buff, "class"); 2903 2908 2904 if (!strcmp(class, "*")) { 2909 strcat(buff, ".*");2905 classexpr = owl_sprintf("class .*"); 2910 2906 } else { 2911 2907 quoted=owl_text_quote(class, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); … … 2913 2909 owl_text_tr(quoted, '\'', '.'); 2914 2910 owl_text_tr(quoted, '"', '.'); 2915 sprintf(buff, "%s ^%s$", buff, quoted);2911 classexpr = owl_sprintf("class ^(un)*%s(\\.d)*$", quoted); 2916 2912 owl_free(quoted); 2917 2913 } 2918 2914 if (!strcmp(inst, "*")) { 2919 strcat(buff," and instance .*");2915 instexpr = owl_sprintf(" and instance .*"); 2920 2916 } else { 2921 2917 quoted=owl_text_quote(inst, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); … … 2923 2919 owl_text_tr(quoted, '\'', '.'); 2924 2920 owl_text_tr(quoted, '"', '.'); 2925 sprintf(buff, "%s and instance ^%s$", buff, quoted);2921 instexpr = owl_sprintf(" and instance ^(un)*%s(\\.d)*$", quoted); 2926 2922 owl_free(quoted); 2927 2923 } 2928 if (strcmp(recip, "*")) { 2924 if (!strcmp(recip, "*")) { 2925 recipexpr = owl_sprintf(""); 2926 } else { 2929 2927 quoted=owl_text_quote(recip, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); 2930 2928 owl_text_tr(quoted, ' ', '.'); 2931 2929 owl_text_tr(quoted, '\'', '.'); 2932 2930 owl_text_tr(quoted, '"', '.'); 2933 sprintf(buff, "%s and recipient ^%s$", buff, quoted);2931 recipexpr = owl_sprintf(" and recipient ^%s$", quoted); 2934 2932 owl_free(quoted); 2935 2933 } 2936 2937 owl_function_debugmsg("About to filter %s", buff); 2938 ret=owl_filter_init_fromstring(f, "punt-filter", buff); 2939 owl_free(buff); 2934 2935 puntexpr = owl_sprintf("%s %s %s", classexpr, instexpr, recipexpr); 2936 owl_function_punt(puntexpr, direction); 2937 owl_free(puntexpr); 2938 owl_free(classexpr); 2939 owl_free(instexpr); 2940 owl_free(recipexpr); 2941 } 2942 2943 void owl_function_punt(char *filter, int direction) 2944 { 2945 owl_filter *f; 2946 owl_list *fl; 2947 int ret, i, j; 2948 fl=owl_global_get_puntlist(&g); 2949 2950 /* first, create the filter */ 2951 f=malloc(sizeof(owl_filter)); 2952 2953 owl_function_debugmsg("About to filter %s", filter); 2954 ret=owl_filter_init_fromstring(f, "punt-filter", filter); 2940 2955 if (ret) { 2941 2956 owl_function_error("Error creating filter for zpunt"); … … 2948 2963 for (i=0; i<j; i++) { 2949 2964 if (owl_filter_equiv(f, owl_list_get_element(fl, i))) { 2965 owl_function_debugmsg("found an equivalent punt filter"); 2950 2966 /* if we're punting, then just silently bow out on this duplicate */ 2951 2967 if (direction==0) { … … 2958 2974 owl_filter_free(owl_list_get_element(fl, i)); 2959 2975 owl_list_remove_element(fl, i); 2976 owl_filter_free(f); 2960 2977 return; 2961 2978 } … … 2963 2980 } 2964 2981 2982 owl_function_debugmsg("punting"); 2965 2983 /* If we're punting, add the filter to the global punt list */ 2966 2984 if (direction==0) {
Note: See TracChangeset
for help on using the changeset viewer.