diff --git a/lib/preprocess.c b/lib/preprocess.c index 0f541e0a6..faf2c029b 100644 --- a/lib/preprocess.c +++ b/lib/preprocess.c @@ -356,36 +356,43 @@ char *rm_pp_compile_patterns(RmSession *session, const char *sortcrit, GError ** static int rm_pp_cmp_by_regex(GRegex *regex, int idx, RmPatternBitmask *mask_a, const char *path_a, RmPatternBitmask *mask_b, const char *path_b) { - int result = 0; + int result_a = 0; + int result_b = 0; if(RM_PATTERN_IS_CACHED(mask_a, idx)) { /* Get the previous match result */ - result = RM_PATTERN_GET_CACHED(mask_a, idx); + result_a = RM_PATTERN_GET_CACHED(mask_a, idx); } else { /* Match for the first time */ - result = g_regex_match(regex, path_a, 0, NULL); - RM_PATTERN_SET_CACHED(mask_a, idx, result); - } - - if(result) { - return -1; + result_a = g_regex_match(regex, path_a, 0, NULL); + RM_PATTERN_SET_CACHED(mask_a, idx, result_a); } if(RM_PATTERN_IS_CACHED(mask_b, idx)) { /* Get the previous match result */ - result = RM_PATTERN_GET_CACHED(mask_b, idx); + result_b = RM_PATTERN_GET_CACHED(mask_b, idx); } else { /* Match for the first time */ - result = g_regex_match(regex, path_b, 0, NULL); - RM_PATTERN_SET_CACHED(mask_b, idx, result); + result_b = g_regex_match(regex, path_b, 0, NULL); + RM_PATTERN_SET_CACHED(mask_b, idx, result_b); } - if(result) { - return +1; + /* Both match */ + if(result_a && result_b) { + return 0; + } + /* Only a */ + else if (result_a) { + return -1; + } + /* Only b */ + else if (result_b) { + return 1; + } + /* Neither */ + else { + return 0; } - - /* Both match or none of the both match */ - return 0; } /*