| 944 | }; |
| 945 | |
| 946 | static int headerless_match_one_pattern(struct grep_pat *p, |
| 947 | const char *bol, const char *eol, |
| 948 | enum grep_context ctx, |
| 949 | regmatch_t *pmatch, int eflags) |
| 950 | { |
| 951 | int hit = 0; |
| 952 | const char *start = bol; |
| 953 | |
| 954 | if ((p->token != GREP_PATTERN) && |
| 955 | ((p->token == GREP_PATTERN_HEAD) != (ctx == GREP_CONTEXT_HEAD))) |
| 956 | return 0; |
| 957 | |
| 958 | again: |
| 959 | hit = patmatch(p, bol, eol, pmatch, eflags); |
| 960 | if (hit < 0) |
| 961 | hit = 0; |
| 962 | |
| 963 | if (hit && p->word_regexp) { |
| 964 | if ((pmatch[0].rm_so < 0) || |
| 965 | (eol - bol) < pmatch[0].rm_so || |
| 966 | (pmatch[0].rm_eo < 0) || |
| 967 | (eol - bol) < pmatch[0].rm_eo) |
| 968 | die("regexp returned nonsense"); |
| 969 | |
| 970 | /* Match beginning must be either beginning of the |
| 971 | * line, or at word boundary (i.e. the last char must |
| 972 | * not be a word char). Similarly, match end must be |
| 973 | * either end of the line, or at word boundary |
| 974 | * (i.e. the next char must not be a word char). |
| 975 | */ |
| 976 | if ( ((pmatch[0].rm_so == 0) || |
| 977 | !word_char(bol[pmatch[0].rm_so-1])) && |
| 978 | ((pmatch[0].rm_eo == (eol-bol)) || |
| 979 | !word_char(bol[pmatch[0].rm_eo])) ) |
| 980 | ; |
| 981 | else |
| 982 | hit = 0; |
| 983 | |
| 984 | /* Words consist of at least one character. */ |
| 985 | if (pmatch->rm_so == pmatch->rm_eo) |
| 986 | hit = 0; |
| 987 | |
| 988 | if (!hit && pmatch[0].rm_so + bol + 1 < eol) { |
| 989 | /* There could be more than one match on the |
| 990 | * line, and the first match might not be |
| 991 | * strict word match. But later ones could be! |
| 992 | * Forward to the next possible start, i.e. the |
| 993 | * next position following a non-word char. |
| 994 | */ |
| 995 | bol = pmatch[0].rm_so + bol + 1; |
| 996 | while (word_char(bol[-1]) && bol < eol) |
| 997 | bol++; |
| 998 | eflags |= REG_NOTBOL; |
| 999 | if (bol < eol) |
| 1000 | goto again; |
| 1001 | } |
| 1002 | } |
| 1003 | if (hit) { |
no test coverage detected