pattern.c (2235c7feac959bcc9ddfd6a2bc6be32102b1f84c) | pattern.c (95270f73baf6fa95ae529bc2eb6a61f5c79f32c0) |
---|---|
1/* | 1/* |
2 * Copyright (C) 1984-2021 Mark Nudelman | 2 * Copyright (C) 1984-2022 Mark Nudelman |
3 * 4 * You may distribute under the terms of either the GNU General Public 5 * License or the Less License, as specified in the README file. 6 * 7 * For more information, see the README file. 8 */ 9 10/* 11 * Routines to do pattern matching. 12 */ 13 14#include "less.h" 15 16extern int caseless; | 3 * 4 * You may distribute under the terms of either the GNU General Public 5 * License or the Less License, as specified in the README file. 6 * 7 * For more information, see the README file. 8 */ 9 10/* 11 * Routines to do pattern matching. 12 */ 13 14#include "less.h" 15 16extern int caseless; |
17extern int is_caseless; |
|
17extern int utf_mode; 18 19/* 20 * Compile a search pattern, for future use by match_pattern. 21 */ 22 static int 23compile_pattern2(pattern, search_type, comp_pattern, show_error) 24 char *pattern; --- 19 unchanged lines hidden (view full) --- 44 { 45 regfree(*comp_pattern); 46 free(*comp_pattern); 47 } 48 *comp_pattern = comp; 49#endif 50#if HAVE_POSIX_REGCOMP 51 regex_t *comp = (regex_t *) ecalloc(1, sizeof(regex_t)); | 18extern int utf_mode; 19 20/* 21 * Compile a search pattern, for future use by match_pattern. 22 */ 23 static int 24compile_pattern2(pattern, search_type, comp_pattern, show_error) 25 char *pattern; --- 19 unchanged lines hidden (view full) --- 45 { 46 regfree(*comp_pattern); 47 free(*comp_pattern); 48 } 49 *comp_pattern = comp; 50#endif 51#if HAVE_POSIX_REGCOMP 52 regex_t *comp = (regex_t *) ecalloc(1, sizeof(regex_t)); |
52 if (regcomp(comp, pattern, REGCOMP_FLAG)) | 53 if (regcomp(comp, pattern, REGCOMP_FLAG | (is_caseless ? REG_ICASE : 0))) |
53 { 54 free(comp); 55 if (show_error) 56 error("Invalid pattern", NULL_PARG); 57 return (-1); 58 } 59 if (*comp_pattern != NULL) 60 { 61 regfree(*comp_pattern); 62 free(*comp_pattern); 63 } 64 *comp_pattern = comp; 65#endif 66#if HAVE_PCRE 67 constant char *errstring; 68 int erroffset; 69 PARG parg; 70 pcre *comp = pcre_compile(pattern, | 54 { 55 free(comp); 56 if (show_error) 57 error("Invalid pattern", NULL_PARG); 58 return (-1); 59 } 60 if (*comp_pattern != NULL) 61 { 62 regfree(*comp_pattern); 63 free(*comp_pattern); 64 } 65 *comp_pattern = comp; 66#endif 67#if HAVE_PCRE 68 constant char *errstring; 69 int erroffset; 70 PARG parg; 71 pcre *comp = pcre_compile(pattern, |
71 (utf_mode) ? PCRE_UTF8 | PCRE_NO_UTF8_CHECK : 0, | 72 ((utf_mode) ? PCRE_UTF8 | PCRE_NO_UTF8_CHECK : 0) | 73 (is_caseless ? PCRE_CASELESS : 0), |
72 &errstring, &erroffset, NULL); 73 if (comp == NULL) 74 { 75 parg.p_string = (char *) errstring; 76 if (show_error) 77 error("%s", &parg); 78 return (-1); 79 } 80 *comp_pattern = comp; 81#endif 82#if HAVE_PCRE2 83 int errcode; 84 PCRE2_SIZE erroffset; 85 PARG parg; 86 pcre2_code *comp = pcre2_compile((PCRE2_SPTR)pattern, strlen(pattern), | 74 &errstring, &erroffset, NULL); 75 if (comp == NULL) 76 { 77 parg.p_string = (char *) errstring; 78 if (show_error) 79 error("%s", &parg); 80 return (-1); 81 } 82 *comp_pattern = comp; 83#endif 84#if HAVE_PCRE2 85 int errcode; 86 PCRE2_SIZE erroffset; 87 PARG parg; 88 pcre2_code *comp = pcre2_compile((PCRE2_SPTR)pattern, strlen(pattern), |
87 0, &errcode, &erroffset, NULL); | 89 (is_caseless ? PCRE2_CASELESS : 0), 90 &errcode, &erroffset, NULL); |
88 if (comp == NULL) 89 { 90 if (show_error) 91 { 92 char msg[160]; 93 pcre2_get_error_message(errcode, (PCRE2_UCHAR*)msg, sizeof(msg)); 94 parg.p_string = msg; 95 error("%s", &parg); --- 53 unchanged lines hidden (view full) --- 149 char *pattern; 150 int search_type; 151 int show_error; 152 PATTERN_TYPE *comp_pattern; 153{ 154 char *cvt_pattern; 155 int result; 156 | 91 if (comp == NULL) 92 { 93 if (show_error) 94 { 95 char msg[160]; 96 pcre2_get_error_message(errcode, (PCRE2_UCHAR*)msg, sizeof(msg)); 97 parg.p_string = msg; 98 error("%s", &parg); --- 53 unchanged lines hidden (view full) --- 152 char *pattern; 153 int search_type; 154 int show_error; 155 PATTERN_TYPE *comp_pattern; 156{ 157 char *cvt_pattern; 158 int result; 159 |
157 if (caseless != OPT_ONPLUS) | 160 if (caseless != OPT_ONPLUS || re_handles_caseless) |
158 cvt_pattern = pattern; 159 else 160 { 161 cvt_pattern = (char*) ecalloc(1, cvt_length(strlen(pattern), CVT_TO_LC)); 162 cvt_text(cvt_pattern, pattern, (int *)NULL, (int *)NULL, CVT_TO_LC); 163 } 164 result = compile_pattern2(cvt_pattern, search_type, comp_pattern, show_error); 165 if (cvt_pattern != pattern) --- 301 unchanged lines hidden --- | 161 cvt_pattern = pattern; 162 else 163 { 164 cvt_pattern = (char*) ecalloc(1, cvt_length(strlen(pattern), CVT_TO_LC)); 165 cvt_text(cvt_pattern, pattern, (int *)NULL, (int *)NULL, CVT_TO_LC); 166 } 167 result = compile_pattern2(cvt_pattern, search_type, comp_pattern, show_error); 168 if (cvt_pattern != pattern) --- 301 unchanged lines hidden --- |