Changeset 1145
- Timestamp:
- 11/15/07 07:43:14 (1 year ago)
- Files:
-
- 1.8.3/branches/devel/hdrs/mypcre.h (modified) (3 diffs)
- 1.8.3/branches/devel/src/funlist.c (modified) (17 diffs)
- 1.8.3/branches/devel/src/parse.c (modified) (1 diff)
- 1.8.3/branches/devel/src/pcre.c (modified) (3 diffs)
- 1.8.3/branches/devel/src/wild.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
1.8.3/branches/devel/hdrs/mypcre.h
r1143 r1145 1 #ifndef _MYPCRE_H 2 #define _MYPCRE_H 3 1 4 /************************************************* 2 5 * Perl-Compatible Regular Expressions * … … 40 43 pcre.c for details. */ 41 44 45 46 #define PENN_MATCH_LIMIT 100000 47 struct pcre_extra; 48 void set_match_limit(struct pcre_extra *); 49 struct pcre_extra * default_match_limit(void); 50 42 51 #ifdef HAVE_PCRE 43 52 #include <pcre.h> 44 53 #else 45 54 46 #ifndef _PCRE_H47 #define _PCRE_H48 55 49 56 #define PCRE_MAJOR 6 … … 205 212 } /* extern "C" */ 206 213 #endif 214 #endif /* !HAVE_PCRE */ 207 215 #endif /* End of pcre.h */ 208 #endif /* !HAVE_PCRE */ 216 1.8.3/branches/devel/src/funlist.c
r1143 r1145 2675 2675 { 2676 2676 pcre *re; 2677 pcre_extra * study = NULL;2677 pcre_extra *extra, *study = NULL; 2678 2678 const char *errptr; 2679 2679 int subpatterns; … … 2747 2747 study = pcre_study(re, 0, &errptr); 2748 2748 if (errptr != NULL) { 2749 mush_free( (Malloc_t)re, "pcre");2749 mush_free(re, "pcre"); 2750 2750 safe_str(T("#-1 REGEXP ERROR: "), buff, bp); 2751 2751 safe_str(errptr, buff, bp); … … 2759 2759 } 2760 2760 2761 if (study) { 2762 extra = study; 2763 set_match_limit(extra); 2764 } else 2765 extra = default_match_limit(); 2766 2761 2767 search = 0; 2762 2768 /* Do all the searches and replaces we can */ 2763 2769 2764 2770 start = prebuf; 2765 subpatterns = pcre_exec(re, study, prebuf, prelen, 0, 0, offsets, 99);2771 subpatterns = pcre_exec(re, extra, prebuf, prelen, 0, 0, offsets, 99); 2766 2772 2767 2773 /* Match wasn't found... we're done */ 2768 2774 if (subpatterns < 0) { 2769 2775 safe_str(prebuf, postbuf, &postp); 2770 mush_free( (Malloc_t)re, "pcre");2776 mush_free(re, "pcre"); 2771 2777 free_ansi_string(orig); 2772 2778 if (study) 2773 mush_free( (Malloc_t)study, "pcre.extra");2779 mush_free(study, "pcre.extra"); 2774 2780 continue; 2775 2781 } … … 2805 2811 match_offset++; 2806 2812 } while (all && match_offset < prelen && 2807 (subpatterns = pcre_exec(re, study, prebuf, prelen,2813 (subpatterns = pcre_exec(re, extra, prebuf, prelen, 2808 2814 match_offset, 0, offsets, 99)) >= 0); 2809 2815 … … 2811 2817 *postp = '\0'; 2812 2818 2813 mush_free( (Malloc_t)re, "pcre");2819 mush_free(re, "pcre"); 2814 2820 if (study != NULL) 2815 mush_free( (Malloc_t)study, "pcre.extra");2821 mush_free(study, "pcre.extra"); 2816 2822 free_ansi_string(orig); 2817 2823 } … … 2849 2855 study = pcre_study(re, 0, &errptr); 2850 2856 if (errptr != NULL) { 2851 mush_free( (Malloc_t)re, "pcre");2857 mush_free(re, "pcre"); 2852 2858 safe_str(T("#-1 REGEXP ERROR: "), buff, bp); 2853 2859 safe_str(errptr, buff, bp); … … 2860 2866 add_check("pcre.extra"); 2861 2867 } 2868 if (study) { 2869 extra = study; 2870 set_match_limit(extra); 2871 } else 2872 extra = default_match_limit(); 2873 2862 2874 search = 0; 2863 2875 /* Do all the searches and replaces we can */ 2864 2876 do { 2865 2877 subpatterns = 2866 pcre_exec(re, study, orig->text, orig->len, search, 0, offsets, 99);2878 pcre_exec(re, extra, orig->text, orig->len, search, 0, offsets, 99); 2867 2879 if (subpatterns >= 0) { 2868 2880 /* We have a match */ … … 2901 2913 } 2902 2914 } while (subpatterns >= 0 && all); 2903 mush_free( (Malloc_t)re, "pcre");2915 mush_free(re, "pcre"); 2904 2916 if (study != NULL) 2905 mush_free( (Malloc_t)study, "pcre.extra");2917 mush_free(study, "pcre.extra"); 2906 2918 } 2907 2919 safe_ansi_string(orig, 0, orig->len, buff, bp); … … 2932 2944 char *qregs[NUMQ], *holder[NUMQ]; 2933 2945 pcre *re; 2946 pcre_extra *extra; 2934 2947 const char *errptr; 2935 2948 int erroffset; … … 2965 2978 } 2966 2979 add_check("pcre"); 2967 subpatterns = pcre_exec(re, NULL, txt, arglens[0], 0, 0, offsets, 99); 2980 extra = default_match_limit(); 2981 2982 subpatterns = pcre_exec(re, extra, txt, arglens[0], 0, 0, offsets, 99); 2968 2983 safe_integer(subpatterns >= 0, buff, bp); 2969 2984 … … 3050 3065 } 3051 3066 for (i = 0; i < nqregs; i++) { 3052 mush_free( (Malloc_t)holder[i], "regmatch");3053 } 3054 mush_free( (Malloc_t)re, "pcre");3067 mush_free(holder[i], "regmatch"); 3068 } 3069 mush_free(re, "pcre"); 3055 3070 free_ansi_string(as); 3056 3071 } … … 3074 3089 int erroffset; 3075 3090 int flags = 0; 3076 3091 bool free_study; 3077 3092 dbref it = match_thing(executor, args[0]); 3093 3078 3094 reharg.first = 0; 3079 3095 if (it == NOTHING || it == AMBIGUOUS) { … … 3110 3126 return; 3111 3127 } 3112 if (reharg.study) 3128 if (reharg.study) { 3113 3129 add_check("pcre.extra"); 3114 3130 free_study = true; 3131 set_match_limit(reharg.study); 3132 } else { 3133 free_study = false; 3134 reharg.study = default_match_limit(); 3135 } 3136 3115 3137 reharg.buff = buff; 3116 3138 reharg.bp = bp; … … 3118 3140 atr_iter_get(executor, it, args[1], 0, regrep_helper, (void *) &reharg); 3119 3141 mush_free(reharg.re, "pcre"); 3120 if ( reharg.study)3142 if (free_study) 3121 3143 mush_free(reharg.study, "pcre.extra"); 3122 3144 } … … 3154 3176 size_t rlen; 3155 3177 pcre *re; 3156 pcre_extra *study ;3178 pcre_extra *study, *extra; 3157 3179 const char *errptr; 3158 3180 int erroffset; … … 3195 3217 return; 3196 3218 } 3197 if (study) 3219 if (study) { 3198 3220 add_check("pcre.extra"); 3221 extra = study; 3222 set_match_limit(extra); 3223 } else 3224 extra = default_match_limit(); 3199 3225 3200 3226 do { 3201 3227 r = remove_markup(split_token(&s, sep), &rlen); 3202 if (pcre_exec(re, study, r, rlen - 1, 0, 0, offsets, 99) >= 0) {3228 if (pcre_exec(re, extra, r, rlen - 1, 0, 0, offsets, 99) >= 0) { 3203 3229 if (all && *bp != b) 3204 3230 safe_str(osep, buff, bp); … … 3209 3235 } while (s); 3210 3236 3211 mush_free( (Malloc_t)re, "pcre");3237 mush_free(re, "pcre"); 3212 3238 if (study) 3213 mush_free( (Malloc_t)study, "pcre.extra");3214 } 3239 mush_free(study, "pcre.extra"); 3240 } 1.8.3/branches/devel/src/parse.c
r1143 r1145 269 269 re = pcre_compile("^#-?\\d+(?::\\d+)?$", 0, &errptr, &erroffset, NULL); 270 270 val = remove_markup((const char *) str, &vlen); 271 return (pcre_exec(re, NULL, val, vlen - 1, 0, 0, NULL, 0) >= 0);271 return pcre_exec(re, NULL, val, vlen - 1, 0, 0, NULL, 0) >= 0; 272 272 } 273 273 1.8.3/branches/devel/src/pcre.c
r1143 r1145 45 45 * 'isblank' as a variable (reported to Philip Hazel for pcre 4.5) */ 46 46 47 #include <string.h> 47 48 #include "config.h" 49 #include "mypcre.h" 48 50 49 51 /* Only use if a system libpcre isn't present. */ … … 57 59 #include <stdio.h> 58 60 #include <stdlib.h> 59 #include <string.h>60 #include "mypcre.h"61 61 #include "confmagic.h" 62 62 #undef min … … 9226 9226 9227 9227 #endif /* !HAVE_PCRE */ 9228 9229 /** Return a default pcre_extra pointer pointing to a static region 9230 set up to use a fairly low match-limit setting. 9231 */ 9232 struct pcre_extra * 9233 default_match_limit(void) 9234 { 9235 static struct pcre_extra ex; 9236 memset(&ex, 0, sizeof ex); 9237 set_match_limit(&ex); 9238 return &ex; 9239 } 9240 9241 9242 /** Set a low match-limit setting in an existing pcre_extra struct. */ 9243 void 9244 set_match_limit(struct pcre_extra *ex) 9245 { 9246 if (!ex) 9247 return; 9248 ex->flags |= PCRE_EXTRA_MATCH_LIMIT; 9249 ex->match_limit = PENN_MATCH_LIMIT; 9250 } 9251 1.8.3/branches/devel/src/wild.c
r1143 r1145 516 516 { 517 517 pcre *re; 518 pcre_extra *extra; 518 519 size_t i; 519 520 const char *errptr; … … 538 539 add_check("pcre"); 539 540 d = remove_markup(val, &delenn); 541 extra = default_match_limit(); 540 542 /* 541 543 * Now we try to match the pattern. The relevant fields will 542 544 * automatically be filled in by this. 543 545 */ 544 if ((subpatterns = pcre_exec(re, NULL, d, delenn - 1, 0, 0, offsets, 99))546 if ((subpatterns = pcre_exec(re, extra, d, delenn - 1, 0, 0, offsets, 99)) 545 547 < 0) { 546 548 mush_free(re, "pcre"); … … 592 594 { 593 595 pcre *re; 596 pcre_extra *extra; 594 597 const char *sptr; 595 598 size_t slen; … … 616 619 add_check("pcre"); 617 620 sptr = remove_markup(d, &slen); 621 extra = default_match_limit(); 618 622 /* 619 623 * Now we try to match the pattern. The relevant fields will 620 624 * automatically be filled in by this. 621 625 */ 622 r = pcre_exec(re, NULL, sptr, slen - 1, 0, 0, offsets, 99);626 r = pcre_exec(re, extra, sptr, slen - 1, 0, 0, offsets, 99); 623 627 624 628 mush_free(re, "pcre"); … … 637 641 int len; 638 642 int offsets[99]; 643 pcre_extra *extra; 639 644 640 645 if (!re || !subj) … … 642 647 643 648 len = strlen(subj); 644 645 return pcre_exec(re, NULL, subj, len, 0, 0, offsets, 99) >= 0; 646 649 extra = default_match_limit(); 650 return pcre_exec(re, extra, subj, len, 0, 0, offsets, 99) >= 0; 647 651 } 648 652
